:root {
    color-scheme: light;
    --bg: #f7f8f3;
    --panel: #ffffff;
    --panel-soft: #f0f5f2;
    --ink: #1f2933;
    --muted: #65717e;
    --line: #d8ded8;
    --line-strong: #1f2933;
    --accent: #1f7a68;
    --accent-dark: #155848;
    --accent-soft: #dceee8;
    --warn: #946200;
    --warn-bg: #fff5d7;
    --danger: #ba2f3a;
    --danger-bg: #fde8ea;
    --ok: #246b3d;
    --ok-bg: #e4f4e8;
    --shadow: 0 18px 42px rgba(31, 41, 51, 0.08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body,
#app {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

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

code {
    color: #185848;
    background: #eef4ef;
    border: 1px solid #d8e2da;
    border-radius: 5px;
    padding: 0 0.25rem;
}

.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
}

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    border-right: 1px solid var(--line);
    background: #fbfcf8;
    padding: 1rem;
}

.brand {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    color: var(--ink);
    text-decoration: none;
}

.brand img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: white;
}

.brand span {
    display: grid;
    gap: 0.1rem;
}

.brand small,
.sidebar-note,
.subtle,
.eyebrow,
.panel-heading p,
.step-copy small,
.input-meta,
.detail-label {
    color: var(--muted);
}

.nav-stack {
    display: grid;
    gap: 0.45rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 42px;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    padding: 0.55rem 0.7rem;
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 700;
}

.nav-icon {
    display: inline-grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 1px solid currentColor;
    border-radius: 50%;
    font-size: 0.8rem;
}

.sidebar-note {
    margin-top: auto;
    display: grid;
    gap: 0.35rem;
    font-size: 0.78rem;
}

