:root {
    /* Dark Theme (Default) */
    --bg-main: #0f172a;
    --bg-panel: rgba(30, 41, 59, 0.7);
    --bg-board: rgba(15, 23, 42, 0.9);
    --border-color: rgba(255, 255, 255, 0.1);
    --border-bold: rgba(255, 255, 255, 0.3);
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-given: #f8fafc;
    --text-input: #38bdf8;
    
    --primary: #38bdf8;
    --primary-glow: rgba(56, 189, 248, 0.5);
    --secondary: #818cf8;
    --success: #10b981;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.2);
    
    --gold: #fbbf24;
    
    --cell-bg: transparent;
    --cell-highlight: rgba(56, 189, 248, 0.15);
    --cell-selected: rgba(56, 189, 248, 0.3);
    --cell-related: rgba(255, 255, 255, 0.05);
    --cell-size: clamp(30px, 10vw, 45px);
    
    --font-main: 'Outfit', sans-serif;
}

.theme-light {
    --bg-main: #f1f5f9;
    --bg-panel: rgba(255, 255, 255, 0.8);
    --bg-board: rgba(255, 255, 255, 0.95);
    --border-color: rgba(0, 0, 0, 0.1);
    --border-bold: rgba(0, 0, 0, 0.3);
    
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-given: #0f172a;
    --text-input: #0284c7;
    
    --primary: #0ea5e9;
    --primary-glow: rgba(14, 165, 233, 0.3);
    
    --cell-highlight: rgba(14, 165, 233, 0.15);
    --cell-selected: rgba(14, 165, 233, 0.3);
    --cell-related: rgba(0, 0, 0, 0.05);
}

.theme-zen {
    --bg-main: #e2e8f0;
    --bg-panel: rgba(248, 250, 252, 0.85);
    --bg-board: #fff;
    --border-color: #cbd5e1;
    --border-bold: #475569;
    
    --text-main: #334155;
    --text-muted: #64748b;
    --text-given: #1e293b;
    --text-input: #10b981;
    
    --primary: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.3);
    
    --cell-highlight: rgba(16, 185, 129, 0.15);
    --cell-selected: rgba(16, 185, 129, 0.3);
    --cell-related: rgba(0, 0, 0, 0.03);
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-main);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: background-color 0.5s ease;
}

#bg-canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
}

#app {
    position: relative;
    width: 100vw; height: 100vh;
    z-index: 1;
}

.screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: 0.4s ease;
    padding: 1rem;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* Typography */
.logo-container { text-align: center; margin-bottom: 3rem; }
.logo { font-size: 3.5rem; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.highlight { color: var(--primary); text-shadow: 0 0 20px var(--primary-glow); }
h2 { font-size: 2rem; font-weight: 700; margin-bottom: 2rem; letter-spacing: 1px; text-align: center; }

.text-gold { color: var(--gold) !important; text-shadow: 0 0 10px rgba(251, 191, 36, 0.4); }
.text-blue { color: var(--primary) !important; text-shadow: 0 0 10px var(--primary-glow); }
.text-red { color: var(--error) !important; text-shadow: 0 0 10px var(--error-bg); }

/* Components */
.stats-bar {
    display: flex; gap: 2rem; background: var(--bg-panel); padding: 0.8rem 2rem;
    border-radius: 30px; border: 1px solid var(--border-color); margin-bottom: 2.5rem;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.stat { display: flex; align-items: center; gap: 0.5rem; font-size: 1.2rem; font-weight: 600; }

.menu-buttons { display: flex; flex-direction: column; gap: 1rem; width: 100%; max-width: 320px; }
.btn {
    background: var(--bg-panel); border: 1px solid var(--border-color);
    color: var(--text-main); padding: 1rem 1.5rem; font-size: 1.1rem; font-weight: 600;
    border-radius: 16px; cursor: pointer; transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center; gap: 0.8rem;
    font-family: var(--font-main); backdrop-filter: blur(5px);
}
.btn:hover { background: rgba(255,255,255,0.1); transform: translateY(-2px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border: none; color: #fff; box-shadow: 0 8px 25px var(--primary-glow); }
.btn.primary:hover { filter: brightness(1.1); }
.diff-btn { flex-direction: column; gap: 0.2rem; align-items: flex-start; padding: 1rem 1.5rem; }
.diff-desc { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }
.mt-2 { margin-top: 2rem; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 var(--primary-glow); } 70% { box-shadow: 0 0 0 15px rgba(56, 189, 248, 0); } 100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); } }
.pulse { animation: pulse 2s infinite; }

/* Gameplay UI */
.game-header {
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; max-width: 500px; margin-bottom: 1rem;
}
.icon-btn {
    background: transparent; border: none; color: var(--text-main); cursor: pointer;
    font-size: 1.5rem; padding: 0.5rem; border-radius: 50%; transition: 0.2s;
}
.icon-btn:hover { background: var(--bg-panel); }
.game-info { display: flex; flex-direction: column; align-items: center; }
#game-difficulty { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
#game-timer { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.game-stats {
    display: flex; justify-content: space-between; width: 100%; max-width: 500px;
    font-size: 0.9rem; font-weight: 600; color: var(--text-muted); margin-bottom: 1rem;
}

