/* Madushan's Rating List - CCRL-style theme */

:root {
  color-scheme: light;
  --page: #e2f2eb;          /* CCRL mint page */
  --surface: #ffffff;
  --surface-2: #f2f7f4;
  --stripe: #cfdbee;        /* CCRL even row */
  --th: #789af0;            /* CCRL table header */
  --th-text: #ffffff;
  --tborder: #8bbede;       /* CCRL table border */
  --h2-bg: #9bc4e1;         /* CCRL section bar */
  --h2-border: #1d72ad;
  --h2-text: #115585;
  --title: #1b7a3a;         /* CCRL title green */
  --date: #d03337;          /* CCRL date red */
  --contents: #127bb8;
  --link: #0000ee;
  --active-bg: #f6f28e;     /* CCRL current-page box */
  --active-border: #000000;
  --text: #000000;
  --text-2: #333333;
  --muted: #808080;
  --grid: #8bbede;
  --axis: #1d72ad;
  --border: #8bbede;
  --accent: #1d72ad;
  --accent-ink: #115585;
  --pos: #3f6fd8;           /* win / stronger */
  --neg: #d03337;           /* loss / weaker  */
  --mid: #bebebe;           /* draw / even    */
  --cell: #dfdfdf;          /* CCRL crosstable cell */
  --cell-head: #bebebe;
  --los: #89ca89;           /* CCRL LOS green */
  --own: #ed6513;           /* CCRL "open source" orange */
  --good: #009000;          /* CCRL "free" green */
  --font: Arial, Helvetica, sans-serif;
  --font-head: Verdana, Helvetica, Arial, sans-serif;
}

/* Dark mode is opt-in via the toggle (CCRL itself is light only) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1c17;
  --surface: #17211d;
  --surface-2: #1d2924;
  --stripe: #1f2b3d;
  --th: #3e5cae;
  --th-text: #ffffff;
  --tborder: #2f4f6a;
  --h2-bg: #1f3b52;
  --h2-border: #2f6fa3;
  --h2-text: #d3e6f7;
  --title: #4cc172;
  --date: #ff6b6e;
  --contents: #6db8e6;
  --link: #8fb3ff;
  --active-bg: #5b5820;
  --active-border: #c9c48a;
  --text: #f0f0f0;
  --text-2: #cfd6d2;
  --muted: #95a39c;
  --grid: #2f4f6a;
  --axis: #4f86b8;
  --border: #2f4f6a;
  --accent: #5b9bd5;
  --accent-ink: #a9cdf0;
  --pos: #5b8ff0;
  --neg: #ef5b5e;
  --mid: #5a5a5a;
  --cell: #262d2a;
  --cell-head: #33403a;
  --los: #3f8f4a;
  --own: #ff8a45;
  --good: #3fc23f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-family: var(--font-head); font-size: 28px; font-weight: 700; color: var(--title); }
h2 { font-family: var(--font-head); font-size: 18px; font-weight: normal; }
h3 { font-size: 16px; font-weight: bold; }
p { margin: 0 0 12px; }
code { font-size: 13px; background: var(--surface); border: 1px solid var(--border); padding: 0 4px; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.site-header {
  background: var(--page);
  border-bottom: 2px solid var(--h2-border);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; gap: 20px; min-height: 68px; flex-wrap: nowrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; color: var(--title); flex: none; }
.brand-title { display: block; font-family: var(--font-head); font-weight: 700; font-size: 20px; color: var(--title); }
.brand-sub { display: block; font-size: 13px; color: var(--muted); }
.main-nav { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.main-nav a {
  color: var(--link); padding: 4px 10px; font-size: 16px; border: 1px solid transparent;
}
.main-nav a.active { background: var(--active-bg); color: var(--text); border-color: var(--active-border); }
.main-nav a.active:hover { text-decoration: none; }
.main-nav .tc { color: var(--muted); margin-left: 4px; font-size: 14px; }
.main-nav a.active .tc { color: var(--text-2); }
.theme-btn {
  border: 1px solid var(--tborder); background: var(--surface); color: var(--h2-text);
  width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center;
}
.theme-btn:hover { background: var(--h2-bg); }

@media (max-width: 960px) { .brand-sub { display: none; } .header-inner { gap: 12px; } }
@media (max-width: 720px) {
  .header-inner { gap: 8px; padding: 10px 0; }
  .header-inner { flex-wrap: wrap; }
  .main-nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; flex-wrap: nowrap; }
  .main-nav a { white-space: nowrap; }
  .theme-btn { margin-left: auto; }
  .brand-sub { display: none; }
}

/* ---------- page heading ---------- */
.page-head { padding: 24px 0 16px; display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; }
.page-head h1 .dim { color: var(--muted); font-weight: normal; }
.page-head .lede { color: var(--text-2); margin: 6px 0 0; max-width: 720px; }
.page-head .meta { margin-left: auto; color: var(--date); font-size: 15px; text-align: right; }
.page-head .meta .pill { font-size: 13px; }
.crumb { font-size: 14px; margin-bottom: 6px; display: inline-block; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: bold;
  padding: 1px 6px; border: 1px solid var(--tborder); background: var(--surface); color: var(--text-2);
  vertical-align: middle; white-space: nowrap; font-family: var(--font);
}
.pill.own { border-color: var(--own); color: var(--own); }
.pill.anchor { border-color: var(--h2-border); background: var(--h2-bg); color: var(--h2-text); }
.pill.prov { color: var(--muted); }
a.pill:hover { text-decoration: none; background: var(--active-bg); color: var(--text); border-color: var(--active-border); }

