:root {
  --bg: #fbf6ef;
  --card: #ffffff;
  --ink: #2a2422;
  --muted: #7a6f69;
  --line: #eadfd3;
  --red: #b02634;
  --red-soft: #f8e3e4;
  --green: #1f6648;
  --green-soft: #e1f0e8;
  --gold: #c8901c;
  --gold-soft: #fbefd2;
  --door: #1f6648;
  --door-open: #f3ebe0;
  --shadow: 0 1px 3px rgba(60, 30, 20, .08), 0 4px 14px rgba(60, 30, 20, .06);
  /* Chart: first three categorical slots (validated together for color-blind safety) + recessive chrome */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --viz-muted: #d3d1c9;
  --viz-grid: #ece9e1;
  --viz-base: #c3c2b7;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120f;
    --card: #221b17;
    --ink: #f3ebe4;
    --muted: #a99c93;
    --line: #3a2f29;
    --red: #e05561;
    --red-soft: #3b1d20;
    --green: #5cc08f;
    --green-soft: #183326;
    --gold: #f0c050;
    --gold-soft: #3a2e14;
    --door: #1d4f39;
    --door-open: #2c241f;
    --shadow: none;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --viz-muted: #4a423c;
    --viz-grid: #2e2622;
    --viz-base: #4a423c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .6rem; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .6rem;
  padding: calc(.7rem + env(safe-area-inset-top)) 16px .7rem;
  background: var(--red); color: #fff;
}
.top h1 { font-size: 1.15rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .pill { background: rgba(255, 255, 255, .18); color: #fff; }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: .45rem 0 .5rem; font-size: .72rem; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: pointer;
}
.tabs button span { font-size: 1.25rem; filter: grayscale(.7); }
.tabs button.on { color: var(--red); font-weight: 600; }
.tabs button.on span { filter: none; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.card + .card, .card + details, details + details, details + .card { margin-top: 12px; }
.pill:empty { display: none; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; background: var(--line); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: .5rem .9rem; cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { padding: .25rem .6rem; font-size: .85rem; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=number], input[type=time], input:not([type]), select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
}
input[type=number] { width: 5.5rem; }
textarea { min-height: 6rem; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
label.check { display: flex; gap: .5rem; align-items: center; cursor: pointer; }
.opts label { display: flex; gap: .55rem; align-items: center; padding: .45rem .6rem; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; margin-top: .35rem; }
.opts label.right { border-color: var(--green); background: var(--green-soft); }
.opts input { width: auto; }

/* Today */
.daynav { display: flex; align-items: center; gap: .5rem; margin-bottom: 12px; }
.daynav .title { flex: 1; text-align: center; }
.daynav .title b { display: block; font-size: 1.3rem; }
.hero { text-align: center; }
.pot { font-size: 2.6rem; font-weight: 800; color: var(--red); line-height: 1; }
.reveal-photo { border-radius: 12px; margin: .4rem auto .6rem; max-height: 340px; object-fit: contain; }
.charname { font-size: 1.5rem; font-weight: 700; }
.who { display: flex; flex-wrap: wrap; gap: .35rem; }
.who .pill { font-size: .82rem; }
.guess-list { list-style: none; padding: 0; margin: .3rem 0 0; }
.guess-list li { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem 0; border-top: 1px solid var(--line); }
.guess-list li:first-child { border-top: 0; }
.guess-list .hit { color: var(--green); font-weight: 600; }

/* Calendar */
.doors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (min-width: 560px) { .doors { grid-template-columns: repeat(6, 1fr); } }
.door {
  aspect-ratio: 3 / 4; border-radius: 10px; border: 2px solid rgba(0, 0, 0, .15); background: var(--door); color: #fff;
  position: relative; overflow: hidden; cursor: pointer; padding: 0; display: flex; align-items: flex-end;
}
.door .num { position: absolute; top: 6px; left: 8px; font-weight: 800; font-size: 1.25rem; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.door.today { outline: 3px solid var(--gold); outline-offset: 1px; }
.door.open { background: var(--door-open); color: var(--ink); }
.door.open img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.door.open .num { color: #fff; }
.door .label { position: relative; width: 100%; font-size: .72rem; padding: 3px 5px; background: rgba(0,0,0,.55); color: #fff;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.door .mine { position: absolute; top: 6px; right: 6px; font-size: .8rem; }

/* Scores */
.board { list-style: none; padding: 0; margin: 0; }
.board li { display: flex; align-items: center; gap: .6rem; padding: .6rem .2rem; border-top: 1px solid var(--line); cursor: pointer; }
.board li:first-child { border-top: 0; }
.board .rank { width: 2rem; text-align: center; font-weight: 800; font-size: 1.1rem; }
.board .pts { font-weight: 800; font-size: 1.15rem; }
.board .move { width: 2.2rem; font-size: .8rem; text-align: right; }
.up { color: var(--green); } .down { color: var(--red); }
.events { list-style: none; padding: 0; margin: .4rem 0 0; font-size: .9rem; }
.events li { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem 0; border-top: 1px dashed var(--line); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .35rem .3rem; border-top: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.n, th.n { text-align: right; }
.scroll-x { overflow-x: auto; }

/* Over-time chart */
.viz { position: relative; overflow: hidden; }
.viz svg { display: block; max-width: 100%; height: auto; touch-action: pan-y; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-base { stroke: var(--viz-base); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-muted { fill: none; stroke: var(--viz-muted); stroke-width: 1.5; stroke-linejoin: round; }
.viz-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-dot { stroke: var(--card); stroke-width: 2; }
.viz-label { fill: var(--ink); font-size: 12px; font-weight: 600; }
.viz-cross { stroke: var(--viz-base); stroke-width: 1; }
.viz-tip { position: absolute; top: 8px; min-width: 130px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: .45rem .6rem; font-size: .8rem; box-shadow: var(--shadow); pointer-events: none; }
.viz-tip .row { gap: .8rem; flex-wrap: nowrap; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .2rem .65rem; font-size: .82rem; cursor: pointer; color: var(--muted); }
.chip.on { color: var(--ink); border-color: var(--ink); font-weight: 600; }

/* Draft */
.picks { list-style: none; padding: 0; margin: .2rem 0 0; }
.picks li { display: flex; justify-content: space-between; padding: .15rem 0; }
.picks li.old { color: var(--muted); text-decoration: line-through; }

/* Host */
.host-day { position: sticky; top: var(--top-h, 52px); z-index: 4; padding: 10px; margin-bottom: 12px; }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.card > summary::after { content: "▾"; color: var(--muted); }
details.card[open] > summary { margin-bottom: .7rem; }
details.card[open] > summary::after { content: "▴"; }
.sched { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.sched label { display: flex; align-items: center; gap: .35rem; font-size: .85rem; }
.sched input { width: 3.4rem; padding: .3rem .4rem; }
.linkbox { font-family: ui-monospace, monospace; font-size: .75rem; word-break: break-all; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 10px; z-index: 20; max-width: 90vw;
}
.toast.err { background: var(--red); color: #fff; }

/* Finale */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(20, 8, 6, .92); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; text-align: center; }
.overlay .place { font-size: 1.1rem; opacity: .8; }
.overlay .name { font-size: 2.6rem; font-weight: 800; margin: .3rem 0; }
.overlay .score { font-size: 1.4rem; color: #f2c04c; }
.overlay .winner .name { font-size: 3.2rem; color: #f2c04c; }
.overlay .hint { position: absolute; bottom: 28px; opacity: .6; font-size: .9rem; }
.pop { animation: pop .45s ease-out; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
