:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #d9dee6;
  --text: #17202a;
  --text-dim: #5b6776;
  --accent: #0d9488;
  --danger: #dc2626;
  --warn: #b45309;
  --p-mine: #0d9488;
  --p-mine-dim: #99e0d8;
  --p-theirs: #ea580c;
  --p-theirs-dim: #fdc9a5;
  --board-bg: #eef1f5;
  --hex-plain: #dde3ea;
  --hex-edge: #c5cdd8;
  --hex-rock: #8a94a3;
  --hex-well: #7c3aed;
  --highlight: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171e26;
    --surface-2: #1f2832;
    --border: #2b3643;
    --text: #e6edf3;
    --text-dim: #93a1b1;
    --accent: #2dd4bf;
    --danger: #f87171;
    --warn: #fbbf24;
    --p-mine: #14b8a6;
    --p-mine-dim: #115e59;
    --p-theirs: #f97316;
    --p-theirs-dim: #7c2d12;
    --board-bg: #131a21;
    --hex-plain: #24303c;
    --hex-edge: #33414f;
    --hex-rock: #4b5563;
    --hex-well: #a78bfa;
    --highlight: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
#app { display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); letter-spacing: -0.02em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--text-dim); }
.small { font-size: .875rem; }
.warn { color: var(--warn); }
.accent { color: var(--p-mine); }

