/* Colors as tokens so dark mode (shared/theme.js) only has to swap values. */
:root {
    --bg: #f4f6f0;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #dfe5d6;
    --primary: #4f7a2e;
    --primary-soft: #e6efdb;
    --line: #2c3325;
    --btn-bg: #111827;
    --btn-text: #ffffff;
    --sq-light: #eeeed2;
    --sq-dark: #769656;
    --coord-light: #769656;
    --coord-dark: #eeeed2;
    --last: rgba(246, 214, 60, .55);
    --dot: rgba(20, 30, 10, .22);
    --over: rgba(255, 255, 255, .8);
    --mark: rgba(235, 97, 80, .8);
    --arrow: #f2a516;
    --piece: #ffffff;
    --piece-edge: #1b1d17;
    --pawn: #1b1d17;
    --overlay: rgba(17, 24, 39, .45);
    --shadow: rgba(0, 0, 0, .08);
    --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
    /* Fonts with full-size chess glyphs first */
    --chess: "Segoe UI Symbol", "Apple Symbols", "Noto Sans Symbols 2", "DejaVu Sans", sans-serif;
}
:root[data-theme="dark"] {
    --bg: #12140f; --card: #1b1e17; --text: #e9ece4; --muted: #9ea494; --border: #2f3429;
    --primary: #9cc777; --primary-soft: #26301d; --line: #0a0b08; --btn-bg: #e9ece4; --btn-text: #12140f;
    --sq-light: #b9bca2; --sq-dark: #587341; --coord-light: #587341; --coord-dark: #b9bca2;
    --last: rgba(230, 196, 50, .5); --dot: rgba(10, 15, 5, .3);
    --over: rgba(255, 255, 255, .65); --mark: rgba(214, 84, 68, .8); --arrow: #e09a14;
    --overlay: rgba(0, 0, 0, .6); --shadow: rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* No double-tap zoom (pinch zoom still works) */
html { touch-action: manipulation; }
body {
    margin: 0;
    font-family: var(--ui);
    background: var(--bg);
    color: var(--text);
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

main {
    max-width: 520px; margin: 0 auto; padding-block: 64px 48px;
    display: flex; flex-direction: column; gap: 16px;
}
header { text-align: center; display: flex; flex-direction: column; gap: 4px; }
h1 { margin: 0; font-size: 32px; letter-spacing: -.01em; text-wrap: balance; }
h1 .icon { color: var(--primary); font-family: var(--chess); font-weight: 400; }
.sub { margin: 0; color: var(--muted); font-size: 15px; }

.modes, .pieces { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.modes button {
    border: 1px solid var(--border); background: var(--card); border-radius: 999px;
    padding: 6px 14px; font-size: 14px; cursor: pointer;
}
.modes button[aria-pressed="true"] { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); }
.pieces button {
    border: 1px solid var(--border); background: transparent; border-radius: 8px;
    padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.pieces button[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.stats {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.stats strong { color: var(--text); font-weight: 600; }

.board-wrap { position: relative; width: 100%; max-width: 480px; margin: 0 auto; }
.board {
    display: grid; grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
    width: 100%; aspect-ratio: 1; border: 3px solid var(--line); border-radius: 8px; overflow: hidden;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.cell {
    position: relative; border: 0; padding: 0; margin: 0; cursor: pointer; min-width: 0; min-height: 0;
    display: grid; place-items: center; line-height: 1;
}
.cell.light { background: var(--sq-light); }
.cell.dark { background: var(--sq-dark); }
.cell.mark { background-image: linear-gradient(var(--mark), var(--mark)); }
.cell:is(.last, .lifted)::before { content: ""; position: absolute; inset: 0; background: var(--last); }
/* The square a dragged piece would land on, or a square it can reach under the mouse */
.cell.over::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 max(3px, .5vmin) var(--over); }
@media (hover: hover) {
    body:not(.dragging) .cell:is(.move, .take):hover::before {
        content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 max(3px, .5vmin) var(--over);
    }
}
/* Only the piece's own square grabs touches, so the rest of the board still scrolls the page */
.cell.at { cursor: grab; touch-action: none; }
.cell.lifted .man { visibility: hidden; }
body.dragging, body.dragging * { cursor: grabbing !important; }
.cell:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; z-index: 2; }
/* Where the piece can go: a dot for a plain move, a ring around a pawn it can take */
.cell.move::after {
    content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--dot);
}
.cell.take::after {
    content: ""; position: absolute; inset: 4%; border-radius: 50%; border: max(3px, 0.45vmin) solid var(--dot);
}
.coord { position: absolute; font-size: clamp(8px, 2.2vw, 11px); font-weight: 700; pointer-events: none; }
.coord.rank { top: 3px; left: 3px; }
.coord.file { bottom: 2px; right: 3px; }
.cell.light .coord { color: var(--coord-light); }
.cell.dark .coord { color: var(--coord-dark); }
.man {
    position: relative; z-index: 1; font-family: var(--chess); font-size: clamp(26px, 8.4vw, 46px);
    pointer-events: none;
}
/* A white piece: filled glyph in white with a dark edge drawn by shadows */
.man.piece {
    color: var(--piece); z-index: 3;
    text-shadow: 1px 0 0 var(--piece-edge), -1px 0 0 var(--piece-edge), 0 1px 0 var(--piece-edge), 0 -1px 0 var(--piece-edge),
        1px 1px 0 var(--piece-edge), -1px -1px 0 var(--piece-edge), 1px -1px 0 var(--piece-edge), -1px 1px 0 var(--piece-edge);
}
.man.pawn { color: var(--pawn); }
.man.gone { position: absolute; inset: 0; display: grid; place-items: center; }
/* The piece while it's dragged, following the pointer */
.man.drag-ghost {
    position: fixed; left: 0; top: 0; z-index: 30; display: grid; place-items: center;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .3)); will-change: transform;
}
.arrows {
    position: absolute; top: 3px; left: 3px; width: calc(100% - 6px); height: calc(100% - 6px);
    pointer-events: none; z-index: 4;
}
.arrows g { opacity: .8; }
.arrows polyline { fill: none; stroke: var(--arrow); stroke-width: .2; }
.arrows polygon { fill: var(--arrow); }
.board.won .man.piece { animation: pop .5s ease both; }
@keyframes pop { 40% { transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { .board.won .man.piece { animation: none; } }

.status { margin: -4px 0 0; text-align: center; font-weight: 600; }
.status:empty { display: none; }

/* Keeps its height while no button is showing, so the page below doesn't jump on the first move */
.tools { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; min-height: 40px; }
.tools button {
    border: 1px solid var(--border); background: var(--card); border-radius: 10px;
    padding: 9px 16px; font-size: 15px; cursor: pointer; box-shadow: 0 1px 2px var(--shadow);
}
/* Narrow enough that a cleared Unlimited board's four buttons still fit on one row at 375px */
@media (max-width: 420px) {
    .tools { gap: 6px; }
    .tools button { padding: 9px 11px; font-size: 14px; }
}
/* Drawn icons rather than ↶ ↺, which each device's fonts draw at different sizes and weights */
.tools .ico {
    width: 1.05em; height: 1.05em; margin-right: 6px; vertical-align: -.17em;
    fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round;
}
/* Replay (Restart on a cleared board) goes without its icon so the row fits on a phone */
.tools .bare .ico { display: none; }
.tools button.primary { background: var(--btn-bg); color: var(--btn-text); border-color: var(--btn-bg); }
.tools button:disabled { opacity: .45; cursor: default; }

.rules {
    background: var(--card); border: 1px solid var(--border); border-radius: 12px;
    padding: 14px 18px; font-size: 14px; line-height: 1.55;
}
.rules h2 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.rules ul { margin: 0; padding-left: 18px; }
.rules p { margin: 8px 0 0; color: var(--muted); }
kbd {
    font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--border);
    border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--bg);
}

.overlay {
    position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center;
    padding: 16px; z-index: 20;
}
.dialog {
    background: var(--card); border-radius: 16px; padding: 24px; max-width: 360px; width: 100%;
    text-align: center; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px var(--shadow);
}
.dialog h2 { margin: 0; font-size: 24px; }
.dialog .big { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dialog .note { margin: 0; color: var(--muted); }
.dialog pre {
    margin: 0; text-align: left; background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: 10px 12px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
    white-space: pre-wrap; word-break: break-all; user-select: all;
}
.dialog .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn {
    border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; font-size: 15px;
    background: var(--btn-bg); color: var(--btn-text);
}
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.toast { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 0; }
