:root {
    --bg: #f7f6fb;
    --surface: #ffffff;
    --text: #1d1b26;
    --muted: #6b6880;
    --border: #d9d6e6;
    --accent: #7c3aed;
    --accent-text: #ffffff;
    --cell: #ffffff;
    --cell-line: #2b2838;
    --cell-word: #e4dafc;
    --cell-cursor: #fcd34d;
    --cell-wrong: #dc2626;
    --cell-revealed: #2563eb;
    --cell-solved: #dcfce7;
    --clue-active: #ede7fd;
    --clue-crossing: #f4f1fb;
    --banner-ok: #dcfce7;
    --banner-ok-text: #14532d;
    --banner-hint: #fef3c7;
    --banner-hint-text: #713f12;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14131a;
        --surface: #1d1c25;
        --text: #ebe9f3;
        --muted: #9d9ab0;
        --border: #34323f;
        --accent: #a78bfa;
        --accent-text: #14131a;
        --cell: #26252f;
        --cell-line: #6b6880;
        --cell-word: #3b2f63;
        --cell-cursor: #a16207;
        --cell-wrong: #f87171;
        --cell-revealed: #60a5fa;
        --cell-solved: #173a26;
        --clue-active: #2e2648;
        --clue-crossing: #23212d;
        --banner-ok: #173a26;
        --banner-ok-text: #bbf7d0;
        --banner-hint: #3d2f0b;
        --banner-hint-text: #fde68a;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #14131a;
    --surface: #1d1c25;
    --text: #ebe9f3;
    --muted: #9d9ab0;
    --border: #34323f;
    --accent: #a78bfa;
    --accent-text: #14131a;
    --cell: #26252f;
    --cell-line: #6b6880;
    --cell-word: #3b2f63;
    --cell-cursor: #a16207;
    --cell-wrong: #f87171;
    --cell-revealed: #60a5fa;
    --cell-solved: #173a26;
    --clue-active: #2e2648;
    --clue-crossing: #23212d;
    --banner-ok: #173a26;
    --banner-ok-text: #bbf7d0;
    --banner-hint: #3d2f0b;
    --banner-hint-text: #fde68a;
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

h1, h2 { line-height: 1.2; }

.muted { color: var(--muted); }

/* ---------- Site chrome ---------- */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 14px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 750;
    font-size: 1.15rem;
    text-decoration: none;
    letter-spacing: -0.01em;
}

.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background:
        linear-gradient(var(--accent-text), var(--accent-text)) 4px 4px / 6px 6px no-repeat,
        linear-gradient(var(--accent-text), var(--accent-text)) 12px 4px / 6px 6px no-repeat,
        linear-gradient(var(--accent-text), var(--accent-text)) 4px 12px / 6px 6px no-repeat,
        var(--accent);
}

.site-header nav { display: flex; gap: 4px; }

.site-header nav a {
    padding: 6px 12px;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 550;
}

.site-header nav a.active { background: var(--clue-active); color: var(--text); }

.site-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 32px;
}

.site-footer {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px 40px;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

.empty-state { text-align: center; padding: 64px 0; }

.page-title { margin: 8px 0 20px; }

/* ---------- Puzzle header ---------- */

.puzzle-header { margin: 4px 0 18px; }
.puzzle-header h1 { margin: 0 0 4px; font-size: clamp(1.4rem, 4vw, 2rem); letter-spacing: -0.02em; }
.puzzle-header p { margin: 0; overflow-wrap: anywhere; }
.eyebrow { color: var(--accent); font-weight: 650; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- Player layout ---------- */

.player {
    display: grid;
    grid-template-columns: minmax(0, 600px) minmax(0, 1fr);
    gap: 28px;
    align-items: start;
}

.board-col { position: sticky; top: 8px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.timer { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 1.05rem; }

.actions { display: flex; gap: 6px; align-items: center; }

button, .menu summary {
    font: inherit;
    font-size: 0.9rem;
    font-weight: 550;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    min-height: 34px;
}

button:hover, .menu summary:hover { border-color: var(--accent); }

button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.menu { position: relative; }
.menu summary { list-style: none; display: flex; align-items: center; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; margin-left: 6px; font-size: 0.75em; color: var(--muted); }

.menu-items {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 10;
    display: flex;
    flex-direction: column;
    min-width: 120px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
}

.menu-items button { border: none; text-align: left; background: transparent; }
.menu-items button:hover { background: var(--clue-active); }

.solved-banner, .hint-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 14px;
    border-radius: var(--radius);
}

.solved-banner { background: var(--banner-ok); color: var(--banner-ok-text); }
.solved-banner button { margin-left: auto; }
.hint-banner { background: var(--banner-hint); color: var(--banner-hint-text); }

.clue-bar {
    display: flex;
    gap: 10px;
    align-items: baseline;
    min-height: 3.2em;
    padding: 10px 14px;
    background: var(--clue-active);
    border-radius: var(--radius);
    font-size: 1.02rem;
    overflow-wrap: anywhere;
}

.clue-bar-num { font-weight: 750; white-space: nowrap; }

/* ---------- Grid ---------- */

.board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), 1fr);
    width: 100%;
    max-width: calc(var(--cols) * 44px);
    container-type: inline-size;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.board-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    border: 0;
    padding: 0;
    font-size: 16px; /* prevents iOS zoom on focus */
    caret-color: transparent;
}

