@import url("fonts/fonts.css");

/* Look and feel: warm parchment, cream cards, deep plum ink, purple actions, gold accents —
   after the Mayor-Baron Type Indicator. Chart colours are validated against the card surfaces:
   good (blue) / evil (rust) / overall (plum) all-pairs, and the player-count ramp as an ordinal scale.
   Good/evil tones follow the type indicator's Townsfolk blue and Minion rust. */
:root {
  color-scheme: light;
  --pc-0: #baa0f3; --pc-1: #a88be3; --pc-2: #9576d1; --pc-3: #8363be; --pc-4: #7150aa; --pc-5: #5f3e94; --pc-6: #4d2e7d; --pc-7: #3c1f66;
  --page: #f3e8d6;
  --surface: #fdf8ee;
  --surface-2: #f8efdf;
  --ink: #2b1d3f;
  --ink-2: #5f5070;
  --muted: #8b7f8e;
  --grid: #ecdfc8;
  --axis: #d5c4a4;
  --border: #e4d3b4;
  --wash: rgba(91, 58, 145, 0.07);
  --good: #3470bf;
  --evil: #c25a35;
  --neutral: #8e4f8a;
  --up: #2f7a2f;
  --down: #c0392b;
  --accent: #5b3a91;
  --accent-ink: #ffffff;
  --accent-soft: #ece3f7;
  --gold: #e3a92c;
  --hero-1: #3d2a5e;
  --hero-2: #20152f;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 28px;
  --gutter: max(20px, calc((100vw - 1440px) / 2));
  font-family: var(--sans);
}
/* Dark is the default look; the light palette above stays available with data-theme="light". */
:root:not([data-theme="light"]) {
  color-scheme: dark;
  --pc-0: #5c4883; --pc-1: #705a9c; --pc-2: #856db5; --pc-3: #9a81ce; --pc-4: #af96e4; --pc-5: #c4acfa; --pc-6: #d9c3ff; --pc-7: #efdbff;
  --page: #1a1324;
  --surface: #261c33;
  --surface-2: #2e2340;
  --ink: #f3eadb;
  --ink-2: #cdbfda;
  --muted: #9a8da8;
  --grid: rgba(243, 234, 219, 0.08);
  --axis: rgba(243, 234, 219, 0.24);
  --border: rgba(243, 234, 219, 0.13);
  --wash: rgba(243, 234, 219, 0.06);
  --good: #4f8fdc;
  --evil: #d46a55;
  --neutral: #985b93;
  --up: #6cc36c;
  --down: #f08a80;
  --accent: #7a55c7;
  --accent-ink: #ffffff;
  --accent-soft: rgba(122, 85, 199, 0.22);
  --gold: #f0bf4c;
  --hero-1: #6a47a8;
  --hero-2: #3b2862;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* The page: a seamless purple grunge texture, tiled at half its pixel size so it stays sharp on retina screens. */
html { background: var(--page); }
:root:not([data-theme="light"]) { --page-texture: url("images/background-tile.webp"); }
body { font-variation-settings: 'SOFT' 50; margin: 0; min-height: 100vh; background: var(--page) var(--page-texture, none) 0 0 / 627px auto repeat; color: var(--ink); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, select, input, textarea { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }

/* Full width up to 1440px; beyond that the content stays centred with equal space either side. */
.top, .filters, main { padding-left: var(--gutter); padding-right: var(--gutter); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 16px 28px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; background: var(--page) var(--page-texture, none) 0 0 / 627px auto repeat; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; border-radius: 12px; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.brand .logo { display: block; }
.brand h1 { font-family: var(--serif); font-size: 30px; line-height: 1; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
/* The wordmark's i carries a gold dot, like the logo's centre. */
.i-dot { position: relative; }
.i-dot::after { content: ""; position: absolute; left: 50%; top: .2em; width: .21em; height: .21em; transform: translateX(-50%); border-radius: 50%; background: var(--gold); }
.tabs, .toggles { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 4px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px; }
.tabs button, .toggle { background: none; border: 0; padding: 8px 18px; border-radius: 999px; cursor: pointer; color: var(--ink-2); font-weight: 600; line-height: 1.2; }
.tabs button:hover, .toggle:hover { background: var(--wash); color: var(--ink); }
.tabs button[aria-selected="true"], .toggle[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.filters { padding-top: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); display: grid; gap: 14px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label, .filters label { font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.filters label { display: flex; flex-direction: column; gap: 5px; }
.filters label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; font-weight: 500; letter-spacing: 0; padding-bottom: 9px; }
input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
select, input[type="text"], input[type="url"], input[type="password"], input[type="number"], textarea {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px; padding: 9px 16px; min-width: 0; color: var(--ink);
}
textarea { border-radius: 18px; }
select { padding-right: 12px; cursor: pointer; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filters select { min-width: 150px; max-width: 240px; }

main { padding-top: 24px; padding-bottom: 72px; }
h2 { font-family: var(--serif); font-size: 24px; line-height: 1.15; margin: 0 0 6px; font-weight: 600; }
h3 { font-family: var(--serif); font-size: 20px; line-height: 1.2; margin: 0 0 10px; font-weight: 600; }
h4 { font-family: var(--serif); font-size: 16px; margin: 0 0 8px; font-weight: 600; color: var(--ink); }
.sub { color: var(--ink-2); margin: -4px 0 14px; font-size: 14px; }
.muted { color: var(--muted); }

.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); }
.card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 24px 26px; min-width: 0; }

/* One highlighted card per view, in the site's mauve (#985b93) with cream text. */
.tile.feature { position: relative; overflow: hidden; background: #985b93; border-color: transparent; color: #f3eadb; }
.tile.feature .label, .tile.feature .value, .tile.feature .note, .tile.feature .lnk { color: #f3eadb; }
.tile.feature .lnk { text-decoration-color: rgba(243, 234, 219, .55); }
/* Green/red would be hard to read on the mauve, so the arrow and sign carry the direction here. */
.tile.feature .delta.up, .tile.feature .delta.down { color: #f3eadb; font-weight: 700; }
.summary.lead { font-family: var(--serif); font-size: 22px; line-height: 1.3; color: var(--ink-2); margin: 4px 0 18px; }
.summary.lead b { font-weight: 800; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 18px; }
.tile .label { color: var(--ink-2); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.tile .value { font-size: 30px; font-weight: 700; margin-top: 4px; line-height: 1.15; font-variant-numeric: lining-nums; }
.tile .note { color: var(--muted); font-size: 13px; margin-top: 2px; }

.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.good { background: var(--good); }
.sw.evil { background: var(--evil); }
.sw.neutral { background: var(--neutral); }

/* 100% split bars: good | evil with a 2px surface gap */
.split-row { display: grid; grid-template-columns: minmax(90px, 180px) 1fr 70px; gap: 12px; align-items: center; padding: 6px 0; }
.split-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-row .n { color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.split { display: flex; gap: 2px; height: 22px; }
.split > div { height: 100%; min-width: 2px; position: relative; display: flex; align-items: center; padding: 0 7px; font-size: 11px; color: #fff; font-weight: 700; white-space: nowrap; overflow: visible; }
.split .good { background: var(--good); border-radius: 6px 0 0 6px; }
.split .evil { background: var(--evil); border-radius: 0 6px 6px 0; justify-content: flex-end; }
.split .good:last-child { border-radius: 6px; }
.split .evil:first-child { border-radius: 6px; }

/* meters inside tables */
.meter { position: relative; height: 10px; background: var(--wash); border-radius: 5px; min-width: 36px; }
.meter > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 5px 5px 0; background: var(--neutral); }
.meter.good > i { background: var(--good); }
.meter.evil > i { background: var(--evil); }
.meter::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.rate { display: grid; grid-template-columns: 40px minmax(36px, 1fr); gap: 8px; align-items: center; min-width: 96px; }
.rate b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--wash); }
tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1.5px solid var(--border); background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.good::before, .pill.evil::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
.pill.good::before { background: var(--good); }
.pill.evil::before { background: var(--evil); }
.pill.won { color: var(--up); }
.pill.lost { color: var(--down); }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.btn { background: var(--surface); border: 1.5px solid var(--border); padding: 9px 20px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--ink); }
.btn:hover { background: var(--surface-2); border-color: var(--axis); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); }
.form { display: grid; gap: 12px; max-width: 560px; }
.form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.msg { font-size: 13px; }
.msg.ok { color: var(--up); }
.msg.err { color: var(--down); }

details.game { border-bottom: 1px solid var(--grid); }
details.game summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 120px 1fr auto; gap: 14px; padding: 14px 12px; border-radius: 20px; align-items: center; }
details.game summary::-webkit-details-marker { display: none; }
details.game summary:hover { background: var(--wash); }
details.game summary b { font-family: var(--serif); font-size: 17px; }
details.game .body { padding: 8px 4px 22px; display: grid; gap: 16px; }
.excluded summary { opacity: 0.55; }

.empty { text-align: center; padding: 64px 20px; color: var(--ink-2); }
.empty h2 { margin-bottom: 8px; }

#tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--hero-2); color: #f6ecd9; border-radius: 10px; padding: 7px 11px; font-size: 12.5px; max-width: 300px; white-space: pre-line; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .grid.two { grid-template-columns: 1fr; }
  .brand h1 { font-size: 22px; }
  :root { --radius: 24px; }
  .tabs { width: 100%; justify-content: space-between; }
  .tabs button { padding: 8px 12px; }
}
.linkish { background: none; border: 0; padding: 0 0 0 4px; color: inherit; cursor: pointer; font: inherit; }
.linkish:hover { color: var(--down); }

/* adaptive dashboard */
.summary { margin: 0 0 14px; color: var(--ink-2); font-size: 15px; }
.summary b { color: var(--ink); font-weight: 700; }
.lnk { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; text-decoration: underline; text-decoration-color: var(--axis); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
.lnk:hover { text-decoration-color: var(--accent); color: var(--accent); }
.grid.inner { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
table.rows td { border-bottom: 0; padding: 7px 8px 7px 0; }
.btn.small { padding: 5px 12px; font-size: 12px; margin-top: 10px; }
.mini-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 14px; margin-bottom: 8px; }
.mini-tiles div { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--surface-2); border-radius: 20px; }
.mini-tiles b { font-size: 26px; font-weight: 700; line-height: 1.1; }
.mini-tiles span { font-size: 12.5px; color: var(--ink-2); }
.bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 42px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 12px; background: var(--wash); border-radius: 6px; }
.bar i { display: block; height: 100%; border-radius: 0 6px 6px 0; background: var(--neutral); }
.bar i.alive { background: var(--axis); }
.games-card { margin-top: 16px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.tiles .tile .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The headline number or name in the top cards: big, in the display face. */
.tiles .tile { display: flex; flex-direction: column; }
.tiles .tile .value { font-family: var(--serif); font-weight: 650; font-size: 58px; line-height: 1; margin-top: 10px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-bottom: 4px; }
.tiles .tile .value .lnk { text-decoration-thickness: 2px; text-underline-offset: 6px; }
.tiles .tile .note { margin-top: 6px; }
@media (max-width: 640px) { .tiles .tile .value { font-size: 46px; } }

.delta { white-space: nowrap; font-weight: 600; }
table.rows { table-layout: fixed; }
table.rows td.num { white-space: nowrap; width: 80px; }
table.rows td:last-child { width: 46%; }

.see-games { margin: 22px 0 0; display: flex; justify-content: center; }
.center { text-align: center; }

.game-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.game-bar .count { margin-left: 4px; opacity: .7; font-variant-numeric: tabular-nums; }
.game-bar .badge { margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--down); color: var(--page); font-weight: 700; }
.btn.icon { width: 42px; height: 42px; padding: 0; display: grid; place-items: center; }
.btn.icon svg { width: 18px; height: 18px; fill: currentColor; }
.btn.icon[aria-expanded="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.game-menu { padding: 20px 22px; background: var(--surface-2); border: 1.5px solid var(--border); border-radius: 22px; display: grid; gap: 18px; }
.game-menu h4 { margin: 0; }
.gm-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px 20px; align-items: end; }
.gm-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.gm-field .toggles { align-self: flex-start; }
.gm-field input, .gm-field textarea { width: 100%; height: 44px; }
.gm-field textarea { height: auto; min-height: 64px; resize: vertical; font: inherit; line-height: 1.4; }
.gm-wide { grid-column: 1 / -1; }
.gm-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.gm-check input { margin-top: 3px; flex: none; }
.gm-check span { display: flex; flex-direction: column; gap: 2px; }
.gm-check b { font-weight: 600; color: var(--ink); }
.gm-check span span { color: var(--muted); font-size: 13px; }
.gm-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 14px; border-top: 1px solid var(--grid); font-size: 13px; }
@media (max-width: 640px) { .gm-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- grimoire (always dark, like the botc.app reveal) ---------- */
.grim-wrap { display: flex; justify-content: center; }
.grimoire {
  container-type: inline-size;
  position: relative; width: min(100%, 780px); aspect-ratio: 1; border-radius: 28px; overflow: hidden;
  background: radial-gradient(circle at 50% 50%, #3a2c55 0%, #241a36 45%, #140e1f 100%);
  color: #f3eee6; font-family: var(--sans);
}
.grimoire.evil { background: radial-gradient(circle at 50% 50%, #5a1a22 0%, #3a1016 45%, #1d070a 100%); }
.grimoire::before { content: ""; position: absolute; inset: 9%; border-radius: 50%; border: 1px solid rgba(255,255,255,.08); box-shadow: inset 0 0 0 1.4cqw rgba(255,255,255,.025); }
/* The result, as botc.app shows it when the grimoire is revealed: the side in big gradient capitals (blue for
   good, orange-red for evil), "has won!" in white beneath, Sorts Mill Goudy bold with a black glow. Sizes follow
   botc.app's: 3vmin text, the side at 14em ÷ its length (3.5em for "Good"/"Evil"); vmin becomes the grimoire's width. */
.g-result { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1; pointer-events: none; white-space: nowrap;
  text-align: center; text-transform: uppercase; color: #fff; font: 700 3cqw/1 "Clockwise Result", "Sorts Mill Goudy", Georgia, serif;
  padding-bottom: 2cqw; filter: drop-shadow(0 0 .55cqw #000); }
.g-result b { display: block; font-size: 3.5em; line-height: 1; margin-bottom: -.1em; padding-top: 2cqw;
  background: linear-gradient(180deg, #46d5ff, #1f65ff); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.g-result.evil b { background-image: linear-gradient(180deg, #ff6900, #ce0100); }

.g-seat { position: absolute; width: var(--tok); height: var(--tok); transform: translate(-50%, -50%); z-index: 2; --ts: var(--tok); }
.g-reminder { position: absolute; width: var(--rem); height: var(--rem); transform: translate(-50%, -50%); z-index: 1; --rs: var(--rem); }
.g-mini { width: 8cqw; height: 8cqw; --ts: 8cqw; }
.g-name { position: absolute; top: calc(100% + .3cqw); left: 50%; transform: translateX(-50%); background: rgba(34, 34, 38, .92); border: 1px solid rgba(255, 255, 255, .1); border-radius: .6cqw; padding: .25cqw 1cqw; white-space: nowrap; max-width: calc(var(--tok) * 1.7); overflow: hidden; text-overflow: ellipsis; box-shadow: 0 .3cqw .8cqw rgba(0,0,0,.4); }
.g-name .lnk, .g-name span { color: #fff; font-size: max(10px, calc(var(--tok) * .14)); text-decoration: none; font-weight: 500; }
.g-corner { position: absolute; display: grid; gap: .6cqw; font-size: max(10px, 1.6cqw); color: #d8cfe8; z-index: 3; }
.g-corner.tl { left: 2.5%; top: 2.5%; }
.g-corner.br { right: 2.5%; bottom: 2.5%; text-align: right; }
.g-corner > div { display: flex; gap: .8cqw; }
.g-corner.br > div { justify-content: flex-end; }
details.game .body { grid-template-columns: minmax(0, 1fr); }
details.game .body > * { min-width: 0; }
@media (max-width: 640px) {
  details.game summary { grid-template-columns: 1fr; gap: 4px; }
  details.game summary .pills { justify-content: flex-start; }
}
/* Small grimoires (phones): text scales with the tokens; full detail is in the seat list below. */
@container (max-width: 520px) {
  .g-name { max-width: calc(var(--tok) * 1.5); padding: .3cqw 1cqw; }
  .g-name .lnk, .g-name span { font-size: calc(var(--tok) * .17); }
  .g-corner { display: none; }
}

/* botc.app images */
.grimoire.has-bg { background-size: cover; background-position: center; }
.grimoire.has-bg::before { display: none; }

/* pie charts */
.pie-card { display: flex; flex-direction: column; }
.pie-wrap { display: flex; justify-content: center; padding: 6px 0 10px; }
.pie { width: min(100%, 240px); height: auto; overflow: visible; }
.pie path, .pie circle { stroke: var(--surface); stroke-width: 2; stroke-linejoin: round; }
.pie path:hover, .pie circle:hover { opacity: .88; }
.pie-chip rect { fill: rgba(32, 21, 47, .78); }
.pie-chip text { fill: #fff; font-size: 13px; font-weight: 700; font-family: var(--sans); }
.pie-caption { text-align: center; margin: 4px 0 0; color: var(--ink-2); }
.legend.wrap { justify-content: center; gap: 6px 14px; }
.legend .pc { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.highlight .value { font-size: 28px; font-family: var(--serif); }
.freq-bar { height: 8px; background: var(--wash); border-radius: 4px; min-width: 60px; }
.freq-bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--neutral); }

/* single-player top row */
.span-all { grid-column: 1 / -1; }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.ring-track { fill: var(--wash); }
.rings path { stroke: var(--surface); stroke-width: 2; }
.pie-caption.compare { font-size: 13px; line-height: 1.6; text-align: left; }
.token-card { display: flex; flex-direction: column; align-items: center; text-align: center; }
.token-card h3 { align-self: stretch; text-align: left; }
.token-card .info { cursor: help; color: var(--muted); font-family: var(--sans); font-size: 14px; font-weight: 400; }
.token-card p { margin: 14px 0 0; color: var(--ink-2); }
.tok-body { flex: 1; align-self: stretch; display: flex; flex-direction: column; align-items: center; justify-content: center; padding-bottom: 8px; }
.toggle.small { padding: 3px 10px; font-size: 12px; }

/* sortable column labels: ▼ natural order, ▲ reversed; inactive columns show a faint arrow on hover */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--ink); }
th.sortable .arrow { display: inline-block; margin-left: 4px; font-size: 10px; opacity: 0; }
th.sortable:hover .arrow { opacity: .4; }
th.sortable.sorted { color: var(--ink); }
th.sortable.sorted .arrow { opacity: 1; }

/* ---------- filter bar: one row (wraps only on narrow windows) ---------- */
.filter-row { flex-wrap: wrap; gap: 10px; align-items: center; }
.filter-row > select { flex: 0 1 180px; min-width: 130px; }
.filter-row > .ms { flex: 1 1 170px; min-width: 168px; max-width: 260px; }
.filter-row > .toggles, .filter-row > .btn { flex: none; }
.btn.clear { height: 44px; padding: 0 18px; }
.filter-row > select, .filter-row .toggles { height: 44px; }
.filter-row .toggles { align-items: center; }

/* Selects: our own chevron with room on the right (the browser's arrow sat against the edge). */
select {
  appearance: none; -webkit-appearance: none; padding: 10px 42px 10px 18px; font-weight: 600; color: var(--ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%235f5070' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center; background-size: 14px;
}
:root:not([data-theme="light"]) select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23cdbfda' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }

/* Searchable checkbox dropdowns (Players, Characters, Character type) */
.ms { position: relative; }
.ms-field { display: flex; align-items: center; height: 44px; padding: 0 8px 0 18px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px; cursor: text; }
.ms-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0; font-weight: 600; color: var(--ink); }
.ms-field input::placeholder { color: var(--ink); opacity: 1; }
.ms.open .ms-field input::placeholder { color: var(--muted); font-weight: 500; }
.ms-icon { flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin-left: 4px; border: 0; background: none; color: var(--ink-2); cursor: pointer; border-radius: 50%; }
.ms-icon svg { width: 14px; height: 14px; }
.ms-icon:hover { background: var(--wash); }
.ms.open .ms-field { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.ms.has-value:not(.open) .ms-field { background: var(--ink); border-color: var(--ink); }
.ms.has-value:not(.open) .ms-field input::placeholder, .ms.has-value:not(.open) .ms-icon { color: var(--surface); }
.ms-panel { position: absolute; z-index: 30; top: calc(100% + 8px); left: 0; right: auto; min-width: min(max(100%, 270px), calc(100vw - 32px)); max-width: calc(100vw - 32px); max-height: 360px; overflow-y: auto; padding: 6px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 22px; box-shadow: 0 16px 40px rgba(43, 29, 63, .18); }
.ms-panel ul { list-style: none; margin: 0; padding: 0; }
.ms-panel li[data-i] { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 14px; cursor: pointer; }
.ms-panel li.active, .ms-panel li[data-i]:hover { background: var(--wash); }
.ms-panel .ms-meta { font-weight: 700; }
.ms-panel .ms-sep { margin-bottom: 4px; box-shadow: 0 6px 0 -5px var(--grid); }
.ms-panel .ms-sub { margin-left: auto; font-size: 12px; color: var(--muted); }
.ms-panel .ms-empty { padding: 10px 12px; color: var(--muted); }
.cb { flex: none; position: relative; width: 18px; height: 18px; border-radius: 6px; border: 1.5px solid var(--axis); background: var(--surface); }
.ms-panel li[aria-selected="true"] .cb { background: var(--accent); border-color: var(--accent); }
.ms-panel li[aria-selected="true"] .cb::after { content: ""; position: absolute; left: 5px; top: 1.5px; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
@media (max-width: 640px) {
  .filter-row > select, .filter-row > .ms { flex: 1 1 calc(50% - 10px); max-width: none; }
  .filter-row > .toggles { flex: 1 1 100%; }
}
.ms.align-right .ms-panel { left: auto; right: 0; }

/* head-to-head score for two players */
.h2h { display: flex; align-items: baseline; justify-content: center; gap: 14px; margin: 4px 0 16px; font-family: var(--serif); }
.h2h span { font-size: 18px; color: var(--ink-2); }
.h2h b { font-size: 40px; font-weight: 800; color: var(--ink); font-variant-numeric: lining-nums; }
td.nowrap { white-space: nowrap; }
@media (min-width: 820px) { .card.wide { grid-column: span 2; } }

/* prediction for characters never (or rarely) seen together */
.predict-nums { display: flex; gap: 28px; align-items: baseline; font-family: var(--serif); font-size: 22px; color: var(--ink-2); }
.predict-nums b { font-size: 44px; font-weight: 800; color: var(--ink); margin-left: 6px; font-variant-numeric: lining-nums; }
.predict-nums .g b { color: var(--good); }
.predict-nums .e b { color: var(--evil); }
.predict-lean { margin: 2px 0 14px; color: var(--ink-2); }
.range { margin: 6px 0 14px; }
.range-track { position: relative; height: 14px; border-radius: 7px; background: linear-gradient(90deg, color-mix(in srgb, var(--evil) 22%, var(--surface)), var(--wash) 50%, color-mix(in srgb, var(--good) 22%, var(--surface))); }
.range-band { position: absolute; top: 0; bottom: 0; border-radius: 7px; background: color-mix(in srgb, var(--neutral) 45%, transparent); }
.range-mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1.5px; background: var(--axis); }
.range-dot { position: absolute; top: 50%; width: 18px; height: 18px; border-radius: 50%; background: var(--neutral); border: 3px solid var(--surface); transform: translate(-50%, -50%); box-shadow: 0 1px 4px rgba(0,0,0,.25); cursor: help; }
.range-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.small { font-size: 12.5px; line-height: 1.5; }

/* combined colour key + comparison under the win-rate rings */
.ring-key { list-style: none; margin: 2px 0 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.ring-key li { display: grid; grid-template-columns: 11px auto 1fr; column-gap: 10px; align-items: center; cursor: help; }
.ring-key .k { font-weight: 600; color: var(--ink); min-width: 4.4em; }
.ring-key .vs { color: var(--ink-2); text-align: right; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- tokens, drawn like botc.app's (see src/tokens.js) ---------- */
/* Character token: parchment disc, art raised 10%, leaves, name in capitals round the bottom. */
.ctok {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 50%;
  border: max(1px, calc(var(--ts, 100px) * .013)) solid #000;
  background: radial-gradient(circle at 50% 40%, #fbf6ea 0%, #efe4cc 70%, #d9c9a6 100%) 50% / 113% no-repeat;
  box-shadow: 0 0 calc(var(--ts, 100px) * .045) rgba(0, 0, 0, .5);
}
.token-art .ctok { background-color: #e9dcc0; }
.ctok .ct-icon { position: absolute; left: 0; top: -10%; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.ctok .leaf { position: absolute; inset: 0; border-radius: 50%; background-position: 50%; background-size: 103%; background-repeat: no-repeat; pointer-events: none; }
.ctok .leaf-orange { background-size: 113%; }
.ctok .ct-name { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; font-size: 20px; text-transform: uppercase; pointer-events: none; }
.ctok .ct-name text { fill: #000; font-family: "Clockwise Token", "Uncial Antiqua", var(--serif); font-weight: 400;
  filter: drop-shadow(0 1.5px rgba(255,255,255,.5)) drop-shadow(0 -1.5px rgba(255,255,255,.5)) drop-shadow(1.5px 0 rgba(255,255,255,.5)) drop-shadow(-1.5px 0 rgba(255,255,255,.5)); }
.ctok .ct-hit { position: absolute; inset: 0; border: 0; border-radius: 50%; background: none; padding: 0; cursor: pointer; z-index: 4; }
.ctok .ct-hit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Death shroud: botc.app's shroud hangs from the top of the token; the skull marks a used dead vote. */
.ctok .ct-shroud { position: absolute; left: 0; top: 0; width: 100%; height: 54%; z-index: 2; pointer-events: none; }
.ctok .ct-shroud.art { background: 50% 0 / auto 100% no-repeat; filter: drop-shadow(0 0 calc(var(--ts, 100px) * .035) rgba(0,0,0,.8)); }
.ctok .ct-shroud:not(.art) { top: -7%; left: 36%; width: 28%; height: 40%; background: linear-gradient(#2a2a2a, #0d0d0d); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 74%, 0 100%); }
.ctok .ct-voteless { position: absolute; left: 0; top: 0; width: 100%; height: 30%; z-index: 3; background: bottom / 30% no-repeat; pointer-events: none; }

/* Reminder token: purple disc, art on top, the reminder in white capitals round the bottom. */
.crem {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 50%;
  border: max(1px, calc(var(--rs, 50px) * .03)) solid #000;
  background: radial-gradient(circle at 50% 35%, #5b3e86, #2b1d44) 50% / 110% no-repeat;
  box-shadow: 0 0 calc(var(--rs, 50px) * .12) rgba(0, 0, 0, .5);
}
.crem .cr-icon { position: absolute; left: 5%; top: 0; width: 90%; height: 90%; object-fit: contain; pointer-events: none; }
.crem .cr-name { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.crem .cr-name text { fill: #fff; font-family: "Clockwise Reminder", var(--sans); font-weight: 700; letter-spacing: 1px; stroke: #000; stroke-width: 3px; paint-order: stroke; stroke-linejoin: round; }
.crem.plain .cr-text { position: absolute; inset: 10%; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; overflow-wrap: anywhere;
  color: #fff; font: 700 calc(var(--rs, 50px) * .16) / 1.05 "Clockwise Reminder", var(--sans); text-shadow: 0 1px 1px #000, 0 -1px 1px #000, 1px 0 1px #000, -1px 0 1px #000; }

/* Token cards (most played / best / worst) */
.token-card .ctok { --ts: 210px; width: min(100%, 210px); }
.token-card .ctok.empty { background: var(--wash); border-color: var(--border); box-shadow: none; }

/* Shown when the files on disk are newer than the extension Chrome is running. */
.update-banner { margin: 16px var(--gutter) 0; padding: 12px 18px; border-radius: 18px; background: var(--accent-soft); border: 1.5px solid var(--accent); color: var(--ink); font-weight: 600; }

/* ---------- shared games ---------- */
/* Website sign-in: just the logo and the password until it's accepted. */
body.signed-out .tabs, body.signed-out #filters { display: none !important; }
.signin { max-width: 420px; margin: 8vh auto; text-align: center; display: grid; gap: 10px; justify-items: center; padding: 36px 32px; }
.signin h2 { font-size: 34px; margin: 4px 0 0; }
.signin form { display: grid; gap: 14px; width: 100%; margin-top: 8px; }
.signin input[type="password"] { width: 100%; height: 46px; text-align: center; }
.signin label.check { justify-content: center; display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; }
.signin .btn { height: 46px; }
/* Extension: invitation to see everyone's games. */
.card.connect { display: flex; gap: 18px 24px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 18px; }
.card.connect h3 { margin-bottom: 4px; }
.card.connect .sub { margin: 0; max-width: 60ch; }
.card.connect form { display: flex; gap: 10px; flex-wrap: wrap; }
.card.connect input { width: 240px; height: 44px; }
.sync-note { margin: 0 0 14px; font-size: 13px; color: var(--ink-2); }
.sync-note.err, .msg.err, .sub .err { color: var(--down); }
details.advanced { margin-top: 16px; }
details.advanced summary { cursor: pointer; color: var(--ink-2); font-weight: 600; }
.gm-fields { border: 0; padding: 0; margin: 0; display: grid; gap: 18px; min-width: 0; }
.gm-fields[disabled] { opacity: .55; }