.app-main {
    min-width: 0;
    padding: clamp(1rem, 2.5vw, 2rem);
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.eyebrow {
    margin: 0 0 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0;
    font-size: 0.75rem;
    font-weight: 800;
}

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

h1 {
    font-size: clamp(1.65rem, 2.8vw, 2.4rem);
}

h2 {
    font-size: 1.05rem;
}

.subtle {
    max-width: 760px;
    margin: 0.5rem 0 0;
    line-height: 1.65;
}

.runtime-badge {
    display: grid;
    gap: 0.2rem;
    min-width: 190px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 0.65rem 0.75rem;
    font-size: 0.85rem;
}

.runtime-badge.ready {
    border-color: #b8d8ca;
    background: #eef8f3;
}

.runtime-badge.blocked {
    border-color: #eed0d4;
    background: #fff2f3;
}

.runtime-badge small {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.solver-grid {
    display: grid;
    grid-template-columns: minmax(320px, 0.9fr) minmax(330px, 1fr);
    grid-template-areas:
        "puzzle board"
        "steps steps";
    gap: 1rem;
    align-items: start;
}

.puzzle-panel {
    grid-area: puzzle;
}

.board-panel {
    grid-area: board;
}

.steps-panel {
    grid-area: steps;
}

.workspace-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: clamp(0.9rem, 1.5vw, 1.15rem);
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 0.9rem;
}

.panel-heading.compact {
    align-items: center;
}

.panel-heading p {
    margin: 0.25rem 0 0;
    line-height: 1.45;
    font-size: 0.9rem;
}

.sudoku-board {
    width: min(100%, 560px);
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 2px solid var(--line-strong);
    background: var(--line-strong);
    margin-inline: auto;
    overflow: hidden;
}

.sudoku-cell {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
    background: #fff;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
}

.sudoku-cell.box-left {
    border-left: 2px solid var(--line-strong);
}

.sudoku-cell.box-top {
    border-top: 2px solid var(--line-strong);
}

.sudoku-cell.is-assignment-target {
    background: var(--ok-bg);
}

.sudoku-cell.has-elimination-target {
    background: #fff8f8;
}

.sudoku-cell input {
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    text-align: center;
    color: var(--ink);
    background: transparent;
    font-size: clamp(1.05rem, 4.5vw, 2rem);
    font-weight: 750;
}

.sudoku-cell input:focus {
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 2px var(--accent);
}

.cell-value {
    font-size: clamp(1.15rem, 4vw, 2.05rem);
    line-height: 1;
}

.cell-value.given {
    color: #111827;
    font-weight: 800;
}

.cell-value.solved {
    color: var(--accent-dark);
    font-weight: 700;
}

.candidate-grid {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.candidate {
    display: grid;
    place-items: center;
    min-width: 0;
    color: #78838c;
    font-size: clamp(0.45rem, 1.55vw, 0.8rem);
    line-height: 1;
}

.candidate.is-elimination {
    color: white;
    background: var(--danger);
    border-radius: 50%;
    width: 72%;
    height: 72%;
    align-self: center;
    justify-self: center;
}

.candidate.is-assignment {
    color: white;
    background: var(--ok);
    border-radius: 50%;
    width: 72%;
    height: 72%;
    align-self: center;
    justify-self: center;
}

.original-progress {
    min-height: min(560px, 68vh);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    text-align: center;
}

.progress-ring {
    position: relative;
    width: 100px;
    height: 100px;
    display: grid;
    place-items: center;
}

.progress-ring span {
    position: absolute;
    font-weight: 800;
    color: var(--accent-dark);
}

.progress-ring svg {
    width: 100px;
    height: 100px;
    transform: rotate(-90deg);
}

.progress-track,
.progress-value {
    fill: none;
    stroke-width: 8;
}

.progress-track {
    stroke: #d9dfda;
}

.progress-value {
    stroke: var(--accent);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.12s ease-out;
}

.progress-label {
    color: var(--muted);
    margin-top: 0.1rem;
}

.progress-searcher {
    max-width: min(100%, 560px);
    color: var(--ink);
    font-size: 1.5rem;
    line-height: 1.25;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.field-label {
    display: block;
    margin-top: 0.9rem;
    margin-bottom: 0.35rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.puzzle-input {
    width: 100%;
    min-height: 86px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfb;
    color: var(--ink);
    padding: 0.75rem;
    line-height: 1.5;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.puzzle-input:focus,
select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.input-meta,
.control-row,
.step-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.input-meta {
    justify-content: space-between;
    margin-top: 0.45rem;
    font-size: 0.85rem;
}

.control-row {
    margin-top: 0.9rem;
}

.select-wrap {
    display: grid;
    gap: 0.25rem;
    min-width: 150px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

select {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    color: var(--ink);
    padding: 0 0.55rem;
}

.primary-button,
.secondary-button,
.icon-button,
.primary-link {
    border-radius: 8px;
    min-height: 38px;
    border: 1px solid transparent;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.85rem;
    font-weight: 800;
}

.primary-button,
.primary-link {
    background: var(--accent);
    color: white;
}

.secondary-button,
.icon-button {
    background: white;
    color: var(--ink);
    border-color: var(--line);
}

.icon-button {
    width: 38px;
    padding: 0;
}

.step-detail {
    margin-top: 0.9rem;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
}

.step-detail > div {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    padding: 0.65rem;
}

.detail-label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
}

.step-detail strong {
    overflow-wrap: anywhere;
}

.empty-state,
.empty-list {
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 0.9rem;
    background: #fbfcfb;
}

.notice {
    border-radius: 8px;
    padding: 0.75rem 0.9rem;
    margin-bottom: 0.8rem;
    border: 1px solid;
}

.notice.error {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: #f2b7bd;
}

.notice.warning {
    color: var(--warn);
    background: var(--warn-bg);
    border-color: #f0d890;
}

.notice.success {
    color: var(--ok);
    background: var(--ok-bg);
    border-color: #b7d8be;
}

.steps-list {
    display: grid;
    gap: 0.5rem;
    max-height: min(44vh, 520px);
    overflow: auto;
    padding-right: 0.2rem;
}

.step-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    color: var(--ink);
    padding: 0.65rem;
}

.step-item.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.step-number,
.step-score {
    display: grid;
    place-items: center;
    min-width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #eef1ed;
    color: var(--muted);
    font-weight: 800;
}

.step-copy {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.step-copy small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.about-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 1rem;
}

.about-copy {
    line-height: 1.75;
}

.about-copy h2 {
    margin-bottom: 0.5rem;
}

.about-logo {
    display: grid;
    place-items: center;
}

.about-logo img {
    width: min(100%, 300px);
    height: auto;
}

.not-found {
    display: grid;
    gap: 0.8rem;
    max-width: 560px;
}

.boot-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--ink);
}

.boot-screen span {
    display: block;
    color: var(--muted);
    margin-top: 0.25rem;
}

.boot-mark {
    width: 42px;
    height: 42px;
    border: 3px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1000;
    background: var(--danger-bg);
    color: var(--danger);
    border-top: 1px solid #f2b7bd;
    padding: 0.75rem 1rem;
}

#blazor-error-ui .reload {
    margin-left: 0.75rem;
    color: var(--danger);
    font-weight: 800;
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 210px minmax(0, 1fr);
    }

    .solver-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "puzzle"
            "board"
            "steps";
    }
}

@media (max-width: 760px) {
    .app-shell {
        display: block;
    }

    .app-sidebar {
        position: sticky;
        z-index: 20;
        height: auto;
        top: 0;
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .brand img {
        width: 34px;
        height: 34px;
    }

    .brand small,
    .sidebar-note {
        display: none;
    }

    .nav-stack {
        display: flex;
        margin-left: auto;
    }

    .nav-link {
        min-height: 36px;
        padding: 0.45rem 0.55rem;
    }

    .nav-icon {
        display: none;
    }

    .app-main {
        padding: 0.85rem;
    }

    .page-header,
    .panel-heading,
    .panel-heading.compact {
        display: grid;
    }

    .runtime-badge {
        width: 100%;
        min-width: 0;
    }

    .step-detail {
        grid-template-columns: 1fr;
    }

    .steps-list {
        max-height: 54vh;
    }
}

@media (max-width: 420px) {
    .workspace-panel {
        padding: 0.75rem;
    }

    .control-row > *,
    .select-wrap,
    .primary-button,
    .secondary-button {
        width: 100%;
    }

    .sudoku-cell input {
        font-size: 1rem;
    }

    .candidate {
        font-size: 0.43rem;
    }
}