header.top {
  display: flex; align-items: center; gap: 1rem; padding: .75rem max(16px, 3vw);
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
header nav { display: flex; gap: 1rem; flex: 1; }
header nav a { color: var(--text-dim); font-weight: 600; }
header nav a:hover { color: var(--text); text-decoration: none; }
.who { margin-left: auto; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .7rem; border-radius: 999px; background: var(--surface-2); color: var(--text); font-weight: 600; font-size: .9rem; }
.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; background: var(--text-dim); }
.dot.mine { background: var(--p-mine); }
.dot.theirs { background: var(--p-theirs); }
.dot.online { background: #22c55e; }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 1.5rem max(16px, 3vw) 2rem; }
footer { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; padding: 1.25rem 16px; color: var(--text-dim); font-size: .85rem; border-top: 1px solid var(--border); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .05s, background .15s, border-color .15s; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--text-dim); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--p-mine); border-color: var(--p-mine); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.big { padding: .8rem 1.4rem; font-size: 1.05rem; }
.btn.small { padding: .3rem .65rem; font-size: .875rem; }
.btn.on { background: var(--highlight); color: #fff; border-color: var(--highlight); }
.btn.grow { flex: 1; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
button.link.danger { color: var(--danger); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row.spread { justify-content: space-between; }

.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 2rem; align-items: center; margin-bottom: 2rem; }
.hero .lead { font-size: 1.1rem; color: var(--text-dim); max-width: 34rem; }
.hero-board { width: 100%; aspect-ratio: 1.1; }
.cta { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card p { color: var(--text-dim); flex: 1; }
.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 2rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.profile .stats { grid-template-columns: repeat(4, 1fr); margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--text-dim); font-size: .85rem; }

.list { display: flex; flex-direction: column; gap: .4rem; }
.match-row { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; padding: .6rem .8rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); color: var(--text); margin-bottom: .4rem; }
a.match-row:hover { text-decoration: none; border-color: var(--text-dim); }
.match-row .go { margin-left: auto; }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 6px; background: var(--surface-2); color: var(--text-dim); }
.tag.live { background: #dc2626; color: #fff; }
.tag.staked, .tag.payout { background: #fef3c7; color: #92400e; }
.tag.ranked { background: #dbeafe; color: #1e40af; }
.tag.win { background: #d1fae5; color: #065f46; }
.tag.loss { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .tag.staked, .tag.payout { background: #422006; color: #fcd34d; }
  .tag.ranked { background: #172554; color: #93c5fd; }
  .tag.win { background: #052e16; color: #6ee7b7; }
  .tag.loss { background: #450a0a; color: #fca5a5; }
}

.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.table th, .table td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.table tr.me td { background: var(--surface-2); font-weight: 700; }

/* game */
body[data-page="match"] main { max-width: 1300px; padding-top: 1rem; }
.game { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.board-wrap { background: var(--board-bg); border-radius: var(--radius); border: 1px solid var(--border); }
canvas.board { display: block; width: 100%; height: min(78vh, 760px); touch-action: manipulation; cursor: pointer; }
.side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 72px; }
.hud, .controls { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; flex-direction: column; gap: .75rem; }
.turnline { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 1.25rem; }
.timer.urgent { color: var(--danger); }
.timebar-wrap { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.timebar { height: 100%; background: var(--highlight); transition: width .25s linear; }
.seat { padding: .6rem .75rem; border-radius: 10px; background: var(--surface-2); border-left: 4px solid var(--text-dim); }
.seat.mine { border-left-color: var(--p-mine); }
.seat.theirs { border-left-color: var(--p-theirs); }
.seat .name { display: flex; align-items: center; gap: .4rem; font-weight: 700; }
.seat .ready { margin-left: auto; font-size: .78rem; color: #16a34a; font-weight: 700; }
.seat .nums { display: flex; gap: 1rem; color: var(--text-dim); font-variant-numeric: tabular-nums; margin-top: .2rem; }
.seat .nums span { display: inline-flex; align-items: center; gap: .25rem; }
.icon { display: inline-flex; }
.energy b { font-size: 2rem; font-variant-numeric: tabular-nums; }
.brushes { display: flex; gap: .4rem; }
.locked { font-weight: 600; color: var(--text-dim); }
.end h2 { font-size: 1.8rem; }
.end.won h2 { color: var(--p-mine); }
.end.lost h2 { color: var(--p-theirs); }
.end .elo { font-weight: 700; font-size: 1.1rem; }
input[type="range"] { width: 100%; }

/* lobby */
.lobby { max-width: 640px; margin: 0 auto; text-align: center; }
.lobby .row { justify-content: center; }
.code { display: inline-block; font-family: ui-monospace, monospace; font-weight: 700; letter-spacing: .15em; background: var(--surface-2); padding: .2rem .6rem; border-radius: 8px; margin-bottom: .5rem; }
.players { display: flex; align-items: stretch; gap: .75rem; margin: 1.5rem 0; }
.slot { flex: 1; padding: 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; gap: .3rem; justify-content: center; }
.slot.mine { border-top: 4px solid var(--p-mine); }
.slot.theirs { border-top: 4px solid var(--p-theirs); }
.slot.empty { color: var(--text-dim); border-style: dashed; }
.vs { align-self: center; font-weight: 800; color: var(--text-dim); }
.pay { font-size: .8rem; color: var(--warn); }
.pay.ok { color: #16a34a; }
.share { display: flex; gap: .5rem; margin-bottom: 1rem; }
.share input { flex: 1; min-width: 0; }

input, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; width: 100%;
}
textarea { resize: vertical; }
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; margin-bottom: .5rem; }
.check { display: flex; align-items: center; gap: .5rem; margin: .5rem 0 1rem; }
.check input { width: auto; }

dialog.modal { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1.25rem; width: min(92vw, 440px); box-shadow: var(--shadow); }
dialog.modal::backdrop { background: rgb(0 0 0 / 45%); }
dialog.modal textarea { margin-bottom: .5rem; }

.prose { max-width: 720px; }
.prose ul { padding-left: 1.25rem; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }

.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 50; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; transition: opacity .4s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }
.offline-banner { display: none; position: fixed; top: 0; left: 0; right: 0; background: var(--warn); color: #000; text-align: center; font-weight: 700; padding: .25rem; z-index: 60; }
body.offline .offline-banner { display: block; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; }
  .hero-board { max-height: 260px; order: -1; }
  .cards { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .game { grid-template-columns: 1fr; }
  .side { position: static; }
  canvas.board { height: min(62vh, 92vw); }
  header nav { gap: .75rem; font-size: .9rem; }
  .profile .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  header.top { gap: .5rem; flex-wrap: wrap; }
  .brand > span:not(.icon) { display: none; }
  .who .btn { padding: .35rem .6rem; font-size: .8rem; }
  .players { flex-direction: column; }
  .vs { display: none; }
}