/* Sudoku Board */
.board-container {
    background: var(--bg-board);
    padding: 4px;
    border-radius: 12px;
    border: 2px solid var(--border-bold);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
    margin-bottom: 1.5rem;
}
.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, var(--cell-size));
    grid-template-rows: repeat(9, var(--cell-size));
    gap: 1px;
    background: var(--border-color);
}
.cell {
    background: var(--bg-board);
    display: flex; align-items: center; justify-content: center;
    font-size: calc(var(--cell-size) * 0.6);
    font-weight: 400; color: var(--text-given);
    cursor: pointer; transition: 0.1s background;
    position: relative;
}
.cell.border-r { border-right: 2px solid var(--border-bold); }
.cell.border-b { border-bottom: 2px solid var(--border-bold); }

.cell.given { font-weight: 700; }
.cell.input { color: var(--text-input); }
.cell.highlight { background: var(--cell-highlight); }
.cell.related { background: var(--cell-related); }
.cell.selected { background: var(--cell-selected); }
.cell.error { color: var(--error); background: var(--error-bg); }

/* Notes styling */
.notes-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    width: 100%; height: 100%; padding: 2px;
}
.note {
    font-size: calc(var(--cell-size) * 0.25); line-height: 1;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}

/* Tools */
.tools-container {
    display: flex; justify-content: center; gap: 1rem; width: 100%; max-width: 500px;
    margin-bottom: 1.5rem;
}
.tool-btn {
    background: transparent; border: none; color: var(--text-main); cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
    font-family: var(--font-main); opacity: 0.8; transition: 0.2s; position: relative;
}
.tool-btn:hover, .tool-btn.active { opacity: 1; color: var(--primary); }
.tool-btn .material-icons-rounded { font-size: 1.8rem; background: var(--bg-panel); padding: 0.8rem; border-radius: 50%; border: 1px solid var(--border-color); }
.tool-btn.active .material-icons-rounded { background: var(--primary-glow); border-color: var(--primary); }
.tool-btn span:last-child { font-size: 0.8rem; font-weight: 600; }
.badge { position: absolute; top: 0; right: 0; background: var(--primary); color: #fff; font-size: 0.7rem; padding: 2px 6px; border-radius: 10px; font-weight: 800; }

/* Numpad */
.numpad {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem;
    width: 100%; max-width: 400px; justify-content: center;
}
.numpad .num-btn:last-child { grid-column: span 5; max-width: 60px; margin: 0 auto; } /* center 9 if 5 cols */
.numpad { grid-template-columns: repeat(9, 1fr); gap: 0.3rem; } /* Override for better mobile layout */
@media (min-width: 500px) {
    .numpad { grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
    .numpad .num-btn:last-child { grid-column: auto; max-width: none; }
}

.num-btn {
    background: var(--bg-panel); border: 1px solid var(--border-color);
    color: var(--primary); font-size: 1.8rem; font-weight: 600; font-family: var(--font-main);
    border-radius: 12px; cursor: pointer; padding: 0.5rem 0;
    transition: 0.1s; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.num-btn:hover { background: rgba(255,255,255,0.1); transform: translateY(-2px); }
.num-btn:active { transform: translateY(1px) scale(0.95); }
.num-btn.completed { opacity: 0.3; pointer-events: none; }

/* Result Card */
.result-card { background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 20px; padding: 2rem; width: 100%; max-width: 400px; margin-bottom: 2rem; backdrop-filter: blur(10px); }
.result-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.2rem; font-weight: 600; margin: 0.8rem 0; }
.result-row .highlight { font-size: 1.5rem; font-weight: 800; }
.divider { height: 1px; background: var(--border-color); margin: 1.5rem 0; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; width: 100%; max-width: 400px; }
.stat-box { background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 16px; padding: 1.5rem; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--primary); margin-bottom: 0.5rem; }
.stat-label { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; }

/* Themes Grid */
.theme-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; width: 100%; max-width: 400px; max-height: 60vh; overflow-y: auto; padding-right: 5px; }
.theme-card {
    background: var(--bg-panel); border: 2px solid var(--border-color);
    border-radius: 16px; padding: 1.5rem 1rem; text-align: center; cursor: pointer; transition: 0.2s;
}
.theme-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.theme-card.active { border-color: var(--primary); box-shadow: 0 0 15px var(--primary-glow); }
.theme-preview { width: 40px; height: 40px; border-radius: 50%; margin: 0 auto 1rem; border: 2px solid var(--border-bold); }
.theme-name { font-weight: 600; font-size: 1rem; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
