:root {
  --bg: #0e1613;
  --bg2: #13201b;
  --card: #18271f;
  --line: #2a3d33;
  --text: #e9efe9;
  --muted: #93a79b;
  --gold: #d9a94e;
  --gold2: #f0c873;
  --good: #5fcf8a;
  --bad: #ef6b5e;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -200px, #1d3328 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--gold2); }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); z-index: 5;
}
.brand { font-family: var(--serif); font-size: 22px; text-decoration: none; color: var(--text); letter-spacing: .5px; }
.brand span { color: var(--gold); }
.who { color: var(--muted); font-size: 14px; margin-left: auto; margin-right: 10px; }
.topbar select.lang { padding: 4px 8px; font-size: 14px; }

main { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0 0 10px; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.hero { text-align: center; padding: 18px 0 8px; }
.hero p { margin: 0 auto; max-width: 420px; }

.btn {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 10px;
  padding: 9px 14px; cursor: pointer; transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1b1408; border-color: var(--gold); font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: var(--gold2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 14px; }

input.field, select.field {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0;
}
input.field:focus, select.field:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
input.code { text-transform: uppercase; letter-spacing: 4px; width: 110px; text-align: center; }

.games { display: grid; gap: 10px; }
.game {
  display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start;
}
.game .icon {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  background: var(--bg); border: 1px solid var(--line); color: var(--gold); font-size: 22px;
}
.game h3 { margin: 0; font-size: 18px; }
.game .meta { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.game .actions { margin-top: 10px; }
.game.soon { opacity: .55; }
.tag { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }

/* room */
.roomcode { font-family: ui-monospace, Consolas, monospace; font-size: 26px; letter-spacing: 6px; color: var(--gold2); }
.players { display: grid; gap: 6px; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--bg2); }
.player .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.player.off { opacity: .5; }
.player.off .dot { background: var(--muted); }
.player .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .score { font-weight: 700; color: var(--gold2); min-width: 2ch; text-align: right; }
.player.me .name { font-weight: 650; }
.badge { font-size: 11px; color: #1b1408; background: var(--gold); border-radius: 5px; padding: 0 6px; font-weight: 700; }
.settings { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; }
.settings label { color: var(--muted); }

.layout { display: grid; gap: 14px; }
@media (min-width: 720px) { .layout.side { grid-template-columns: 1fr 220px; align-items: start; } }

/* rectangle game */
.stage { text-align: center; }
.board-wrap { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 14px 0; flex-wrap: wrap; }
.board { display: grid; gap: 0; border: 2px solid var(--text); background: var(--text); }
.cell {
  width: var(--cs, 64px); height: var(--cs, 64px); display: grid; place-items: center;
  background: #f4efe2; color: #1c1a16; font-family: var(--serif); font-size: calc(var(--cs, 64px) * .48); font-weight: 600;
  outline: 1px solid #1c1a16; position: relative; transition: background .2s;
}
.cell.hl { background: var(--gold2); }
.target { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 18px; min-width: 96px; }
.target .lbl { font-size: 11px; letter-spacing: 2px; color: var(--muted); }
.target .val { font-family: var(--serif); font-size: 44px; line-height: 1.1; color: var(--gold2); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; background: var(--gold); width: 100%; transition: width .1s linear; }
.buzz {
  font-family: var(--serif); font-size: 30px; letter-spacing: 3px; padding: 16px 0; width: min(320px, 100%);
  border-radius: 16px; border: 0; cursor: pointer; background: linear-gradient(#e6b862, #b9862f); color: #1b1408;
  box-shadow: 0 6px 0 #7a5517, 0 10px 24px #0008;
}
.buzz:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 #7a5517; }
.buzz:disabled { filter: grayscale(.8); opacity: .5; cursor: not-allowed; }
.answer-row { display: flex; gap: 8px; justify-content: center; }
.answer-row input { width: 120px; font-size: 26px; text-align: center; }
.log { list-style: none; padding: 0; margin: 10px auto 0; max-width: 320px; }
.log li { display: flex; justify-content: space-between; padding: 4px 10px; border-radius: 8px; }
.log li.ok { color: var(--good); }
.log li.no { color: var(--bad); }
.big { font-family: var(--serif); font-size: 64px; color: var(--gold2); line-height: 1; }
.verdict { font-size: 20px; margin: 6px 0; }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* cube stack */
.cube-wrap { display: flex; justify-content: center; }
.cubeview { width: min(380px, 82vw); aspect-ratio: 1; cursor: grab; display: block; }
.cubeview:active { cursor: grabbing; }
.hgrid { display: inline-grid; gap: 3px; margin: 0 auto; font-variant-numeric: tabular-nums; }
.hgrid > div { width: 30px; height: 30px; display: grid; place-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 6px; font-weight: 650; }

/* six chambers */
.ring-wrap { display: flex; justify-content: center; }
.ring { position: relative; width: min(400px, 86vw); aspect-ratio: 1; }
.barrel {
  position: absolute; left: 50%; top: 50%; width: 30%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #3b4a43, #141c18); border: 2px solid var(--line);
  display: grid; place-items: center; text-align: center; padding: 6px;
}
.seat {
  position: absolute; transform: translate(-50%, -50%); width: 96px; text-align: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 4px; transition: border-color .2s, box-shadow .2s;
}
.seat.turn { border-color: var(--gold); box-shadow: 0 0 0 2px #d9a94e55, 0 0 18px #d9a94e44; }
.seat.me .sname { font-weight: 700; }
.seat.hit { border-color: var(--bad); background: #3a1915; }
.seat.safe { border-color: var(--good); }
.seat .sname { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chamber, .chip {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--gold); font-weight: 700; color: var(--gold2); margin: 0 auto 2px;
}
.chip { width: 22px; height: 22px; border-width: 1px; font-size: 12px; margin: 1px; }
.chip.loaded { background: var(--bad); color: #fff; border-color: var(--bad); }
.shot { font-weight: 800; letter-spacing: 1px; font-size: 13px; }
.seat.hit .shot { color: var(--bad); }
.seat.safe .shot { color: var(--good); }
.actions-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.btn.action { display: grid; text-align: left; gap: 2px; }
.credits { color: var(--gold2); font-size: 20px; }
.plainlog { list-style: none; padding: 0; margin: 6px 0 0; font-size: 14px; }
.plainlog li { padding: 3px 0; border-bottom: 1px solid var(--line); }
.known { width: 100%; border-collapse: collapse; font-size: 14px; }
.known th, .known td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.known th { color: var(--muted); font-weight: 500; }
.known .good { color: var(--good); }
.known .bad { color: var(--bad); }
@media (max-width: 420px) { .seat { width: 76px; } .seat .sname { font-size: 12px; } }

/* fence building */
.loop-wrap { display: flex; justify-content: center; }
.loopboard { width: min(440px, 90vw); aspect-ratio: 1; display: block; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.loopboard .dot { fill: var(--text); }
.loopboard .dot.bad { fill: var(--bad); }
.loopboard .clue { font: 600 0.55px var(--serif); fill: var(--text); text-anchor: middle; dominant-baseline: central; }
.loopboard .clue.done { fill: var(--muted); opacity: .6; }
.loopboard .clue.over { fill: var(--bad); }
.loopboard .edge.on { stroke: var(--gold2); stroke-width: 0.11; stroke-linecap: round; }
.loopboard .edge.sol { stroke: var(--good); }
.loopboard .cross { stroke: var(--bad); stroke-width: 0.045; stroke-linecap: round; opacity: .8; }
.loopboard .hit { stroke: transparent; stroke-width: 0.42; cursor: pointer; pointer-events: stroke; }
.loopboard .hit:hover { stroke: #d9a94e22; }

.results li { font-size: 18px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b1714; color: #ffd6d0;
  border: 1px solid #6b2d26; padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: 90vw;
}
.modal-bg { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 10; padding: 16px; }
.modal { max-width: 520px; width: 100%; max-height: 85dvh; overflow: auto; }
.modal ol { padding-left: 20px; }
.modal li + li { margin-top: 8px; }

/* ---------- Heavy Thirteen ---------- */
.piles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pile { --c: #c9584c; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: var(--radius); padding: 10px; min-height: 140px; display: flex; flex-direction: column; gap: 8px; }
.pile-g { --c: #4fa86a; }
.pile-b { --c: #4f86c9; }
.pile.hot { box-shadow: 0 0 0 2px var(--c); }
.pile-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.pile-head .danger { color: var(--bad); font-weight: 700; }
.stones { display: flex; flex-wrap: wrap-reverse; gap: 4px; align-content: flex-start; flex: 1; }
.stone { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px 10px 7px 11px; background: color-mix(in srgb, var(--c) 35%, #3a3f3c); border: 1px solid color-mix(in srgb, var(--c) 60%, transparent); font-weight: 700; }
.stone.new { animation: drop .45s ease-out; outline: 2px solid var(--gold2); }
@keyframes drop { from { transform: translateY(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
.chipdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; background: #888; }
.chipdot.c-r { background: #c9584c; }
.chipdot.c-g { background: #4fa86a; }
.chipdot.c-b { background: #4f86c9; }
.chipdot.c-w { background: conic-gradient(#c9584c, #d9a94e, #4fa86a, #4f86c9, #9a6bc9, #c9584c); }
.chipcount { margin-right: 10px; white-space: nowrap; }
.btn.stonebtn { width: 44px; height: 44px; padding: 0; font-weight: 700; font-size: 18px; }
.btn.sel { border-color: var(--gold2); background: color-mix(in srgb, var(--gold) 25%, var(--card)); }
.your-turn { border-color: var(--gold); }
.order li.now { color: var(--gold2); }
.order li.next { color: var(--muted); }
.order .bad { color: var(--bad); }
.stones-table td, .stones-table th { padding: 4px 6px; }
.stones-table tr.me td { color: var(--gold2); }
@media (max-width: 480px) {
  .pile { padding: 8px 6px; }
  .stone { width: 24px; height: 24px; font-size: 13px; }
}

/* ---------- Memory Poker ---------- */
.pcards { display: flex; gap: 6px; flex-wrap: wrap; }
.pcard { width: 48px; height: 66px; border-radius: 7px; background: #f4f1ea; color: #1b1b1b; display: grid; place-items: center; align-content: center; gap: 0; font-weight: 700; line-height: 1.05; border: 1px solid #c9c3b4; box-shadow: 0 1px 2px #0006; }
.pcard .rk { font-size: 19px; }
.pcard .st { font-size: 18px; }
.pcard.red { color: #c43b2f; }
.pcard.back { background: repeating-linear-gradient(45deg, #24473a 0 6px, #1c382e 6px 12px); border-color: var(--gold); }
.pcard.comm { opacity: .75; }
.pcards.mini .pcard { width: 30px; height: 42px; border-radius: 5px; }
.pcards.mini .pcard .rk, .pcards.mini .pcard .st { font-size: 13px; }
.pgrid-wrap { display: flex; justify-content: center; }
.pgrid { display: grid; grid-template-columns: repeat(4, auto); gap: 10px; }
.pslot { position: relative; display: grid; justify-items: center; gap: 2px; border-radius: 9px; padding: 3px; border: 2px solid transparent; }
.pgrid.picking .pslot { cursor: pointer; }
.pgrid.picking .pslot:hover { border-color: var(--line); }
.pslot.sel { border-color: var(--gold2); background: color-mix(in srgb, var(--gold) 18%, transparent); }
.pslot.win .pcard { outline: 3px solid var(--good); }
.pslot.best .pos { color: var(--good); font-weight: 700; }
.pslot .pos { font-size: 12px; color: var(--muted); }
.winrow td { color: var(--good); }
.gold { color: var(--gold2); }
@media (max-width: 480px) {
  .pgrid { gap: 6px; }
  .pcard { width: 44px; height: 60px; }
}

/* ---------- Piggy Bank ---------- */
.piggy-table { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.piggy-seat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 6px; }
.piggy-seat.turn { border-color: var(--gold); }
.piggy-seat.me b { color: var(--gold2); }
.piggy-seat .slots { display: grid; gap: 4px; }
.piggy-seat .slot { min-height: 30px; display: flex; align-items: center; }
.piggy-seat .slot.top { border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.piggy { display: inline-flex; align-items: center; gap: 6px; }
.pig { font-size: 22px; line-height: 1; }
.banktag { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.coinrow { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.coin { width: 18px; height: 18px; border-radius: 50%; display: inline-block; border: 2px solid #777; }
.coin.black { background: radial-gradient(circle at 35% 30%, #5a5a5a, #111 70%); border-color: #9a9a9a; }
.coin.white { background: #f3f1ea; border-color: #bbb; }
.lastadd .coin { width: 26px; height: 26px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper b { min-width: 22px; text-align: center; font-size: 18px; }
.btn.doubt { font-size: 22px; padding: 14px; width: 100%; background: var(--bad); border-color: var(--bad); color: #fff; }
.field.num { width: 64px; }

/* ---------- Wall Go ---------- */
.wallboard-wrap { display: flex; justify-content: center; padding: 10px; }
.wallboard { width: 100%; max-width: 480px; touch-action: manipulation; }
.wcell { fill: var(--bg2); stroke: var(--line); stroke-width: 1; }
.wcell.dest { stroke: var(--good); stroke-width: 2.5; cursor: pointer; }
.wcell.dest.brk { stroke: #e39a3b; stroke-dasharray: 5 3; }
.wall { stroke: #e9e3d2; stroke-width: 6; stroke-linecap: round; }
.wall.new { stroke: var(--gold2); }
.wall.broken { stroke: var(--bad); stroke-dasharray: 4 5; opacity: .7; }
.wall-slot { stroke: var(--gold); stroke-width: 10; stroke-linecap: round; opacity: .35; cursor: pointer; }
.wall-slot:hover { opacity: .7; }
.wall-slot.on { opacity: 1; stroke: var(--gold2); }
.trail { fill: none; stroke-width: 3; stroke-dasharray: 4 4; opacity: .6; }
.wpiece { stroke: #0007; stroke-width: 2; }
.wpiece.mine { cursor: pointer; stroke: #fff; stroke-width: 2; }
.wpiece.sel { stroke: var(--gold2); stroke-width: 4; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------- Equation Hi-Lo ---------- */
.good { color: var(--good); }
.bad { color: var(--bad); }
.pot { font-weight: 700; color: var(--gold2); }
.hilo-table { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.hilo-seat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 6px; }
.hilo-seat.turn { border-color: var(--gold); }
.hilo-seat.me b { color: var(--gold2); }
.hilo-seat.dim { opacity: .55; }
.hilo-seat .chips { font-size: 13px; color: var(--muted); }
.hilo-seat .hand { display: flex; gap: 4px; flex-wrap: wrap; }
.hcard { width: 30px; height: 40px; border-radius: 6px; display: inline-grid; place-items: center; font-weight: 800; font-size: 17px; border: 2px solid; box-shadow: 0 1px 2px #0006; }
.hcard.small { width: 26px; height: 34px; font-size: 15px; }
.hcard.gold { background: #f4d27a; color: #3b2a05; border-color: #b8902c; }
.hcard.silver { background: #dfe3e8; color: #26303a; border-color: #98a1ab; }
.hcard.bronze { background: #d39a6a; color: #3a1f0b; border-color: #96603a; }
.hcard.black { background: #2a2a2a; color: #f1f1f1; border-color: #8a8a8a; }
.hcard.special { background: #2d3f6b; color: #fff; border-color: #6f8fd6; }
.hcard.back { background: repeating-linear-gradient(45deg, #24473a 0 5px, #1c382e 5px 10px); color: var(--gold2); border-color: var(--gold); }
.hcard.mine-hidden { outline: 2px dashed var(--gold2); outline-offset: 1px; }
.tag.side.high { color: #f0a35e; border-color: #f0a35e; }
.tag.side.low { color: #6fb7f0; border-color: #6fb7f0; }
.tag.side.swing { color: #c58af0; border-color: #c58af0; }
.tag.good { color: var(--good); border-color: var(--good); }
.eqline { min-height: 52px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 6px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); }
.tokbtn { background: none; border: 0; padding: 2px; cursor: pointer; border-radius: 8px; }
.tokbtn:disabled { opacity: .3; cursor: default; }
.tokbtn.op { min-width: 40px; height: 44px; font-size: 22px; font-weight: 700; background: var(--card); border: 1px solid var(--line); color: var(--text); }
.tokbtn.op sub { font-size: 11px; color: var(--muted); }
.tokbtn.placed:hover { background: color-mix(in srgb, var(--bad) 25%, transparent); }
.tray { gap: 6px; }
.hop { font-size: 20px; font-weight: 700; padding: 0 3px; }
.heq { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.hilo-result { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: grid; gap: 6px; }
.hilo-result.won { border-color: var(--good); }
