/* Colors as tokens so dark mode (shared/theme.js) only has to swap values. */
:root {
    --bg: #f6f4f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e4deec;
    --primary: #6d4fc2;
    --primary-soft: #ece6f8;
    --wrong: #d93a40;
    --wrong-soft: rgba(217, 58, 64, .28);
    --line: #2a2533;
    --btn-bg: #111827;
    --btn-text: #ffffff;
    --mark: rgba(31, 41, 55, .55);
    --queen: #1b1726;
    --overlay: rgba(17, 24, 39, .45);
    --shadow: rgba(0, 0, 0, .08);
    --r0: #c9b6f0; --r1: #f7c59f; --r2: #a9dcb8; --r3: #f2a7b5; --r4: #a6cdf2;
    --r5: #f3e08c; --r6: #d6d1c9; --r7: #9fe0dc; --r8: #e8b8e8;
    --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-theme="dark"] {
    --bg: #141218; --card: #1d1a22; --text: #ece8f1; --muted: #a39cae; --border: #312c3a;
    --primary: #b48fe6; --primary-soft: #2e2540; --wrong: #ff6b70; --wrong-soft: rgba(255, 107, 112, .32);
    --line: #0b0a0e; --btn-bg: #ece8f1; --btn-text: #141218; --mark: rgba(20, 18, 24, .6); --queen: #141218;
    --overlay: rgba(0, 0, 0, .6); --shadow: rgba(0, 0, 0, .4);
    --r0: #9a84cf; --r1: #d39a6c; --r2: #78b28a; --r3: #cc7a8b; --r4: #779fcb;
    --r5: #c8b55a; --r6: #a9a39a; --r7: #6db5b0; --r8: #bd88bd;
}

* { 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 .crown { color: var(--primary); }
.sub { margin: 0; color: var(--muted); font-size: 15px; }

.modes { display: flex; justify-content: center; gap: 6px; }
.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); }
.sizes { display: flex; justify-content: center; gap: 6px; }
.sizes button {
    border: 1px solid var(--border); background: transparent; border-radius: 8px;
    padding: 4px 10px; font-size: 13px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.sizes 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;
    font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.stats strong { color: var(--text); font-weight: 600; }

.board-wrap { width: 100%; max-width: 480px; margin: 0 auto; }
.board {
    display: grid; width: 100%; aspect-ratio: 1; max-width: 100%;
    border: 3px solid var(--line); border-radius: 10px; overflow: hidden;
    background: var(--line); gap: 1px; user-select: none; -webkit-user-select: none;
    touch-action: none;
}
.cell {
    position: relative; border: 0; padding: 0; margin: 0; cursor: pointer; min-width: 0; min-height: 0; overflow: hidden;
    display: grid; place-items: center; font-size: clamp(18px, 6vw, 30px); line-height: 1;
}
.cell.bt { box-shadow: inset 0 2px 0 var(--line); }
.cell.bl { box-shadow: inset 2px 0 0 var(--line); }
.cell.bt.bl { box-shadow: inset 0 2px 0 var(--line), inset 2px 0 0 var(--line); }
.cell:focus-visible { outline: 3px solid var(--primary); outline-offset: -3px; z-index: 1; }
.cell .x { color: var(--mark); font-size: .62em; font-weight: 700; }
.cell .auto { opacity: .55; }
.cell .q { color: var(--queen); }
.cell.clash::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: repeating-linear-gradient(45deg, var(--wrong-soft) 0 5px, transparent 5px 10px);
}
.cell.clash .q { color: var(--wrong); }
.board.won .cell .q { animation: pop .5s ease both; }
@keyframes pop { 40% { transform: scale(1.3); } }
@media (prefers-reduced-motion: reduce) { .board.won .cell .q { animation: none; } }

.tools { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.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);
}
.tools button:disabled { opacity: .45; cursor: default; }
.opt { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.opt input { accent-color: var(--primary); width: 16px; height: 16px; }

.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 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; user-select: all;
}
.dialog .row { display: flex; gap: 8px; justify-content: center; }
.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; }
