/* ==========================================================
   Sudoku – Mobile-First Stylesheet
   ========================================================== */

/* ---- CSS Custom Properties ---- */
:root {
    --primary-blue: #2196F3;
    --primary-blue-dark: #1976D2;
    --light-blue: #E3F2FD;
    --lightest-blue: #f0f7ff;
    --dark-text: #1a1a1a;
    --gray-text: #666666;
    --gray-light: #999999;
    --error-red: #f44336;
    --error-red-light: #ffebee;
    --success-green: #4CAF50;
    --border-light: #e0e0e0;
    --border-medium: #bdbdbd;
    --border-dark: #333333;
    --background: #ffffff;
    --surface: #f8f9fa;
    --card-bg: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --transition: 0.2s ease;

    /* Pastel block colors */
    --block-0-0: #fce4ec;
    /* pink */
    --block-0-1: #fff3e0;
    /* peach */
    --block-0-2: #ede7f6;
    /* lavender */
    --block-1-0: #e8f5e9;
    /* mint */
    --block-1-1: #fffde7;
    /* butter */
    --block-1-2: #e1f5fe;
    /* sky */
    --block-2-0: #f3e5f5;
    /* lilac */
    --block-2-1: #e0f2f1;
    /* sage */
    --block-2-2: #fbe9e7;
    /* rose */
}

/* ---- Dark Mode ---- */
[data-theme="dark"] {
    --dark-text: #e8e8e8;
    --gray-text: #aaaaaa;
    --gray-light: #777777;
    --background: #121212;
    --surface: #1e1e1e;
    --card-bg: #252525;
    --border-light: #333333;
    --border-medium: #444444;
    --border-dark: #cccccc;
    --light-blue: #1a3a5c;
    --lightest-blue: #162a3e;
    --error-red-light: #3a1a1a;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    /* Dark pastel block colors */
    --block-0-0: #2d1a1e;
    --block-0-1: #2d261a;
    --block-0-2: #231e2d;
    --block-1-0: #1a2d1e;
    --block-1-1: #2d2d1a;
    --block-1-2: #1a242d;
    --block-2-0: #261a2d;
    --block-2-1: #1a2d2a;
    --block-2-2: #2d1f1a;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--background);
    color: var(--dark-text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ---- App Container ---- */
.app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ---- Header ---- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    position: sticky;
    top: 0;
    background: var(--background);
    z-index: 10;
}

.header__btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--primary-blue);
    transition: background var(--transition);
}

.header__btn:hover {
    background: var(--light-blue);
}

.header__btn:active {
    transform: scale(0.92);
}

.header__score {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark-text);
}

.header__actions {
    display: flex;
    gap: 4px;
}

/* ---- Stats Bar ---- */
.stats-bar {
    display: flex;
    justify-content: space-between;
    padding: 10px 4px;
    gap: 4px;
}

.stats-bar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.stats-bar__label {
    font-size: 11px;
    color: var(--gray-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.stats-bar__value {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark-text);
}

.stats-bar__item--timer {
    min-width: 80px;
}

.stats-bar__timer-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.stats-bar__pause-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--surface);
    color: var(--gray-text);
    transition: all var(--transition);
    border: 1.5px solid var(--border-light);
}

.stats-bar__pause-btn:hover {
    background: var(--light-blue);
    color: var(--primary-blue);
}

.stats-bar__pause-btn.is-paused svg {
    display: none;
}

.stats-bar__pause-btn.is-paused::after {
    content: '';
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 10px;
    border-color: transparent transparent transparent currentColor;
    margin-left: 2px;
}

/* ---- Board ---- */
.board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 480px;
    margin: 4px auto;
}

.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
    border: 2.5px solid var(--border-dark);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border-light);
    gap: 1px;
    box-shadow: var(--shadow-md);
}

.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--cell-bg, var(--card-bg));
    font-size: 22px;
    font-weight: 500;
    color: var(--primary-blue);
    cursor: pointer;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    transition: background var(--transition);
}

