:root {
    color-scheme: light;
    --background: #ffffff;
    --surface: #ffffff;
    --surface-raised: #f0f5f5;
    --text: #212529;
    --muted: #526368;
    --accent: #1c6972;
    --accent-ink: #ffffff;
    --border: #c6d6d8;
    --danger: #b3261e;
    --header-background: #0f1112;
    --header-text: #ffffff;
    --highlight: #008e96;
}

html[data-color-mode="dark"] {
    color-scheme: dark;
    --background: #0f1112;
    --surface: #16191a;
    --surface-raised: #24292b;
    --text: #ffffff;
    --muted: #becacc;
    --border: #526368;
    --danger: #ff9e8e;
}
html[data-color-mode="dark"] body { color-scheme: dark; }
html[data-color-mode="dark"] main a:not(.button),
html[data-color-mode="dark"] h2,
html[data-color-mode="dark"] .site-footer a { color: var(--highlight); }
@media (prefers-color-scheme: dark) {
    html:not([data-color-mode]) {
        color-scheme: dark;
        --background: #0f1112;
        --surface: #16191a;
        --surface-raised: #24292b;
        --text: #ffffff;
        --muted: #becacc;
        --border: #526368;
        --danger: #ff9e8e;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--background);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
}

a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }

.site-header, main, .site-footer {
    width: min(1080px, calc(100% - 40px));
    margin-inline: auto;
}

.site-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    justify-content: space-between;
    align-items: center;
    min-height: 86px;
    width: 100%;
    padding-inline: max(20px, calc((100% - 1080px) / 2));
    padding-block: 12px;
    background: var(--header-background);
    color: var(--header-text);
    border-bottom: 3px solid var(--highlight);
}

.brand {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    color: var(--header-text);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0;
    text-decoration: none;
}

.brand span { color: var(--header-text); }
.site-header .button-secondary { border-color: #687578; color: var(--header-text); }

.nav-links { display: flex; flex-wrap: wrap; max-width: 100%; align-items: center; gap: 8px 24px; }
.nav-links a { color: var(--header-text); text-decoration: none; }
.nav-links a:hover, .nav-links a:focus-visible { color: var(--header-text); text-decoration: underline; }
.nav-links a.button { color: var(--accent-ink); }
.nav-links form { margin: 0; }
.language-form { display: flex; align-items: center; gap: 6px; }
.language-form select {
    min-height: 36px;
    max-width: 120px;
    padding: 5px 8px;
    border: 1px solid #687578;
    border-radius: 6px;
    background: var(--header-background);
    color: var(--header-text);
    font: inherit;
}
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

main { min-height: calc(100vh - 166px); padding-block: 64px 80px; }

.hero { max-width: 760px; padding-block: 36px 54px; }
.eyebrow {
    color: var(--accent);
    font-weight: 700;
    font-size: .76rem;
    letter-spacing: .13em;
    text-transform: uppercase;
}

h1 { max-width: 750px; margin: 18px 0; font-size: clamp(2.2rem, 6vw, 4rem); line-height: 1.12; letter-spacing: -.025em; }
h2 { margin-top: 0; color: var(--accent); letter-spacing: -.01em; }
.hero p, .muted { color: var(--muted); line-height: 1.7; }
.hero p { max-width: 560px; font-size: 1.1rem; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 46px;
    padding: 0 18px;
    border: 1px solid var(--accent);
    border-radius: 3px;
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
.button:hover, .button:focus-visible { filter: brightness(1.08); }
.button-secondary { border-color: var(--border); background: transparent; color: var(--text); }
.button-small { min-height: 36px; padding-inline: 12px; font-size: .9rem; }

.panel, .form-card {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
}

.panel { max-width: 720px; padding: 28px; }
.account-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.account-tabs a { padding: 10px 12px; color: var(--text); text-decoration: none; border-bottom: 3px solid transparent; }
.account-tabs a.is-active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 700; }
.account-tabs a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.panel > .button { margin-top: 8px; }
.games-heading { max-width: 700px; margin-bottom: 32px; }
.games-heading h1 { margin-block: 14px; font-size: clamp(2rem, 6vw, 3.5rem); }
.games-heading p { line-height: 1.7; }
.game-selector {
    width: min(100%, 520px);
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}
.game-selector form { margin: 0; }
.game-choice-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 14px; }
.game-choice-field label { margin-bottom: 10px; }
.game-selector select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
.game-choice-fields .button { grid-column: 1 / -1; }
.game-selector select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.selected-game { margin: 0 0 18px; color: var(--muted); }
.selected-game strong { color: var(--accent); }
.game-rules {
    margin: 0 0 20px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}
