:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1d1b18;
  --muted: #6b665e;
  --border: #ddd8cf;
  --accent: #2f5bd8;
  --accent-text: #ffffff;
  --warn: #b86e00;
  --warn-bg: #fff3dc;
  --danger: #c62f2f;
  --ok: #2e8b4a;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1d1f22;
    --surface-2: #26292d;
    --text: #ecebe8;
    --muted: #9b9890;
    --border: #34373c;
    --accent: #6f93ff;
    --accent-text: #0e1220;
    --warn: #f0b04a;
    --warn-bg: #3a2c12;
    --danger: #ff6b6b;
    --ok: #5fcf83;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
[hidden] { display: none !important; }

/* ---- controls ---- */
input:not([type=radio]) {
  width: 100%;
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; margin-bottom: 14px; font-weight: 500; }
label > input { margin-top: 4px; }
.field { margin-bottom: 14px; }
button, .button {
  font: inherit;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover:not(:disabled) { filter: brightness(0.96); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.warn-btn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.danger-text { color: var(--danger); }
.big { width: 100%; padding: 12px; font-size: 1.05rem; }
.confirming { background: var(--danger) !important; border-color: var(--danger) !important; color: #fff !important; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.notice { background: var(--surface-2); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }

/* ---- landing ---- */
.hero { text-align: center; padding: 32px 0 16px; }
.hero h1 { font-size: 2.4rem; letter-spacing: -0.02em; }
.hero p { color: var(--muted); }
.recent-list { margin: 0; padding-left: 18px; }
.recent-list li { margin: 4px 0; }

/* ---- swatches & chips ---- */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.swatch {
  width: 34px; height: 34px; padding: 0;
  border-radius: 50%;
  background: var(--c);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.swatch.selected { box-shadow: 0 0 0 3px var(--text); }
.swatch:disabled { opacity: 0.15; }
.chip {
  display: inline-block; width: 11px; height: 11px;
  border-radius: 50%; background: var(--c);
  margin-right: 6px; vertical-align: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}
.tag {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  padding: 1px 6px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); margin-left: 6px;
}
.tag.you { background: var(--accent); color: var(--accent-text); }
.online { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--border); margin-right: 8px; vertical-align: 2px; }
.online.on { background: var(--ok); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.conn.ok { background: var(--ok); }

/* ---- links ---- */
.links summary { cursor: pointer; font-weight: 600; }
.link-row { margin-top: 12px; }
.copy-field { display: flex; gap: 6px; margin-top: 4px; }
.copy-field input { font-family: ui-monospace, monospace; font-size: 0.85rem; }

/* ---- lobby ---- */
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.lobby-grid .card { margin: 0; }
.player-list { margin: 0 0 12px; padding: 0; list-style: none; }
.player-list.ordered { counter-reset: n; }
.player-list li { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.player-list li:last-child { border-bottom: 0; }
.player-list.ordered li::before { counter-increment: n; content: counter(n); width: 26px; color: var(--muted); font-variant-numeric: tabular-nums; }
.reorder { margin-left: auto; display: flex; gap: 4px; }
.reorder button { padding: 2px 8px; font-size: 0.8rem; }
.segmented label { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 6px 0; }
.waiting { color: var(--muted); font-style: italic; }
body:not(.is-host) .host-only { display: none; }
body.is-host .guest-only { display: none; }

/* ---- board view ---- */
.banner { text-align: center; padding: 14px; margin-bottom: 12px; border-radius: var(--radius); }
.banner-main { font-size: 1.35rem; font-weight: 700; }
.banner.mine { background: var(--accent); color: var(--accent-text); animation: pulse 2s ease-in-out infinite; }
.banner.mine .muted { color: inherit; opacity: 0.8; }
@keyframes pulse { 50% { filter: brightness(1.12); } }
@media (prefers-reduced-motion: reduce) { .banner.mine { animation: none; } }

.pick-form { border: 2px solid var(--accent); }
.pick-form label { margin-bottom: 8px; }
.pick-row { display: flex; gap: 8px; }
.pick-row button { white-space: nowrap; }
.pick-row input { font-size: 1.05rem; }
.dup-warning { margin-top: 10px; padding: 10px; border-radius: 8px; background: var(--warn-bg); color: var(--text); }
.dup-warning button { margin-left: 8px; }

.host-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius); }
.up-next { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; margin-bottom: 12px; font-size: 0.92rem; }
.up-next .arrow { color: var(--muted); }

.complete { text-align: center; }
.complete .row { justify-content: center; }
.warn { color: var(--warn); }

.board-wrap { overflow-x: auto; margin-bottom: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.board { border-collapse: collapse; width: 100%; min-width: max-content; }
.board th, .board td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; }
.board thead th {
  padding: 10px 12px; text-align: left; white-space: nowrap;
  border-bottom: 3px solid var(--c); background: var(--surface);
  position: sticky; top: 0;
}
.board .round-col { width: 44px; text-align: center; color: var(--muted); font-weight: 600; position: sticky; left: 0; background: var(--surface); z-index: 1; padding: 6px; }
.board .dir { display: block; font-size: 0.75rem; font-weight: 400; }
.board td { min-width: 150px; max-width: 240px; vertical-align: top; }
/* Styling lives on the td itself: table cells always grow to fit their content. */
.board td.cell { padding: 8px 10px 10px 14px; height: 64px; }
.cell.filled { box-shadow: inset 4px 0 0 var(--c); cursor: pointer; }
.cell.filled:hover, .cell.filled:focus { background: var(--surface-2); outline: none; }
.pick-no { display: block; font-size: 0.72rem; color: var(--muted); }
.pick-text { display: block; font-weight: 600; overflow-wrap: anywhere; }
.struck { text-decoration: line-through; opacity: 0.6; }
.cell.current { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 0 0 0 2px var(--accent); }
.cell.current.filled { box-shadow: inset 4px 0 0 var(--c), inset 0 0 0 2px var(--accent); }
.on-clock { color: var(--accent); font-style: italic; font-weight: 600; }
.status-contested { background: var(--warn-bg); }
.badge { display: inline-block; margin-top: 4px; font-size: 0.75rem; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.badge.contest { background: var(--warn); color: #fff; }
.badge.kept { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.invalid { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.history { display: block; margin-top: 4px; font-size: 0.75rem; color: var(--muted); text-decoration: line-through; }

.log summary { cursor: pointer; font-weight: 600; }
.log ul { list-style: none; margin: 10px 0 0; padding: 0; max-height: 260px; overflow-y: auto; }
.log li { padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { position: relative; width: 100%; max-width: 460px; margin: 0; }
.modal-close { position: absolute; top: 10px; right: 10px; border: 0; background: none; font-size: 1.1rem; }
.modal-pick { font-size: 1.5rem; margin: 6px 0 10px; overflow-wrap: anywhere; padding-right: 24px; }
.status-line { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.status-line.status-contested { background: var(--warn-bg); color: var(--warn); }
.status-line.status-kept { color: var(--ok); }
.status-line.status-invalid { color: var(--danger); }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 8px; background: var(--danger); color: #fff;
  transition: 0.2s; z-index: 100; max-width: calc(100% - 32px);
}
.toast.ok { background: var(--ok); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .pick-row { flex-direction: column; }
  .board td { min-width: 130px; }
  .topbar .brand { display: none; }
}

/* ---- contests, votes, comments ---- */
.reason { display: block; margin-top: 4px; font-size: 0.82rem; font-style: italic; color: var(--warn);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.badge { margin-right: 4px; }
.badge.comments { background: var(--surface-2); color: var(--muted); }
textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); resize: vertical; margin: 6px 0 8px; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.contest-box { margin: 12px 0; padding: 12px; border-radius: 8px; background: var(--warn-bg); }
.contest-box.kept { background: var(--surface-2); }
.contest-box label { margin: 0; }
.contest-reason { margin: 0 0 10px; overflow-wrap: anywhere; }
.tally { display: grid; gap: 4px; margin-bottom: 10px; }
.tally > div { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.vote-label { font-weight: 700; }
.vote-label.remove { color: var(--danger); }
.vote-label.keep { color: var(--ok); }
.vote-prompt { margin: 0 0 6px; font-weight: 600; }
.vote { flex: 1; min-width: 120px; }
.vote.remove { border-color: var(--danger); color: var(--danger); background: var(--surface); }
.vote.keep { border-color: var(--ok); color: var(--ok); background: var(--surface); }
.vote.remove.chosen { background: var(--danger); color: #fff; }
.vote.keep.chosen { background: var(--ok); color: #fff; }
.host-ruling { margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--border); }
.comments { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.comments h3 { margin-bottom: 8px; }
.comments ul { list-style: none; margin: 0 0 10px; padding: 0; max-height: 240px; overflow-y: auto; }
.comments li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.comment-text { overflow-wrap: anywhere; }
.comment-form { display: flex; gap: 6px; }
.link-btn { border: 0; background: none; padding: 0 4px; color: var(--muted); font-size: 0.8rem; text-decoration: underline; }
.modal-box { max-height: calc(100vh - 32px); overflow-y: auto; }
.checkbox { display: flex; justify-content: center; align-items: center; gap: 6px; margin: 10px 0 0; font-weight: 400; }
