:root {
  --bg: #14121c; --panel: #1f1c2b; --panel2: #29253a; --line: #3a3550; --text: #ece9f5; --muted: #a39dbb;
  --accent: #d9b45a; --good: #3d7fe0; --out: #8cc8ff; --minion: #f0908f; --demon: #d6283c;
  --ok: #4fbf7a; --bad: #e0596b; --warn: #e0a84f;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f3ec; --panel: #ffffff; --panel2: #f0ebe0; --line: #d9d0bf; --text: #1e1a14; --muted: #6b6253;
    --accent: #9a6d10; --good: #1d5fc4; --out: #5aa8e8; --minion: #e47b7b; --demon: #b3172b;
    --ok: #227a48; --bad: #b8283c; --warn: #9a6410; color-scheme: light;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-height: 44px; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #1a1408; border-color: transparent; font-weight: 600; }
button.danger { border-color: var(--bad); color: var(--bad); }
button.sel { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--panel); }
button.icon { min-height: 36px; padding: 4px 10px; background: transparent; border: none; font-size: 20px; }
input, select, textarea { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%; }
textarea { min-height: 90px; font-family: ui-monospace, monospace; font-size: 13px; }
label { display: block; color: var(--muted); font-size: 14px; margin: 10px 0 4px; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.title { font-weight: 700; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; color: var(--muted); text-align: right; }
.status.bad { color: var(--bad); font-weight: 600; }
main { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); z-index: 6; }
.tabs button { border: none; background: transparent; color: var(--muted); }
.tabs button.on { color: var(--accent); background: var(--panel2); font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
.btns button { flex: 0 0 auto; min-width: 44px; padding: 8px 12px; }
.spacer { height: 10px; }

/* seating circle */
.circle { position: relative; width: min(100%, 520px); aspect-ratio: 1; margin: 4px auto 8px; }
.circle .centre { position: absolute; inset: 30%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; color: var(--muted); font-size: 13px; }
.circle .centre b { color: var(--text); font-size: 18px; }
.tok { position: absolute; width: 19%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%;
  background: var(--panel); border: 3px solid var(--good); display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2px; min-height: 0; text-align: center; overflow: hidden; }
.tok .num { font-size: 11px; color: var(--muted); line-height: 1; }
.tok .nm { font-size: 12px; font-weight: 600; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tok .ct { font-size: 10px; color: var(--muted); line-height: 1.1; }
.tok.townsfolk { --team: var(--good); }
.tok.outsider { --team: var(--out); }
.tok.minion { --team: var(--minion); }
.tok.demon { --team: var(--demon); }
.tok { border-color: var(--team, var(--good)); background: color-mix(in srgb, var(--team, var(--good)) 22%, var(--panel)); }
.tok.dead { opacity: .55; background: var(--panel2); }
.tok.dead .nm::before { content: "☠ "; }
.tok .ghost { position: absolute; top: 4%; right: 14%; width: 10px; height: 10px; border-radius: 50%; background: var(--text); }
.tok.pending { box-shadow: 0 0 0 3px var(--warn); }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); white-space: nowrap; }
.chip.townsfolk { border-color: var(--good); }
.chip.outsider { border-color: var(--out); }
.chip.minion { border-color: var(--minion); }
.chip.demon { border-color: var(--demon); }
.chip.unknown { opacity: .6; border-style: dashed; }
.chip.ok { background: color-mix(in srgb, var(--ok) 25%, transparent); border-color: var(--ok); }
.chip.no { opacity: .45; text-decoration: line-through; }
.chip.maybe { border-style: dashed; border-color: var(--warn); }

.seatlist .seat { display: grid; grid-template-columns: 2.2em 1fr; gap: 6px 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.seatlist .seat:last-child { border-bottom: none; }
.seat .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.seat .who { font-weight: 600; }
.seat .who .tag { font-weight: 400; font-size: 12px; margin-left: 6px; padding: 1px 6px; border-radius: 6px; }
.tag.evil { background: color-mix(in srgb, var(--minion) 35%, transparent); }
.seatlist .seat { border-left: 4px solid var(--team, var(--good)); padding-left: 8px; }
.seat.townsfolk { --team: var(--good); } .seat.outsider { --team: var(--out); } .seat.minion { --team: var(--minion); } .seat.demon { --team: var(--demon); }
.tag.demon { background: color-mix(in srgb, var(--demon) 40%, transparent); }
.tag.dead { background: var(--panel2); }

.claimrow { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; margin: 6px 0; }
.claimrow .c { color: var(--muted); font-size: 14px; text-align: right; }
.claimrow.done .c { color: var(--text); }
.claimrow.done { border-color: var(--ok); }

.verdict { padding: 10px 12px; border-radius: 10px; margin: 10px 0; font-weight: 600; }
.verdict.ok { background: color-mix(in srgb, var(--ok) 22%, transparent); border: 1px solid var(--ok); }
.verdict.no { background: color-mix(in srgb, var(--bad) 22%, transparent); border: 1px solid var(--bad); }
.verdict.unk { background: color-mix(in srgb, var(--warn) 22%, transparent); border: 1px solid var(--warn); }
.verdict.busy { background: var(--panel2); border: 1px solid var(--line); font-weight: 400; }

.log li { padding: 6px 0; border-bottom: 1px solid var(--line); list-style: none; }
.log { padding: 0; margin: 0; }
.log .ph { color: var(--accent); font-weight: 600; margin-top: 10px; border-bottom: none; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { background: var(--panel); width: 100%; max-width: 640px; max-height: 92dvh; overflow: auto; border-radius: 16px 16px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); border: 1px solid var(--line); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -12px; background: var(--panel); padding: 4px 0 8px; }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
details { margin: 10px 0; }
summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
table.ex { width: 100%; border-collapse: collapse; font-size: 14px; }
table.ex td { padding: 4px 6px; border-bottom: 1px solid var(--line); }

/* full-screen "You are ..." reveal */
.reveal { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center; background: var(--bg); --team: var(--good);
  background-image: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--team) 45%, transparent), transparent 70%); cursor: pointer; }
.reveal[hidden] { display: none; }
.reveal.townsfolk { --team: var(--good); } .reveal.outsider { --team: var(--out); } .reveal.minion { --team: var(--minion); } .reveal.demon { --team: var(--demon); }
.reveal-seat { color: var(--muted); font-size: 18px; }
.reveal-you { font-size: 28px; color: var(--muted); }
.reveal-char { font-size: clamp(40px, 13vw, 84px); font-weight: 800; color: var(--text); line-height: 1.05; text-shadow: 0 2px 18px color-mix(in srgb, var(--team) 60%, transparent); }
.reveal-hint { position: absolute; bottom: calc(24px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 14px; }
.tag.locked { background: color-mix(in srgb, var(--accent) 30%, transparent); }