.void { aspect-ratio: 1; }

.cell {
    position: relative;
    aspect-ratio: 1;
    background: var(--cell);
    outline: 1px solid var(--cell-line);
    outline-offset: -0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell.in-word { background: var(--cell-word); }
.cell.cursor { background: var(--cell-cursor); }
.cell.solved { background: var(--cell-solved); }

.cell-num {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: calc(100cqi / var(--cols) * 0.27);
    line-height: 1;
    color: var(--muted);
    font-weight: 600;
}

.cell-letter {
    font-size: calc(100cqi / var(--cols) * 0.56);
    font-weight: 650;
    line-height: 1;
    text-transform: uppercase;
}

.cell.wrong .cell-letter { color: var(--cell-wrong); text-decoration: line-through; }
.cell.revealed .cell-letter { color: var(--cell-revealed); }
.cell.revealed::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    border-style: solid;
    border-width: 0 calc(100cqi / var(--cols) * 0.22) calc(100cqi / var(--cols) * 0.22) 0;
    border-color: transparent var(--cell-revealed) transparent transparent;
}

/* ---------- Clues ---------- */

.clue-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    min-width: 0;
}

.clue-section h2 {
    margin: 0 0 8px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.clue-list {
    position: relative;
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.clue {
    display: flex;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    border-left: 3px solid transparent;
    overflow-wrap: anywhere;
}

.clue:hover { background: var(--clue-crossing); }
.clue.crossing { background: var(--clue-crossing); }
.clue.active { background: var(--clue-active); border-left-color: var(--accent); }
.clue.filled .clue-text { color: var(--muted); }

.clue-num { font-weight: 750; min-width: 1.6em; text-align: right; }

.clue-meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.clue-meta a { text-decoration: none; }

.emote {
    height: 1.5em;
    width: auto;
    vertical-align: middle;
    margin: -0.25em 0.1em;
}

.blank { display: inline-flex; gap: 2px; vertical-align: baseline; margin: 0 0.15em; }

.blank-cell {
    display: inline-block;
    width: 0.85em;
    border-bottom: 2px solid currentColor;
    text-align: center;
    font-weight: 700;
    line-height: 1.15;
    text-transform: uppercase;
}

/* ---------- Archive ---------- */

.archive-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.archive-list a {
    display: grid;
    gap: 2px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}

.archive-list a:hover { border-color: var(--accent); }
.archive-date { font-weight: 700; }
.archive-title { overflow-wrap: anywhere; }
.archive-meta { color: var(--muted); font-size: 0.85rem; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
    .clue-col { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
    .player { grid-template-columns: minmax(0, 1fr); gap: 20px; }
    .board-col { position: static; }
    .clue-bar { position: sticky; top: 0; z-index: 5; box-shadow: 0 0 0 4px var(--bg); }
    .clue-list { max-height: none; overflow: visible; }
    .board { max-width: none; }
}

/* ---------- Blazor ---------- */

h1:focus { outline: none; }

#blazor-error-ui {
    display: none;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after { content: "An error has occurred." }