/* ---- Pastel block backgrounds ---- */
/* Block (0,0): rows 0-2, cols 0-2 */
.cell[data-row="0"][data-col="0"],
.cell[data-row="0"][data-col="1"],
.cell[data-row="0"][data-col="2"],
.cell[data-row="1"][data-col="0"],
.cell[data-row="1"][data-col="1"],
.cell[data-row="1"][data-col="2"],
.cell[data-row="2"][data-col="0"],
.cell[data-row="2"][data-col="1"],
.cell[data-row="2"][data-col="2"] {
    --cell-bg: var(--block-0-0);
}

/* Block (0,1): rows 0-2, cols 3-5 */
.cell[data-row="0"][data-col="3"],
.cell[data-row="0"][data-col="4"],
.cell[data-row="0"][data-col="5"],
.cell[data-row="1"][data-col="3"],
.cell[data-row="1"][data-col="4"],
.cell[data-row="1"][data-col="5"],
.cell[data-row="2"][data-col="3"],
.cell[data-row="2"][data-col="4"],
.cell[data-row="2"][data-col="5"] {
    --cell-bg: var(--block-0-1);
}

/* Block (0,2): rows 0-2, cols 6-8 */
.cell[data-row="0"][data-col="6"],
.cell[data-row="0"][data-col="7"],
.cell[data-row="0"][data-col="8"],
.cell[data-row="1"][data-col="6"],
.cell[data-row="1"][data-col="7"],
.cell[data-row="1"][data-col="8"],
.cell[data-row="2"][data-col="6"],
.cell[data-row="2"][data-col="7"],
.cell[data-row="2"][data-col="8"] {
    --cell-bg: var(--block-0-2);
}

/* Block (1,0): rows 3-5, cols 0-2 */
.cell[data-row="3"][data-col="0"],
.cell[data-row="3"][data-col="1"],
.cell[data-row="3"][data-col="2"],
.cell[data-row="4"][data-col="0"],
.cell[data-row="4"][data-col="1"],
.cell[data-row="4"][data-col="2"],
.cell[data-row="5"][data-col="0"],
.cell[data-row="5"][data-col="1"],
.cell[data-row="5"][data-col="2"] {
    --cell-bg: var(--block-1-0);
}

/* Block (1,1): rows 3-5, cols 3-5 */
.cell[data-row="3"][data-col="3"],
.cell[data-row="3"][data-col="4"],
.cell[data-row="3"][data-col="5"],
.cell[data-row="4"][data-col="3"],
.cell[data-row="4"][data-col="4"],
.cell[data-row="4"][data-col="5"],
.cell[data-row="5"][data-col="3"],
.cell[data-row="5"][data-col="4"],
.cell[data-row="5"][data-col="5"] {
    --cell-bg: var(--block-1-1);
}

/* Block (1,2): rows 3-5, cols 6-8 */
.cell[data-row="3"][data-col="6"],
.cell[data-row="3"][data-col="7"],
.cell[data-row="3"][data-col="8"],
.cell[data-row="4"][data-col="6"],
.cell[data-row="4"][data-col="7"],
.cell[data-row="4"][data-col="8"],
.cell[data-row="5"][data-col="6"],
.cell[data-row="5"][data-col="7"],
.cell[data-row="5"][data-col="8"] {
    --cell-bg: var(--block-1-2);
}

/* Block (2,0): rows 6-8, cols 0-2 */
.cell[data-row="6"][data-col="0"],
.cell[data-row="6"][data-col="1"],
.cell[data-row="6"][data-col="2"],
.cell[data-row="7"][data-col="0"],
.cell[data-row="7"][data-col="1"],
.cell[data-row="7"][data-col="2"],
.cell[data-row="8"][data-col="0"],
.cell[data-row="8"][data-col="1"],
.cell[data-row="8"][data-col="2"] {
    --cell-bg: var(--block-2-0);
}

