/* Calm, low-contrast-glare palette. No neon, no blinking. Follows the system light/dark setting. */
:root {
    --page: #dde5e8;
    --paper: #fbf8f1;
    --ink: #2a3841;
    --muted: #7a8790;
    --line: #c9cfd0;
    --line-strong: #56666f;
    --peer: #eef0ea;
    --same: #e1ecdf;
    --sel: #d5e4f4;
    --accent: #3a6ea5;
    --bad: #b2403a;
    --bad-bg: #f6e0dc;
    --card: #fbf8f1;
    --shadow: rgba(40, 55, 65, 0.18);
    --cell: clamp(30px, min(calc((100vw - 28px) / 9.4), calc((100vh - 270px) / 9.4)), 56px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --page: #1d252a;
        --paper: #262f35;
        --ink: #dfe5e8;
        --muted: #8b99a1;
        --line: #3b474e;
        --line-strong: #8da0ab;
        --peer: #2b353b;
        --same: #2f3f37;
        --sel: #2d4458;
        --accent: #8fb8e6;
        --bad: #e58f88;
        --bad-bg: #402a29;
        --card: #2b353b;
        --shadow: rgba(0, 0, 0, 0.4);
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--page);
    color: var(--ink);
    font-family: ui-rounded, 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */
.top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    max-width: 880px;
    margin: 0 auto;
    padding: 12px 14px 6px;
}

/* leave room for the player chip (top right) on phones */
@media (max-width: 560px) {
    .top { padding-top: 38px; }
}

.top h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 650;
    letter-spacing: 0.02em;
}

.home {
    color: var(--muted);
    font-size: 13px;
    text-decoration: none;
}

.home:hover,
.home:focus-visible {
    color: var(--ink);
    text-decoration: underline;
}

.stats {
    display: flex;
    gap: 16px;
    margin-left: auto;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 10px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ---------- Buttons ---------- */
.btn {
    font: inherit;
    font-size: 14px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    touch-action: manipulation;
}

.btn:hover {
    border-color: var(--line-strong);
}

.btn:focus-visible,
.level:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn.primary {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

@media (prefers-color-scheme: dark) {
    .btn.primary { color: #14202b; }
}

.btn:disabled {
    opacity: 0.45;
    cursor: default;
}

/* ---------- Play area ---------- */
.play {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 18px;
    max-width: 880px;
    margin: 0 auto;
    padding: 8px 14px 24px;
}

.board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell));
    grid-template-rows: repeat(9, var(--cell));
    border: 2px solid var(--line-strong);
    border-radius: 4px;
    background: var(--paper);
    box-shadow: 0 6px 18px var(--shadow);
}

.cell {
    position: relative;
    display: block;
    width: var(--cell);
    height: var(--cell);
    margin: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 0;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    cursor: pointer;
    touch-action: manipulation;
}

/* thicker lines between the 3x3 blocks, and none at the outer edge (the board has its own border) */
.cell.c-block { border-right: 2px solid var(--line-strong); }
.cell.r-block { border-bottom: 2px solid var(--line-strong); }
.cell.c-end { border-right: 0; }
.cell.r-end { border-bottom: 0; }

.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell:focus { outline: none; } /* the selected square already shows a clear frame */
.cell.selected { background: var(--sel); box-shadow: inset 0 0 0 2px var(--accent); }

.val {
    display: block;
    width: 100%;
    line-height: var(--cell);
    text-align: center;
    font-size: calc(var(--cell) * 0.6);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.cell.given .val {
    font-weight: 700;
    color: var(--ink);
}

/* a wrong number: red, italic, a wavy line under it, and a soft red square */
.cell.wrong {
    background: var(--bad-bg);
}

.cell.wrong .val {
    color: var(--bad);
    font-style: italic;
    font-weight: 600;
    text-decoration: underline wavy var(--bad);
    text-decoration-thickness: 2px;
    text-underline-offset: calc(var(--cell) * 0.1);
}

.cell.wrong.selected {
    background: var(--bad-bg);
    box-shadow: inset 0 0 0 2px var(--bad);
}

/* pencil notes: a tiny 3x3 grid inside the square */
.notes {
    position: absolute;
    inset: 2px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    pointer-events: none;
}

.notes i {
    display: flex;
    align-items: center;
    justify-content: center;
    font-style: normal;
    font-size: calc(var(--cell) * 0.24);
    line-height: 1;
    color: var(--muted);
    visibility: hidden;
}

.notes i.on { visibility: visible; }

/* a note that can't be right, because that number is already placed in the same row, column or block */
.notes i.out {
    text-decoration: line-through;
    text-decoration-thickness: 1.5px;
    opacity: 0.5;
}

/* ---------- Number pad ---------- */
.pad {
    width: calc(var(--cell) * 4.6);
    min-width: 230px;
}

.digits {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.digit {
    position: relative;
    font: inherit;
    font-size: 24px;
    height: 54px;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    touch-action: manipulation;
}

.digit:hover { border-color: var(--line-strong); }
.digit:disabled { opacity: 0.35; cursor: default; }

.digit small {
    position: absolute;
    right: 7px;
    bottom: 4px;
    font-size: 10px;
    color: var(--muted);
}

.pad.pencil-on .digit {
    font-size: 17px;
    background: var(--peer);
}

.tools {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.tool {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    font-size: 12px;
}

.tool-icon { font-size: 18px; line-height: 1; }
.tool-state { font-size: 10px; color: var(--muted); }
.tool[aria-pressed="true"] { border-color: var(--accent); background: var(--sel); }

.help {
    margin: 12px 2px 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
}

@media (max-width: 720px) {
    .pad { width: min(100%, 420px); }
    .digits { grid-template-columns: repeat(9, 1fr); gap: 4px; }
    .digit { height: 46px; font-size: 20px; }
    .pad.pencil-on .digit { font-size: 15px; }
    .digit small { right: 3px; bottom: 2px; font-size: 8px; }
    .help { display: none; }
}

/* ---------- Dialogs ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(30, 40, 46, 0.45);
}

.overlay[hidden] { display: none; }

.card {
    width: min(420px, 100%);
    padding: 22px 22px 20px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 12px 34px var(--shadow);
}

.card h2 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 650;
}

.card-text {
    margin: 0 0 14px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--muted);
}

.card-text.busy { margin: 12px 0 0; }

.levels {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.level {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 12px 14px;
    font: inherit;
    text-align: left;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    touch-action: manipulation;
}

.level:hover { border-color: var(--accent); background: var(--sel); }
.level-name { font-size: 17px; font-weight: 650; }
.level-note { font-size: 13px; color: var(--muted); }

.row-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

.cancel { margin-top: 12px; width: 100%; }

a.cancel {
    display: block;
    text-align: center;
    text-decoration: none;
}
