:root {
    /* Color Palette - Default Dark Theme */
    --bg-gradient: linear-gradient(135deg, #090d16, #111827, #070a10);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --board-bg: rgba(17, 24, 39, 0.7);
    --cell-bg: rgba(31, 41, 55, 0.35);
    --cell-text: #e5e7eb;
    --cell-hint: #60a5fa; /* Original puzzle numbers */
    --cell-input: #38bdf8; /* User correct inputs */
    --cell-wrong: #ef4444; /* User mistakes */
    --cell-wrong-bg: rgba(239, 68, 68, 0.12);
    --cell-border: rgba(75, 85, 99, 0.3);
    --block-border: rgba(156, 163, 175, 0.65);
    
    /* Highlight States */
    --highlight-select: rgba(59, 130, 246, 0.35);
    --highlight-related: rgba(59, 130, 246, 0.08);
    --highlight-same-val: rgba(147, 197, 253, 0.18);
    
    /* UI Components */
    --card-bg: rgba(31, 41, 55, 0.55);
    --card-border: rgba(255, 255, 255, 0.06);
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --numpad-bg: rgba(31, 41, 55, 0.65);
    --numpad-btn: rgba(55, 65, 81, 0.6);
    --numpad-btn-text: #f3f4f6;
    --shadow-main: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
}

[data-theme="light"] {
    --bg-gradient: linear-gradient(135deg, #f8fafc, #e2e8f0, #f1f5f9);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --board-bg: rgba(255, 255, 255, 0.75);
    --cell-bg: rgba(255, 255, 255, 0.85);
    --cell-text: #0f172a;
    --cell-hint: #1e3a8a;
    --cell-input: #2563eb;
    --cell-wrong: #dc2626;
    --cell-wrong-bg: rgba(220, 38, 38, 0.08);
    --cell-border: rgba(203, 213, 225, 0.75);
    --block-border: rgba(71, 85, 105, 0.8);
    
    --highlight-select: rgba(37, 99, 235, 0.22);
    --highlight-related: rgba(37, 99, 235, 0.05);
    --highlight-same-val: rgba(37, 99, 235, 0.12);
    
    --card-bg: rgba(255, 255, 255, 0.8);
    --card-border: rgba(0, 0, 0, 0.05);
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --numpad-bg: rgba(226, 232, 240, 0.75);
    --numpad-btn: rgba(255, 255, 255, 0.95);
    --numpad-btn-text: #1e293b;
    --shadow-main: 0 10px 30px -10px rgba(148, 163, 184, 0.35);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Background glows */
.glow {
    position: absolute;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    filter: blur(80px);
    z-index: 0;
    opacity: 0.18;
    pointer-events: none;
    transition: all 0.5s ease;
}
.glow-1 {
    top: 10%;
    left: 5%;
    background-color: #6366f1;
}
.glow-2 {
    bottom: 10%;
    right: 5%;
    background-color: #38bdf8;
}

.app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    padding: 12px 16px;
    z-index: 1;
    overflow-y: auto;
}

/* Header style */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-shrink: 0;
}
.logo-area {
    display: flex;
    align-items: center;
    gap: 8px;
}
.logo-icon {
    color: var(--accent);
    width: 26px;
    height: 26px;
}
.logo-area h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.logo-accent {
    color: var(--accent);
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.icon-btn:active {
    transform: scale(0.92);
}

/* Game Area Layout */
.game-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    justify-content: space-between;
    gap: 8px;
}

/* Stats view */
.game-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    flex-shrink: 0;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-main);
    text-align: center;
}
.stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 2px;
}
.stat-value {
    font-size: 14px;
    font-weight: 700;
}

/* Custom dropdown styled */
.custom-select {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
#difficulty-select {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    width: 100%;
    padding-right: 12px;
    appearance: none;
    -webkit-appearance: none;
}
.select-arrow {
    position: absolute;
    right: 4px;
    pointer-events: none;
    width: 12px;
    height: 12px;
    color: var(--text-secondary);
}

