html,
body {
    width: 100%;
    min-height: 100%;
    overflow-x: hidden;
}

body.sudoku-page {
    align-items: center;
    justify-content: center;
    padding: clamp(8px, 2vw, 22px);
}

.sudoku-shell {
    width: min(100%, 980px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: clamp(0.65rem, 2vw, 1rem);
    padding: clamp(0.75rem, 2.5vw, 1.35rem);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.82);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(22px);
    text-align: center;
}

.sudoku-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    text-align: left;
}

.sudoku-kicker {
    margin: 0 0 0.15rem;
    color: var(--highlight-color);
    font-weight: 800;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.sudoku-subtitle {
    margin: 0;
    color: var(--muted-color);
    font-size: clamp(0.85rem, 2vw, 1rem);
}

.status-pill {
    flex: 0 0 auto;
    padding: 0.55rem 0.75rem;
    border-radius: 999px;
    color: var(--primary-strong);
    background: rgba(37, 99, 235, 0.09);
    font-weight: 800;
    font-size: 0.82rem;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: center;
    align-items: center;
}

.controls select,
.controls button {
    flex: 1 1 150px;
    max-width: 230px;
    font-weight: 800;
}

#toggle-checking {
    background: linear-gradient(135deg, var(--secondary-color), var(--secondary-strong));
    box-shadow: 0 10px 22px rgba(16, 185, 129, 0.22);
}

.sudoku-play-area {
    display: grid;
    grid-template-columns: minmax(0, auto) minmax(210px, 0.42fr);
    gap: clamp(0.85rem, 3vw, 1.4rem);
    align-items: center;
    justify-content: center;
}

.board-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0;
}

#sudoku-board {
    border-collapse: collapse;
    table-layout: fixed;
    width: min(78vmin, 540px);
    height: min(78vmin, 540px);
    overflow: hidden;
    border-radius: 16px;
    background: #ffffff;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
}

#sudoku-board td {
    width: calc(100% / 9);
    height: calc(100% / 9);
    padding: 0;
    text-align: center;
    border: 1px solid rgba(15, 23, 42, 0.24);
    background: rgba(255, 255, 255, 0.94);
    box-sizing: border-box;
}

#sudoku-board tr:nth-child(3n+1) td {
    border-top: 3px solid var(--grid-border-color);
}

#sudoku-board td:nth-child(3n+1) {
    border-left: 3px solid var(--grid-border-color);
}

#sudoku-board td:last-child {
    border-right: 3px solid var(--grid-border-color);
}

#sudoku-board tr:last-child td {
    border-bottom: 3px solid var(--grid-border-color);
}

#sudoku-board input {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 0;
    text-align: center;
    color: var(--text-color);
    background: transparent;
    font-size: clamp(1.05rem, 4.8vmin, 2rem);
    font-weight: 800;
    cursor: pointer;
    caret-color: transparent;
    user-select: none;
}

#sudoku-board input.editable {
    color: #0f172a;
    background: rgba(37, 99, 235, 0.035);
}

#sudoku-board input.given {
    color: var(--primary-strong);
    background: rgba(37, 99, 235, 0.1);
    cursor: default;
}

#sudoku-board input.selected {
    color: #ffffff;
    background: linear-gradient(135deg, var(--highlight-color), #fb7185);
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.65);
}

#sudoku-board input.related {
    background: rgba(251, 146, 60, 0.16);
}

#sudoku-board input.solution {
    color: #64748b;
    font-style: italic;
}

#sudoku-board input.incorrect {
    color: #ffffff !important;
    background: linear-gradient(135deg, #ef4444, #f97316) !important;
}

#sudoku-board input.hint {
    color: var(--secondary-strong);
    background: rgba(16, 185, 129, 0.14);
}

.sudoku-side-panel {
    display: grid;
    gap: 0.85rem;
    min-width: 210px;
}

.number-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(54px, 1fr));
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.22), var(--shadow-card);
}

