/* Layout: one phone column — header, the thread-track of rooms, then the stage for this player's role. */
:root {
  --bg: #EEEDF3; --surface: #FFFFFF; --ink: #1A1924; --muted: #5F5D6E; --line: #D6D3E1;
  --thread: #A86A12; --thread-soft: #F5E8D3; --ok: #157A47; --warn: #C2410C;
  --blue: #2563EB; --red: #DC2626; --on-team: #FFFFFF; --ring: #FFFFFF;
  --blue-soft: #E4ECFD; --red-soft: #FCE6E6;
  --display: "Unbounded", "Manrope", system-ui, sans-serif;
  --body: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #13121A; --surface: #1E1D28; --ink: #F2F0F8; --muted: #A9A6BA; --line: #353341;
    --thread: #E3A646; --thread-soft: #3A2D18; --ok: #2EB36B; --warn: #FB8A3C; --ring: #13121A;
    --blue-soft: #1B2647; --red-soft: #3A1C1E;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--thread); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; }
h2 { font-size: clamp(1.2rem, 5.4vw, 1.55rem); line-height: 1.2; font-weight: 800; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.app {
  max-width: 34rem; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top .brand-s { font-family: var(--display); font-weight: 800; font-size: 0.95rem; margin-right: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 0.8rem; font-weight: 700; min-height: 32px; }
.chip.t0 { border-color: var(--blue); }
.chip.t1 { border-color: var(--red); }
button.chip { min-height: 36px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.dot.off { background: var(--muted); opacity: 0.5; }
.dot.lost { background: var(--warn); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.eyebrow { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stage { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.stage > .actions:last-child { margin-top: auto; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.btn { min-height: 56px; border-radius: var(--r); border: 0; padding: 10px 16px; font-weight: 800; font-size: 1.08rem; background: var(--ink); color: var(--bg); width: 100%; line-height: 1.2; }
.btn.t0 { background: var(--blue); color: var(--on-team); }
.btn.t1 { background: var(--red); color: var(--on-team); }
.btn.ok { background: var(--ok); color: #FFFFFF; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); }
.btn.quiet { min-height: 44px; font-size: 0.95rem; background: transparent; color: var(--muted); border: 1px dashed var(--line); }
.btn.small { min-height: 44px; font-size: 0.95rem; width: auto; padding: 8px 14px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.reason { font-size: 0.88rem; font-weight: 700; color: var(--warn); text-align: center; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-weight: 700; font-size: 0.95rem; }
input[type="text"], input[inputmode] {
  min-height: 52px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); padding: 8px 14px; font-size: 1.05rem; font-weight: 700; width: 100%; min-width: 0;
}
input:focus { border-color: var(--thread); outline: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg.two { grid-template-columns: repeat(2, 1fr); }
.seg button { min-height: 50px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); font-weight: 800; }
.seg button small { display: block; font-size: 0.72rem; font-weight: 600; opacity: 0.8; }
.seg button[aria-pressed="true"] { border-color: var(--thread); background: var(--thread); color: var(--surface); }
.seg button:disabled { opacity: 0.6; cursor: default; }

/* home */
.brand { display: flex; align-items: center; gap: 12px; padding-top: 8px; }
.brand h1 { font-size: clamp(1.8rem, 8.5vw, 2.5rem); font-weight: 800; line-height: 1.05; }
.brand svg { flex: 0 0 auto; width: 56px; height: 56px; }
.or { text-align: center; color: var(--muted); font-weight: 700; font-size: 0.85rem; }
.back { align-self: flex-start; display: inline-flex; align-items: center; min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 700; font-size: 0.9rem; text-decoration: none; }
.mode {
  display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; text-align: left; width: 100%;
  padding: 18px 16px; border-radius: var(--r); border: 2px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
}
.mode:hover, .mode:focus-visible { border-color: var(--thread); }
.mode:active { transform: translateY(1px); }
.mode-i { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--thread-soft); color: var(--thread); }
.mode-i svg { width: 34px; height: 34px; }
.mode-b { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mode-t { font-family: var(--display); font-weight: 800; font-size: 1.2rem; line-height: 1.2; }
.mode-d { font-size: 0.92rem; color: var(--muted); line-height: 1.4; }

/* lobby */
.code { font-family: var(--display); font-weight: 800; font-size: clamp(2.6rem, 15vw, 3.6rem); letter-spacing: 0.08em; line-height: 1; font-variant-numeric: tabular-nums; }
.share { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.qr { width: 132px; height: 132px; background: #FFFFFF; padding: 6px; border-radius: 10px; }
.qr img, .qr canvas { width: 100% !important; height: 100% !important; }
.link { font-size: 0.8rem; color: var(--muted); overflow-wrap: anywhere; user-select: all; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; border: 2px solid transparent; }
.team.t0 { background: var(--blue-soft); border-color: var(--blue); }
.team.t1 { background: var(--red-soft); border-color: var(--red); }
.team h3 { font-size: 0.95rem; display: flex; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.plist li { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 0.92rem; min-width: 0; }
.plist li span.n { overflow-wrap: anywhere; min-width: 0; }
.tag { font-size: 0.7rem; font-weight: 800; padding: 2px 7px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; color: var(--muted); }
.tag.ok { color: var(--ok); }
.tag.bad { color: var(--warn); }
.tag.gold { color: var(--thread); }
details.rules summary { cursor: pointer; font-weight: 800; }
details.rules ul { margin: 8px 0 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }

/* board */
.board { display: flex; flex-direction: column; gap: 8px; }
.board-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.round { font-family: var(--display); font-weight: 800; font-size: 1rem; }
.exit { font-size: 0.85rem; font-weight: 700; color: var(--thread); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.85rem; font-weight: 700; }
.legend span { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.legend b { overflow-wrap: anywhere; }
.track { position: relative; display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.track::before { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: var(--thread); opacity: 0.55; transform: translateY(-50%); }
.cell { position: relative; z-index: 1; min-height: 58px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 4px 2px 6px; }
.cell.top { border: 2px solid var(--thread); }
.cell.gone { background: repeating-linear-gradient(135deg, var(--surface) 0 5px, var(--line) 5px 7px); border-style: dashed; }
.cell .n { font-family: var(--display); font-weight: 600; font-size: 0.8rem; color: var(--muted); }
.cell.top .n { color: var(--thread); }
.cell.gone .n { text-decoration: line-through; opacity: 0.7; }
.marks { display: flex; gap: 2px; min-height: 22px; }
.mk { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 0.7rem; color: var(--on-team); box-shadow: 0 0 0 2px var(--ring); flex: 0 0 auto; }
.mk.t0 { background: var(--blue); }
.mk.t1 { background: var(--red); border-radius: 5px; }
.legend .mk, .team .mk, .chip .mk { width: 18px; height: 18px; font-size: 0.6rem; box-shadow: none; }

/* word */
.wordbox { padding: 18px 12px; text-align: center; border: 2px dashed var(--thread); border-radius: var(--r); background: var(--surface); display: flex; flex-direction: column; gap: 8px; }
.word { font-family: var(--display); font-weight: 800; white-space: nowrap; overflow: hidden; line-height: 1.15; font-size: 52px; }
.note { font-size: 0.9rem; color: var(--muted); line-height: 1.35; text-wrap: pretty; }
.handoff { border-radius: var(--r); padding: 18px 16px; color: var(--on-team); display: flex; flex-direction: column; gap: 8px; }
.handoff.t0 { background: var(--blue); }
.handoff.t1 { background: var(--red); }
.handoff.draw { background: var(--ink); color: var(--bg); }
.handoff .eyebrow { color: inherit; opacity: 0.85; }

/* prep */
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { width: 100%; border-radius: var(--r); border: 2px dashed var(--line); background: var(--surface); padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 4px; text-align: center; }
.choice .pick { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.choice.on { border: 3px solid var(--thread); background: var(--thread-soft); }
.choice.on .pick { color: var(--thread); }
.choice:disabled { cursor: default; }
.counter { font-family: var(--display); font-weight: 800; }
.counter.ok { color: var(--ok); }
.counter.bad { color: var(--warn); }
.addrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.drafts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.draft { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 6px 6px 6px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.draft.sel { border-color: var(--thread); background: var(--thread-soft); }
.draft .tick { width: 36px; height: 36px; border-radius: 9px; border: 2px solid var(--line); background: var(--surface); font-weight: 800; color: var(--thread); }
.draft.sel .tick { border-color: var(--thread); background: var(--thread); color: var(--surface); }
.draft .txt { min-width: 0; display: flex; flex-direction: column; }
.draft .txt b { font-size: 1.05rem; overflow-wrap: anywhere; }
.draft .txt span { font-size: 0.78rem; color: var(--muted); }
.draft .del { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 1.1rem; }
.progress { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; }

/* timer */
.timer { text-align: center; gap: 6px; }
.count { font-family: var(--display); font-weight: 800; font-size: clamp(4.5rem, 30vw, 8rem); line-height: 1; font-variant-numeric: tabular-nums; }
.count.low { color: var(--warn); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.bar { height: 14px; border-radius: 7px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--thread); transition: width 0.25s linear; }
.bar.low i { background: var(--warn); }
.big .btn { min-height: 70px; font-size: 1.2rem; }
.trapbtns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.trapbtn { min-height: 54px; border-radius: 12px; border: 2px solid var(--warn); background: var(--surface); color: var(--ink); font-weight: 800; font-size: 1rem; overflow-wrap: anywhere; padding: 6px; }
.btn.trap { background: var(--warn); color: #FFFFFF; min-height: 76px; font-size: 1.35rem; font-family: var(--display); }
.trapchips { display: flex; flex-wrap: wrap; gap: 6px; }
.trapchips span { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); font-weight: 700; font-size: 0.9rem; }
.trapchips span.hit { border-color: var(--warn); color: var(--warn); }

.result-head { font-family: var(--display); font-weight: 800; font-size: clamp(1.5rem, 7vw, 2rem); }
.result-head.ok { color: var(--ok); }
.result-head.bad { color: var(--warn); }
.srow { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.srow:first-of-type { border-top: 0; }
.srow .w { font-weight: 700; overflow-wrap: anywhere; min-width: 0; }
.collapse { border: 2px dashed var(--warn); }
.hist { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.hist th, .hist td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.hist th { font-size: 0.75rem; color: var(--muted); font-weight: 800; }
.hist td { overflow-wrap: anywhere; }
.hist td:first-child { font-variant-numeric: tabular-nums; font-weight: 800; width: 3.6em; }
.cv { display: block; white-space: nowrap; font-size: 0.65rem; font-weight: 800; color: var(--warn); text-transform: uppercase; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; }
.overlay .app { min-height: auto; }
.overlay ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 6px; }
.overlay h3 { font-size: 1rem; margin-top: 6px; }
.dialog-wrap { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(10, 9, 16, 0.55); }
.dialog { width: 100%; max-width: 26rem; }
#toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; max-width: min(30rem, calc(100% - 32px)); background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 700; box-shadow: 0 6px 24px rgba(0,0,0,0.25); }

@media (max-width: 360px) {
  .teams { grid-template-columns: 1fr; }
  .mk { width: 19px; height: 19px; font-size: 0.62rem; }
  .cell { min-height: 54px; }
  .share { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { .count.low { animation: none; } .bar i { transition: none; } }
