/* Quoridor: a quiet, tactile board rather than a dashboard of cards. */
:root {
    color-scheme: light;
    --bg: #f5f4ee;
    --surface: #eeeee7;
    --text: #272e28;
    --muted: #747b70;
    --line: #d6dacd;
    --accent: #426147;
    --accent-soft: #dfe8d9;
    --board: #b9ab96;
    --tile: #a69580;
    --tile-line: #8e806e;
    --wall: #51483e;
    --board-ink: #50483e;
    --preview: #426147;
    --danger: #995844;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #191e1a;
    --surface: #232a24;
    --text: #e8ece1;
    --muted: #9da696;
    --line: #394137;
    --accent: #b5c7a3;
    --accent-soft: #303d2c;
    --board: #6b6455;
    --tile: #807561;
    --tile-line: #5c5649;
    --wall: #e1d7c4;
    --board-ink: #e0d6c3;
    --preview: #d2dfbc;
    --danger: #d8a28c;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100svh; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button, input { touch-action: manipulation; }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
[hidden], .hidden { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; }
.page { width: min(1100px, calc(100% - 48px)); margin: auto; padding: 24px 0; }
.nav { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 32px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 9px; align-items: center; font-size: 15px; font-weight: 700; letter-spacing: -.4px; }
.brand-mark { font-size: 20px; font-weight: 850; color: var(--accent); border-left: 2px solid var(--accent); padding-left: 7px; line-height: 22px; }
.nav-actions, .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.eyebrow { color: var(--muted); font: 600 10px/1.5 ui-monospace, monospace; letter-spacing: 1.4px; text-transform: uppercase; }
.quiet { color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--text); font-size: 12px; font-weight: 550; white-space: nowrap; }
.button:hover:not(:disabled) { background: var(--surface); }
.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent); opacity: .9; }
.danger { color: var(--danger); }
.tiny { padding: 5px 10px; min-height: 32px; font-size: 11px; }
.icon-button { min-width: 36px; padding: 7px 9px; font-size: 16px; }
.badge { font: 11px/1.5 ui-monospace, monospace; color: var(--muted); padding: 2px 0; }
.connection { font-size: 10px; color: var(--muted); }
.connection::before { content: ''; display: inline-block; width: 5px; height: 5px; background: var(--danger); margin-right: 5px; }
.connection.online::before { background: var(--accent); }

