:root {
  color-scheme: light;
  --canvas: #edf0eb;
  --surface: #fff;
  --ink: #19221f;
  --muted: #69736f;
  --line: #d5dbd7;
  --green: #2f6755;
  --wood: #d8ad68;
  --wood-dark: #795226;
  --black: #202522;
  --white: #f5f2e9;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { min-height: 100vh; background: var(--canvas); color: var(--ink); letter-spacing: 0; }
button, select { font: inherit; }
a, button, select { -webkit-tap-highlight-color: transparent; }
a:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid rgba(47, 103, 85, .24); outline-offset: 2px; }

.topbar { min-height: 70px; padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .96); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { position: relative; width: 36px; height: 36px; border-radius: 6px; background: var(--wood); box-shadow: inset 0 0 0 1px rgba(93, 60, 25, .25); }
.brand-mark i, .brand-mark b { position: absolute; width: 14px; height: 14px; border-radius: 50%; }
.brand-mark i { top: 6px; left: 6px; background: var(--black); }
.brand-mark b { right: 5px; bottom: 5px; border: 1px solid #aaa59b; background: var(--white); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; font-weight: 750; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .nav-link { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.icon-button { width: 38px; padding: 0; display: grid; place-items: center; cursor: pointer; font-size: 19px; }
.nav-link { padding: 0 12px; display: inline-flex; align-items: center; gap: 7px; text-decoration: none; font-size: 12px; font-weight: 780; }

.game-layout { width: min(1080px, calc(100% - 42px)); margin: 0 auto; padding: 34px 0 60px; display: grid; grid-template-columns: minmax(0, 700px) minmax(270px, 1fr); gap: 34px; align-items: start; }
.play-area { min-width: 0; }
.game-heading { min-height: 48px; margin-bottom: 16px; display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; }
.eyebrow, .section-heading p, .modal-kicker { margin: 0 0 5px; color: var(--green); font-size: 10px; font-weight: 850; }
h1 { margin: 0; font-size: 29px; line-height: 1.1; }
.turn-indicator { display: flex; align-items: center; gap: 9px; }
.turn-indicator small, .turn-indicator strong { display: block; }
.turn-indicator small { margin-bottom: 2px; color: var(--muted); font-size: 9px; }
.turn-indicator strong { min-width: 76px; font-size: 12px; }
.mini-stone { width: 25px; height: 25px; flex: 0 0 auto; border-radius: 50%; }
.mini-stone.black, .result-mark.black { background: radial-gradient(circle at 35% 30%, #515956, #171b19 68%); box-shadow: 0 2px 5px rgba(15, 18, 17, .28); }
.mini-stone.white, .result-mark.white { border: 1px solid #b9b5ab; background: radial-gradient(circle at 35% 30%, #fff, #dfddd6 72%); box-shadow: 0 2px 5px rgba(43, 46, 44, .16); }

.board-stage { position: relative; }
.board-toolbar { position: relative; z-index: 8; display: flex; justify-content: flex-end; gap: 7px; margin-bottom: 8px; }
.stage-action { min-height: 38px; padding: 0 13px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; cursor: pointer; }
.stage-action:disabled { opacity: .45; }
.record-actions { margin-top: 8px; }
.import-button { position: relative; display: grid; place-items: center; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 11px; font-weight: 760; overflow: hidden; }
.import-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.board-toolbar .icon-button { border-color: rgba(84, 55, 24, .28); background: rgba(255, 251, 241, .88); }
.board-shell { width: min(100%, 680px); aspect-ratio: 1; padding: 22px; border: 1px solid #9d713e; border-radius: 7px; background: var(--wood); box-shadow: 0 14px 34px rgba(49, 37, 23, .13), inset 0 0 0 4px rgba(255, 241, 205, .2); }
.gomoku-board { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); grid-template-rows: repeat(15, minmax(0, 1fr)); }
.intersection { position: relative; min-width: 0; min-height: 0; padding: 0; border: 0; background: transparent; cursor: pointer; }
.intersection::before, .intersection::after { content: ""; position: absolute; z-index: 0; background: rgba(84, 54, 24, .72); pointer-events: none; }
.intersection::before { top: 50%; left: 0; width: 100%; height: 1px; }
.intersection::after { top: 0; left: 50%; width: 1px; height: 100%; }
.intersection.edge-left::before { left: 50%; width: 50%; }
.intersection.edge-right::before { width: 50%; }
.intersection.edge-top::after { top: 50%; height: 50%; }
.intersection.edge-bottom::after { height: 50%; }
.intersection.star::marker { display: none; }
.intersection.star > i { position: absolute; z-index: 1; top: 50%; left: 50%; width: 5px; height: 5px; transform: translate(-50%, -50%); border-radius: 50%; background: var(--wood-dark); pointer-events: none; }
.stone { position: absolute; z-index: 3; inset: 8%; border-radius: 50%; pointer-events: none; }
.stone.black { background: radial-gradient(circle at 34% 29%, #59605d 0, #292e2c 36%, #131614 78%); box-shadow: 0 2px 4px rgba(35, 26, 17, .4); }
.stone.white { border: 1px solid rgba(126, 119, 105, .48); background: radial-gradient(circle at 34% 29%, #fff 0, #f1eee5 48%, #d7d4cc 86%); box-shadow: 0 2px 4px rgba(35, 26, 17, .25); }
.intersection.last .stone::after { content: ""; position: absolute; top: 50%; left: 50%; width: 24%; height: 24%; transform: translate(-50%, -50%); border-radius: 50%; background: #c74d40; }
.intersection.winning .stone { box-shadow: 0 0 0 3px #c45243, 0 2px 4px rgba(35, 26, 17, .35); }
.intersection:not(.occupied):not(:disabled):hover { background: radial-gradient(circle, rgba(49, 57, 53, .18) 0 31%, transparent 33%); }
.intersection:disabled { cursor: default; }
.board-caption { width: min(100%, 680px); min-height: 38px; padding: 8px 2px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 11px; }
.board-caption span:last-child { overflow: hidden; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

.board-stage.board-immersive { position: fixed; z-index: 100; inset: 0; min-height: 100vh; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); display: grid; place-content: center; justify-items: center; background: var(--canvas); overflow: auto; }
.board-stage.board-immersive .board-shell { width: min(92vw, 78vh, 760px); }
.board-stage.board-immersive .board-toolbar { position: fixed; top: max(14px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); }
.board-stage.board-immersive .board-caption { width: min(92vw, 78vh, 760px); }
.board-stage:fullscreen { display: grid; place-content: center; justify-items: center; min-height: 100dvh; padding: 66px 16px 20px; background: var(--canvas); overflow: auto; }
.board-stage:fullscreen .board-shell, .board-stage:fullscreen .board-caption { width: min(90vw, 72dvh, 760px); }
.board-stage:fullscreen .board-toolbar { position: fixed; top: 14px; right: 14px; }
.board-stage.board-immersive { min-height: 100dvh; padding-top: 66px; }
.board-stage.board-immersive .board-shell, .board-stage.board-immersive .board-caption { width: min(90vw, 72dvh, 760px); }
body.board-immersive-active { overflow: hidden; }

.game-sidebar { padding-top: 64px; }
.side-section { padding: 19px 0 21px; border-top: 1px solid var(--line); }
.side-section:last-child { border-bottom: 1px solid var(--line); }
.section-heading { margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.segmented-control { height: 44px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border: 1px solid var(--line); border-radius: 6px; background: #e3e7e4; }
.segmented-control button { border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 780; }
.segmented-control button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 5px rgba(25, 37, 33, .11); }
.bot-options { margin-top: 12px; }
.bot-options > label:first-child { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 780; }
.bot-options select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); font-size: 12px; }
.switch-control { margin-top: 12px; display: flex; align-items: center; gap: 8px; color: var(--ink); cursor: pointer; font-size: 11px; font-weight: 730; }
.switch-control input { width: 17px; height: 17px; margin: 0; accent-color: var(--green); }
.primary-button { width: 100%; min-height: 43px; margin-top: 12px; border: 1px solid var(--green); border-radius: 6px; background: var(--green); color: #fff; cursor: pointer; font-weight: 800; }
.primary-button:disabled { cursor: wait; opacity: .55; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-grid button, .text-button { min-height: 42px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-size: 11px; font-weight: 760; }
.action-grid button span { margin-right: 5px; font-size: 17px; }
.action-grid button:disabled { cursor: default; opacity: .42; }
.text-button { width: 100%; margin-top: 8px; color: var(--green); }
.record-list { margin: 0; }
.record-list div { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid #e2e6e3; }
.record-list div:last-child { border-bottom: 0; }
.record-list dt { color: var(--muted); font-size: 11px; }
.record-list dd { margin: 0; font-size: 13px; font-weight: 820; }
.local-note { margin: 13px 0 0; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 9px; }
.local-note span { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.move-list { max-height: 168px; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; overflow: auto; list-style: none; }
.move-list li { min-width: 0; padding: 5px 0; border-bottom: 1px solid #e2e6e3; color: var(--muted); font-size: 10px; }
.move-list li strong { margin-right: 6px; color: var(--ink); }
.move-list .empty-moves { grid-column: 1 / -1; border: 0; }

.modal { width: min(430px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 24px 80px rgba(22, 32, 28, .28); }
.modal::backdrop { background: rgba(22, 32, 28, .46); backdrop-filter: blur(3px); }
.modal form { padding: 25px; }
.modal h2 { margin: 0; font-size: 21px; }
.modal form > p:not(.modal-kicker) { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.rules-modal ol { margin: 17px 0 0; padding-left: 21px; color: #3e4a46; font-size: 12px; line-height: 1.85; }
.modal-actions { margin-top: 23px; display: flex; justify-content: flex-end; gap: 8px; }
.secondary-button, .primary-button.compact { width: auto; min-height: 40px; margin: 0; padding: 0 16px; }
.secondary-button { border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-weight: 750; }
.result-modal form { text-align: center; }
.result-mark { width: 48px; height: 48px; margin: 0 auto 13px; display: block; border-radius: 50%; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); max-width: calc(100% - 28px); padding: 10px 14px; transform: translate(-50%, 14px); border-radius: 6px; background: #202b27; color: #fff; opacity: 0; pointer-events: none; font-size: 12px; transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.thinking::after { content: ""; width: 10px; height: 10px; margin-left: 7px; display: inline-block; border: 2px solid rgba(25, 34, 31, .2); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 840px) {
  .game-layout { width: min(680px, calc(100% - 28px)); grid-template-columns: 1fr; gap: 5px; padding-top: 24px; }
  .game-sidebar { padding-top: 0; }
  .side-section { padding: 18px 0; }
}

@media (max-width: 540px) {
  .topbar { min-height: 62px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .brand small, .nav-link span:last-child { display: none; }
  .nav-link { width: 38px; padding: 0; justify-content: center; }
  .header-actions { gap: 5px; }
  .game-layout { width: calc(100% - 18px); padding-top: 18px; }
  .game-heading { align-items: center; margin-bottom: 11px; }
  h1 { font-size: 24px; }
  .turn-indicator strong { min-width: 68px; }
  .board-shell { padding: 10px; border-radius: 5px; }
  .board-toolbar { top: 6px; right: 6px; }
  .board-toolbar .icon-button { width: 34px; min-height: 34px; }
  .stone { inset: 5%; }
  .board-caption { font-size: 10px; }
  .move-section { padding-bottom: 28px; }
}

@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } .thinking::after { animation: none; } }