/* Mistake Hearts */
.mistakes-container {
    position: relative;
}
.mistake-hearts {
    display: flex;
    gap: 2px;
    margin-top: 2px;
}
.heart-icon {
    width: 13px;
    height: 13px;
    color: #4b5563; /* empty state tint */
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.heart-icon.filled {
    color: #ef4444;
    fill: #ef4444;
    animation: pulseHeart 0.3s ease-out;
}
@keyframes pulseHeart {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Board Board Board */
.board-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
}
.sudoku-board {
    width: 100%;
    max-width: 440px;
    aspect-ratio: 1 / 1;
    background: var(--board-bg);
    border: 3px solid var(--block-border);
    border-radius: 16px;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    overflow: hidden;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: var(--shadow-main);
    touch-action: none;
}

/* Cell Style */
.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(16px, 5.5vw, 24px);
    font-weight: 600;
    color: var(--cell-text);
    background-color: var(--cell-bg);
    border: 0.5px solid var(--cell-border);
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
    cursor: pointer;
    position: relative;
}

/* Thick borders for 3x3 grids */
.cell:nth-child(3n) {
    border-right: 2px solid var(--block-border);
}
.cell:nth-child(9n) {
    border-right: none;
}
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--block-border);
}

/* Cell status styles */
.cell.hint {
    color: var(--cell-hint);
    font-weight: 700;
}
.cell.input {
    color: var(--cell-input);
}
.cell.wrong {
    color: var(--cell-wrong);
    background-color: var(--cell-wrong-bg);
    animation: shake 0.4s ease;
}

/* Highlights */
.cell.highlight-related {
    background-color: var(--highlight-related);
}
.cell.highlight-same-val {
    background-color: var(--highlight-same-val);
}
.cell.selected {
    background-color: var(--highlight-select) !important;
    box-shadow: inset 0 0 0 2px var(--accent);
    z-index: 2;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

/* Game Control Buttons */
.game-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    flex-shrink: 0;
}
.control-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-main);
    touch-action: manipulation;
}
.control-btn i {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}
.control-btn:active {
    transform: translateY(1px);
    background: rgba(255, 255, 255, 0.05);
}
.control-btn.accent {
    background: var(--accent);
    border-color: transparent;
    color: #ffffff;
}
.control-btn.accent i {
    color: #ffffff;
}
.control-btn.accent:active {
    background: var(--accent-hover);
}

/* Number Pad (Numpad) */
.numpad {
    background: var(--numpad-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
    flex-shrink: 0;
    box-shadow: var(--shadow-main);
    touch-action: manipulation;
}
.num-btn {
    background: var(--numpad-btn);
    border: none;
    border-radius: 10px;
    color: var(--numpad-btn-text);
    font-size: clamp(18px, 6vw, 24px);
    font-weight: 700;
    aspect-ratio: 1/1;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}
.num-btn:active {
    transform: scale(0.9);
    background-color: var(--accent);
    color: #ffffff;
    box-shadow: 0 0 10px var(--accent);
}

/* Modal styling */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(7, 10, 16, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}
.glass-card {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border-radius: 24px;
    width: 100%;
    max-width: 360px;
    padding: 32px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: #f3f4f6;
}
[data-theme="light"] .glass-card {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 20px 50px rgba(100, 116, 139, 0.2);
    color: #1e293b;
}

.modal-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}
.error-glow {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}
.success-glow {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
}
.icon-xl {
    width: 32px;
    height: 32px;
}

.modal-content h2 {
    font-size: 24px;
    font-weight: 800;
}
.modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.game-summary {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 16px;
    padding: 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}
[data-theme="light"] .game-summary {
    background: rgba(241, 245, 249, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.04);
}
.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.summary-label {
    color: var(--text-secondary);
}
.summary-val {
    font-weight: 700;
}

.modal-primary-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 14px;
    padding: 12px 32px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-primary-btn:active {
    transform: scale(0.96);
    background: var(--accent-hover);
}

.animate-pop {
    transform: scale(0.85);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-backdrop.show .animate-pop {
    transform: scale(1);
}

/* Animations and tweaks */
@media (max-height: 600px) {
    .app-container {
        padding: 6px 12px;
    }
    .app-header {
        margin-bottom: 4px;
    }
    .logo-area h1 {
        font-size: 16px;
    }
    .logo-icon {
        width: 20px;
        height: 20px;
    }
    .icon-btn {
        width: 32px;
        height: 32px;
    }
    .game-stats {
        gap: 4px;
    }
    .stat-card {
        padding: 4px;
    }
    .sudoku-board {
        max-width: 320px;
    }
    .cell {
        font-size: 16px;
    }
    .numpad {
        gap: 4px;
        padding: 6px;
    }
    .num-btn {
        font-size: 16px;
        border-radius: 6px;
    }
}