/* Landing screen */
body:has(#home:not([hidden])) .page { width: min(860px, calc(100% - 48px)); padding-top: 16px; padding-bottom: 16px; }
body:has(#home:not([hidden])) .nav { margin-bottom: 16px; padding-bottom: 12px; }
#home { min-height: calc(100svh - 104px); display: flex; align-items: center; }
.home-stage { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); align-items: center; gap: 28px; padding: 24px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.home-preview { min-width: 0; display: grid; place-items: center; }
.intro h1 { font-size: 36px; letter-spacing: -1.3px; line-height: 1.1; font-weight: 600; margin: 0 0 8px; }
.intro p { color: var(--muted); font-size: 12px; margin: 0 0 18px; }
.home-setup { min-width: 0; }
#home .field { margin-bottom: 10px; }
#home .field label { margin-bottom: 4px; }
.forms { display: block; }
.forms > .tab-hidden { display: none; }
.panel { padding: 0; border: 0; background: transparent; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; }
input, select { width: 100%; min-height: 40px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 3px; background: var(--bg); color: var(--text); font-size: 13px; }
.name-field { width: 100%; margin-bottom: 14px; }
.note { margin: 10px 0 0; font-size: 11px; line-height: 1.65; color: var(--muted); }
.home-tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.home-tabs button { flex: 1; min-height: 44px; border: 0; border-bottom: 2px solid transparent; padding: 10px; font-size: 12px; background: transparent; color: var(--muted); }
.home-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.forms .button { width: 100%; min-height: 44px; }
.form-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }

/* A physical board, with coordinates kept in the frame. */
.board-shell { position: relative; padding: 26px 26px 30px; background: var(--board); border-radius: 6px; }
.board-shell.demo { width: min(100%, 400px, calc(100svh - 190px)); transform: none; }
.demo .cell small { display: none; }
.demo .pawn { font-size: 0; }
.board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr) 9px) minmax(0, 1fr); grid-template-rows: repeat(8, minmax(0, 1fr) 9px) minmax(0, 1fr); aspect-ratio: 1; position: relative; }
.cell { position: relative; min-width: 0; padding: 0; display: grid; place-items: center; border: 0; border-radius: 1px; background: var(--tile); color: var(--board-ink); }
.cell:disabled { opacity: 1; cursor: default; }
.cell small { position: absolute; left: 3px; bottom: 1px; font: 7px ui-monospace, monospace; color: var(--board-ink); opacity: .28; pointer-events: none; }
.cell.legal { cursor: pointer; outline: 1px solid var(--preview); outline-offset: -1px; }
.cell.legal::after { content: ''; width: 6px; height: 6px; background: var(--preview); border-radius: 50%; opacity: .8; }
.cell.legal:hover { outline-width: 2px; }
.pawn { display: grid; place-items: center; width: 68%; height: 68%; border-radius: 50%; background: var(--color); color: #f6f1e9; font-size: 13px; font-weight: 650; }
.pawn.light-pawn { color: #4a433c; }
.pawn.current { outline: 1px solid var(--board-ink); outline-offset: 3px; }
.pawn-layer { position: absolute; inset: 0; display: grid; grid-template-columns: inherit; grid-template-rows: inherit; pointer-events: none; z-index: 6; }
.pawn-layer .pawn { place-self: center; transition: opacity 120ms; }
.pawn.pending { opacity: .75; outline-style: dashed; }
.slot { position: relative; min-width: 0; padding: 0; border: 0; background: transparent; z-index: 3; border-radius: 2px; }
.slot:disabled { opacity: 1; cursor: default; }
.slot.h { grid-column-end: span 3; }
.slot.v { grid-row-end: span 3; }
.slot.active { background: var(--wall); z-index: 4; }
.slot.preview { background: var(--preview); outline: 1px dashed var(--board-ink); outline-offset: 2px; z-index: 5; }
.slot.preview { animation: wall-preview 140ms ease-out; }
@keyframes wall-preview { from { opacity: .35; } to { opacity: 1; } }
.slot.available:hover { background: var(--preview); opacity: .65; }
.slot.available::before { content: ''; position: absolute; }
.slot.h.available::before { inset: -7px 0; }
.slot.v.available::before { inset: 0 -7px; }
.axis-x { position: absolute; display: flex; justify-content: space-around; left: 26px; right: 26px; bottom: 7px; font: 11px/1.5 ui-monospace, monospace; color: var(--board-ink); }
.axis-y { position: absolute; display: flex; flex-direction: column; justify-content: space-around; top: 26px; bottom: 30px; left: 8px; font: 11px/1.5 ui-monospace, monospace; color: var(--board-ink); }
.goal-label { color: var(--muted); text-align: left; font: 10px/1.5 ui-monospace, monospace; margin: 0 0 8px; }

/* Match screen */
.game-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.game-header h1 { font-size: 28px; line-height: 1.2; letter-spacing: -.8px; font-weight: 550; margin: 0 12px 0 0; display: inline; }
.game-header .eyebrow { display: none; }
.room-code { color: var(--muted); font: 11px/1.5 ui-monospace, monospace; letter-spacing: 1px; }
.game-grid { display: grid; grid-template-columns: minmax(0, 620px) minmax(230px, 1fr); gap: 42px; align-items: start; }
.game-board-area { width: 100%; max-width: 550px; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.turn-title { font-size: 13px; font-weight: 650; }
.timer { color: var(--accent); font: 600 14px/1.5 ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.controls { display: flex; gap: 6px; margin-top: 12px; }
.controls .button { min-height: 36px; }
.controls .selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; border-bottom: 1px solid var(--line); padding: 0 0 10px; font: 11px/1.5 ui-monospace, monospace; }
.preview-bar .button { min-height: 30px; }
.board-toolbar { display: none; }
.sidebar .panel { margin: 0 0 28px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.section-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-top h2 { margin: 0; font-size: 13px; }
.player-list { display: grid; gap: 0; }
.player { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-left: 2px solid transparent; padding: 10px 0 10px 9px; }
.player.is-turn { border-left-color: var(--accent); background: var(--surface); }
.player-name { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 650; }
.player-dot { width: 11px; height: 11px; background: var(--color); border: 1px solid #8b867a; border-radius: 50%; flex-shrink: 0; }
.player-detail { font-size: 10px; color: var(--muted); margin-left: 19px; }
.player-right { color: var(--muted); font: 10px/1.5 ui-monospace, monospace; text-align: right; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.message { color: var(--muted); font-size: 11px; line-height: 1.65; margin: 16px 0 0; overflow-wrap: anywhere; }
.connection { white-space: nowrap; }
.footnote { font: 10px/1.5 ui-monospace, monospace; color: var(--muted); margin: 24px 0 0; }
.winner { color: var(--accent); }
.match-strip { display: none; }
#mobileLobby { display: none; }

/* Dialogs are deliberately plain; the mobile room panel is a bottom sheet. */
dialog { padding: 24px; width: min(480px, calc(100% - 24px)); max-height: 86svh; overflow: auto; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--text); }
dialog::backdrop { background: #11180fcc; }
dialog .close { float: right; }
dialog h2 { margin: 8px 0 18px; }
dialog p, dialog li { color: var(--muted); font-size: 12px; line-height: 1.7; }
dialog ol { padding-left: 20px; }
dialog li { margin-bottom: 10px; }
.code-box { padding: 16px 8px; margin: 16px 0; background: var(--surface); font: 600 20px/1.5 ui-monospace, monospace; text-align: center; user-select: all; overflow-wrap: anywhere; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 24px); width: max-content; padding: 11px 16px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 4px; font-size: 12px; z-index: 20; }

@media (max-width: 780px) {
    .page { width: calc(100% - 28px); padding: 12px 0 16px; }
    .nav { min-height: 34px; gap: 6px; margin-bottom: 14px; padding-bottom: 10px; }
    .brand { font-size: 13px; gap: 6px; }
    .brand-mark { font-size: 18px; }
    .nav-actions { gap: 5px; flex-wrap: nowrap; }
    .nav-actions .button { font-size: 10px; padding: 6px 9px; min-height: 32px; }
    .nav-actions .icon-button { font-size: 14px; padding: 5px; min-width: 30px; }
    .connection { font-size: 0; }
    .connection::before { width: 5px; height: 5px; margin-right: 2px; }
    body:has(#home:not([hidden])) .page { width: calc(100% - 28px); padding-top: 12px; }
    body:has(#home:not([hidden])) .nav { margin-bottom: 14px; padding-bottom: 10px; }
    #home { display: block; min-height: 0; max-width: 440px; margin: auto; }
    .home-stage { display: block; padding: 0; border: 0; background: transparent; }
    .home-preview { display: none; }
    .intro h1 { font-size: 32px; letter-spacing: -1px; margin: 0 0 6px; }
    .intro p { font-size: 12px; margin: 0 0 16px; }
    #home .field { margin-bottom: 12px; }
    #home input:not([type="range"]), #home select { min-height: 44px; font-size: 16px; padding: 8px; }
    .home-tabs { margin-bottom: 12px; }
    .form-fields { gap: 10px; }
    .game-header { margin-bottom: 12px; gap: 8px; }
    .game-header h1 { font-size: 22px; margin-right: 8px; }
    .game-header .row { flex-wrap: nowrap; gap: 5px; }
    .game-header .row a { display: none; }
    .game-header .button { font-size: 10px; min-height: 30px; }
    .room-code { font-size: 9px; letter-spacing: .5px; }
    .game-grid { display: block; }
    .game-board-area { width: min(100%, calc(100svh - 235px)); margin: auto; }
    .match-strip { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 10px; }
    #mobileLobby { display: flex; }
    .strip-player { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 5px 0 7px; border-bottom: 2px solid transparent; }
    .strip-player.current { border-bottom-color: var(--accent); }
    .strip-player .player-dot { width: 10px; height: 10px; }
    .strip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 650; }
    .strip-meta { font: 9px ui-monospace, monospace; color: var(--muted); margin-left: auto; }
    .status-line { margin-bottom: 3px; }
    .turn-title { font-size: 12px; }
    .timer { font-size: 13px; }
    .goal-label { font-size: 9px; margin-bottom: 7px; }
    .board-shell { padding: 20px 20px 25px; border-radius: 5px; }
    .board { grid-template-columns: repeat(8, minmax(0, 1fr) 7px) minmax(0, 1fr); grid-template-rows: repeat(8, minmax(0, 1fr) 7px) minmax(0, 1fr); }
    .cell small { display: none; }
    .pawn { font-size: 11px; }
    .pawn.current { outline-offset: 2px; }
    .axis-x { left: 20px; right: 20px; bottom: 5px; font-size: 10px; }
    .axis-y { left: 6px; top: 20px; bottom: 25px; font-size: 10px; }
    .controls { gap: 5px; margin-top: 10px; }
    .controls .button { min-height: 36px; padding: 7px 11px; font-size: 11px; }
    .preview-bar { margin-top: 8px; padding-bottom: 7px; font-size: 10px; }
    .preview-bar .row { gap: 5px; }
    .preview-bar .button { min-height: 28px; font-size: 10px; padding: 4px 8px; }
    .board-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
    .board-toolbar .button { min-height: 30px; padding: 5px 10px; font-size: 10px; }
    #compactMessage { min-width: 0; color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    body.in-match .footnote { display: none; }
    #drawerDialog { position: fixed; inset: auto 0 0; margin: 0; width: 100%; max-height: 80svh; border-radius: 7px 7px 0 0; padding: 18px 20px; }
    #drawerDialog .sidebar .panel { margin-bottom: 18px; padding-bottom: 18px; }
    #drawerDialog .sidebar .panel:last-child { margin-bottom: 0; border: 0; padding-bottom: 0; }
    #drawerDialog .section-top h2 { font-size: 14px; }
    #drawerDialog input, #drawerDialog select { min-height: 42px; }
}
@media (max-width: 360px) {
    .nav-actions .button { padding: 5px 7px; font-size: 9px; }
    .game-board-area { width: min(100%, calc(100svh - 215px)); }
    .game-header h1 { font-size: 20px; }
    .room-code { font-size: 8px; }
}

/* Explanations live in Info; the match keeps only actionable state. */
.stake-summary { font: 11px/1.5 ui-monospace, monospace; color: var(--accent); padding: 10px 0; margin: 8px 0 0; border-top: 1px solid var(--line); }
#infoDialog details { border-top: 1px solid var(--line); padding: 14px 0; }
#infoDialog summary { cursor: pointer; font-size: 13px; font-weight: 600; }
#infoDialog details[open] summary { margin-bottom: 12px; }
#infoDialog details > :last-child { margin-bottom: 0; }
.command-list { overflow-wrap: anywhere; white-space: pre-wrap; font: 11px/1.8 ui-monospace, monospace; color: var(--muted); }
#betControls { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }

/* Keep the board and its controls together within the available screen height. */
body.in-match .page { padding-top: 14px; padding-bottom: 14px; }
body.in-match .nav { margin-bottom: 16px; padding-bottom: 12px; }
body.in-match .game-header { margin-bottom: 12px; }
body.in-match .game-header h1 { font-size: 24px; }
.game-board-area { margin-left: auto; margin-right: auto; }
.action-dock { display: grid; grid-template-rows: 38px 32px; gap: 8px; padding-top: 10px; min-height: 88px; }
.action-dock .controls { margin: 0; }
.action-dock .preview-bar, .action-hint { grid-row: 2; margin: 0; padding: 0; border: 0; }
.action-hint { align-self: center; font-size: 11px; color: var(--muted); }
.action-dock .preview-bar { font-size: 10px; gap: 6px; }
.action-dock .preview-bar .row { flex-wrap: nowrap; gap: 5px; }
.action-dock .preview-bar .button { min-height: 32px; }
.range-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.range-label label { margin: 0; }
.range-label output { font: 600 12px ui-monospace, monospace; color: var(--accent); }
input[type="range"] { accent-color: var(--accent); border: 0; padding: 0; min-height: 30px; cursor: pointer; background: transparent; }
.cheat-field .note { margin-top: 0; }
.audio-setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 12px; }
.audio-setting .button { min-width: 64px; }
.player-right > .button { min-height: 24px; padding: 1px 6px; margin-left: 7px; font-size: 16px; }
.player > div:first-child { min-width: 0; }
.player-name { overflow-wrap: anywhere; }
#audioBtn.selected { color: var(--accent); border-color: var(--accent); }
#audioDialog .field { margin-top: 18px; }
@media (max-width: 780px) {
    body.in-match .page { padding-top: 10px; padding-bottom: 12px; }
    body.in-match .nav { margin-bottom: 10px; padding-bottom: 8px; }
    body.in-match .game-header { margin-bottom: 8px; }
    body.in-match .game-header h1 { font-size: 20px; }
    .game-board-area { width: 100%; }
    .action-dock { grid-template-rows: 38px 32px; }
    .action-dock .controls .button { min-height: 38px; }
    .board-toolbar { margin-top: 5px; }
}
@media (prefers-reduced-motion: reduce) { .pawn-layer .pawn { transition: none; } .slot.preview { animation: none; } }

/* Short screens keep setup controls reachable without shrinking touch targets. */
@media (max-width: 780px) and (max-height: 650px) {
    #home .intro h1 { font-size: 28px; margin-bottom: 3px; }
    #home .intro p { font-size: 11px; margin-bottom: 10px; }
    #home .field { margin-bottom: 8px; }
    #home .home-tabs { margin-bottom: 8px; }
    #home .field label { margin-bottom: 3px; }
    #home .cheat-field .note { font-size: 10px; }
}

@media (min-width: 781px) and (max-height: 650px) {
    .home-stage { padding: 16px; gap: 24px; }
    #home .intro h1 { font-size: 32px; margin-bottom: 6px; }
    #home .intro p { margin-bottom: 12px; }
    #home .field { margin-bottom: 8px; }
    #home .field label { margin-bottom: 3px; }
    #home .home-tabs { margin-bottom: 12px; }
}
@media (min-width: 781px) and (max-height: 550px) {
    body:has(#home:not([hidden])) .page { padding-top: 12px; padding-bottom: 12px; }
    body:has(#home:not([hidden])) .nav { margin-bottom: 10px; padding-bottom: 8px; }
    #home { min-height: calc(100svh - 86px); }
    .home-stage { padding: 12px; }
    #home .home-setup { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; align-items: center; }
    #home .home-tabs, #home .forms { grid-column: 1 / -1; }
    #home .intro h1 { font-size: 28px; margin: 0; }
    #home .intro p { display: none; }
    #home .field { margin-bottom: 8px; }
    #home .home-tabs { margin-bottom: 10px; }
}

/* Theme-aware menus keep the same interaction on desktop and touch screens. */
.select-control { position: relative; min-width: 0; width: 100%; flex: 1; }
.native-select { position: absolute; width: 1px !important; height: 1px; min-height: 0 !important; padding: 0; clip-path: inset(50%); overflow: hidden; }
.select-trigger { width: 100%; min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 3px; background: var(--bg); color: var(--text); text-align: left; font-size: 13px; font-weight: 400; }
.select-trigger > span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.select-trigger > svg { flex: 0 0 16px; color: var(--muted); }
.select-trigger:hover:not(:disabled), .select-trigger[aria-expanded="true"] { border-color: var(--accent); }
.select-popup { position: fixed; inset: auto; margin: 0; padding: 5px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--text); box-shadow: 0 8px 24px #0002; z-index: 100; scrollbar-width: thin; }
.select-option { min-height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 10px; border-radius: 2px; font-size: 13px; cursor: pointer; }
.select-option[aria-selected="true"] { color: var(--accent); background: var(--accent-soft); }
.select-option[aria-selected="true"]::after { content: '✓'; font-size: 12px; }
.select-option:hover, .select-option.highlighted { background: var(--surface); outline: 1px solid var(--line); outline-offset: -1px; }
.select-option[aria-disabled="true"] { opacity: .4; cursor: default; }
@media (max-width: 780px) {
    #home .select-trigger { min-height: 44px; font-size: 16px; padding: 8px; }
    .select-option { min-height: 44px; padding: 10px; font-size: 14px; }
    #drawerDialog .select-trigger { min-height: 42px; }
}
