:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151d;
  --line: #232837;
  --fg: #e8eaf0;
  --muted: #8b91a3;
  --blue: #4f8cff;
  --red: #ff5a6e;
  --accent: #c9d4ff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--fg); line-height: 1.5; min-height: 100vh; }
a { color: var(--accent); }
b.blue { color: var(--blue); }
b.red { color: var(--red); }
button, input { font: inherit; color: inherit; }
button {
  background: #1b2030; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { border-color: #3a4260; background: #20263a; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: #e8eaf0; color: #0b0d12; border-color: #e8eaf0; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #fff; }
.ghost { background: none; border: none; color: var(--muted); padding: 6px 0; font-size: .9rem; text-decoration: none; cursor: pointer; }
.ghost:hover { color: var(--fg); background: none; }
input {
  background: #0d1017; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; min-width: 0;
}
input:focus { outline: 2px solid #3d5bd9; outline-offset: -1px; }
kbd { font: 11px ui-monospace, monospace; opacity: .6; margin-left: 6px; }

/* Landing */
.landing { max-width: 560px; margin: 0 auto; padding: clamp(32px, 8vh, 96px) 16px 64px; }
.home { color: var(--muted); text-decoration: none; font-size: .9rem; }
.landing h1 { font-size: clamp(2.2rem, 7vw, 3.2rem); letter-spacing: -.03em; margin: 12px 0 8px; }
.lede { color: var(--muted); font-size: 1.05rem; margin: 0 0 32px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: grid; gap: 10px; }
.card label { font-size: .85rem; color: var(--muted); }
.card .primary { padding: 12px; font-size: 1rem; }
.hint { margin: 0; font-size: .85rem; color: var(--muted); }
.join { display: flex; gap: 8px; margin: 16px 0 40px; }
.rules h2 { font-size: 1rem; margin: 0 0 8px; }
.rules ol, .rules ul { padding-left: 20px; color: #c3c7d3; }
.rules li { margin: 6px 0; }

/* Game */
.game {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start;
  max-width: 1180px; margin: 0 auto; padding: 20px 16px;
}
.board-wrap { display: flex; justify-content: center; min-width: 0; }
#board { display: block; border-radius: 14px; touch-action: manipulation; cursor: crosshair; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px;
  display: grid; gap: 14px; position: sticky; top: calc(20px + env(safe-area-inset-top, 0px));
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.title { font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; letter-spacing: -.01em; }
.conn { font-size: .75rem; color: var(--muted); }
.conn.bad { color: #ffb35a; }

.players { display: grid; gap: 8px; }
.player {
  display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: #0e1118;
  transition: border-color .2s, box-shadow .2s;
}
.player.active { border-color: var(--seat); box-shadow: 0 0 0 1px var(--seat) inset; }
.player .swatch { width: 14px; height: 14px; border-radius: 4px; background: var(--seat); }
.player .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .name small { color: var(--muted); }
.player .count { font-variant-numeric: tabular-nums; font-weight: 600; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 6px; vertical-align: middle; background: #4a5068; }
.dot.on { background: #3ddc84; }

.status { margin: 0; min-height: 3em; }
.status .big { display: block; font-size: 1.25rem; font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions:empty { display: none; }
.invite { display: flex; gap: 8px; }
.invite input { font-size: .85rem; color: var(--muted); }
.meta { display: flex; justify-content: space-between; gap: 8px; font-size: .85rem; color: var(--muted); flex-wrap: wrap; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: #c3c7d3; cursor: pointer; }
.toggle input { width: auto; }
.you-row { display: grid; gap: 6px; }
.you-row label { font-size: .8rem; color: var(--muted); }
.rules.small { font-size: .88rem; color: #c3c7d3; }
.rules.small summary { cursor: pointer; color: var(--fg); }
.rules.small p { margin: 8px 0; }
.panel-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: #2a3045; border: 1px solid #3a4260; padding: 10px 16px; border-radius: 10px; font-size: .9rem;
  max-width: calc(100vw - 32px);
}

@media (max-width: 860px) {
  .game { grid-template-columns: 1fr; gap: 16px; padding-top: 12px; }
  .panel { position: static; }
}
