/* Go (js/go.js) — wooden board drawn with CSS gradients, stones in SVG.
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. */
:root {
    --gq-accent: #a16207;
    --gq-accent-ink: #ffffff;
    --gq-page-bg: #f8f4ec;
    --gq-card-bg: #ffffff;
    --gq-card-border: #e6dfd1;
    --gq-muted: #6b6457;
    --gq-shadow: 0 10px 30px rgba(90, 60, 20, .10);
    --gq-wood-1: #ecc67c;
    --gq-wood-2: #dcab58;
    --gq-wood-3: #c98f3f;
    --gq-grain: rgba(122, 72, 18, .09);
    --gq-line: #3d2a12;
    --gq-star: #2f1f0b;
    --gq-coord: #5b3f18;
    --gq-ok: #0f9d58;
    --gq-bad: #dc2626;
}

body.dark-theme {
    --gq-accent: #f2b544;
    --gq-accent-ink: #1f1300;
    --gq-page-bg: #111827;
    --gq-card-bg: #1f2937;
    --gq-card-border: #374151;
    --gq-muted: #9ca3af;
    --gq-shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --gq-wood-1: #c99a4f;
    --gq-wood-2: #b5843c;
    --gq-wood-3: #9c6c2b;
    --gq-grain: rgba(60, 32, 6, .14);
    --gq-line: #2a1a07;
    --gq-star: #1f1404;
    --gq-coord: #3a2508;
    --gq-ok: #34d399;
    --gq-bad: #f87171;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a dead scroll
   container and silently kills position: sticky. */
.gq-body, body.gq-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--gq-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.gq-main { padding-top: 100px; padding-bottom: 40px; }
.gq-hero .container { max-width: 620px; }

/* ---- hero ---- */
.gq-hero { text-align: center; padding: 4px 0 10px; }
.gq-hero h1 { font-weight: 800; font-size: clamp(1.8rem, 6vw, 2.4rem); margin-bottom: 4px; display: inline-flex; align-items: center; gap: 12px; }
.gq-lead { margin: 0 auto; color: var(--gq-muted); font-size: 1rem; line-height: 1.5; }
.gq-title-stones { display: inline-flex; }
.gq-title-stones .gq-mini { width: 26px; height: 26px; }
.gq-title-stones .gq-mini + .gq-mini { margin-left: -8px; }

.gq-mini, .gq-pstone, .gq-turn-stone { display: inline-block; border-radius: 50%; flex: none; }
.gq-mini { width: 16px; height: 16px; vertical-align: -3px; box-shadow: 0 1px 2px rgba(0, 0, 0, .35); }
.is-b { background: radial-gradient(circle at 35% 30%, #6d7178 0%, #2b2e33 35%, #050506 100%); }
.is-w { background: radial-gradient(circle at 35% 30%, #fff 0%, #eeebe4 55%, #b9b3a6 100%); }
body.dark-theme .gq-mini.is-b, body.dark-theme .gq-pstone.is-b, body.dark-theme .gq-turn-stone.is-b { box-shadow: 0 0 0 1px rgba(255, 255, 255, .28), 0 2px 4px rgba(0, 0, 0, .4); }

/* ---- layout ---- */
.gq-layout { max-width: 560px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.gq-board-col { min-width: 0; }

/* ---- mode + options ---- */
.gq-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin: 6px 0 10px; border-radius: 16px; background: var(--gq-card-bg); border: 1px solid var(--gq-card-border); }
.gq-seg { min-height: 46px; padding: 6px 8px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-weight: 700; font-size: .88rem; line-height: 1.2; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center; gap: 7px; text-align: center; }
.gq-seg[aria-checked="true"] { background: var(--gq-accent); color: var(--gq-accent-ink); }
.gq-opts { display: grid; gap: 6px; margin-bottom: 10px; }
.gq-opt { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.gq-opt[hidden] { display: none; }
.gq-opt-label { min-width: 58px; color: var(--gq-muted); font-weight: 700; font-size: .85rem; }
.gq-chip { min-height: 40px; min-width: 64px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--gq-card-border); background: var(--gq-card-bg); color: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.gq-chip[aria-checked="true"] { border-color: var(--gq-accent); background: color-mix(in srgb, var(--gq-accent) 16%, var(--gq-card-bg)); box-shadow: inset 0 0 0 1px var(--gq-accent); }
.gq-seg:focus-visible, .gq-chip:focus-visible, .gq-btn:focus-visible, .gq-link:focus-visible { outline: 2px solid var(--gq-accent); outline-offset: 2px; }

/* ---- turn banner ---- */
.gq-turn { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin-bottom: 10px; min-height: 68px; border-radius: 18px; background: var(--gq-card-bg); border: 1px solid var(--gq-card-border); box-shadow: var(--gq-shadow); }
.gq-turn-stone { width: 38px; height: 38px; box-shadow: 0 2px 5px rgba(0, 0, 0, .35); }
.gq-turn-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.gq-turn-main { font-weight: 800; font-size: clamp(1.1rem, 4.8vw, 1.4rem); line-height: 1.2; }
.gq-turn-sub { color: var(--gq-muted); font-size: .92rem; font-weight: 600; min-height: 1.3em; overflow: hidden; text-overflow: ellipsis; }
.gq-turn.is-bad .gq-turn-sub { color: var(--gq-bad); }
.gq-turn.is-over { border-color: var(--gq-accent); }
.gq-think { display: inline-flex; gap: 4px; }
.gq-think[hidden] { display: none; }
.gq-think span { width: 8px; height: 8px; border-radius: 50%; background: var(--gq-accent); animation: gq-dot 1s ease-in-out infinite; }
.gq-think span:nth-child(2) { animation-delay: .15s; }
.gq-think span:nth-child(3) { animation-delay: .3s; }
@keyframes gq-dot { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-4px); } }

/* ---- board ---- */
.gq-board {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 0 auto 12px;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    background:
        radial-gradient(ellipse 80% 60% at 28% 18%, rgba(255, 255, 255, .22), transparent 70%),
        radial-gradient(ellipse 70% 50% at 80% 90%, rgba(80, 40, 0, .14), transparent 70%),
        repeating-linear-gradient(91deg, var(--gq-grain) 0 2px, transparent 2px 11px),
        repeating-linear-gradient(88.5deg, transparent 0 17px, rgba(110, 60, 10, .07) 17px 19px, transparent 19px 41px),
        repeating-radial-gradient(ellipse 140% 18% at 50% -40%, transparent 0 14px, rgba(120, 70, 20, .05) 14px 16px),
        linear-gradient(135deg, var(--gq-wood-1), var(--gq-wood-2) 55%, var(--gq-wood-3));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25), inset 0 -6px 14px rgba(70, 35, 0, .18), 0 14px 30px rgba(60, 30, 0, .28), 0 2px 0 #8a5a22;
}
.gq-svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; cursor: pointer; border-radius: 12px; }
.gq-svg:focus { outline: none; }
.gq-svg:focus-visible { outline: 3px solid var(--gq-accent); outline-offset: 3px; }
.gq-board.is-busy .gq-svg { cursor: progress; }
.gq-grid line { stroke: var(--gq-line); stroke-width: 1.15; shape-rendering: crispEdges; }
.gq-grid .gq-edge { stroke-width: 2.2; }
.gq-grid .gq-star { fill: var(--gq-star); }
.gq-grid text { fill: var(--gq-coord); font: 700 11px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central; opacity: .85; }

.gq-stone { fill: url(#gq-grad-b); }
.gq-stone.is-w { fill: url(#gq-grad-w); stroke: rgba(90, 80, 60, .35); stroke-width: .6; }
.gq-shine { fill: rgba(255, 255, 255, .16); pointer-events: none; }
.gq-shadow { fill: url(#gq-grad-shadow); }
.gq-new { transform-box: fill-box; transform-origin: center; animation: gq-drop .22s cubic-bezier(.2, 1.4, .5, 1); }
@keyframes gq-drop { from { transform: scale(1.25); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.gq-gone { transform-box: fill-box; transform-origin: center; animation: gq-gone .5s ease-in forwards; pointer-events: none; }
@keyframes gq-gone { to { transform: scale(.4) translateY(-30%); opacity: 0; } }
.gq-dead { opacity: .42; }

.gq-last { fill: none; stroke-width: 2.4; }
.gq-last.on-b { stroke: #f4f1ea; }
.gq-last.on-w { stroke: #16181c; }
.gq-terr { stroke-width: .8; }
.gq-terr.is-b { fill: #111; stroke: rgba(255, 255, 255, .35); }
.gq-terr.is-w { fill: #fafafa; stroke: rgba(0, 0, 0, .45); }
.gq-ghost { opacity: .45; pointer-events: none; }
.gq-ghost.is-confirm { opacity: .7; }
.gq-ghost-ring { fill: none; stroke: var(--gq-accent); stroke-width: 2.4; stroke-dasharray: 5 4; pointer-events: none; }
.gq-cursor { fill: none; stroke: var(--gq-accent); stroke-width: 2.4; pointer-events: none; }
.gq-flash { fill: var(--gq-bad); opacity: 0; pointer-events: none; animation: gq-flash .6s ease-out; }
@keyframes gq-flash { 0% { opacity: .55; } 100% { opacity: 0; } }

/* ---- players ---- */
.gq-players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.gq-player { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border-radius: 16px; background: var(--gq-card-bg); border: 2px solid var(--gq-card-border); transition: border-color .2s, box-shadow .2s; }
.gq-player.is-active { border-color: var(--gq-accent); box-shadow: var(--gq-shadow); }
.gq-pstone { width: 28px; height: 28px; box-shadow: 0 2px 4px rgba(0, 0, 0, .35); }
.gq-pinfo { display: flex; flex-direction: column; min-width: 0; }
.gq-pname { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gq-pstat { color: var(--gq-muted); font-size: .82rem; }
.gq-pstat b { color: var(--text-color); }
.gq-komi-tag { display: block; white-space: nowrap; }

/* ---- actions ---- */
.gq-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.gq-actions[hidden], .gq-scoring[hidden] { display: none; }
.gq-actions-3 { grid-template-columns: repeat(3, 1fr); }
.gq-btn { min-height: 50px; padding: 6px 8px; border: 1px solid var(--gq-card-border); border-radius: 14px; background: var(--gq-card-bg); color: inherit; font-weight: 700; font-size: .9rem; line-height: 1.15; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.gq-btn:hover:not(:disabled) { border-color: var(--gq-accent); }
.gq-btn:disabled { opacity: .45; cursor: not-allowed; }
.gq-btn-primary { background: var(--gq-accent); border-color: var(--gq-accent); color: var(--gq-accent-ink); }
.gq-btn[data-armed="1"] { border-color: var(--gq-bad); color: var(--gq-bad); background: color-mix(in srgb, var(--gq-bad) 10%, var(--gq-card-bg)); }

.gq-scoring { padding: 12px; border-radius: 16px; border: 2px solid var(--gq-accent); background: color-mix(in srgb, var(--gq-accent) 8%, var(--gq-card-bg)); }
.gq-scoring-help { margin: 0 0 8px; font-size: .92rem; line-height: 1.45; }
.gq-tally { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; font-size: .92rem; }
.gq-tally > div { padding: 6px 10px; border-radius: 10px; background: var(--gq-card-bg); border: 1px solid var(--gq-card-border); }
.gq-tally b { font-size: 1.1rem; }
.gq-tally .gq-tally-res { grid-column: 1 / -1; text-align: center; font-weight: 800; }

.gq-record { margin: 10px 0 0; text-align: center; color: var(--gq-muted); font-size: .9rem; min-height: 1.4em; }
.gq-record b { color: var(--text-color); }
.gq-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0 0; }
.gq-link { border: 0; background: none; padding: 8px 8px; min-height: 40px; color: var(--gq-muted); font-size: .88rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; gap: 6px; }
.gq-link span[hidden] { display: none; }
.gq-link#gq-reset-score { text-decoration: underline; }
.gq-link[aria-pressed="true"]#gq-coords { color: var(--gq-accent); font-weight: 700; }
.gq-link[data-armed="1"] { color: var(--gq-bad); }

.gq-help { margin-top: 12px; padding: 12px 16px; border-radius: 14px; background: var(--gq-card-bg); border: 1px solid var(--gq-card-border); }
.gq-help summary { cursor: pointer; font-weight: 700; min-height: 30px; }
.gq-help ol { margin: 10px 0 0; padding-left: 20px; color: var(--gq-muted); line-height: 1.55; }
.gq-help li { margin-bottom: 4px; }
.gq-help strong { color: var(--text-color); }
.gq-help p { color: var(--gq-muted); margin: 10px 0 0; line-height: 1.55; }
.gq-powered { text-align: center; color: var(--gq-muted); font-size: .85rem; margin: 26px 0 0; }

/* ---- result overlay ---- */
.gq-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .45); animation: gq-fade .25s ease-out; }
.gq-overlay[hidden] { display: none; }
@keyframes gq-fade { from { opacity: 0; } }
.gq-win { width: 100%; max-width: 350px; padding: 22px 18px 18px; border-radius: 22px; background: var(--gq-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: gq-rise .3s ease-out; }
@keyframes gq-rise { from { transform: translateY(20px) scale(.96); opacity: 0; } }
.gq-win-icon { font-size: 34px; color: #f59e0b; }
.gq-win-stone { width: 40px; height: 40px; margin: 6px auto 4px; display: block; }
.gq-win h2 { font-weight: 800; font-size: 1.45rem; margin: 4px 0 6px; }
.gq-win-reason { color: var(--gq-muted); margin: 0 0 6px; }
.gq-win-score { font-weight: 700; margin: 0 0 14px; }
.gq-win-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.gq-win-actions .gq-btn { flex-direction: row; gap: 6px; }

@media (min-width: 992px) {
    .gq-layout { max-width: 1080px; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "board top" "board turn" "board bottom"; grid-template-rows: auto auto 1fr; column-gap: 26px; align-items: start; }
    .gq-board-col { grid-area: board; }
    .gq-side-top { grid-area: top; }
    .gq-turn { grid-area: turn; }
    .gq-side-bottom { grid-area: bottom; }
    .gq-board { max-width: clamp(440px, calc(100vh - 300px), 700px); margin-top: 6px; }
    .gq-actions { grid-template-columns: 1fr 1fr; }
    .gq-actions-3 { grid-template-columns: 1fr 1fr; }
    .gq-actions-3 .gq-btn-primary { grid-column: 1 / -1; }
}

@media (max-width: 400px) {
    .gq-seg { font-size: .8rem; gap: 5px; }
    .gq-chip { min-width: 56px; padding: 4px 10px; font-size: .86rem; }
    .gq-opt-label { min-width: 50px; }
    .gq-btn { font-size: .82rem; flex-direction: column; gap: 3px; }
    .gq-player { padding: 8px 10px; gap: 8px; }
    .gq-turn { padding: 9px 12px; }
}

@media (prefers-reduced-motion: reduce) {
    .gq-new, .gq-gone, .gq-think span, .gq-flash { animation: none !important; }
}
