:root {
  color-scheme: light;
  --bg: #f2f1ee;
  --surface: #ffffff;
  --surface-2: #e9e7e2;
  --line: #d6d3cc;
  --ink: #1d1f24;
  --ink-2: #63666f;
  --accent: #b5442e;
  --accent-ink: #ffffff;
  --felt: #2f6b53;
  --ok: #2f7d5a;
  --warn: #b57a1f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29,31,36,.08), 0 8px 24px rgba(29,31,36,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15171c;
    --surface: #1e2128;
    --surface-2: #272b34;
    --line: #333844;
    --ink: #e8e6e1;
    --ink-2: #9a9fad;
    --accent: #e4674a;
    --accent-ink: #1a1207;
    --felt: #3d8a6b;
    --ok: #4cae82;
    --warn: #d6a44a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171c;
  --surface: #1e2128;
  --surface-2: #272b34;
  --line: #333844;
  --ink: #e8e6e1;
  --ink-2: #9a9fad;
  --accent: #e4674a;
  --accent-ink: #1a1207;
  --felt: #3d8a6b;
  --ok: #4cae82;
  --warn: #d6a44a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { margin: 0; font-weight: 600; text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-2); }
.eyebrow {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger:hover { color: var(--accent); border-color: var(--accent); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--ink-2); }
.field input, .field select, textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  width: 100%;
}
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-bottom: 14px; }

/* ---------- gate ---------- */
.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(380px, 100%);
}
.gate-card h1 { font-size: 24px; margin-bottom: 4px; }
.gate-card p { margin: 0 0 20px; font-size: 14px; }
.gate-card .btn { width: 100%; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chip {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--surface-2); border-radius: 8px; flex: none;
}
.room-name {
  border: 1px solid transparent; background: transparent;
  font-weight: 600; font-size: 16px; padding: 5px 8px; border-radius: 8px;
  min-width: 0; width: 100%; max-width: 320px;
}
.room-name:hover, .room-name:focus { border-color: var(--line); }
.topbar-right { display: flex; align-items: center; gap: 6px; flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-right: 4px; }
.dot.live { background: var(--ok); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  align-items: start;
}
.tasks {
  border-right: 1px solid var(--line);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  height: calc(100dvh - 52px);
  position: sticky; top: 52px;
}
.pane-head { display: flex; align-items: baseline; justify-content: space-between; }
.pane-head h2 { font-size: 15px; }
.counter { font-size: 12px; color: var(--ink-2); font-family: "IBM Plex Mono", monospace; }
.task-form { display: grid; gap: 8px; }
.task-form textarea { resize: vertical; min-height: 72px; font-size: 14px; line-height: 1.4; }
.task-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: grid; gap: 6px; align-content: start; }
.task {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 9px 10px; border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; font-size: 14px;
}
.task:hover { background: var(--surface-2); }
.task.active { background: var(--surface); border-color: var(--accent); box-shadow: var(--shadow); }
.task.done .t-title { color: var(--ink-2); }
.t-title { overflow-wrap: anywhere; }
.t-right { display: flex; align-items: center; gap: 4px; }
.badge {
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 13px;
  background: var(--felt); color: #fff; border-radius: 6px; padding: 2px 7px;
}
.t-btn {
  border: none; background: none; cursor: pointer; color: var(--ink-2);
  padding: 2px 4px; border-radius: 5px; font-size: 13px; line-height: 1;
}
.t-btn:hover { background: var(--surface-2); color: var(--ink); }
.pane-foot { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- table ---------- */
.table { padding: 24px 24px 40px; display: grid; gap: 22px; align-content: start; }
.current { display: grid; gap: 4px; }
.current h2 { font-size: 22px; overflow-wrap: anywhere; }
.task-link { font-size: 13px; color: var(--accent); text-decoration: none; }
.task-link:hover { text-decoration: underline; }

.seats {
  display: flex; flex-wrap: wrap; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  min-height: 132px;
  align-content: center;
}
.seat { display: grid; justify-items: center; gap: 7px; width: 74px; }
.card-back {
  width: 54px; height: 76px; border-radius: 8px;
  display: grid; place-items: center;
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 20px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  transition: transform .18s ease, background .18s;
}
.seat.voted .card-back {
  background: var(--felt); border-color: var(--felt); color: #fff;
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 5px, transparent 5px 10px);
}
.seat.revealed .card-back {
  background: var(--surface); border-color: var(--ink-2); color: var(--ink);
  background-image: none; font-size: 22px;
}
.seat.high .card-back { border-color: var(--accent); color: var(--accent); }
.seat.low .card-back { border-color: var(--felt); color: var(--felt); }
.seat-name { font-size: 12px; text-align: center; overflow-wrap: anywhere; line-height: 1.25; }
.seat.offline { opacity: .4; }
.seat.observer .card-back { border-style: dashed; background: transparent; font-size: 14px; }

.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.timer {
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 20px;
  padding: 6px 12px; border-radius: var(--radius); background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}
.timer.low { background: var(--accent); color: var(--accent-ink); }

.result {
  display: flex; gap: 26px; flex-wrap: wrap; align-items: center;
  border-left: 3px solid var(--felt); padding: 12px 18px;
  background: var(--surface); border-radius: 0 var(--radius) var(--radius) 0;
}
.stat { display: grid; gap: 2px; }
.stat b { font-family: "IBM Plex Mono", monospace; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); }
.result .consensus { color: var(--ok); font-weight: 600; }
.result .spread { color: var(--warn); font-weight: 600; }
.save-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.deck { display: flex; flex-wrap: wrap; gap: 10px; }
.card {
  width: 62px; height: 88px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-family: "IBM Plex Mono", monospace; font-weight: 600; font-size: 22px;
  cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s;
}
.card:hover:not([disabled]) { transform: translateY(-6px); border-color: var(--ink-2); }
.card.picked { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); transform: translateY(-8px); }
.hint { font-size: 13px; color: var(--ink-2); margin: 0; }

/* ---------- dialog / toast ---------- */
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 0; box-shadow: var(--shadow); width: min(420px, 92vw); }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg-body { padding: 22px; }
.dlg-body h3 { margin-bottom: 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px;
  font-size: 14px; z-index: 50;
}

.only-mobile { display: none; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .tasks { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); max-height: 60vh; }
  .tasks[hidden] { display: none; }
  .table { padding: 18px 16px 32px; }
  .only-mobile { display: inline-block; }
  .card { width: 54px; height: 76px; font-size: 19px; }
  .seat { width: 64px; }
  .card-back { width: 46px; height: 66px; font-size: 17px; }
  .result { gap: 16px; padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