/* Block (2,1): rows 6-8, cols 3-5 */
.cell[data-row="6"][data-col="3"],
.cell[data-row="6"][data-col="4"],
.cell[data-row="6"][data-col="5"],
.cell[data-row="7"][data-col="3"],
.cell[data-row="7"][data-col="4"],
.cell[data-row="7"][data-col="5"],
.cell[data-row="8"][data-col="3"],
.cell[data-row="8"][data-col="4"],
.cell[data-row="8"][data-col="5"] {
    --cell-bg: var(--block-2-1);
}

/* Block (2,2): rows 6-8, cols 6-8 */
.cell[data-row="6"][data-col="6"],
.cell[data-row="6"][data-col="7"],
.cell[data-row="6"][data-col="8"],
.cell[data-row="7"][data-col="6"],
.cell[data-row="7"][data-col="7"],
.cell[data-row="7"][data-col="8"],
.cell[data-row="8"][data-col="6"],
.cell[data-row="8"][data-col="7"],
.cell[data-row="8"][data-col="8"] {
    --cell-bg: var(--block-2-2);
}

/* 3x3 block borders */
.cell[data-col="2"],
.cell[data-col="5"] {
    border-right: 2px solid var(--border-dark);
}

.cell[data-row="2"],
.cell[data-row="5"] {
    border-bottom: 2px solid var(--border-dark);
}

/* Clue (given) cells */
.cell--clue {
    font-weight: 700;
    color: var(--dark-text);
}

/* Selected cell */
.cell--selected {
    background: var(--light-blue) !important;
    z-index: 2;
}

/* Highlighted (same row/col/box) */
.cell--highlighted {
    background: var(--lightest-blue);
}

/* Same number highlight */
.cell--same-number {
    background: var(--light-blue);
}

/* Error cell */
.cell--error {
    color: var(--error-red) !important;
    animation: shake 0.4s ease-in-out;
}

.cell--error-bg {
    background: var(--error-red-light) !important;
}

/* Hint cell */
.cell--hint {
    animation: hintPulse 0.6s ease;
}

/* Notes in cell */
.cell__notes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    padding: 1px;
}

.cell__note {
    font-size: 9px;
    font-weight: 500;
    color: var(--gray-text);
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ---- Pause Overlay ---- */
.pause-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    z-index: 5;
}

[data-theme="dark"] .pause-overlay {
    background: rgba(18, 18, 18, 0.95);
}

.pause-overlay.is-visible {
    display: flex;
}

.pause-overlay__content {
    text-align: center;
    color: var(--gray-text);
}

.pause-overlay__content svg {
    margin-bottom: 12px;
    opacity: 0.4;
}

.pause-overlay__content p {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--dark-text);
}

.pause-overlay__resume-btn {
    padding: 10px 32px;
    background: var(--primary-blue);
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-lg);
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
}

.pause-overlay__resume-btn:hover {
    background: var(--primary-blue-dark);
    transform: translateY(-1px);
}

/* ---- Action Buttons ---- */
.actions {
    display: flex;
    justify-content: space-around;
    padding: 16px 0 8px;
}

.actions__btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    color: var(--gray-text);
    font-size: 11px;
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
    min-width: 60px;
}

.actions__btn:hover {
    color: var(--primary-blue);
    background: var(--lightest-blue);
}

.actions__btn:active {
    transform: scale(0.92);
}

.actions__btn svg {
    width: 24px;
    height: 24px;
}

.actions__btn.is-active {
    color: var(--primary-blue);
    background: var(--light-blue);
}

.actions__badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    background: var(--primary-blue);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

.actions__badge--notes {
    background: var(--gray-light);
    font-size: 8px;
    letter-spacing: 0.5px;
}

.actions__badge--notes.is-on {
    background: var(--success-green);
}

/* ---- Number Pad ---- */
.numpad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    padding: 8px 0 20px;
}

.numpad__btn {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    color: var(--primary-blue);
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1.5px solid var(--border-light);
    transition: all var(--transition);
    max-height: 56px;
}

