/* Theme tokens: dark by default, light via prefers-color-scheme or data-theme. */
:root {
  --bg: #111318; --fg: #f2f3f5; --muted: #9aa0ab; --card: #1a1d24; --line: #2a2e38;
  --input-bg: #0d0f13; --btn: #2a2f3a; --btn-hover: #353b48; --track: #2a2f3a;
  --accent: #4f8cff; --accent-hover: #3d78e6; --ok: #3ccf7a; --warn: #f5b942; --danger: #ff5c5c;
  --ok-bg: #14361f; --warn-bg: #3f3210; --danger-bg: #3d1717; --flash-bg: #2a3350;
  --body-warn: #2a2208; --body-danger: #3a1010; --end-flash: #8a1c1c;
  --c-red: #ff6b6b; --c-orange: #ffb347; --c-green: #4fd88a; --c-blue: #6aa3ff; --c-purple: #c79bff;
  --radius: 12px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f5f6f8; --fg: #16181d; --muted: #5f6570; --card: #ffffff; --line: #d9dde5;
  --input-bg: #ffffff; --btn: #e3e6ec; --btn-hover: #d3d7df; --track: #dfe3ea;
  --accent: #2f6fe0; --accent-hover: #2358bd; --ok: #1f9d55; --warn: #c48a00; --danger: #d93838;
  --ok-bg: #d9f3e3; --warn-bg: #fff1c9; --danger-bg: #ffdcdc; --flash-bg: #dbe6ff;
  --body-warn: #fff3cc; --body-danger: #ffd9d9; --end-flash: #ff9c9c;
  --c-red: #d62828; --c-orange: #d97706; --c-green: #15803d; --c-blue: #1d4ed8; --c-purple: #7e22ce;
  color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --fg: #16181d; --muted: #5f6570; --card: #ffffff; --line: #d9dde5;
    --input-bg: #ffffff; --btn: #e3e6ec; --btn-hover: #d3d7df; --track: #dfe3ea;
    --accent: #2f6fe0; --accent-hover: #2358bd; --ok: #1f9d55; --warn: #c48a00; --danger: #d93838;
    --ok-bg: #d9f3e3; --warn-bg: #fff1c9; --danger-bg: #ffdcdc; --flash-bg: #dbe6ff;
    --body-warn: #fff3cc; --body-danger: #ffd9d9; --end-flash: #ff9c9c;
    --c-red: #d62828; --c-orange: #d97706; --c-green: #15803d; --c-blue: #1d4ed8; --c-purple: #7e22ce;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
  /* keep content clear of the iOS status bar / notch when installed (viewport-fit=cover) */
  padding-top: env(safe-area-inset-top);
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: .2em 0 .5em; }
h2 { font-size: 1.1rem; margin: .8em 0 .4em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.lead { font-size: 1.1rem; color: var(--muted); }

.top { display: flex; align-items: center; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.top nav { display: flex; gap: 1rem; align-items: center; margin-left: auto; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; }
.brand.small { font-size: .9rem; color: var(--muted); }
.page { max-width: 880px; width: 100%; margin: 0 auto; padding-block: 1rem 2rem; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem 0 max(1rem, env(safe-area-inset-bottom)); }
.foot a { color: var(--muted); }
.crumbs { color: var(--muted); }

input, button, select { font: inherit; }
input { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: .55em .7em; width: 100%; }
label { display: flex; flex-direction: column; gap: .3em; font-size: .95rem; }
label.check { flex-direction: row; align-items: center; gap: .5em; }
label.check input { width: auto; }
label.strong { font-weight: 600; }
button { background: var(--btn); color: var(--fg); border: 0; border-radius: 8px; padding: .55em 1em; cursor: pointer; }
button:hover { background: var(--btn-hover); }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(.9); }
button.link { background: none; color: var(--accent); padding: 0; }
button.small { padding: .3em .7em; font-size: .85rem; }
button.icon { background: none; font-size: 1.3rem; padding: .2em .35em; line-height: 1; text-decoration: none; color: var(--fg); }
button.icon[aria-pressed="true"], .bar .icon[aria-pressed="true"] { background: var(--btn); border-radius: 8px; }
form.inline { display: inline; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.narrow { max-width: 420px; }
.row { display: flex; gap: .6rem; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row > .grow { flex: 1 1 200px; }
.grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.danger { border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem 1rem; }
.tablist { display: flex; flex-wrap: wrap; gap: .2rem; border-bottom: 1px solid var(--line); margin: 1rem 0; }
.tab { background: none; color: var(--muted); border-radius: 8px 8px 0 0; padding: .5em .9em; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { background: var(--btn); color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); font-weight: 600; border-bottom-color: var(--accent); }
.tabpanel[hidden], .subpanel[hidden] { display: none; }
.subtabs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .8rem; }
.sub { background: var(--btn); color: var(--muted); font-size: .9rem; padding: .4em .8em; }
.sub[aria-selected="true"] { background: var(--accent); color: #fff; }
fieldset.ext { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin: 0 0 .8rem; }
fieldset.ext legend { font-weight: 600; padding: 0 .3em; }
.flash { padding: .6em .9em; border-radius: 8px; }
.flash.ok { background: var(--ok-bg); } .flash.err { background: var(--danger-bg); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .5em .4em; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list .actions a { margin-right: .6em; }
table.list.small, .small { font-size: .85rem; }
table.num td, table.num th { text-align: right; font-variant-numeric: tabular-nums; }
table.num td:first-child, table.num th:first-child { text-align: left; }
.pill { padding: .1em .6em; border-radius: 999px; font-size: .8rem; background: var(--btn); white-space: nowrap; }
.pill.phase-ordering, .pill.diff-easy, .pill.int-normal { background: var(--ok-bg); color: var(--ok); }
.pill.phase-cleared, .pill.diff-medium, .pill.int-moderate { background: var(--warn-bg); color: var(--warn); }
.pill.phase-finished, .pill.diff-expert, .pill.int-extreme { background: var(--danger-bg); color: var(--danger); }
.pill.avail { background: var(--flash-bg); }
.danger-link { color: var(--danger); }
.btn { display: inline-block; background: var(--btn); color: var(--fg); text-decoration: none; padding: .55em 1em; border-radius: 8px; }
.btn:hover { background: var(--btn-hover); }
.page.wide { max-width: 1180px; }
.pre { white-space: pre-wrap; }
textarea { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: .55em .7em; width: 100%; font: inherit; }
select { background: var(--input-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: .5em .6em; width: 100%; }
.langs button.current { font-weight: 700; text-decoration: underline; }
.account { margin-top: 2rem; } .or { color: var(--muted); text-align: center; }
.choice { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
.pos { color: var(--ok); } .neg { color: var(--danger); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* landing */
.hero { text-align: center; margin: 1.5rem 0 2rem; }
.hero h1 { font-size: 2.4rem; margin: .3em 0 .2em; }
.features, .roles { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .6rem; }
.features li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .7em .9em; }
.role-card { display: flex; gap: .7rem; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .7em .9em; cursor: default; }
.role-card .ricon { font-size: 1.6rem; line-height: 1; }
.roles.pick .role-card { cursor: pointer; flex-direction: row; }
.roles.pick input[type=radio] { width: auto; margin-top: .4em; }
.roles.pick .role-card:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.roles.pick details { margin-top: .3em; }
.code-input { font-family: ui-monospace, monospace; font-size: 1.4rem; letter-spacing: .2em; text-transform: uppercase; }

/* play banner */
.banner { display: grid; grid-template-columns: 1.2fr 1.6fr 1fr; gap: 1rem; align-items: start; }
.banner h1 { margin: 0; }
.banner-scen { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.banner-scen p { margin: .1em 0; }
.banner-side { text-align: right; }
.balance strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.clock { font-family: ui-monospace, monospace; font-size: 1.2rem; margin: .2em 0; }
.clock.warn { color: var(--warn); } .clock.danger { color: var(--danger); }
.clock.big { font-size: 2.4rem; }
.factors { color: var(--muted); }
#btn-ready.on { background: var(--ok); }
@media (max-width: 800px) { .banner { grid-template-columns: 1fr; } .banner-side { text-align: left; } }

/* schedule table */
.sched { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.sched th, .sched td { padding: .25em .4em; border-bottom: 1px solid var(--line); text-align: right; }
.sched th:first-child, .sched td:first-child { text-align: left; }
.sched input { width: 5.5em; padding: .25em .4em; text-align: right; }
.sched tr.peak td:first-child { font-weight: 600; }
.sched .bar { display: inline-block; height: .6em; background: var(--accent); border-radius: 2px; vertical-align: middle; }
.quick { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .6rem 0; }
.quick input { width: 4.5em; }
.chart { width: 100%; overflow-x: auto; }
.chart svg { width: 100%; height: auto; display: block; }
.hour-range { width: 100%; margin-top: .5rem; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .5rem; }
.kv div { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .5em .7em; }
.kv .k { color: var(--muted); font-size: .8rem; display: block; }
.kv .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.hint { background: var(--flash-bg); border-radius: 8px; padding: .5em .8em; margin: .4rem 0; font-size: .9rem; }
.sp-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.feed { display: flex; flex-direction: column; gap: .4rem; max-height: 50vh; overflow-y: auto; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .4em .7em; }
.msg .who { font-weight: 600; } .msg.leader { border-color: var(--accent); } .msg .when { color: var(--muted); font-size: .8rem; margin-left: .4em; }
dialog { background: var(--card); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; max-width: min(720px, 92vw); width: 100%; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.tranche { display: grid; grid-template-columns: 1fr 1fr auto; gap: .4rem; align-items: end; margin-bottom: .4rem; }
.rules h2 { margin-top: 1.2em; } .rules ul, .rules ol { padding-left: 1.3em; }
.scen-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .6rem; }
.scen-list li p { margin: .2em 0; }
.scen-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .5rem; }
.scen-day.played { opacity: .6; } .scen-day.today span { color: var(--accent); font-weight: 600; }
.rank-row.me { background: var(--flash-bg); }
.qr { display: block; background: #fff; color: #000; border-radius: 8px; padding: 6px; }
.watch .code-big { font-family: ui-monospace, monospace; font-size: 2.2rem; letter-spacing: .15em; margin: .2em 0; }
.watch-head { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.joincard { text-align: center; }
.scenario { font-size: 1.3rem; }
@media (max-width: 700px) { .watch-head { grid-template-columns: 1fr; } .tranche { grid-template-columns: 1fr 1fr auto; } }
.ready-dot { display: inline-block; width: .6em; height: .6em; border-radius: 50%; background: var(--muted); margin-right: .3em; }
.ready-dot.on { background: var(--ok); }
.legend { display: flex; flex-wrap: wrap; gap: .8rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: .9em; height: .9em; border-radius: 2px; vertical-align: middle; margin-right: .3em; }
.me { font-size: .95rem; }