/* ---------- tiles (mini CCRL tables) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 2px ridge var(--tborder); padding: 0 0 10px; min-width: 0; }
.tile .label {
  background: var(--th); color: var(--th-text); font-size: 14px; text-align: center;
  padding: 3px 8px; border-bottom: 2px ridge var(--tborder); margin-bottom: 8px;
}
.tile .value { font-size: 24px; font-weight: bold; padding: 0 12px; text-align: center; }
.tile .value small { font-size: 14px; font-weight: normal; color: var(--muted); }
.tile .hint { font-size: 13px; color: var(--text-2); padding: 2px 12px 0; text-align: center; }

/* ---------- sub tabs (CCRL link row) ---------- */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; margin: 4px 0 16px; }
.subtabs a { padding: 4px 10px; font-size: 17px; border: 1px solid transparent; white-space: nowrap; }
.subtabs a.active { background: var(--active-bg); color: var(--text); border-color: var(--active-border); }
.subtabs a.active:hover { text-decoration: none; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 12px; }
.search {
  flex: 1 1 220px; max-width: 320px; padding: 6px 10px; font: inherit; font-size: 14px;
  border: 1px solid var(--h2-border); background: var(--surface); color: var(--text);
}
.search:focus { outline: 2px solid var(--th); outline-offset: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); cursor: pointer; user-select: none; }
.check input { accent-color: var(--h2-border); width: 15px; height: 15px; margin: 0; }
.btn {
  font: inherit; font-size: 14px; padding: 5px 12px; cursor: pointer;
  border: 1px solid var(--h2-border); background: var(--h2-bg); color: var(--h2-text);
}
.btn:hover { background: var(--th); color: var(--th-text); }
.toolbar .spacer { margin-left: auto; }
.count-note { font-size: 13px; color: var(--muted); }

/* ---------- cards: CCRL section bar + content ---------- */
.card { margin-bottom: 22px; min-width: 0; }
.card-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  background: var(--h2-bg); border: 1px solid var(--h2-border); color: var(--h2-text);
  padding: 6px 10px 6px 12px; margin-bottom: 10px;
}
.card-head h2 { font-size: 20px; }
.card-head .sub { font-size: 13px; color: var(--h2-text); opacity: .85; }
.card-body { padding: 4px 0 0; }
.card > .scroll, .card-body > .scroll { background: var(--surface); }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* CCRL rating table */
table.data {
  width: 100%; border-collapse: collapse; font-size: 15px; background: var(--surface);
  border: 2px ridge var(--tborder);
}
table.data th, table.data td { padding: 3px 7px; text-align: left; white-space: nowrap; }
table.data thead th {
  font-size: 15px; font-weight: normal; color: var(--th-text); background: var(--th);
  text-align: center; border-bottom: 2px ridge var(--tborder); position: sticky; top: 0;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { text-decoration: underline; }
table.data th .arrow { font-size: 10px; margin-left: 3px; }
table.data tbody td { border-bottom: 1px solid var(--tborder); }
table.data tbody tr:nth-child(odd) { background: var(--surface); }
table.data tbody tr:nth-child(even) { background: var(--stripe); }
table.data tbody tr:hover { background: var(--active-bg); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .rank { font-weight: bold; width: 1%; }
table.data .rating { font-weight: bold; }
table.data .err { color: var(--muted); font-weight: bold; }
table.data .eng a { color: var(--link); font-weight: bold; }
table.data tr.own .eng a { color: var(--own); }
table.data .eng .pill { margin-left: 6px; }
table.data tr.prov .eng a, table.data tr.prov .rating { font-style: italic; font-weight: normal; }
table.data td.los { text-align: center; font-size: 13px; font-weight: bold; padding: 2px 4px; color: var(--text); }
td.ci-cell { width: 24%; min-width: 160px; }
.dim { color: var(--muted); }
.pos-t { color: var(--good); font-weight: bold; }
.neg-t { color: var(--neg); font-weight: bold; }

/* uncertainty bar */
.ci { position: relative; height: 16px; }
.ci::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px dotted var(--tborder); }
.ci-line {
  position: absolute; top: 50%; height: 6px; margin-top: -3px;
  background: var(--th); border: 1px solid var(--h2-border);
}
.ci-dot {
  position: absolute; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%;
  background: var(--h2-text); box-shadow: 0 0 0 2px var(--surface);
}
tr.own .ci-line { background: color-mix(in srgb, var(--own) 55%, var(--surface)); border-color: var(--own); }
tr.own .ci-dot { background: var(--own); }
.ci-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--th-text); opacity: .9; }

