/* Go, a warm wooden board on quiet paper, black and white stones drawn in SVG. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1eee7;
  --card: #fffdf8;
  --ink: #1f2024;
  --muted: #74767d;
  --line: #e1dbcf;
  --wood: #e2b877;
  --wood-2: #d4a45f;
  --wood-3: #9c6f35;
  --grid: #4a3418;
  --black: #25262b;
  --white: #f6f3ec;
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #1f2024;
  --tut-bubble: #fffdf8;
  --tut-ink: #1f2024;
  --tut-muted: #74767d;
  --tut-dim: rgba(28, 20, 8, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(31, 32, 36, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, color .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .pt:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 12px; padding-bottom: 12px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.has-tally { padding-right: 8px; }
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.tally {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; background: var(--bg);
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px;
}
.tally .stone-icon.s1 { margin-left: 6px; }

.actions { display: flex; justify-content: center; }
.btn.act { min-width: 120px; }
.hint {
  justify-self: center; min-height: 22px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(3px); transition: opacity .25s, transform .25s;
}
.hint.show { opacity: 1; transform: none; }

/* ---------- stone icon (turn pill, game over) ---------- */
.stone-icon { display: inline-block; flex: none; width: 20px; height: 20px; border-radius: 50%; }
.stone-icon.s0 { background: radial-gradient(circle at 36% 32%, #5a5c63, var(--black) 62%); }
.stone-icon.s1 { background: radial-gradient(circle at 36% 32%, #fff, var(--white) 55%, #d6d0c4); box-shadow: inset 0 0 0 1px #cfc8ba; }
.stone-icon.sm { width: 14px; height: 14px; }
.stone-icon.none { background: var(--line); }

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board-frame {
  position: relative;
  width: min(100%, calc(100vh - 250px), 620px);
  aspect-ratio: 1;
  padding: 2.2%;
  border-radius: 14px;
  background:
    repeating-linear-gradient(88deg, rgba(120, 72, 20, .07) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(92deg, rgba(255, 240, 210, .09) 0 5px, transparent 5px 17px),
    linear-gradient(155deg, var(--wood), var(--wood-2));
  box-shadow: 0 6px 0 var(--wood-3), 0 16px 30px rgba(60, 40, 15, .25);
  user-select: none; -webkit-user-select: none;
}
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board-frame { width: min(100cqw, calc(100cqh - 10px), 620px); }
}
.board-svg { position: absolute; inset: 2.2%; width: 95.6%; height: 95.6%; display: block; overflow: visible; }
.points {
  position: absolute; inset: 2.2%;
  display: grid; grid-template-columns: repeat(var(--n, 9), minmax(0, 1fr)); grid-template-rows: repeat(var(--n, 9), minmax(0, 1fr));
}
.pt { border: 0; margin: 0; padding: 0; background: transparent; cursor: default; min-width: 0; min-height: 0; border-radius: 50%; }
.pt.can { cursor: pointer; }

.grid-line { stroke: var(--grid); stroke-width: .16; stroke-linecap: square; opacity: .8; }
.grid-edge { stroke: var(--grid); stroke-width: .3; fill: none; opacity: .85; }
.star { fill: var(--grid); opacity: .85; }
.stone { transform-box: fill-box; transform-origin: center; }
.stone.place { animation: place .26s cubic-bezier(.2, .9, .3, 1.25) both; }
@keyframes place { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.stone.gone { animation: gone .45s ease-in both; }
@keyframes gone { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(.7); } }
.stone.dead { opacity: .42; }
.stone.ghost { opacity: .5; pointer-events: none; }
.last-mark { fill: none; stroke-width: .55; }
.terr { pointer-events: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(31, 32, 36, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 238, 231, .55); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(31, 32, 36, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.caps { font-size: 13px; color: var(--muted); margin: 10px 4px 0; font-variant-numeric: tabular-nums; }
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(31, 32, 36, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.over-mark .stone-icon { width: 52px; height: 52px; box-shadow: 0 4px 10px rgba(0, 0, 0, .18); }
.over-title { font-size: 28px; font-weight: 800; }
.over-title.small { font-size: 22px; }
.over-sub { color: var(--muted); margin: 4px 0 20px; font-variant-numeric: tabular-nums; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 520px) {
  .bar { min-height: 50px; }
  .game { gap: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
@media (hover: hover) {
  .pt.can.p0:hover { background: radial-gradient(circle, rgba(37, 38, 43, .42) 0 42%, transparent 44%); }
  .pt.can.p1:hover { background: radial-gradient(circle, rgba(255, 253, 248, .7) 0 42%, transparent 44%); }
}
.btn.act.gone { visibility: hidden; }

/* The tutorial kit's first-visit chip sits over the turn pill instead of on top of the Pass button
   (it goes away once you make your first move). */
body > .tut-chip { top: calc(env(safe-area-inset-top, 0px) + 58px); bottom: auto; }

/* Online play (online.js): no New game while a friend is playing; a presence line under the turn. */
body.is-online #btn-new { display: none; }
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.net { color: var(--muted, #767a86); }
/* The online rows sit above How to play: they carry its divider (one line), and it joins them. */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online + #menu-leave + #menu-help, .menu-sheet #menu-leave + #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }
