:root {
  --bg: #0b1220;
  --bg2: #0f1a2e;
  --surface: #14213a;
  --surface2: #1a2a49;
  --line: #27395d;
  --text: #eef3fb;
  --muted: #9fb0cc;
  --turf: #22c55e;
  --turf-d: #15803d;
  --amber: #ffb020;
  --amber-ink: #3a2500;
  --danger: #ff6b6b;
  --mine: #1d4ed8;
  --radius: 14px;
  --display: "Barlow Condensed", "Arial Narrow", Impact, system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-scheme="dark"]) {
    --bg: #f3f6fb;
    --bg2: #e9eff8;
    --surface: #ffffff;
    --surface2: #eef3fa;
    --line: #d3ddec;
    --text: #0b1220;
    --muted: #4b5d7c;
    --turf: #15803d;
    --turf-d: #166534;
    --amber: #b45309;
    --amber-ink: #fff7e6;
    --danger: #c0262d;
    --mine: #1d4ed8;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 500px at 50% -10%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--body);
  min-height: 100vh;
}
a { color: var(--turf); }
.wrap { width: min(100% - 32px, 760px); margin-inline: auto; }
.wrap.wide { width: min(100% - 32px, 1040px); }
.display { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .02em; line-height: 1.02; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 2px solid transparent;
  font: 700 16px var(--body); text-decoration: none; cursor: pointer; color: #fff;
  background: var(--turf-d); transition: transform .12s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .cell:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.btn.amber { background: var(--amber); color: #1a1200; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-family: var(--display); font-weight: 800; font-size: 22px; text-transform: uppercase; letter-spacing: .03em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }

/* ---------- Board ---------- */
.head { padding: 6px 0 14px; }
.head h1 { margin: 0; font-size: clamp(34px, 9vw, 54px); word-break: break-word; }
.matchup { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-family: var(--display); font-weight: 700; font-size: 22px; text-transform: uppercase; letter-spacing: .03em; }
.matchup .vs { color: var(--amber); font-size: 15px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font: 700 13px var(--body); letter-spacing: .04em; text-transform: uppercase; border: 1px solid var(--line); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip.open { color: var(--turf); }
.chip.locked { color: var(--amber); }
.chip.drawn { color: #7cb5ff; }

.progress { margin: 4px 0 14px; }
.progress-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.bar { height: 10px; background: var(--surface2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--turf-d), var(--turf)); transition: width .5s cubic-bezier(.2, .8, .2, 1); }

.notice { padding: 12px 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); margin-bottom: 14px; font-size: 15px; }
.notice.warn { border-color: var(--amber); }
.notice strong { color: var(--amber); }

/* grid */
.gridbox { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 10px; }
.axis-top { text-align: center; font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; font-size: 15px; color: var(--amber); padding: 0 0 6px 8.2%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board { display: grid; grid-template-columns: 22px 1fr; gap: 4px; }
.axis-left { writing-mode: vertical-rl; transform: rotate(180deg); text-align: center; font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; font-size: 15px; color: var(--amber); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 3px; }
.hd { display: grid; place-items: center; aspect-ratio: 1; border-radius: 8px; background: var(--surface2); font: 800 clamp(15px, 4.4vw, 22px) var(--display); color: var(--amber); }
.hd.corner { background: transparent; }
.cell {
  position: relative; aspect-ratio: 1; display: grid; place-items: center; min-width: 0; padding: 1px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: 700 clamp(9px, 2.5vw, 12px)/1.05 var(--body); text-align: center; cursor: default; overflow: hidden;
  -webkit-tap-highlight-color: transparent; transition: background .2s, border-color .2s, transform .12s;
}
.cell .nm { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; word-break: break-all; }
.cell.free { background: transparent; border-style: dashed; color: var(--muted); }
.cell.free.can { cursor: pointer; border-color: var(--turf); }
.cell.free.can:hover { background: color-mix(in srgb, var(--turf) 18%, transparent); }
.cell.taken { background: var(--surface2); }
.cell.mine { background: var(--mine); border-color: #7da2ff; color: #fff; }
.cell.mine.can { cursor: pointer; }
.cell.pending { opacity: .6; }
.cell:active.can { transform: scale(.92); }
.cell.win { background: var(--amber); border-color: var(--amber); color: #1a1200; box-shadow: 0 0 0 2px var(--amber), 0 0 18px color-mix(in srgb, var(--amber) 60%, transparent); z-index: 1; }
.cell .tag { position: absolute; top: 0; right: 1px; font: 800 8px var(--body); letter-spacing: .02em; opacity: .85; }
.cell.pop { animation: pop .6s cubic-bezier(.2, 1.4, .3, 1); }
@keyframes pop {
  0% { transform: scale(.4); box-shadow: 0 0 0 0 var(--turf); }
  55% { transform: scale(1.18); box-shadow: 0 0 0 8px transparent; }
  100% { transform: scale(1); }
}
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--line); }
.legend .l-mine { background: var(--mine); } .legend .l-free { border-style: dashed; } .legend .l-win { background: var(--amber); }

.mybar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 12px 0; padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 15px; }
.mybar button { background: none; border: none; color: var(--turf); font: 600 15px var(--body); cursor: pointer; min-height: 40px; padding: 0 6px; text-decoration: underline; }

/* scores */
h2.sec { font-family: var(--display); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: 26px; margin: 26px 0 10px; }
.scores { display: grid; gap: 8px; }
.score { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.score .per { font: 800 24px var(--display); text-transform: uppercase; color: var(--amber); }
.score .pts { font: 800 22px var(--display); letter-spacing: .04em; }
.score .who { color: var(--muted); font-size: 14px; }
.score .who b { color: var(--text); font-size: 17px; }
.score.won { border-color: var(--amber); background: color-mix(in srgb, var(--amber) 11%, var(--surface)); }
.score.na .pts { color: var(--muted); }
.note { white-space: pre-wrap; word-break: break-word; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--turf); border-radius: var(--radius); }

.cta { margin: 26px 0; padding: 20px; border-radius: 18px; background: linear-gradient(135deg, var(--turf-d), #0e5a3a); color: #fff; display: grid; gap: 14px; }
.cta h3 { margin: 0; font-size: 30px; }
.cta p { margin: 0; opacity: .92; }
.cta .row { display: flex; gap: 10px; flex-wrap: wrap; }
.cta .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .5); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }

footer { padding: 26px 0 40px; color: var(--muted); font-size: 13px; text-align: center; }
footer a { color: var(--muted); }

/* dialog + toast */
dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); padding: 22px; width: min(92vw, 380px); }
dialog::backdrop { background: rgba(3, 8, 18, .7); }
dialog h3 { margin: 0 0 6px; font-size: 28px; }
dialog p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
dialog input { width: 100%; min-height: 48px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); color: var(--text); padding: 0 14px; font: 600 17px var(--body); }
dialog .row { display: flex; gap: 10px; margin-top: 14px; justify-content: flex-end; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); opacity: 0; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px; z-index: 50; max-width: 92vw; transition: opacity .25s, transform .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }

.state { text-align: center; padding: 60px 0; }
.state h1 { font-size: 44px; margin: 10px 0; }
.state p { color: var(--muted); }
.skeleton { height: 340px; border-radius: 18px; background: linear-gradient(100deg, var(--surface) 30%, var(--surface2) 50%, var(--surface) 70%); background-size: 200% 100%; animation: sk 1.4s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* board themes (field "theme") */
[data-theme="neon"] { --amber: #ff3df2; --turf: #2ef2ff; --turf-d: #0891b2; }
[data-theme="sunset"] { --amber: #ff8a3d; --turf: #ff5d73; --turf-d: #c2314a; }
[data-theme="ocean"] { --amber: #5eead4; --turf: #38bdf8; --turf-d: #0369a1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 720px) {
  .cell { font-size: 13px; }
  .grid { gap: 4px; }
  .board { grid-template-columns: 28px 1fr; }
}