/* W/D/L bar */
.wdl { display: flex; height: 12px; overflow: hidden; gap: 1px; background: var(--surface); border: 1px solid var(--tborder); min-width: 90px; }
.wdl span { display: block; height: 100%; }
.wdl .w { background: var(--pos); }
.wdl .d { background: var(--mid); }
.wdl .l { background: var(--neg); }
.wdl.big { height: 18px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 11px; height: 11px; margin-right: 5px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.25); }

/* CCRL crosstable */
.matrix {
  border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--cell); border: 1px outset #909090;
}
.matrix th { font-weight: bold; padding: 3px 6px; white-space: nowrap; background: var(--cell-head); color: var(--text); border: 1px inset #909090; }
.matrix thead th { text-align: center; min-width: 44px; }
.matrix tbody th { text-align: left; position: sticky; left: 0; z-index: 1; }
.matrix tbody th a { color: var(--link); }
.matrix tbody th .rk { color: var(--text-2); display: inline-block; width: 22px; font-weight: normal; }
.matrix td { min-width: 44px; height: 28px; text-align: center; color: var(--text); background: var(--cell); border: 1px inset #909090; }
.matrix td.self { background: var(--cell-head); }
.matrix td.none { color: var(--muted); }
.matrix tr.own th a { color: var(--own); }
.card-body > .scroll:has(.matrix) { background: transparent; }

/* charts */
.chart-box { background: var(--surface); border: 2px ridge var(--tborder); padding: 12px; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg text { fill: var(--text-2); font-size: 11px; font-family: var(--font); }
.chart-svg .gridline { stroke: var(--tborder); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-svg .baseline { stroke: var(--axis); stroke-width: 1; }
.chart-svg .bar { fill: var(--th); }
.chart-svg .bar-hit { fill: transparent; }
.chart-svg g:hover .bar { fill: var(--h2-border); }

.hbars { display: grid; grid-template-columns: max-content 1fr max-content; gap: 8px 12px; align-items: center; font-size: 14px; }
.hbars .lbl { color: var(--text); }
.hbars .track { height: 12px; position: relative; }
.hbars .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--th); border: 1px solid var(--h2-border); min-width: 2px; }
.hbars .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 0 24px; }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-2);
  background: var(--surface); border: 2px ridge var(--tborder); margin: 20px 0;
}
.empty h2 { margin-bottom: 8px; color: var(--h2-text); }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

/* prose (about page) */
.prose { max-width: 850px; }
.prose h2 {
  margin: 28px 0 10px; font-size: 20px; color: var(--h2-text); background: var(--h2-bg);
  border: 1px solid var(--h2-border); padding: 6px 10px 6px 12px;
}
.prose h3 { margin: 18px 0 6px; color: var(--contents); font-weight: normal; font-size: 18px; }
.prose ul { padding-left: 20px; margin: 0 0 12px; }
.prose li { margin-bottom: 4px; }
.prose dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.prose dt { font-weight: bold; }
.prose dd { margin: 0; color: var(--text-2); }
.card-body.prose { background: var(--surface); border: 2px ridge var(--tborder); padding: 12px 14px; }

.site-footer { border-top: 2px solid var(--h2-border); margin-top: 40px; padding: 18px 0 30px; color: var(--muted); font-size: 13px; text-align: center; }

#tip {
  position: fixed; z-index: 100; pointer-events: none; max-width: 300px;
  background: #ffffe1; color: #000; border: 1px solid #767676; font-size: 12px; line-height: 1.45;
  padding: 6px 9px; white-space: pre-line; box-shadow: 2px 2px 6px rgba(0,0,0,.2);
}
#tip b { font-weight: bold; }

@media (max-width: 720px) {
  h1 { font-size: 22px; }
  .page-head .meta { margin-left: 0; text-align: left; }
  .tile .value { font-size: 20px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .hint { font-size: 12px; }
  td.ci-cell, th.ci-cell { display: none; }
}

@media (forced-colors: active) {
  .wdl .w, .wdl .l, .wdl .d, .ci-dot, .ci-line, .hbars .fill, td.los { forced-color-adjust: none; }
}