.game-rules h2 { margin: 0 0 6px; font-size: 1rem; }
.game-rules p { margin: 0; color: var(--muted); line-height: 1.55; }
.game-panel {
    width: min(100%, 760px);
    padding: clamp(18px, 4vw, 30px);
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}
.game-difficulty { margin: 0; color: var(--muted); }
.game-difficulty strong { color: var(--text); }
.game-status { box-sizing: content-box; height: 3.2em; margin: 14px 0; overflow-y: auto; line-height: 1.6; color: var(--accent); font-weight: 600; }
.game-board { margin: 0 auto; }
.game-controls { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.game-controls[hidden], [hidden] { display: none !important; }
.ttt-board {
    display: grid;
    width: min(100%, 390px);
    aspect-ratio: 1;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-inline: auto;
    direction: ltr;
}
.board-cell {
    display: flex;
    min-width: 0;
    min-height: 0;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
}
.board-cell:disabled { cursor: default; }
.ttt-cell { border-radius: 10px; font-size: clamp(2.5rem, 14vw, 5.5rem); font-weight: 700; }
.maze-viewport {
    --maze-tile: 32px;
    position: relative;
    width: min(100%, calc(15 * var(--maze-tile) + 14 * 2px + 12px));
    height: calc(11 * var(--maze-tile) + 10 * 2px + 12px);
    margin-inline: auto;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #161c1a;
    direction: ltr;
}
.maze-touch-controls { display: none; }
.maze-board {
    display: grid;
    width: max-content;
    grid-template-columns: repeat(var(--maze-cols, 11), var(--maze-tile));
    grid-template-rows: repeat(var(--maze-rows, 11), var(--maze-tile));
    gap: 2px;
    padding: 6px;
}
.maze-board:focus-visible { outline: none; }
.maze-viewport:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.maze-cell { min-width: 0; border-radius: 2px; font-size: 14px; }
.maze-wall { border: 1px solid #62706a; background: #36413c; }
.maze-board .maze-floor { border-color: #b4a989; background: #d8ccac; color: #454133; }
.maze-board .maze-player { border: 2px solid #fff; background: #24834b; color: #fff; font-size: 20px; }
.maze-board .maze-target { border: 3px solid #d6a91d; background: #fff0a8; color: #634c00; font-size: 16px; }
.maze-board .maze-shard { background: #8ee4ee; color: #064f5a; font-size: 18px; }
.maze-c0 { --mc: #d64545; } .maze-c1 { --mc: #3b78d8; } .maze-c2 { --mc: #2e9e5b; }
.maze-c3 { --mc: #e2b81c; } .maze-c4 { --mc: #8a4fc7; } .maze-c5 { --mc: #e8812a; }
.maze-board .maze-key { background: var(--mc); color: #fff; font-weight: 800; text-shadow: 0 0 2px #000; }
.maze-board .maze-gate { border: 3px solid var(--mc); background: #2b2430; color: var(--mc); font-weight: 800; }
.maze-board .maze-open-gate { border: 2px dashed var(--mc); background: #9aab9e; color: #36413c; }
.maze-chip { display: inline-block; min-width: 1.5em; margin-inline: 2px; border-radius: 4px; background: var(--mc); color: #fff; font-style: normal; font-weight: 800; text-align: center; text-shadow: 0 0 2px #000; }
.maze-board .maze-player.maze-open-gate { border: 2px solid #fff; background: #24834b; color: #fff; }
.maze-board .maze-target.maze-gate, .maze-board .maze-target.maze-key { outline: 3px solid #d6a91d; outline-offset: -3px; }
.maze-board .maze-cell { padding: 0; overflow: hidden; }
.maze-board .maze-exit { font-size: 9px; font-weight: 800; }
.maze-board .maze-locked-exit { background: #a39a84; color: #514a3d; }
.maze-progress { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin: 0 auto 12px; color: var(--muted); }
@media (max-width: 600px), (hover: none) and (pointer: coarse) and (max-height: 600px) {
    body.playing-game.game-in-progress {
        display: flex;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        flex-direction: column;
        overflow: hidden;
        overflow: clip;
        overscroll-behavior: none;
    }
    html:has(body.playing-game.game-in-progress) { overflow: hidden; overscroll-behavior: none; }
    body.playing-game.game-in-progress .site-header,
    body.playing-game.game-in-progress .site-footer,
    body.playing-game.game-in-progress .games-heading,
    body.playing-game.game-in-progress .game-rules,
    body.playing-game.game-in-progress .game-difficulty { display: none; }
    body.playing-game.game-in-progress main {
        display: flex;
        width: 100%;
        min-height: 0;
        flex: 1 1 auto;
        overflow: hidden;
        overflow: clip;
        padding: 0;
    }
    body.playing-game.game-in-progress .game-panel {
        display: flex;
        width: 100%;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
        overflow: hidden;
        overflow: clip;
        padding: 8px;
        border: 0;
        border-radius: 0;
    }
    body.playing-game.game-in-progress .game-status {
        box-sizing: border-box;
        height: auto;
        min-height: 2.8em;
        max-height: 4.8em;
        flex: 0 0 auto;
        margin: 4px 0 8px;
    }
    body.playing-game.game-in-progress .game-board {
        display: flex;
        min-height: 0;
        flex: 1 1 auto;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        overflow: clip;
    }
    body.playing-game.game-in-progress .ttt-board,
    body.playing-game.game-in-progress .grid-board {
        width: min(100%, 56dvh, 560px);
        max-height: 100%;
        flex: 0 1 auto;
    }
    body.playing-game.game-in-progress .game-board-chess {
        gap: 6px;
    }
    body.playing-game.game-in-progress .chess-board {
        width: min(100%, 44dvh, 560px);
    }
    body.playing-game.game-in-progress .captured-pieces {
        width: 100%;
        flex: 0 0 auto;
        gap: 6px;
        margin-top: 0;
    }
    body.playing-game.game-in-progress .captured-group {
        padding: 4px;
    }
    body.playing-game.game-in-progress .captured-group > span {
        margin-bottom: 2px;
        font-size: .68rem;
    }
    body.playing-game.game-in-progress .captured-group .captured-piece-icon {
        width: 21px;
        height: 21px;
        font-size: 1rem;
    }
    body.playing-game.game-in-progress .maze-viewport {
        --maze-tile: clamp(12px, 5vw, 22px);
        width: min(100%, calc(15 * var(--maze-tile) + 14 * 2px + 12px));
        height: min(100%, calc(11 * var(--maze-tile) + 10 * 2px + 12px));
        max-height: 100%;
        flex: 0 1 auto;
    }
    body.playing-game.game-in-progress .maze-touch-controls {
        position: fixed;
        z-index: 20;
        right: max(14px, env(safe-area-inset-right, 0px));
        bottom: max(14px, env(safe-area-inset-bottom, 0px));
        display: grid;
        grid-template: repeat(3, 64px) / repeat(3, 64px);
        gap: 4px;
        padding: 6px;
        border: 1px solid rgb(243 246 238 / 38%);
        border-radius: 16px;
        background: rgb(22 28 26 / 72%);
        box-shadow: 0 4px 18px rgb(0 0 0 / 35%);
        -webkit-backdrop-filter: blur(3px);
        backdrop-filter: blur(3px);
    }
    body.playing-game.game-in-progress .maze-touch-controls[hidden] { display: none; }
    body.playing-game.game-in-progress .maze-touch-controls button {
        display: flex;
        min-width: 64px;
        min-height: 64px;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: 1px solid rgb(243 246 238 / 38%);
        border-radius: 12px;
        background: rgb(32 39 37 / 82%);
        color: #ffffff;
        font-size: 2rem;
        line-height: 1;
        touch-action: manipulation;
        user-select: none;
    }
    body.playing-game.game-in-progress .maze-touch-controls button:active {
        background: var(--accent);
        color: var(--accent-ink);
    }
    body.playing-game.game-in-progress .maze-touch-controls button:nth-child(1) { grid-area: 1 / 2; }
    body.playing-game.game-in-progress .maze-touch-controls button:nth-child(2) { grid-area: 2 / 1; }
    body.playing-game.game-in-progress .maze-touch-controls button:nth-child(3) { grid-area: 2 / 3; }
    body.playing-game.game-in-progress .maze-touch-controls button:nth-child(4) { grid-area: 3 / 2; }
    body.playing-game.game-in-progress .backgammon-board {
        width: 100%;
        min-height: 0;
        flex: 0 1 auto;
        overflow: hidden;
        padding: 3px;
    }
    body.playing-game.game-in-progress .bg-row {
        height: clamp(56px, min(23vw, 17dvh), 110px);
        grid-template-columns: repeat(12, minmax(0, 1fr));
    }
    body.playing-game.game-in-progress .bg-mid,
    body.playing-game.game-in-progress .bg-off {
        gap: 3px;
        padding: 3px;
        font-size: .6rem;
    }
    body.playing-game.game-in-progress .bg-bar,
    body.playing-game.game-in-progress .bg-off-target {
        padding: 3px;
        font-size: .6rem;
    }
    body.playing-game.game-in-progress .game-controls {
        min-height: 46px;
        flex: 0 0 auto;
        justify-content: center;
        gap: 6px;
        margin-top: 6px;
    }
    body.playing-game.game-in-progress .game-controls .button {
        min-height: 40px;
        padding-inline: 10px;
        font-size: .85rem;
    }
}
.grid-board {
    display: grid;
    width: min(100%, 560px);
    aspect-ratio: 1;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, minmax(0, 1fr));
    overflow: hidden;
    margin-inline: auto;
    border: 4px solid #8d6845;
    border-radius: 4px;
    direction: ltr;
}
.square-light { background: #e6d3b5; }
.square-dark { background: #76563b; }
.chess-piece { font-size: clamp(1.65rem, 7vw, 3.65rem); line-height: 1; }
.piece-human { color: #f6f1e7; text-shadow: 0 1px 2px #202020, 0 0 3px #202020; }
.piece-ai { color: #222522; text-shadow: 0 1px 1px #fff6; }
.checker-piece {
    display: inline-flex;
    width: 70%;
    aspect-ratio: 1;
    align-items: center;
    justify-content: center;
    border: 2px solid #282b27;
    border-radius: 50%;
}
.checker-piece.piece-human { background: #f3eee1; }
.checker-piece.piece-ai { background: #292d2b; border-color: #b8b4a8; }
.forced-piece { outline: 3px solid #c4f269; outline-offset: 3px; box-shadow: 0 0 12px 3px #c4f269; }
.king-piece::after { content: "♛"; font-size: .8em; }
.cell-selected { outline: 4px solid var(--accent); outline-offset: -4px; }
.cell-target { box-shadow: inset 0 0 0 4px #c4f269; }
.captured-pieces {
    display: grid;
    width: min(100%, 560px);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 12px auto 0;
}
.captured-group { min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); }
.captured-group > span { display: block; margin-bottom: 4px; font-size: .8rem; color: var(--muted); }
.captured-group > div { display: flex; min-height: 1.6em; flex-wrap: wrap; align-items: center; gap: 3px; }
.captured-group .captured-piece-icon {
    display: inline-flex;
    width: 26px;
    height: 26px;
    align-items: center;
    justify-content: center;
    border: 1px solid #4c5049;
    border-radius: 4px;
    font-size: 1.25rem;
    line-height: 1;
}
.captured-group .captured-piece-icon.piece-ai { background: #f3eee1; color: #202522; text-shadow: 0 0 1px #fff; }
.captured-group .captured-piece-icon.piece-human { background: #292d2b; border-color: #b8b4a8; color: #fffdf5; text-shadow: 0 1px 2px #000; }
.backgammon-board {
    width: 100%;
    overflow-x: auto;
    padding: 14px;
    border: 5px solid #805538;
    border-radius: 10px;
    background: #b77a47;
    direction: ltr;
}
.bg-row {
    display: grid;
    min-width: 0;
    height: clamp(108px, 26vw, 205px);
    grid-template-columns: repeat(12, minmax(35px, 1fr));
    background: #e0c39b;
}
.bg-top { border-bottom: 3px solid #75482e; }
.bg-bottom { border-top: 3px solid #75482e; }
.bg-point {
    position: relative;
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}
.bg-point:nth-child(4n+1), .bg-point:nth-child(4n+3) { background: rgb(80 49 34 / 8%); }
.point-bottom { flex-direction: column-reverse; }
.point-checkers { display: flex; width: 100%; flex-direction: column; align-items: center; }
.point-bottom .point-checkers { flex-direction: column-reverse; }
.bg-point .checker-piece { width: min(84%, 39px); margin-block: -2px; }
.point-number { position: absolute; z-index: 1; top: 50%; font-size: .65rem; color: #33281e; }
.bg-mid, .bg-off {
    display: flex;
    min-width: 0;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px;
    color: #fff8ed;
    font-size: clamp(.62rem, 2vw, .85rem);
}
.bg-mid { background: #75482e; }
.bg-off { background: #805538; }
.bg-bar, .bg-off-target { padding: 5px 8px; border: 1px solid #cba47e; border-radius: 5px; background: #523824; color: white; font: inherit; cursor: pointer; }
.bg-bar:disabled, .bg-off-target:disabled { opacity: .65; cursor: default; }
.form-card { width: min(100%, 470px); padding: clamp(24px, 6vw, 38px); }
.form-card h1 { margin: 0 0 8px; font-size: clamp(2rem, 5vw, 2.7rem); letter-spacing: -.06em; }
.form-card > p { margin: 0 0 26px; color: var(--muted); }
.field { margin-top: 19px; }
label { display: block; margin-bottom: 8px; font-weight: 600; }
input {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { display: block; margin-top: 7px; color: var(--muted); font-size: .88rem; }
.field-error, .alert { color: var(--danger); }
.field-error { display: block; margin-top: 7px; font-size: .9rem; }
.alert { margin: 18px 0; padding: 12px; border: 1px solid currentColor; border-radius: 6px; }
.form-card .button { width: 100%; margin-top: 24px; }
.form-foot { margin-top: 22px !important; text-align: center; }
.form-foot a { color: var(--accent); }
.profile-grid { display: grid; grid-template-columns: 150px 1fr; gap: 14px 20px; }
.profile-grid dt { color: var(--muted); }
.profile-grid dd { margin: 0; overflow-wrap: anywhere; }
.game-history-panel { width: min(100%, 960px); max-width: none; margin-top: 24px; }
.game-history-panel h2 { margin-bottom: 16px; }
.table-scroll { width: 100%; overflow-x: auto; }
.game-history-table { width: 100%; border-collapse: collapse; text-align: left; }
.game-history-table th, .game-history-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.game-history-table th { color: var(--muted); font-size: .85rem; font-weight: 600; }
.game-history-table tbody tr:last-child td { border-bottom: 0; }
.form-error { color: var(--danger); }
html[dir="rtl"] .game-history-table { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.site-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding-block: 22px; border-top: 3px solid var(--text); color: var(--muted); font-size: .86rem; }
.site-footer a[aria-current="page"] { font-weight: 700; }
.legal-page { max-width: 900px; line-height: 1.7; overflow-wrap: anywhere; }
.legal-page h1 { font-size: clamp(2rem, 6vw, 3rem); margin-top: 0; }
.legal-page h2 { margin-block: 1.8em .6em; font-size: 1.4rem; line-height: 1.35; }
.legal-page h3 { margin-block: 1.5em .5em; font-size: 1.1rem; }
.legal-page li + li { margin-top: .5em; }
.legal-page [id] { scroll-margin-block: 24px; }

html[dir="rtl"] body { font-family: Tahoma, Arial, system-ui, sans-serif; }
html[dir="rtl"] .profile-grid { text-align: right; }
html[dir="rtl"] input, html[dir="rtl"] .game-selector select { text-align: right; }

html[dir="rtl"] .mono, html[dir="rtl"] input[type="email"], html[dir="rtl"] input[type="password"] {
    direction: ltr;
    text-align: left;
}

@media (max-width: 540px) {
    .game-status { height: 6.4em; }
    main, .site-footer { width: min(100% - 28px, 1080px); }
    .site-header { min-height: 72px; padding-inline: 14px; }
    .brand { font-size: .96rem; }
    .nav-links { gap: 8px; font-size: .82rem; }
    .language-form { gap: 4px; }
    .language-form select { max-width: 104px; font-size: .82rem; }
    .game-choice-fields { grid-template-columns: 1fr; }
    .game-choice-fields .button { grid-column: auto; }
    main { padding-top: 34px; }
    .profile-grid { grid-template-columns: 1fr; gap: 4px; }
    .profile-grid dd { margin-bottom: 14px; }
}

@media (max-width: 600px) {
    .site-header {
        min-height: 0;
        flex-wrap: wrap;
        gap: 8px;
        padding-block: 8px;
    }
    .nav-links {
        width: 100%;
        flex: 1 0 100%;
        justify-content: space-between;
        gap: 6px;
        flex-wrap: wrap;
    }
    body.playing-game main { min-height: 0; padding-block: 12px 18px; }
    body.playing-game .games-heading { margin-bottom: 12px; }
    body.playing-game .games-heading h1 { margin-block: 8px; font-size: clamp(1.8rem, 8vw, 2.6rem); }
    body.playing-game .game-panel { padding: 12px; }
    body.playing-game .game-status { margin-block: 8px; }
    body.playing-game .game-controls { margin-top: 10px; }
    .backgammon-board { padding: 4px; border-width: 3px; }
    .bg-row { height: clamp(78px, 23vw, 128px); grid-template-columns: repeat(12, minmax(0, 1fr)); }
    .bg-point .checker-piece { width: min(94%, 26px); margin-block: -2px; border-width: 1px; }
    .bg-mid, .bg-off { flex-wrap: wrap; padding: 5px 3px; font-size: .58rem; }
    .bg-bar, .bg-off-target { padding: 4px; font-size: .58rem; }
    .point-number { font-size: .56rem; }
    .bg-mid { gap: 3px; }
}

@media (max-width: 360px) {
    main, .site-footer { width: calc(100% - 20px); }
    .site-header { padding-inline: 10px; }
    body.playing-game main { padding-block: 8px 10px; }
    body.playing-game .games-heading { margin-bottom: 8px; }
    body.playing-game .game-panel { padding: 8px; }
    body.playing-game .game-status { margin-block: 6px; }
    body.playing-game .game-controls { gap: 6px; margin-top: 6px; }
    body.playing-game .game-controls .button { min-height: 40px; padding-inline: 10px; font-size: .85rem; }
    .ttt-board, .grid-board { width: min(100%, 244px); }
    .chess-board { width: min(100%, 224px); }
    .ttt-board { gap: 5px; }
    .captured-pieces { gap: 6px; margin-top: 6px; }
    .captured-group { display: flex; align-items: center; gap: 4px; padding: 3px 4px; }
    .captured-group > span { flex: 0 0 auto; margin: 0; font-size: .65rem; }
    .captured-group > div { min-width: 0; gap: 1px; }
    .captured-group .captured-piece-icon { width: 21px; height: 21px; font-size: 1rem; }
    .bg-row { height: 74px; }
    .bg-point .checker-piece { width: min(92%, 21px); }
    .bg-point .point-checkers { gap: 0; }
    .bg-mid, .bg-off { padding: 3px 1px; font-size: .53rem; }
    .bg-bar, .bg-off-target { padding: 3px 2px; font-size: .53rem; }
}

/* Scavenger hunt */
.hunt-app { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 8px; height: 100%; min-height: 0; min-width: 0; }
.hunt-app:has(.hunt-background-image) { position: relative; isolation: isolate; }
.hunt-background-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .22; z-index: -1; pointer-events: none; }
.admin-fold-group { min-width: 0; margin-block: 12px; border: 1px solid var(--border); border-radius: 8px; }
.admin-fold-group > summary { padding: 12px 14px; cursor: pointer; font-weight: 700; }
.admin-fold-group > .admin-group { border: 0; }
.admin-fold-group > .field { margin-inline: 14px; }
.hunt-bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; }
.hunt-bar p { margin: 0; }
.hunt-status { min-height: 2.6em; margin: 0; color: var(--muted); }
.hunt-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); }
.hunt-tab { padding: 8px 16px; border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.hunt-tab[aria-selected="true"] { border-color: var(--border); background: var(--surface-raised); color: inherit; font-weight: 600; }
.hunt-tab[hidden], .hunt-panel[hidden] { display: none; }
.hunt-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-height: 0; min-width: 0; overflow-y: auto; }
.hunt-panel[data-panel="map"] { grid-template-rows: auto minmax(0, 1fr); overflow: hidden; }
.hunt-tools { position: absolute; top: 8px; right: 8px; z-index: 1000; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.hunt-tools .button { width: auto; min-height: 0; padding: 6px 10px; font-size: .8rem; background: var(--surface); color: var(--text); }
.hunt-tools .button[hidden] { display: none; }
.hunt-status { overflow: hidden; min-height: 0; margin: 0; font-size: .85rem; text-overflow: ellipsis; white-space: nowrap; }
/* The game fills the screen: tabs stay visible and only the panel contents scroll. */
body:has(.hunt-app) { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
body:has(.hunt-app) main { flex: 1 1 auto; min-height: 0; padding-block: 8px; }
body:has(.hunt-app) .site-header, body:has(.hunt-app) .site-footer { flex: none; }
.hunt-app .games-heading { margin: 0; padding: 0; }
.hunt-app .games-heading h1 { margin-block: 4px; font-size: 1.6rem; }
.hunt-app .hunt-bar p, .hunt-app .hunt-attribution { margin: 0; }
.hunt-map-wrap { position: relative; min-height: 0; }
.hunt-toasts { position: absolute; top: 8px; left: 50%; z-index: 1100; width: min(90%, 360px); transform: translateX(-50%); pointer-events: none; }
.hunt-map { height: 100%; min-height: 160px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); z-index: 0; }
.hunt-detail { position: absolute; right: 8px; bottom: 8px; left: 8px; z-index: 1000; max-height: 55%; overflow-y: auto; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
.hunt-detail[hidden] { display: none; }
.hunt-detail-close { position: sticky; top: 0; float: right; width: 36px; height: 36px; padding: 0; font-size: 1.5rem; line-height: 1; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); color: inherit; cursor: pointer; }
.hunt-heading, .hunt-hint { background: none; border: 0; pointer-events: none; }
.hunt-heading-beam, .hunt-hint-arrow { display: block; transform-origin: 50% 50%; }
.hunt-grid { padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-raised); }
.hunt-grid h2 { margin: 0; font-size: 1.05rem; }
.hunt-grid-hint { margin: 4px 0 10px; }
.hunt-grid-cells { display: grid; grid-template-columns: repeat(var(--hunt-grid-size), minmax(0, 1fr)); gap: 6px; }
.hunt-grid-cell { display: flex; min-width: 0; min-height: 72px; flex-direction: column; justify-content: center; gap: 3px; padding: 6px; overflow-wrap: anywhere; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); text-align: center; }
.hunt-grid-number, .hunt-grid-owner { color: var(--muted); font-size: .75rem; }
.hunt-grid-title { font-size: .85rem; }
.hunt-grid-mine, .hunt-grid-team { border-color: var(--accent); }
.hunt-grid-opponent { border-color: var(--danger); }
.hunt-arrows { position: absolute; inset: 0; z-index: 800; pointer-events: none; overflow: hidden; }
.hunt-arrow { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; clip-path: polygon(0 0, 100% 50%, 0 100%); filter: drop-shadow(0 0 2px #000); }
.hunt-fog { position: absolute; top: 0; left: 0; pointer-events: none; }
.hunt-side { display: grid; gap: 14px; }
.hunt-side h2 { margin: 0 0 6px; font-size: 1.05rem; }
.hunt-scores { display: grid; gap: 12px; margin-top: 16px; }
.hunt-score-card { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--line, #3a4a5a); border-radius: 8px; margin-bottom: 8px; }
.hunt-score-card h3 { margin: 0 0 4px; }
.hunt-score-line { display: flex; justify-content: space-between; gap: 12px; }
.hunt-score-total { border-top: 1px solid var(--line, #3a4a5a); padding-top: 4px; }
.hunt-final { padding: 10px 12px; border: 2px solid var(--accent, #4caf50); border-radius: 8px; }
.hunt-players { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.hunt-dot { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 50%; background: var(--muted); }
.hunt-dot-on { background: var(--accent); }
.hunt-image { display: block; max-width: 100%; max-height: 220px; margin-bottom: 8px; border-radius: 6px; object-fit: cover; }
.hunt-quiz { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.hunt-options { margin: 6px 0; padding: 0; border: 0; display: grid; gap: 4px; }
.hunt-option { display: grid; grid-template-columns: 20px 1fr; align-items: start; gap: 8px; margin: 0; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-weight: 400; line-height: 1.3; cursor: pointer; }
.hunt-option input { width: 18px; min-height: 0; height: 18px; margin: 1px 0 0; padding: 0; accent-color: var(--accent); }
.hunt-option:has(input:checked) { border-color: var(--accent); background: var(--surface-raised); }
.hunt-quiz input[type="text"] { width: 100%; }
.hunt-ok { color: var(--accent); }
.hunt-note, .hunt-result { color: var(--danger); }
.hunt-flash { padding: 6px 8px; border-radius: 6px; background: var(--surface); border: 1px solid var(--accent); }
.hunt-area-list { margin: 10px 0 0; padding-left: 18px; }
.hunt-places { margin: 12px 0 0; padding: 10px 14px; border: 1px solid currentColor; border-radius: 8px; }
.hunt-place { display: block; padding: 6px 0; }
.hunt-attribution { font-size: .8rem; }
.hunt-hotspot-icon { display: flex; align-items: center; justify-content: center; border: 2px solid #fff; border-radius: 50%; background: #dd6b20; color: #fff; font-size: 16px; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
.hunt-hotspot-done { background: #2f855a; }
.leaflet-tooltip.hunt-player-label { padding: 1px 6px; font-size: .75rem; font-weight: 600; }


/* Administration */
.admin-manual-dialog { width: min(1100px, calc(100% - 24px)); height: calc(100dvh - 24px); max-width: none; max-height: none; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.admin-manual-dialog[open] { display: flex; flex-direction: column; }
.admin-manual-dialog::backdrop { background: rgb(0 0 0 / 65%); }
.admin-manual-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.admin-manual-bar h2 { margin: 0; font-size: 1.1rem; }
.admin-manual-bar form { margin: 0; margin-inline-start: auto; }
.admin-manual-dialog iframe { width: 100%; flex: 1; min-height: 0; border: 0; background: #fff; }
.admin-panel { max-width: 1000px; }
main:has(.admin-hunt-panel) { width: calc(100% - 40px); }
.admin-hunt-panel { max-width: none; }
.admin-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.admin-table th, .admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.admin-table small { display: block; }
.admin-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; margin: 16px 0; align-items: start; }
.admin-group { margin: 0; padding: 4px 14px 10px; border: 1px solid var(--border); border-radius: 8px; min-width: 0; }
.admin-group legend { padding: 0 8px; font-weight: 700; }
.admin-rows { margin: 16px 0; }
.admin-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.admin-cell { min-width: 0; }
.admin-cell-main { flex: 1 1 200px; overflow-wrap: anywhere; }
.admin-cell-main small { display: block; }
.admin-cell[data-label]::before { content: attr(data-label) ": "; font-size: .8rem; color: var(--muted); opacity: .7; }
.admin-cell-action { margin-left: auto; }
.admin-hotspot-row { display: grid; grid-template-columns: 20px minmax(0, 1fr); }
.admin-hotspot-select { width: 20px; min-height: 0; margin: 0; }
.admin-hotspot-details { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; min-width: 0; }
.admin-hotspot-details .admin-cell-main label { margin: 0; }
.admin-hotspot-details .admin-inline { margin-top: 0; }
.admin-map { width: 100%; max-width: 640px; aspect-ratio: 1 / 1; border: 1px solid var(--border); border-radius: 8px; margin-top: 8px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 16px; }
.admin-langs { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px 16px; margin-top: 8px; }
.admin-lang label { margin-bottom: 4px; font-weight: 500; font-size: .9rem; }
.admin-checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; }
.admin-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.admin-check input { width: auto; min-height: 0; }
.admin-scroll { max-height: 260px; overflow: auto; flex-direction: column; flex-wrap: nowrap; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.admin-card { padding: 14px; margin: 14px 0 6px; border: 1px solid var(--border); border-radius: 8px; }
.admin-inline { display: inline-block; margin-top: 12px; }
.admin-flash { padding: 8px 12px; border-radius: 6px; background: var(--surface-raised); color: var(--accent); }
.admin-form textarea, .admin-form select {
    width: 100%; box-sizing: border-box; padding: 10px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface-raised); color: var(--text); font: inherit;
}
.admin-filter { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
.admin-filter label { margin: 0; }
.admin-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.admin-dot-in { background: #2f7bff; }
.admin-dot-out { background: #e5484d; }
.admin-dot-free { background: #f5c518; }
.admin-mode { background: #fff; color: #17200c; padding: 4px 8px; display: grid; gap: 2px; font-size: .85rem; }
.admin-mode label { cursor: pointer; white-space: nowrap; }
.admin-map.mode-map .leaflet-hotspots-pane { opacity: .3; }
.admin-map.mode-map .leaflet-hotspots-pane .leaflet-interactive { pointer-events: none !important; }
.admin-map.mode-hotspots .leaflet-marker-pane { opacity: .3; }
.admin-map.mode-hotspots .leaflet-marker-pane .leaflet-marker-icon { pointer-events: none !important; }
.admin-vertex { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #17200c; background: var(--accent); }
[hidden] { display: none !important; }
.admin-image-pick { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
.admin-image-pick select { width: auto; max-width: 100%; }
.hunt-high-scores-table { max-width: 100%; overflow-x: auto; margin-top: 16px; }
.hunt-high-scores-table th, .hunt-high-scores-table td { white-space: nowrap; }
.admin-thumb { display: block; max-width: 160px; max-height: 120px; margin-top: 8px; border-radius: 6px; }

.admin-map-fs { margin-top: 6px; }
.admin-map.is-fullscreen { position: fixed; inset: 0; z-index: 2000; max-width: none; width: 100vw; height: 100dvh; aspect-ratio: auto; margin: 0; border-radius: 0; }
.admin-map-fs:is(body > .admin-map-fs) { position: fixed; top: 10px; right: 10px; z-index: 2001; }
body.admin-map-locked { overflow: hidden; }
.admin-map.is-fullscreen .leaflet-top.leaflet-right { margin-top: 52px; }

.hunt-readonly #hunt-hint, .hunt-readonly #hunt-dev-reveal, .hunt-readonly .hunt-team-pick, .hunt-readonly #hunt-answer-form { display: none !important; }
.admin-map.mode-delete .admin-vertex { cursor: crosshair; background: #ff6b6b; }
.admin-dot-del { background: #8a2be2; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.settings-block { padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.brand-logo { display: block; width: 220px; height: auto; max-height: 48px; max-width: 100%; object-fit: contain; }
.admin-color { display: flex; gap: 8px; align-items: center; }
.admin-color input[type=color] { width: 44px; height: 38px; padding: 2px; flex: none; }
.admin-filter { flex-wrap: wrap; }

/* Urban Escape */
.escape-pattern { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0; }
.escape-char { min-width: 2.4rem; padding: 0.5rem; text-align: center; font: 700 1.4rem monospace; border: 2px solid currentColor; border-radius: 0.4rem; opacity: 0.45; }
.escape-char.known { opacity: 1; }
.escape-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 1rem 0; }
.escape-question { font-size: 1.15rem; font-weight: 600; }

.escape-graph[hidden] { display: none; }
.escape-graph:not(.graph-fullscreen) .graph-canvas { aspect-ratio: 5 / 3; max-height: 70vh; }
.graph-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }
.graph-tools .button { min-width: 2.75rem; }
.graph-status { margin: 0 0 0.5rem; }
.graph-canvas { display: block; width: 100%; touch-action: none; user-select: none; -webkit-user-select: none; border: 1px solid rgba(128, 128, 128, 0.5); border-radius: 0.4rem; background-color: #f8fafc; background-image: radial-gradient(rgba(100, 116, 139, 0.25) 1px, transparent 1px); background-size: 24px 24px; color: #64748b; cursor: grab; }
.graph-edge { stroke: #64748b; stroke-width: 3; fill: none; pointer-events: none; }
.graph-edge.selected { stroke: #ef4444; stroke-width: 5; }
.graph-edge.pending { stroke-dasharray: 8 6; }
.graph-edge-hit { stroke: transparent; stroke-width: 22; cursor: pointer; }
.graph-body { fill: #fff; stroke: #3b82f6; stroke-width: 4; cursor: move; }
.graph-node.start .graph-body { stroke: #16a34a; }
.graph-node.selected .graph-body, .graph-node.from .graph-body { fill: #dbeafe; stroke-width: 6; }
.graph-label { text-anchor: middle; font: 700 15px sans-serif; fill: #0f172a; pointer-events: none; }
.graph-sub { text-anchor: middle; font: 13px sans-serif; fill: #475569; pointer-events: none; }
.graph-start { text-anchor: middle; font: 700 13px sans-serif; fill: #16a34a; pointer-events: none; }
.graph-sat { stroke-width: 2.5; }
.graph-sat.used { fill: #64748b; stroke: #fff; cursor: pointer; }
.graph-sat.free { fill: #fff; pointer-events: none; }
.graph-sat.output { stroke: #d000d0; }
.graph-sat.input { stroke: #00bcd4; }
.graph-sat.used.output { fill: #d000d0; }
.graph-sat.used.input { fill: #00bcd4; }
.graph-sat-plus { text-anchor: middle; font: 700 15px sans-serif; fill: #d000d0; pointer-events: none; }
.graph-sat-hit { fill: transparent; cursor: crosshair; }
.graph-node.from .graph-sat.free { fill: #d000d0; }
.graph-node.exit .graph-body { stroke: #00bcd4; stroke-dasharray: 6 3; }
.graph-node.from .graph-sat-plus { fill: #fff; }
.graph-node-form { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.75rem; }
.graph-node-form label { display: flex; flex-direction: column; gap: 0.25rem; }
.escape-graph.graph-fullscreen { position: fixed; inset: 0; z-index: 10000; margin: 0; padding: 0.75rem; display: flex; flex-direction: column; background: var(--surface, #fff); color: inherit; overflow: auto; }
.escape-graph.graph-fullscreen > strong, .escape-graph.graph-fullscreen > p.muted:not(.graph-status) { display: none; }
.escape-graph.graph-fullscreen .graph-canvas { flex: 1 1 auto; min-height: 50vh; }
html.graph-fullscreen-open, html.graph-fullscreen-open body { overflow: hidden; }
.escape-graph { position: relative; }
.graph-confirm { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 1rem; background: rgba(0, 0, 0, 0.45); }
.graph-confirm[hidden] { display: none; }
.graph-confirm-panel { max-width: 26rem; padding: 1rem 1.25rem; border-radius: 0.5rem; background: var(--surface, #fff); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.graph-confirm-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }
.hunt-content { display: flex; gap: 1rem; align-items: flex-start; }
.hunt-content-above { flex-direction: column; }
.hunt-content-below { flex-direction: column-reverse; }
.hunt-content-right { flex-direction: row-reverse; }
.hunt-content-text { white-space: pre-wrap; flex: 1; margin: 0; min-width: 0; }
.hunt-content-image { display: block; flex: none; width: auto; height: auto; max-width: 100%; max-height: 28rem; object-fit: contain; border-radius: 0.5rem; }
.hunt-content-above .hunt-content-image, .hunt-content-below .hunt-content-image { width: 100%; }
.hunt-content-left .hunt-content-image, .hunt-content-right .hunt-content-image { width: 40%; }
.hunt-success { margin: 1rem 0; padding: 1rem; border: 1px solid var(--accent); border-radius: 0.5rem; }
.hunt-success[hidden] { display: none; }
.hunt-info-next { font-weight: 700; }
@media (max-width: 480px) {
    .hunt-content-left, .hunt-content-right { flex-direction: column; }
    .hunt-content-left .hunt-content-image, .hunt-content-right .hunt-content-image { width: 100%; }
}
