:root {
  --bg: #0b0d12;
  --panel: #131722;
  --panel-2: #1a2030;
  --line: #262e40;
  --text: #d7dce6;
  --muted: #8791a6;
  --gold: #f5c542;
  --green: #4ade80;
  --red: #f87171;
  --blue: #6ea8ff;
  --purple: #c084fc;
  --teal: #2dd4bf;
  --orange: #fb923c;
  --tile: #2b3449;
  --tile-hi: #3a4560;
  --tile-lo: #1b2233;
  --open: #121724;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.3; margin: 0; text-wrap: balance; }
h2 { font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 700; letter-spacing: 0.18em; font-size: 15px; }

.coin {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--bg);
  font-weight: 800;
  font-size: 13px;
  box-shadow: inset 0 0 0 2px var(--gold), inset 0 0 0 3.5px var(--bg);
}

.top nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--muted); padding: 4px 10px; border-radius: 6px; }
.top nav a:hover { color: var(--text); text-decoration: none; }
.top nav a.on { color: var(--gold); background: var(--panel); }

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }

.foot {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.primary { background: var(--gold); border-color: var(--gold); color: var(--bg); font-weight: 700; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); }
button.on { border-color: var(--gold); color: var(--gold); }
button:disabled { opacity: 0.45; cursor: default; }

.section { margin-top: 32px; }
.section > h2 { margin-bottom: 10px; }

.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(26px, 6vw, 44px); letter-spacing: 0.12em; }
.hero h1 .cur { color: var(--gold); animation: blink 1.1s steps(1) infinite; }
.hero p { color: var(--muted); max-width: 62ch; margin: 12px 0 0; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) {
  .hero h1 .cur, .badge.live::before { animation: none; }
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }

.connect { display: grid; gap: 8px; }
.connect .row { display: grid; grid-template-columns: 9.5em minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.connect code { min-width: 0; overflow-x: auto; white-space: nowrap; }
.connect .label { color: var(--muted); }
@media (max-width: 620px) {
  .connect .row { grid-template-columns: minmax(0, 1fr) auto; }
  .connect .label { grid-column: 1 / -1; }
}

code {
  font-family: var(--mono);
  background: var(--open);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
}

.list { display: grid; gap: 6px; }
.game-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.6fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}
.game-row:hover { border-color: var(--muted); text-decoration: none; }
.game-row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.game-row .what { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-row .score { font-variant-numeric: tabular-nums; text-align: right; min-width: 4.5em; }
.game-row > .badge { justify-self: end; }
@media (max-width: 620px) {
  .game-row { grid-template-columns: minmax(0, 1fr) auto auto; row-gap: 2px; }
  .game-row .who { grid-column: 1; grid-row: 1; }
  .game-row .score { grid-column: 2; grid-row: 1; }
  .game-row .badge { grid-column: 3; grid-row: 1; }
  .game-row .what { grid-column: 1 / -1; grid-row: 2; }
}

.empty { color: var(--muted); padding: 14px 0; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge.live { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 1.2s ease-in-out infinite; }
.badge.won { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 50%, transparent); }
.badge.lost { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); }
.badge.abandoned { color: var(--muted); }
.badge.tools { color: var(--orange); border-color: color-mix(in srgb, var(--orange) 50%, transparent); }
.badge.human { color: var(--teal); border-color: color-mix(in srgb, var(--teal) 50%, transparent); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; background: var(--panel); }
td:nth-child(2), th:nth-child(2), td.l, th.l { text-align: left; }
tr:last-child td { border-bottom: 0; }
tr.dim td { color: var(--muted); }
td.model { font-weight: 600; }
td.big { color: var(--gold); font-weight: 700; }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* game viewer */
.game-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.game-head h1 { font-size: 20px; }
.meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); margin-top: 6px; }
.meta b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; margin-top: 16px; align-items: start; }
.stage.wide { grid-template-columns: minmax(0, 1fr); }
.stage.wide .side { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
@media (max-width: 860px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .stage.wide .side { grid-template-columns: minmax(0, 1fr); }
}

.board-wrap { overflow-x: auto; padding: 12px; background: #0e1119; border: 1px solid var(--line); border-radius: 10px; }
.board {
  --cell: 30px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: 2px;
  width: max-content;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.board.wide { --cell: 28px; }
.board.complex { --cell: 34px; }
.board.complex.wide { --cell: 30px; }

.cell {
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.5);
  line-height: 1;
  background: #171c2a;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.035);
  color: var(--text);
  overflow: hidden;
}
.board.complex .cell { font-size: calc(var(--cell) * 0.4); }
.cell.h { background: var(--tile); box-shadow: inset 1.5px 1.5px 0 var(--tile-hi), inset -1.5px -1.5px 0 var(--tile-lo); }
.board.playable .cell.h, .board.playable .cell.num { cursor: pointer; }
.board.playable .cell.h:hover { background: var(--tile-hi); }
.cell.last { outline: 2px solid var(--gold); outline-offset: -1px; }
.cell.n1 { color: #6ea8ff; } .cell.n2 { color: #4ade80; } .cell.n3 { color: #f87171; } .cell.n4 { color: #c084fc; }
.cell.n5 { color: #fb923c; } .cell.n6 { color: #2dd4bf; } .cell.n7 { color: #e5e7eb; } .cell.n8 { color: #9ca3af; }
.cell.n0 { color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.cell.rad { color: var(--gold); }
.cell.k1 { color: #f87171; } .cell.k2 { color: #6ea8ff; } .cell.k3 { color: #c084fc; } .cell.k4 { color: #2dd4bf; }
.cell.flag { font-size: calc(var(--cell) * 0.42); }
.cell.mine { background: #241a2b; border-radius: 50%; }
.cell.boom { background: #b91c1c; color: #fff; border-radius: 50%; }
.cell.wrong { color: var(--red); }

.side { display: grid; gap: 12px; }
.controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.controls input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--gold); }
.log { max-height: 360px; overflow-y: auto; font-size: 12.5px; display: grid; gap: 1px; }
.log div { display: flex; gap: 8px; padding: 1px 4px; border-radius: 4px; color: var(--muted); }
.log div.cur { background: var(--panel-2); color: var(--text); }
.log .i { color: var(--muted); min-width: 2.6em; text-align: right; }
.log .boom { color: var(--red); } .log .win { color: var(--gold); } .log .refused { color: var(--orange); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; margin-top: 10px; }
.legend i { font-style: normal; font-weight: 700; }

.msg { min-height: 1.7em; color: var(--muted); margin-top: 8px; }
.msg.bad { color: var(--red); } .msg.good { color: var(--gold); }

.picker { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* rules */
.prose { max-width: 78ch; }
.prose h1 { font-size: 20px; margin: 28px 0 8px; }
.prose h2 { font-size: 14px; margin: 22px 0 6px; }
.prose p { margin: 8px 0; }
.prose ul, .prose ol { margin: 6px 0; padding-left: 22px; }
.prose li { margin: 3px 0; }
