:root {
    color-scheme: light;
    --ink: #1c2526;
    --muted: #647174;
    --paper: #f6f4ee;
    --panel: #fffdf8;
    --line: #c7c2b5;
    --line-strong: #263234;
    --accent: #1d6f66;
    --accent-strong: #12554e;
    --accent-soft: #d7eee9;
    --warn: #b5482e;
    --warn-soft: #f7dfd8;
    --given: #27383a;
    --found: #fff0b8;
    --shadow: 0 18px 42px rgba(38, 50, 52, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    overflow-x: hidden;
    scroll-padding-bottom: max(24px, env(safe-area-inset-bottom));
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background:
        linear-gradient(135deg, rgba(29, 111, 102, 0.12), rgba(196, 92, 54, 0.08)),
        var(--paper);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    overflow-x: hidden;
}

button,
input,
textarea {
    font: inherit;
    color-scheme: light;
}

button {
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
    min-height: 42px;
    border-radius: 8px;
    padding: 0 14px;
    cursor: pointer;
    touch-action: manipulation;
}

button:hover {
    border-color: var(--accent);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(29, 111, 102, 0.28);
    outline-offset: 2px;
}

.app-shell {
    width: min(1180px, calc(100vw - 28px));
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0 auto;
    padding: 28px 0 max(28px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: minmax(330px, 1fr) 390px;
    gap: 22px;
    align-items: start;
}

.board-panel,
.side-panel {
    background: var(--panel);
    border: 1px solid rgba(38, 50, 52, 0.12);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.board-panel {
    padding: 22px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(1.65rem, 2.5vw, 2.55rem);
    line-height: 1.05;
}

h2 {
    font-size: 1rem;
    margin-bottom: 10px;
}

.status-pill {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    color: var(--muted);
    border-radius: 999px;
    padding: 7px 11px;
    font-weight: 700;
    background: #fff;
}

.board-wrap {
    width: min(100%, 660px);
    max-width: 100%;
    margin: 0 auto;
    overflow: hidden;
}

.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    aspect-ratio: 1;
    background: var(--line-strong);
    border: 3px solid var(--line-strong);
    width: 100%;
    max-width: 100%;
}

.cell {
    position: relative;
    width: 100%;
    min-width: 0;
    border: 1px solid var(--line);
    background-color: #fffefb;
}

.cell:nth-child(3n) {
    border-right-color: var(--line-strong);
    border-right-width: 3px;
}

.cell:nth-child(9n) {
    border-right-width: 1px;
}

.cell[data-col="0"] {
    border-left-width: 0;
}

.cell[data-row="0"] {
    border-top-width: 0;
}

.cell[data-row="2"],
.cell[data-row="5"] {
    border-bottom-color: var(--line-strong);
    border-bottom-width: 3px;
}

.cell input {
    -webkit-appearance: none;
    appearance: none;
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    background-color: inherit;
    color: var(--given);
    -webkit-text-fill-color: var(--given);
    opacity: 1;
    font-size: clamp(1.45rem, 5.5vw, 2.7rem);
    font-weight: 780;
    text-align: center;
    padding: 0;
    caret-color: transparent;
    touch-action: manipulation;
}

.cell.is-selected {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 3px rgba(35, 2, 113, 0.8);
}

.cell.is-selected::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    box-shadow: inset 0 0 0 3px rgba(35, 2, 113, 0.88);
}

.cell.is-related {
    background: #f1faf7;
}

.cell.is-same-value {
    background: #e5f2ff;
}

.cell.is-same-value input {
    color: #145c9e;
    -webkit-text-fill-color: #145c9e;
    font-weight: 900;
}

.cell.is-conflict {
    background: var(--warn-soft);
}

.cell.is-suggestion {
    background: var(--found);
}

.cell.is-suggestion input {
    color: #8b5b00;
    -webkit-text-fill-color: #8b5b00;
}

.cell.is-locked {
    background: #eef1ec;
}

.cell.is-locked input {
    color: #111819;
    -webkit-text-fill-color: #111819;
    font-weight: 860;
}

.cell.is-same-value,
.cell.is-locked.is-same-value {
    background: #d8ecff;
    box-shadow: inset 0 0 0 3px rgba(20, 92, 158, 0.42);
}

.cell.is-same-value input,
.cell.is-locked.is-same-value input {
    color: #0d4f8f;
    -webkit-text-fill-color: #0d4f8f;
    font-weight: 920;
}

.candidates {
    position: absolute;
    inset: 6px;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    align-items: center;
    justify-items: center;
    color: #527174;
    font-size: clamp(0.46rem, 1.9vw, 0.78rem);
    font-weight: 700;
    pointer-events: none;
}

.candidate-mark {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    cursor: pointer;
    pointer-events: auto;
}

.candidate-mark:hover {
    background: rgba(29, 111, 102, 0.12);
    color: var(--accent-strong);
}

.candidate-mark.is-active-candidate {
    background: #dbeeff;
    color: #145c9e;
    font-size: 1.16em;
    font-weight: 900;
}

.candidate-mark.is-removed {
    color: rgba(181, 72, 46, 0.62);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

.number-pad {
    width: min(100%, 660px);
    max-width: 100%;
    margin: 16px auto 0;
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 7px;
    overflow: hidden;
}

.number-pad button {
    padding: 0;
    min-width: 0;
    font-weight: 760;
}

.number-pad .pad-clear {
    grid-column: span 1;
    font-size: 0.82rem;
}

.side-panel {
    padding: 18px;
    position: sticky;
    top: 18px;
}

.actions,
.mini-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
}

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

.primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.result,
.details {
    border-top: 1px solid rgba(38, 50, 52, 0.12);
    margin-top: 16px;
    padding-top: 16px;
}

.result p {
    margin: 0 0 10px;
    color: var(--muted);
    line-height: 1.5;
}

.answer {
    display: grid;
    grid-template-columns: 68px 1fr;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.answer-number {
    display: grid;
    place-items: center;
    height: 68px;
    border-radius: 8px;
    background: var(--found);
    color: #8b5b00;
    font-size: 2.2rem;
    font-weight: 850;
}

.answer strong {
    display: block;
    margin-bottom: 3px;
}

.reason-list {
    padding-left: 20px;
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.45;
}

.message-bad {
    color: var(--warn);
    font-weight: 720;
}

textarea {
    width: 100%;
    min-height: 104px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    color: var(--ink);
    background: #fff;
    line-height: 1.45;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.mini-actions {
    grid-template-columns: repeat(3, 1fr);
    margin-top: 9px;
}

@media (max-width: 860px) {
    .app-shell {
        width: min(100vw - 20px, 640px);
        grid-template-columns: 1fr;
        padding: 10px 0 max(18px, env(safe-area-inset-bottom));
    }

    .side-panel {
        position: static;
    }

    .board-panel,
    .side-panel {
        padding: 14px;
    }

    .topbar {
        align-items: flex-start;
    }

    .number-pad {
        grid-template-columns: repeat(5, 1fr);
    }

    .number-pad .pad-clear {
        grid-column: span 5;
    }
}

@media (max-width: 420px) {
    .app-shell {
        width: 100%;
        padding: 0;
        overflow-x: hidden;
    }

    .board-panel,
    .side-panel {
        border-radius: 0;
        box-shadow: none;
        border-left: 0;
        border-right: 0;
    }

    .board-panel {
        padding: 14px 8px 12px;
    }

    .side-panel {
        padding: 12px 8px max(18px, env(safe-area-inset-bottom));
    }

    .topbar {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 14px;
    }

    .eyebrow {
        font-size: 14px;
        line-height: 1.1;
    }

    h1 {
        max-width: 100%;
        font-size: clamp(32px, 9.5vw, 38px);
        line-height: 1.05;
        overflow-wrap: anywhere;
    }

    .status-pill {
        justify-self: start;
        max-width: 100%;
        font-size: 16px;
        line-height: 1.1;
        padding: 7px 10px;
    }

    .board-wrap,
    .number-pad {
        width: 100%;
    }

    button {
        min-height: 40px;
        padding: 0 10px;
        font-size: 15px;
        line-height: 1.15;
    }

    .number-pad {
        gap: 6px;
    }

    .number-pad button {
        font-size: 24px;
        line-height: 1;
    }

    .number-pad .pad-clear {
        font-size: 17px;
    }

    .cell input {
        font-size: 24px;
        line-height: 1;
    }

    .candidates {
        inset: 3px;
        font-size: 9px;
        line-height: 1;
    }
}

@media (max-width: 380px) {
    h1 {
        font-size: clamp(30px, 9vw, 34px);
    }

    .board-panel {
        padding-left: 6px;
        padding-right: 6px;
    }

    .cell input {
        font-size: 22px;
    }

    .number-pad button {
        font-size: 22px;
    }
}