.numpad__btn:hover {
    background: var(--light-blue);
    border-color: var(--primary-blue);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.numpad__btn:active {
    transform: scale(0.92);
}

.numpad__btn--completed {
    opacity: 0.3;
    pointer-events: none;
}

/* ---- Modals ---- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.is-visible {
    display: flex;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
}

.modal__content {
    position: relative;
    background: var(--card-bg);
    padding: 32px 28px;
    border-radius: var(--radius-xl);
    max-width: 340px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.3s ease;
    z-index: 1;
}

.modal__title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--dark-text);
}

.modal__text {
    font-size: 14px;
    color: var(--gray-text);
    margin-bottom: 24px;
}

.modal__icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.modal__buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal__btn {
    padding: 14px 24px;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.modal__btn--easy {
    background: #e8f5e9;
    color: #2e7d32;
}

.modal__btn--easy:hover {
    background: #c8e6c9;
    transform: translateY(-1px);
}

.modal__btn--medium {
    background: #fff3e0;
    color: #ef6c00;
}

.modal__btn--medium:hover {
    background: #ffe0b2;
    transform: translateY(-1px);
}

.modal__btn--hard {
    background: #ffebee;
    color: #c62828;
}

.modal__btn--hard:hover {
    background: #ffcdd2;
    transform: translateY(-1px);
}

.modal__btn--primary {
    background: var(--primary-blue);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
}

.modal__btn--primary:hover {
    background: var(--primary-blue-dark);
    transform: translateY(-1px);
}

.modal__close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 28px;
    color: var(--gray-light);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition);
}

.modal__close:hover {
    background: var(--surface);
    color: var(--dark-text);
}

.modal__stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 24px;
}

.modal__stat {
    text-align: center;
}

.modal__stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-blue);
}

.modal__stat-label {
    font-size: 12px;
    color: var(--gray-text);
    margin-top: 2px;
}

/* ---- Settings ---- */
.settings-list {
    text-align: left;
}

.settings-list__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 15px;
}

.settings-list__item:last-child {
    border-bottom: none;
}

.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle__slider {
    position: absolute;
    inset: 0;
    background: var(--border-light);
    border-radius: 26px;
    transition: var(--transition);
    cursor: pointer;
}

.toggle__slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: #ffffff;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle input:checked+.toggle__slider {
    background: var(--primary-blue);
}

.toggle input:checked+.toggle__slider::before {
    transform: translateX(22px);
}

/* ---- Loading Spinner ---- */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

[data-theme="dark"] .loading {
    background: rgba(18, 18, 18, 0.8);
}

.loading.is-visible {
    display: flex;
}

.loading__spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-light);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ---- Animations ---- */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-4px);
    }

    40% {
        transform: translateX(4px);
    }

    60% {
        transform: translateX(-3px);
    }

    80% {
        transform: translateX(3px);
    }
}

@keyframes hintPulse {
    0% {
        background: var(--success-green);
        color: #ffffff;
    }

    100% {
        background: var(--card-bg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes celebrate {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100%) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* ---- Responsive: Tablet ---- */
@media (min-width: 768px) {
    .app {
        max-width: 520px;
        padding: 0 24px;
    }

    .cell {
        font-size: 26px;
    }

    .cell__note {
        font-size: 11px;
    }

    .numpad__btn {
        font-size: 28px;
    }

    .actions__btn {
        font-size: 12px;
        padding: 10px 16px;
    }
}

/* ---- Responsive: Desktop ---- */
@media (min-width: 1024px) {
    .app {
        max-width: 560px;
        padding-top: 20px;
    }

    .header {
        padding: 16px 0;
    }

    .cell {
        font-size: 28px;
    }

    .cell:hover:not(.cell--clue):not(.cell--selected) {
        background: var(--lightest-blue);
    }

    .numpad {
        gap: 8px;
    }

    .numpad__btn {
        font-size: 30px;
        max-height: 64px;
    }
}

/* ---- Safe area for iPhone notch ---- */
@supports (padding-top: env(safe-area-inset-top)) {
    .header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .numpad {
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
}

/* ---- Print hidden ---- */
@media print {

    .header,
    .stats-bar,
    .actions,
    .numpad,
    .modal {
        display: none !important;
    }
}