.number-pad button {
    aspect-ratio: 1;
    min-height: 0;
    padding: 0;
    border-radius: 18px;
    font-size: clamp(1.15rem, 4vw, 1.55rem);
    font-weight: 900;
    background: linear-gradient(135deg, #ffffff, #eff6ff);
    color: var(--primary-strong);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18), 0 8px 20px rgba(37, 99, 235, 0.14);
}

.number-pad button.utility {
    aspect-ratio: auto;
    grid-column: span 3;
    min-height: 44px;
    color: #ffffff;
    background: linear-gradient(135deg, #ef4444, #f97316);
}

.sudoku-tip {
    margin: 0;
    padding: 0.75rem 0.9rem;
    border-radius: 18px;
    color: var(--muted-color);
    background: rgba(15, 23, 42, 0.045);
    font-size: 0.88rem;
    text-align: left;
}

#message {
    min-height: 1.45rem;
    margin: 0;
    color: var(--secondary-strong);
    font-weight: 800;
}

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    background: rgba(15, 23, 42, 0.45);
    transition: opacity 0.25s ease;
    backdrop-filter: blur(12px);
}

.overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.congratulations {
    max-width: min(86vw, 420px);
    padding: 1.35rem;
    border-radius: 28px;
    text-align: center;
    background: #ffffff;
    box-shadow: var(--shadow-card);
    transform: rotate(-2deg);
}

.congratulations h2 {
    color: var(--primary-strong);
    margin-top: 0;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(15, 23, 42, 0.54);
    backdrop-filter: blur(14px);
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-overlay p {
    margin-top: 0.8rem;
    color: #ffffff;
    font-weight: 800;
}

@media (max-width: 760px) {
    body.sudoku-page {
        justify-content: flex-start;
    }

    .sudoku-shell {
        min-height: calc(100dvh - 18px);
        padding: 0.65rem;
        border-radius: 22px;
    }

    .sudoku-header {
        align-items: center;
        text-align: center;
        justify-content: center;
    }

    .status-pill,
    .sudoku-subtitle {
        display: none;
    }

    .controls {
        gap: 0.4rem;
    }

    .controls select,
    .controls button {
        flex: 1 1 30%;
        min-height: 40px;
        padding: 0.5rem 0.45rem;
        font-size: 0.82rem;
    }

    .sudoku-play-area {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    #sudoku-board {
        width: min(calc(100vw - 24px), calc(100dvh - 250px), 540px);
        height: min(calc(100vw - 24px), calc(100dvh - 250px), 540px);
        border-radius: 12px;
    }

    #sudoku-board input {
        font-size: clamp(1rem, 7.3vw, 1.65rem);
    }

    .sudoku-side-panel {
        min-width: 0;
        gap: 0.45rem;
    }

    .number-pad {
        grid-template-columns: repeat(10, 1fr);
        gap: 0.28rem;
        padding: 0.4rem;
        border-radius: 18px;
        position: sticky;
        bottom: max(6px, env(safe-area-inset-bottom));
        z-index: 10;
    }

    .number-pad button {
        min-height: 34px;
        aspect-ratio: auto;
        border-radius: 12px;
        font-size: 1rem;
    }

    .number-pad button.utility {
        grid-column: auto;
        font-size: 0.82rem;
    }

    .sudoku-tip {
        display: none;
    }
}

@media (max-width: 380px) {
    .sudoku-shell {
        gap: 0.45rem;
        padding: 0.45rem;
    }

    .sudoku-kicker {
        display: none;
    }

    #title {
        font-size: 1.35rem;
    }

    .controls select,
    .controls button {
        min-height: 36px;
        font-size: 0.74rem;
        padding: 0.42rem 0.3rem;
    }

    #sudoku-board {
        width: min(calc(100vw - 16px), calc(100dvh - 218px));
        height: min(calc(100vw - 16px), calc(100dvh - 218px));
    }

    .number-pad button {
        min-height: 30px;
        font-size: 0.92rem;
    }
}
