:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --text: #1d2733;
    --muted: #66768a;
    --line: #dde3ea;
    --accent: #2f6fd6;
    --accent-text: #ffffff;
    --you: #1f8a4c;
    --button: #eef2f6;
    --button-hover: #e2e8ef;
    --panel-w: 300px;
    --topbar-h: 52px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14181d;
        --surface: #1d232a;
        --text: #e6ebf1;
        --muted: #93a1b2;
        --line: #2c343d;
        --accent: #5b93ec;
        --you: #4cc282;
        --button: #262e37;
        --button-hover: #303943;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    min-height: 100vh;
    min-height: 100svh;
}

.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 max(16px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.topbar h1 { font-size: 17px; font-weight: 650; margin: 0; letter-spacing: 0.01em; }
.tag {
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 8px;
}
.topbar h1 a { color: inherit; text-decoration: none; }
.nav { margin-left: auto; }
a { color: var(--accent); }

/* Text pages (about.html). */
.page { max-width: 680px; margin: 0 auto; padding: 24px max(16px, env(safe-area-inset-left)); }
.page h2 { font-size: 20px; margin: 0 0 12px; }
.page h3 { font-size: 16px; margin: 24px 0 8px; }
.page p, .page ul { margin: 0 0 12px; }

/* Board as large as fits next to the panel and below the top bar. */
.layout {
    --gap: 24px;
    --board: min(100vw - var(--panel-w) - 3 * var(--gap), 100vh - var(--topbar-h) - 2 * var(--gap), 760px);
    display: grid;
    grid-template-columns: var(--board) var(--panel-w);
    gap: var(--gap);
    justify-content: center;
    align-items: start;
    padding: var(--gap);
}
@supports (height: 100svh) {
    .layout { --board: min(100vw - var(--panel-w) - 3 * var(--gap), 100svh - var(--topbar-h) - 2 * var(--gap), 760px); }
}

.board-area { min-width: 0; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: var(--board);
    min-height: min(var(--board), 420px);
}

.status {
    font-weight: 600;
    font-size: 16px;
    min-height: 1.45em;
}
.status[data-state="you"] { color: var(--you); }
.status[data-state="them"] { color: var(--muted); }

.controls { display: flex; flex-direction: column; gap: 10px; }
.buttons { display: flex; gap: 8px; }

button {
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--button);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 7px 12px;
    cursor: pointer;
    flex: 1;
    white-space: nowrap;
}
button:hover { background: var(--button-hover); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.segmented { display: flex; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 7px 0 0 7px; }
.segmented button:last-child { border-radius: 0 7px 7px 0; border-left: none; }
.segmented button[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.moves {
    flex: 1;
    min-height: 60px;
    overflow-y: auto;
    margin: 0;
    padding: 6px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    list-style: none;
    counter-reset: none;
    font-variant-numeric: tabular-nums;
}
.moves li {
    display: grid;
    grid-template-columns: 2.6em 1fr 1fr;
    padding: 2px 4px;
    border-radius: 5px;
}
.moves li::before {
    content: attr(value) ".";
    color: var(--muted);
}
.moves li:nth-child(odd) { background: color-mix(in srgb, var(--button) 60%, transparent); }
.move { padding: 0 6px; border-radius: 4px; }
.move.current { background: var(--accent); color: var(--accent-text); }
.move.placeholder { color: var(--muted); }

.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* ---- narrow screens: board full width on top, panel below */

@media (max-width: 760px) {
    .layout {
        --gap: 12px;
        grid-template-columns: minmax(0, 1fr);
        padding: var(--gap) 0 calc(var(--gap) + env(safe-area-inset-bottom));
    }
    .board-area {
        width: min(100%, 100vh - var(--topbar-h) - 120px);
        justify-self: center;
    }
    .panel {
        margin: 0 16px;
        max-height: none;
        min-height: 0;
    }
    .moves { max-height: 30vh; }
}

/* Phones: edge-to-edge board for the biggest squares. */
@media (max-width: 520px) {
    .layout { padding-top: 0; }
    .board-area { width: 100%; }
    .board-area .osb { border-radius: 0; box-shadow: none; }
}
