:root {
    /* Base Typography */
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Layout Variables */
    --board-size: 100vw;
    --max-board-size: 450px;
    --cell-size: calc(var(--max-board-size) / 9);
    --border-radius: 12px;
    --cell-radius: 4px;
    
    /* Colors light */
    --theme-light-bg: #f8f9fa;
    --theme-light-surface: #ffffff;
    --theme-light-text: #1a1a1a;
    --theme-light-text-muted: #6c757d;
    --theme-light-border: #dee2e6;
    --theme-light-border-thick: #343a40;
    
    --theme-light-primary: #4361ee;
    --theme-light-primary-hover: #3a56d4;
    --theme-light-secondary: #f0f4f8;
    
    /* Board colors Light */
    --theme-light-cell-bg: #ffffff;
    --theme-light-cell-selected: #e0e7ff;
    --theme-light-cell-highlight: #f3f4f6; /* Same row/col/box */
    --theme-light-cell-same-num: #c7d2fe;
    --theme-light-text-fixed: #111827;
    --theme-light-text-user: #4361ee;
    --theme-light-text-error: #ef4444;
    --theme-light-cell-error-bg: #fee2e2;
    --theme-light-notes: #6b7280;

    /* Colors dark */
    --theme-dark-bg: #0f172a; /* Slate 900 */
    --theme-dark-surface: #1e293b; /* Slate 800 */
    --theme-dark-text: #f8fafc; /* Slate 50 */
    --theme-dark-text-muted: #94a3b8; /* Slate 400 */
    --theme-dark-border: #334155; /* Slate 700 */
    --theme-dark-border-thick: #94a3b8; /* Slate 400 */
    
    --theme-dark-primary: #6366f1; /* Indigo 500 */
    --theme-dark-primary-hover: #4f46e5; /* Indigo 600 */
    --theme-dark-secondary: #334155;
    
    /* Board colors Dark */
    --theme-dark-cell-bg: #1e293b;
    --theme-dark-cell-selected: #312e81; /* Indigo 900 */
    --theme-dark-cell-highlight: #334155; /* Slate 700 */
    --theme-dark-cell-same-num: #4338ca; /* Indigo 700 */
    --theme-dark-text-fixed: #f8fafc;
    --theme-dark-text-user: #818cf8; /* Indigo 400 */
    --theme-dark-text-error: #fca5a5; /* Red 300 */
    --theme-dark-cell-error-bg: #7f1d1d; /* Red 900 */
    --theme-dark-notes: #94a3b8;

    /* Active theme variable bindings (fallback to Light) */
    --bg-color: var(--theme-light-bg);
    --surface-color: var(--theme-light-surface);
    --text-color: var(--theme-light-text);
    --text-muted: var(--theme-light-text-muted);
    --border-color: var(--theme-light-border);
    --border-thick: var(--theme-light-border-thick);
    --primary-color: var(--theme-light-primary);
    --primary-hover: var(--theme-light-primary-hover);
    --secondary-color: var(--theme-light-secondary);
    
    --cell-bg: var(--theme-light-cell-bg);
    --cell-selected: var(--theme-light-cell-selected);
    --cell-highlight: var(--theme-light-cell-highlight);
    --cell-same-num: var(--theme-light-cell-same-num);
    --text-fixed: var(--theme-light-text-fixed);
    --text-user: var(--theme-light-text-user);
    --text-error: var(--theme-light-text-error);
    --cell-error-bg: var(--theme-light-cell-error-bg);
    --notes-color: var(--theme-light-notes);
}

.theme-dark {
    --bg-color: var(--theme-dark-bg);
    --surface-color: var(--theme-dark-surface);
    --text-color: var(--theme-dark-text);
    --text-muted: var(--theme-dark-text-muted);
    --border-color: var(--theme-dark-border);
    --border-thick: var(--theme-dark-border-thick);
    --primary-color: var(--theme-dark-primary);
    --primary-hover: var(--theme-dark-primary-hover);
    --secondary-color: var(--theme-dark-secondary);
    
    --cell-bg: var(--theme-dark-cell-bg);
    --cell-selected: var(--theme-dark-cell-selected);
    --cell-highlight: var(--theme-dark-cell-highlight);
    --cell-same-num: var(--theme-dark-cell-same-num);
    --text-fixed: var(--theme-dark-text-fixed);
    --text-user: var(--theme-dark-text-user);
    --text-error: var(--theme-dark-text-error);
    --cell-error-bg: var(--theme-dark-cell-error-bg);
    --notes-color: var(--theme-dark-notes);
}

/* Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 20px 10px;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.difficulty-selector {
    display: flex;
    background: var(--surface-color);
    border-radius: 20px;
    padding: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.theme-dark .difficulty-selector {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.diff-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.diff-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--secondary-color);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    font-weight: 600;
    font-size: 0.95rem;
}

.mistakes, .timer {
    color: var(--text-color);
}

.pause-play svg {
    width: 20px;
    height: 20px;
}

/* Board */
.game-area {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    gap: 1px;
    width: var(--board-size);
    max-width: var(--max-board-size);
    height: var(--board-size);
    max-height: var(--max-board-size);
    background-color: var(--border-color);
    border: 2px solid var(--border-thick);
    border-radius: var(--border-radius);
    overflow: hidden;
    touch-action: manipulation;
}

/* Every 3rd cell right/bottom gets a thicker border to form the 3x3 blocks */
.sudoku-cell {
    background-color: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-fixed);
    cursor: pointer;
    transition: background-color 0.15s;
    position: relative;
    user-select: none;
}

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

/* Cell States */
.sudoku-cell.selected {
    background-color: var(--cell-selected) !important;
}
.sudoku-cell.highlighted {
    background-color: var(--cell-highlight);
}
.sudoku-cell.same-number {
    background-color: var(--cell-same-num);
}
.sudoku-cell.user-input {
    color: var(--text-user);
    font-weight: 600;
}
.sudoku-cell.error {
    color: var(--text-error);
    background-color: var(--cell-error-bg);
}

/* Notes Grid inside a Cell */
.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    padding: 2px;
}

.note {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    color: var(--notes-color);
    line-height: 1;
}

/* Pause Overlay */
.pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(var(--bg-color), 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 10;
    border-radius: var(--border-radius);
    transition: opacity 0.3s;
}

.pause-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Controls */
.controls-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: var(--max-board-size);
    margin: 0 auto;
}

.tools {
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
}

.tool-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0.8;
    transition: all 0.2s;
    position: relative;
}

.tool-btn:hover, .tool-btn:active {
    opacity: 1;
    transform: translateY(-2px);
    color: var(--primary-color);
}

.badge {
    position: absolute;
    top: -5px;
    right: -10px;
    background: var(--surface-color);
    color: var(--text-muted);
    font-size: 0.5rem;
    padding: 2px 4px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.tool-btn.active .badge {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.tool-btn.active {
    opacity: 1;
    color: var(--primary-color);
}

/* Numpad */
.numpad {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 8px;
}

.num-btn {
    aspect-ratio: 1;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1.5rem;
    font-family: inherit;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: all 0.1s;
    touch-action: manipulation;
}

.theme-dark .num-btn {
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.num-btn.completed {
    opacity: 0.25;
    pointer-events: none;
    background: var(--bg-color);
    border-color: var(--border-color);
    color: var(--text-muted);
    box-shadow: none;
}

.num-btn:active {
    transform: scale(0.92);
    background: var(--primary-color);
    color: white;
}

/* Buttons */
.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    width: 100%;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.primary-btn:active {
    transform: scale(0.98);
}

.mt-4 { margin-top: 16px; }
.w-full { width: 100%; }

/* Utilities */
.hidden { display: none !important; }

/* Animations */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px) rotate(-2deg); }
    40% { transform: translateX(4px) rotate(2deg); }
    60% { transform: translateX(-4px) rotate(-1deg); }
    80% { transform: translateX(4px) rotate(1deg); }
}

.animate-shake {
    animation: shake 0.4s ease-in-out;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.animate-pop {
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Confetti Layer */
.confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-content {
    background: var(--surface-color);
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 320px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

.glass-panel {
    background: rgba(var(--surface-color-rgb), 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-content h2 {
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    line-height: 1.5;
}

.stats-summary {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    text-align: left;
}

.stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}
.stat:last-child { margin-bottom: 0; }

.stat .label { color: var(--text-muted); }
.stat .val { font-weight: 600; color: var(--text-color); }

/* Responsive Adjustments */
@media (max-height: 650px) {
    .app-container { gap: 10px; }
    .header h1 { font-size: 1.5rem; }
    .primary-btn { padding: 10px 20px; }
}
