@import url('/design-tokens.css');

html, body { margin: 0; }
/* Two quick taps on the same point (preview, then confirm) must not trigger
   iOS double-tap zoom, which nudges the whole page. Pinch-zoom still works. */
html, body, button, input, summary { touch-action: manipulation; }
.board-grid { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { min-width: 320px; min-height: 100vh; background: var(--paper); color: var(--ink); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* One centered column for phone and desktop. */
.app { --col: min(560px, 100%, calc(100dvh - 244px)); --shell-col: min(560px, 100%); display: flex; flex-direction: column; align-items: center; min-height: 100vh; min-height: 100dvh; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.topbar, .banner, .result-bar, .status-row, .board-area, .status-card, .session-tools, .page-footer, .room-list-section { width: var(--shell-col); flex-shrink: 0; }
.board-area { width: var(--col); }
.topbar { display: flex; align-items: center; gap: 12px; height: 60px; }
.topbar .menu-wrap { margin-left: auto; }
/* The current game names the page; the other games wait behind it. */
.game-picker { position: relative; display: flex; align-items: center; min-width: 0; padding-left: 13px; }
.game-picker::before { content: ''; position: absolute; left: 0; top: 50%; width: 1px; height: 20px; margin-top: -10px; background: var(--line-strong); }
.game-picker-button { display: inline-flex; align-items: center; gap: 6px; min-width: 0; height: 44px; padding: 0 10px 0 8px; border: 0; border-radius: 10px; background: none; color: var(--ink); font: 600 16px/1 var(--sans); cursor: pointer; }
.game-picker-button:hover, .game-picker-button[aria-expanded="true"] { background: rgba(35, 41, 37, .07); }
.game-picker-chevron { flex: none; color: var(--muted); transition: transform .15s var(--ease-overlay); }
.game-picker-button[aria-expanded="true"] .game-picker-chevron { transform: rotate(180deg); }
.game-picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-picker-label { padding-left: 8px; color: var(--ink); font: 600 16px/44px var(--sans); }
.game-switch { position: absolute; z-index: 20; top: calc(100% + 6px); left: 5px; width: 236px; max-height: calc(100dvh - 80px); overflow-y: auto; padding: 6px; border: 1px solid var(--invite-line); border-radius: 14px; background: var(--invite-surface); box-shadow: var(--invite-shadow); }
.game-switch a { display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 12px; border-radius: 10px; color: var(--invite-text); font-size: 15px; font-weight: 500; text-decoration: none; }
.game-switch a:hover, .game-switch a:focus-visible { background: var(--paper); outline: none; }
.game-switch a[aria-current="page"] { color: var(--ink); font-weight: 650; }
.game-switch a[aria-current="page"]::after { content: ''; width: 12px; height: 7px; margin: -3px 2px 0 auto; border: solid var(--invite-action); border-width: 0 0 2px 2px; transform: rotate(-45deg); }
.game-icon { display: grid; flex: none; place-items: center; width: 22px; height: 22px; }
.game-icon svg { width: 20px; height: 20px; }
/* Wordmark: the µ descends below the baseline, so give it room to breathe. */
.brand { display: inline-flex; align-items: center; height: 44px; padding-bottom: 4px; color: var(--ink); text-decoration: none; font: 540 25px/1 var(--serif); letter-spacing: -.015em; }
.brand:hover { color: var(--ink-soft); }

/* Reconnect banner: non-blocking, the board stays visible. */
.banner { box-sizing: border-box; display: flex; align-items: center; gap: 12px; margin-bottom: 8px; padding: 11px 12px 11px 14px; border-radius: 14px; background: var(--warn); color: var(--warn-ink); font-size: 14px; line-height: 1.45; }
.banner-text { flex: 1; min-width: 0; }
.banner-text strong, .banner-text span { display: block; }
.banner-text strong { font-weight: 600; }
.banner-text span { opacity: .85; font-size: 13px; }
.banner .spinner { width: 16px; height: 16px; border-width: 2px; }
.banner-button { box-sizing: border-box; flex: none; min-height: var(--control-target); height: auto; padding: 0 14px; border: 0; border-radius: 10px; background: var(--invite-surface); color: var(--warn-ink); font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.banner-actions { flex: none; display: flex; flex-wrap: wrap; gap: 6px; }
.banner-button-quiet { background: transparent; box-shadow: none; text-decoration: underline; text-underline-offset: 3px; }
/* Waiting on the friend is not an alarm: a calm card colour. Only "your own
   network is down" keeps the amber warning, because it is yours to fix. */
.banner[data-reason="friend_unknown"], .banner[data-reason="peer_away"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.banner[data-reason="friend_unknown"] .banner-button, .banner[data-reason="peer_away"] .banner-button { background: var(--ink); color: var(--surface); }
.banner[data-reason="friend_unknown"] .banner-button-quiet, .banner[data-reason="peer_away"] .banner-button-quiet { background: transparent; color: var(--muted); }
.banner[data-reason="peer_away"] .spinner { display: none; }
/* The friend's chip dims while their page is away or reconnecting. */
.player-chip.is-away .stone-icon, .player-chip.is-away .piece-icon { opacity: .4; }
.player-chip.is-away small { color: var(--muted); }

/* Result under the board; the winning line stays visible. */
.result-bar { box-sizing: border-box; display: flex; align-items: center; gap: 14px; margin-top: 14px; padding: 16px 16px 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--card-shadow); animation: rise .28s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.result-bar .result-stone { width: 40px; height: 40px; }
.result-stone-draw { background: linear-gradient(90deg, #1c1d1b 50%, #f1efe9 50%); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.result-text { flex: 1; min-width: 0; }
.result-text strong, .result-text small { display: block; }
.result-text strong { font: 540 23px/1.15 var(--serif); letter-spacing: -.01em; }
.result-text small { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.result-text #result-sub[data-tone="invite"] { color: var(--accent-deep); font-weight: 600; }
.result-text .result-score { margin-top: 1px; font-variant-numeric: tabular-nums; }
.result-text .result-score:empty { display: none; }
.result-bar .result-button { width: auto; flex: none; height: 46px; padding: 0 22px; font-size: 15px; }
/* Next round's sides: a quiet line that is itself the swap control. */
.next-sides { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; min-height: var(--control-target); margin-top: 8px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); color: var(--ink); font: inherit; font-size: 13px; line-height: 1.3; text-align: left; cursor: pointer; transition: border-color .15s, background .15s; }
.next-sides:hover:not(:disabled) { border-color: var(--line-strong); background: var(--paper-deep); }
.next-sides:disabled { opacity: .55; cursor: default; }
.next-sides-action { flex: none; color: var(--accent); font-weight: 600; }

/* Players and whose turn it is. Who you are matters more than the colour name. */
/* The headline owns a full row; player identities never compete with it.
   Reserve the same space during invitation, play and short interruptions. */
.status-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: 26px 50px; align-items: center; column-gap: 8px; row-gap: 4px; height: 80px; }
.player-chip { justify-self: start; display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; padding: 6px 4px; border: 1px solid transparent; border-radius: 14px; transition: background .25s, box-shadow .25s, border-color .25s; }
.player-chip-right { justify-self: end; flex-direction: row-reverse; text-align: right; }
.player-chip > span:last-child { display: flex; flex-direction: column-reverse; min-width: 0; }
.player-chip strong, .player-chip small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-chip small { color: var(--ink); font-size: 15px; font-weight: 600; line-height: 1.25; }
.player-chip strong { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.3; }
.player-chip small:empty { display: none; }
.player-chip span:has(> small:empty) > strong { color: var(--ink); font-size: 15px; font-weight: 600; }
.player-chip.is-turn { border-color: var(--line); background: var(--surface); box-shadow: var(--shadow); }
.player-chip.is-turn .stone-icon { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4.5px var(--ink); }
.player-chip.is-turn .stone-icon-white { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2), 0 0 0 3px var(--surface), 0 0 0 4.5px var(--ink); }
.stone-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; }
.stone-icon-black { background: radial-gradient(circle at 35% 30%, #5c5f5a, #1c1d1b 55%, #0d0e0c); }
.stone-icon-white { background: radial-gradient(circle at 35% 30%, #fff, #f1efe9 55%, #d9d6cd); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); }
.turn-indicator { min-width: 0; max-width: 100%; min-height: 26px; display: inline-flex; align-items: center; gap: 8px; font: 520 18px/1.25 var(--serif); text-align: center; color: var(--ink); }
.turn-indicator:not(:has(#headline:empty)) .turn-dot { display: inline-block; }
.turn-indicator:has(#headline:empty) { visibility: hidden; }
.turn-dot { display: none; flex: none; width: 8px; height: 8px; border-radius: 50%; background: #b9b8ad; }
.turn-indicator[data-state="active"] .turn-dot { background: var(--ink-soft); }
.turn-indicator[data-state="go"] { color: var(--ink); }
.turn-indicator[data-state="go"] .turn-dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
html[data-game="gomoku"] .turn-indicator[data-state="go"] .turn-dot { animation: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* Your chip is always on the left: swap the colour chips when you hold the second colour. */
.status-row > .player-chip:not(.player-chip-right) { grid-column: 1; }
.turn-indicator { grid-column: 1 / -1; grid-row: 1; justify-self: center; }
.status-row > .player-chip-right { grid-column: 2; grid-row: 2; }
.status-row > .player-chip { grid-row: 2; }
.status-row[data-mine="second"] > .player-chip:not(.player-chip-right) { grid-column: 2; justify-self: end; flex-direction: row-reverse; text-align: right; }
.status-row[data-mine="second"] > .player-chip-right { grid-column: 1; justify-self: start; flex-direction: row; text-align: left; }

/* Both games keep the same geometry before and after the invitation closes.
   Only the board is blurred; the invitation and fatal overlay are siblings. */
.board-area {
  --invite-top: auto;
  --invite-bottom: -96px;
  --invite-reserve: 112px;
  position: relative;
  display: grid;
  min-width: 0;
}
.board-area > * { grid-area: 1 / 1; }
.board-wrap { position: relative; align-self: start; width: 100%; aspect-ratio: 1; border-radius: 16px; background: linear-gradient(145deg, var(--wood-light), var(--wood) 45%, var(--wood-dark)); box-shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 10px 30px rgba(60, 40, 10, .12), inset 0 0 0 1px rgba(120, 85, 30, .18); transition: filter var(--motion-overlay) var(--ease-overlay); }
.board-wrap::before { position: absolute; inset: 3.3333%; content: ''; pointer-events: none; background-image: linear-gradient(to right, var(--grid) 1px, transparent 1px), linear-gradient(to bottom, var(--grid) 1px, transparent 1px); background-size: calc(100% / 14) calc(100% / 14); box-shadow: inset -1px 0 var(--grid), inset 0 -1px var(--grid); }
/* Star points at 4-4, 12-4, 8-8, 4-12, 12-12. */
.board-wrap::after { position: absolute; inset: 0; content: ''; pointer-events: none;
  background:
    radial-gradient(circle at 23.333% 23.333%, var(--grid) 0 3px, transparent 3.5px),
    radial-gradient(circle at 76.667% 23.333%, var(--grid) 0 3px, transparent 3.5px),
    radial-gradient(circle at 50% 50%, var(--grid) 0 3px, transparent 3.5px),
    radial-gradient(circle at 23.333% 76.667%, var(--grid) 0 3px, transparent 3.5px),
    radial-gradient(circle at 76.667% 76.667%, var(--grid) 0 3px, transparent 3.5px); }
.board-grid { position: absolute; inset: 0; z-index: 1; display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); }
.cell { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: default; -webkit-tap-highlight-color: transparent; }
.cell.can-play { cursor: pointer; }
.cell:disabled { opacity: 1; }
.cell .stone { position: relative; width: 86%; aspect-ratio: 1; border-radius: 50%; pointer-events: none; }
.stone.black { background: radial-gradient(circle at 35% 30%, #5c5f5a, #1c1d1b 55%, #0d0e0c); box-shadow: 0 2px 3px rgba(0, 0, 0, .35); }
.stone.white { background: radial-gradient(circle at 35% 30%, #fff, #f1efe9 55%, #d9d6cd); box-shadow: 0 2px 3px rgba(0, 0, 0, .25), inset 0 0 0 1px rgba(0, 0, 0, .06); }
.cell .stone.is-preview { opacity: .6; outline: 2px solid var(--accent); outline-offset: 2px; }
.cell.is-win .stone { box-shadow: 0 0 0 3px #f2c84b, 0 2px 6px rgba(0, 0, 0, .35); }
.last-marker { position: absolute; z-index: 2; width: 22%; aspect-ratio: 1; border-radius: 50%; background: var(--accent); pointer-events: none; }
.app[data-offline="true"] .board-wrap { filter: saturate(.6) brightness(.98); }

/* A friend's gesture belongs to the table, without covering playable cells. */
.table-tap { position:absolute; z-index:5; bottom:-62px; left:50%; display:flex; flex-direction:column; align-items:center; width:108px; height:62px; padding:0; border:0; border-radius:12px; background:transparent; transform:translateX(-50%); cursor:pointer; }
.nudge-hand { display:block; width:48px; height:48px; overflow:visible; filter:drop-shadow(0 2px 2px #50391825); }
.nudge-label { display:block; color:var(--ink-soft); font:500 12px/16px var(--sans); white-space:nowrap; }
.table-tap:not(.is-tapping) { animation:nudge-enter .3s ease-out; }
.table-tap:disabled { cursor:default; }
.table-tap.is-tapping .nudge-hand { animation:nudge-tap 1.5s ease-in-out both; }
.table-tap.is-tapping .nudge-label { visibility:hidden; }
.table-knock { position:absolute; z-index:5; top:-64px; left:50%; display:none; flex-direction:column; align-items:center; width:110px; pointer-events:none; transform:translateX(-50%); }
.table-knock.is-knocking { display:flex; }
.nudge-incoming-art { transform:rotate(180deg); }
.table-knock .nudge-label { position:absolute; top:48px; }
.table-knock.is-knocking .nudge-hand { animation:nudge-tap 1.5s ease-in-out both; }
.nudge-hand .impact { opacity:0; stroke:#775c35; stroke-width:2; stroke-linecap:round; }
.is-knocking .impact,.is-tapping .impact { animation:nudge-impact 1.5s ease-in-out both; }
.board-area:has(.table-tap:not([hidden])) { margin-bottom:62px; }
@keyframes nudge-enter { from {opacity:0} to {opacity:1} }
@keyframes nudge-tap { 0%,12%,42%,72%,100% {transform:translateY(0) rotate(-8deg)} 24%,54% {transform:translateY(-7px) rotate(-2deg)} 30%,60% {transform:translateY(1px) rotate(-8deg)} }
@keyframes nudge-impact { 0%,27%,40%,57%,70%,100% {opacity:0} 30%,60% {opacity:1} }
@media(prefers-reduced-motion:reduce) { .table-tap,.table-tap.is-tapping .nudge-hand,.table-knock.is-knocking .nudge-hand,.is-knocking .impact,.is-tapping .impact {animation:none} }


/* The seats and turn band reserve their playing-space from the first paint. */
.app[data-seats="true"] .player-chip:not(.seat-chip), .app:not([data-seats="true"]) .seat-chip { display: none; }
.app[data-pregame="true"] .player-chip, .app[data-pregame="true"] .turn-indicator { visibility: hidden; }
.app:is([data-view="home"], [data-view="boot"]) .turn-indicator { visibility: hidden; }
.app[data-pregame="true"] .board-wrap { filter: blur(.6px); }
.app[data-view="fatal"] .board-wrap { filter: saturate(.5) opacity(.45); }
.app[data-view="fatal"] .status-row { visibility: hidden; }
.seat-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; background: linear-gradient(135deg, #2a2b28 50%, #f1efe9 50%); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.seat-friend { font: inherit; background: none; cursor: default; }
.seat-friend:not(:disabled) { cursor: pointer; }
.seat-friend[data-state="empty"] { border: 1.5px dashed var(--line-strong); }
.seat-friend[data-state="empty"]:hover:not(:disabled) { border-color: var(--ink-soft); background: var(--surface); }
.seat-friend[data-state="empty"] .seat-icon { opacity: .35; }
.seat-friend:is([data-state="empty"], [data-state="invited"]) strong { color: var(--accent); font-weight: 600; }
.seat-friend[data-state="invited"] .seat-icon { opacity: .55; }
.turn-indicator[data-state="busy"] .turn-dot { background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }

/* One small invitation at the lower board edge, on phones and desktops alike.
   Its reserved tail only affects content below the board, never its geometry. */
.board-area:has(> .invite-panel:not([hidden])) { margin-bottom: var(--invite-reserve); }
.invite-panel { position: absolute; z-index: 6; top: var(--invite-top); left: 50%; bottom: var(--invite-bottom); width: min(var(--invitation-card-width, 420px), calc(100% - 24px)); padding: 20px 20px 0; border: 1px solid var(--invite-line); border-radius: 18px; background: var(--invite-surface); box-shadow: var(--invite-shadow); opacity: 1; transform: translate(-50%, 0); transition: opacity var(--motion-overlay) var(--ease-overlay), transform var(--motion-overlay) var(--ease-overlay); }
.invite-panel[data-state="closing"], .invite-panel[data-state="closed"] { opacity: 0; transform: translate(-50%, 8px); pointer-events: none; }
.invite-panel[data-state="closed"] { visibility: hidden; }
/* Reveal the fully composed invitation on its first local render, before any
   network preparation. Avoid painting the fallback title and then adding tabs. */
.invite-panel[data-initializing="true"] { visibility: hidden; }
@media (max-height: 680px) {
  .invite-panel:has(.invite-qr:not([hidden])) { position: fixed; top: 64px; bottom: auto; max-height: calc(100dvh - 80px); overflow-y: auto; overscroll-behavior: contain; }
}
.side-pip { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #5a5a5a, #111 70%); }
.side-pip[data-color="white"] { background: radial-gradient(circle at 35% 30%, #fff, #ddd8cc 75%); box-shadow: inset 0 0 0 1px #0000002a; }
.side-pip[data-color="red"] { background: #fffaf0; box-shadow: inset 0 0 0 2px #b23a2a; }
.side-pip[data-color="black-piece"] { background: #fffaf0; box-shadow: inset 0 0 0 2px #2b2b2b; }
.side-swap { margin-left: 4px; color: var(--invite-text); font-size: 16px; }
#computer-retry { margin-top: 12px; padding: 0 12px; }
.inline-button:not([hidden]) { display: flex; align-items: center; justify-content: center; min-height: 48px; border: 0; border-radius: 6px; background: none; color: var(--invite-text); font: 500 14px/1.35 var(--sans); text-align: center; cursor: pointer; }
.inline-button:not([hidden]):hover { color: var(--invite-action-hover); text-decoration: underline; text-underline-offset: 4px; }
#local-return { margin-top: 12px; padding: 0 12px; }

.overlay { position: relative; z-index: 5; display: grid; place-items: center; padding: 12px; }
.overlay:not(:has(> :not([hidden]))) { pointer-events: none; }
.card { width: 100%; padding: 30px 26px 24px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--card-shadow); text-align: center; }
.card h1 { margin: 0 0 8px; font: 540 29px/1.15 var(--serif); letter-spacing: -.015em; text-wrap: balance; }
.card-sub { margin: 0 0 22px; color: var(--muted); font-size: 15px; line-height: 1.55; text-wrap: pretty; }
.eyebrow { margin: 0 0 6px; color: var(--accent); font: italic 500 17px/1.3 var(--serif); }
.card-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.card-note-text { display: block; }
.card-fine { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.waiting-note { color: var(--ink); font-size: 14px; }
.waiting-note .spinner { color: var(--accent); }
.mini-stone { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.mini-stone-black { background: #1c1d1b; }
.divider { display: flex; align-items: center; gap: 10px; margin: 22px 0 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.busy-state { padding: 14px 0 6px; }
.busy-state h1 { font-size: 24px; }
.fatal-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 50%; background: var(--danger-soft); color: var(--danger); font: 600 26px/1 var(--serif); }
#fatal-card .card-sub { margin-bottom: 4px; color: var(--ink); }
.card-note-plain { margin-top: 0; }
.card-actions { display: grid; gap: 10px; margin-top: 20px; }
.busy-state .card-sub { margin-bottom: 0; }

.primary-button, .secondary-button { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 52px; border-radius: 14px; font-size: 16px; font-weight: 600; cursor: pointer; transition: transform .08s, background .2s, opacity .2s, border-color .2s, color .2s; }
.primary-button { border: 0; background: var(--ink); color: var(--surface); text-decoration: none; }
.primary-button:hover:not(:disabled) { background: var(--ink-soft); }
.primary-button.is-copied, .primary-button.is-copied:hover:not(:disabled) { background: var(--tint); color: var(--ink); }
.secondary-button { border: 1px solid var(--line-strong); background: transparent; color: var(--ink); }
.secondary-button:hover:not(:disabled) { background: var(--paper); }
.secondary-button.is-copied { border-color: var(--tint); background: var(--tint); }
.primary-button:active:not(:disabled), .secondary-button:active:not(:disabled) { transform: scale(.985); }
.primary-button:disabled, .secondary-button:disabled { cursor: not-allowed; opacity: .35; }

.spinner { display: inline-block; flex: none; width: 12px; height: 12px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .9s linear infinite; }
.spinner-large { display: block; width: 28px; height: 28px; margin: 0 auto 16px; border-width: 2px; color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  :root { --motion-overlay: 0ms; }
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; animation-delay: 0s !important; scroll-behavior: auto !important; }
  .spinner, .turn-indicator .turn-dot, .result-bar { animation: none; }
  .invite-panel[data-state="closing"], .invite-panel[data-state="closed"] { transform: translate(-50%, 0); }
}

/* Live status: inside the home card, or under the board during a game. */
.status-card { margin-top: 12px; padding: 10px 14px; border-radius: 12px; background: var(--tint); color: var(--ink-soft); font-size: 14px; line-height: 1.5; text-align: left; }
.status-card p { margin: 0; }
.status-card[data-tone="error"] { background: var(--danger-soft); color: var(--danger); }
.card .status-card { margin: 0 0 10px; padding: 0; background: none; text-align: center; font-size: 13px; }
.card .status-card:not([data-tone="error"]) { color: var(--muted); }
.session-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px; margin-top: 12px; }
.saved-state { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.session-tools .secondary-button { width: auto; height: 38px; padding: 0 14px; font-size: 14px; }
/* Game actions: one quiet row under the board; confirmations happen in place. */
.game-actions { width: var(--shell-col); flex-shrink: 0; margin-top: 10px; }
.game-tools { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.tool-button { display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: none; color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer; }
.tool-button:last-child { margin-left: auto; }
.tool-button:hover:not(:disabled) { background: rgba(35, 41, 37, .07); }
.tool-button:disabled { color: var(--muted); opacity: .55; cursor: default; }
.tool-button svg { flex: none; }
.action-card { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; padding: 14px 16px; border: 1px solid var(--invite-line); border-radius: 16px; background: var(--invite-surface); box-shadow: 0 1px 2px rgba(40, 35, 20, .05); }
.undo-panel { width: var(--shell-col); flex-shrink: 0; margin-top: 10px; }
.action-copy { flex: 1 1 auto; min-width: 0; }
.action-copy strong, .action-copy span { display: block; }
.action-copy strong { color: var(--ink); font-size: 15px; font-weight: 650; line-height: 1.35; }
.action-copy span { margin-top: 3px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.action-copy span:empty { display: none; }
.action-buttons { display: flex; flex: none; gap: 8px; }
.action-buttons :is(.primary-button, .secondary-button, .danger-button) { width: auto; min-width: 120px; height: 44px; padding: 0 16px; border-radius: 10px; font-size: 15px; }

/* The shared column also shrinks with short viewports. Stack these shared
   cards by that layout condition, even when a landscape viewport is wide. */
@media (max-height: 520px) {
  /* Preserve a readable shared interface column while the board itself stays
     sized for the available height. The invitation floats above that board. */
  html:root[data-game] .app {
    --col: min(560px, 100%, max(320px, calc(100dvh - 244px)));
    --shell-col: min(560px, 100%);
  }
  .invite-panel { box-sizing: border-box; position: fixed; top: 64px; bottom: auto; left: 50vw;
    width: min(var(--invitation-card-width, 420px), calc(100vw - 32px)); max-height: calc(100dvh - 80px);
    overflow-y: auto; overscroll-behavior: contain; padding-bottom: 20px; }
  .banner { display: grid; grid-template-columns: minmax(0, 1fr); }
  .banner-text { width: 100%; }
  .banner-actions { width: 100%; justify-content: flex-end; }
  .result-bar { flex-wrap: wrap; padding: 14px; gap: 12px; }
  .result-bar .result-stone { width: 34px; height: 34px; }
  .result-text { flex: 1 0 100%; }
  .result-bar .result-button { box-sizing: border-box; width: 100%; }
  .next-sides { box-sizing: border-box; display: flex; width: 100%; justify-content: space-between; }
  #next-sides-text { min-width: 0; overflow-wrap: anywhere; }
  .action-card { flex-direction: column; align-items: stretch; }
  .action-copy { flex-basis: auto; width: 100%; }
  .action-buttons { display: grid; flex: 1 1 auto; width: 100%; grid-template-columns: minmax(0, 1fr); }
  .action-buttons :is(.primary-button, .secondary-button, .danger-button) { box-sizing: border-box; width: 100%; min-width: 0; padding-inline: 8px; }
}

.page-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 12px; margin-top: 18px; padding: 0 4px; color: var(--muted); font-size: 12px; text-align: center; }
.text-button { padding: 6px 0; border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; }
.text-button:hover { color: var(--ink); text-decoration: underline; }
.text-button-danger { color: var(--danger); }
.text-button-danger:hover { color: var(--danger); }

@media (max-width: 520px) {
  .app { padding: 0 12px calc(16px + env(safe-area-inset-bottom)); }
  .topbar { position: relative; height: 54px; }
  .game-picker { position: static; padding-left: 0; }
  .game-picker::before { position: static; flex: none; margin: 0 12px 0 0; }
  .game-switch { top: calc(100% + 1px); left: auto; right: 0; }
  .brand { font-size: 23px; }
  .turn-indicator { font-size: 19px; }
  .board-wrap { border-radius: 12px; }
  .card { padding: 26px 18px 18px; border-radius: 20px; }
  .card h1 { font-size: 26px; }
  .card-sub { margin-bottom: 18px; }
  .divider { margin: 16px 0 10px; }
  .primary-button, .secondary-button { height: 50px; }
  .banner { padding: 10px 10px 10px 12px; flex-wrap: wrap; }
  .banner-actions { width: 100%; justify-content: flex-end; }
  .result-bar { flex-wrap: wrap; padding: 14px; gap: 12px; }
  .result-bar .result-stone { width: 34px; height: 34px; }
  .result-bar .result-button { width: 100%; }
  .action-card { flex-wrap: wrap; }
  .action-copy { flex-basis: 100%; }
  .action-buttons { display: grid; flex: 1 1 100%; grid-template-columns: 1fr 1fr; }
  .action-buttons :is(.primary-button, .secondary-button, .danger-button) { width: 100%; min-width: 0; }
}

/* Hover ghost (mouse only, rendered by app.js in your own colour) */
.cell .stone.is-ghost { opacity: .5; }

/* Top bar menu */
.menu-wrap { position: relative; }
.menu-button { display: grid; place-items: center; width: 44px; height: 44px; margin-right: -10px; border: 0; border-radius: 12px; background: none; color: var(--ink); cursor: pointer; }
.menu-button:hover, .menu-button[aria-expanded="true"] { background: rgba(35, 41, 37, .07); }
.menu { position: absolute; z-index: 20; top: calc(100% + 6px); right: -6px; min-width: 188px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 12px 32px rgba(40, 30, 10, .16); }
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 9px; background: none; color: var(--ink); font: inherit; font-size: 15px; text-align: left; cursor: pointer; }
.menu button:hover, .menu button:focus-visible { background: var(--paper); outline: none; }
.menu button:disabled { color: var(--muted); cursor: default; }
.menu button[hidden], .menu hr[hidden] { display: none; }
.menu hr { margin: 4px 6px; border: 0; border-top: 1px solid var(--line); }
.menu .menu-danger { color: var(--danger); }

/* In-page dialogs */
.dialog { width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 26px 22px 20px; border: 0; border-radius: 22px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(40, 30, 10, .26); }
.dialog::backdrop { background: rgba(30, 26, 18, .36); }
.dialog h1 { margin: 0 0 8px; font: 540 23px/1.2 var(--serif); text-align: center; }
.dialog p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.6; text-align: center; }
.dialog .card-actions { display: grid; gap: 10px; }
.danger-button { width: 100%; height: 50px; border: 0; border-radius: 14px; background: var(--danger); color: #fff; font: inherit; font-size: 16px; font-weight: 600; cursor: pointer; }
.danger-button:hover { filter: brightness(.94); }
.rules-list { margin: 0 0 20px; padding-left: 20px; color: var(--ink); font-size: 14px; line-height: 1.65; }
.rules-list li + li { margin-top: 6px; }
.rules-list li::marker { color: var(--accent); font-family: var(--serif); }

/* Toast */
.toast { position: fixed; z-index: 30; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); margin: 0; padding: 12px 16px; border-radius: 14px; background: rgba(35, 41, 37, .94); color: var(--surface); font-size: 13px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast[hidden] { display: none; }

/* Rooms on the home card */
.room-list-section .divider { margin-top: 22px; }
.room-list { display: grid; gap: 8px; max-height: 232px; margin: 0; padding: 0; overflow-y: auto; list-style: none; text-align: left; }
.room-item { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 0; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); transition: border-color .15s; }
.room-item:hover { border-color: var(--line-strong); }
.room-open { flex: 1; min-width: 0; padding: 9px 12px; color: var(--ink); text-decoration: none; }
.room-open strong, .room-open small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-open strong { font-size: 15px; font-weight: 600; }
.room-open small { margin-top: 2px; color: var(--muted); font-size: 13px; }
.room-remove { flex: none; height: 36px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.room-remove:hover { background: var(--surface); color: var(--danger); }
.text-link { display: inline-block; margin-top: 16px; color: var(--muted); font-size: 14px; text-underline-offset: 3px; }
.text-link:hover { color: var(--ink); }

/* Public page explanation: below the play action, never in a room. */
.game-faq { width: min(100%, 560px); margin: 48px auto 18px; padding: 28px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 15px; line-height: 1.7; }
.game-faq h2 { margin: 0 0 18px; color: var(--ink); font: 540 24px/1.25 var(--serif); letter-spacing: -.01em; }
.game-faq h3 { margin: 22px 0 4px; color: var(--ink); font-size: 15px; font-weight: 600; }
.game-faq p { margin: 0; }
.game-faq p + p { margin-top: 8px; }
.game-faq .piece-reference, #rules-dialog .piece-reference { margin: 14px 0 0; }
.game-faq .piece-reference dt, #rules-dialog .piece-reference dt { margin-top: 12px; color: var(--ink); font-weight: 600; }
.game-faq .piece-reference dd, #rules-dialog .piece-reference dd { margin: 2px 0 0; }
.game-faq .reference-glyphs, #rules-dialog .reference-glyphs { font: 500 18px/1.4 var(--xiangqi-font); white-space: nowrap; }

/* Quiet public navigation below the play area. */
.trust-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; margin: 12px auto 0; color: var(--muted); font-size: 14px; }
.trust-links[hidden] { display: none; }
.trust-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; color: inherit; text-decoration: none; }
.trust-links a:hover { text-decoration: underline; text-underline-offset: 4px; }

/* Accepted board transitions: overlays never receive input or own game state. */
.board-motion-layer{position:fixed;inset:0;z-index:20;pointer-events:none;overflow:visible;contain:layout style}
.board-motion-sprite{pointer-events:none!important;will-change:transform,opacity}
.board-motion-ring{position:fixed;border:2px solid var(--accent,#a64d35);border-radius:50%;pointer-events:none;box-sizing:border-box}
.board-motion-hit,.board-motion-contact{border-color:var(--accent,#a64d35)}
.board-motion-miss{border-color:var(--ink-soft,#777)}
.board-motion-sunk,.board-motion-result,.board-motion-check{border-width:3px}
@media(prefers-reduced-motion:reduce){.board-motion-layer{display:none}}

/* Pregame omits player places; the invitation already describes the task.
   Preserve the board's anchor; real player identities return during play. */
.app[data-pregame="true"] .seat-chip { visibility: hidden; }
