/* CSS Variables & Themes */
:root {
    /* Dark Theme (Default) */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --bg-card: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --accent-glow: rgba(99, 102, 241, 0.2);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-color: #2a2a2a;
    --shadow-sm: 0 2px 4px 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);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e5e5e5;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --border-color: #e0e0e0;
    --shadow-sm: 0 2px 4px 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);
}

[data-theme="midnight"] {
    --bg-primary: #0a1628;
    --bg-secondary: #111d33;
    --bg-tertiary: #1a2940;
    --bg-card: #142238;
    --accent-primary: #3b82f6;
    --accent-secondary: #60a5fa;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --accent-glow: rgba(59, 130, 246, 0.25);
    --border-color: #1e3a5f;
}

[data-theme="forest"] {
    --bg-primary: #0a1510;
    --bg-secondary: #0f1f17;
    --bg-tertiary: #162b1f;
    --bg-card: #132419;
    --accent-primary: #22c55e;
    --accent-secondary: #4ade80;
    --accent-gradient: linear-gradient(135deg, #22c55e 0%, #10b981 100%);
    --accent-glow: rgba(34, 197, 94, 0.25);
    --border-color: #1a3d28;
}

[data-theme="sunset"] {
    --bg-primary: #1a0f0a;
    --bg-secondary: #2d1810;
    --bg-tertiary: #3d2218;
    --bg-card: #2a1a12;
    --accent-primary: #f97316;
    --accent-secondary: #fb923c;
    --accent-gradient: linear-gradient(135deg, #f97316 0%, #ef4444 100%);
    --accent-glow: rgba(249, 115, 22, 0.25);
    --border-color: #4a2c1a;
}

[data-theme="cherry"] {
    --bg-primary: #150a10;
    --bg-secondary: #1f1018;
    --bg-tertiary: #2d1520;
    --bg-card: #251220;
    --accent-primary: #ec4899;
    --accent-secondary: #f472b6;
    --accent-gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
    --accent-glow: rgba(236, 72, 153, 0.25);
    --border-color: #3d1a2a;
}

[data-theme="ocean"] {
    --bg-primary: #0a1520;
    --bg-secondary: #0d1f2d;
    --bg-tertiary: #12293a;
    --bg-card: #0f2433;
    --accent-primary: #06b6d4;
    --accent-secondary: #22d3ee;
    --accent-gradient: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    --accent-glow: rgba(6, 182, 212, 0.25);
    --border-color: #1a3d5c;
}

[data-theme="lavender"] {
    --bg-primary: #12101a;
    --bg-secondary: #1a1625;
    --bg-tertiary: #231e32;
    --bg-card: #1e192a;
    --accent-primary: #a78bfa;
    --accent-secondary: #c4b5fd;
    --accent-gradient: linear-gradient(135deg, #a78bfa 0%, #ec4899 100%);
    --accent-glow: rgba(167, 139, 250, 0.25);
    --border-color: #352d4a;
}

[data-theme="emerald"] {
    --bg-primary: #071510;
    --bg-secondary: #0c1f18;
    --bg-tertiary: #122a22;
    --bg-card: #0f241c;
    --accent-primary: #10b981;
    --accent-secondary: #34d399;
    --accent-gradient: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
    --accent-glow: rgba(16, 185, 129, 0.25);
    --border-color: #1a4d3a;
}

[data-theme="rose"] {
    --bg-primary: #18080d;
    --bg-secondary: #220c14;
    --bg-tertiary: #2e101c;
    --bg-card: #280e18;
    --accent-primary: #fb7185;
    --accent-secondary: #fda4af;
    --accent-gradient: linear-gradient(135deg, #fb7185 0%, #f472b6 100%);
    --accent-glow: rgba(251, 113, 133, 0.25);
    --border-color: #4a1a2a;
}

[data-theme="amber"] {
    --bg-primary: #1a1408;
    --bg-secondary: #261c0c;
    --bg-tertiary: #332610;
    --bg-card: #2c200e;
    --accent-primary: #f59e0b;
    --accent-secondary: #fbbf24;
    --accent-gradient: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
    --accent-glow: rgba(245, 158, 11, 0.25);
    --border-color: #4a3810;
}

[data-theme="slate"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;
    --accent-primary: #64748b;
    --accent-secondary: #94a3b8;
    --accent-gradient: linear-gradient(135deg, #64748b 0%, #475569 100%);
    --accent-glow: rgba(100, 116, 139, 0.25);
    --border-color: #475569;
}

[data-theme="neon"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-tertiary: #1a1a1a;
    --bg-card: #141414;
    --text-primary: #00ff88;
    --text-secondary: #00cc6a;
    --text-muted: #009950;
    --accent-primary: #00ff88;
    --accent-secondary: #00ffcc;
    --accent-gradient: linear-gradient(135deg, #00ff88 0%, #00ffcc 100%);
    --accent-glow: rgba(0, 255, 136, 0.3);
    --border-color: #003322;
}

[data-theme="dracula"] {
    --bg-primary: #282a36;
    --bg-secondary: #21222c;
    --bg-tertiary: #343746;
    --bg-card: #2d2f3b;
    --text-primary: #f8f8f2;
    --text-secondary: #bfbfbf;
    --text-muted: #6272a4;
    --accent-primary: #bd93f9;
    --accent-secondary: #ff79c6;
    --accent-gradient: linear-gradient(135deg, #bd93f9 0%, #ff79c6 100%);
    --accent-glow: rgba(189, 147, 249, 0.25);
    --border-color: #44475a;
}

[data-theme="nord"] {
    --bg-primary: #2e3440;
    --bg-secondary: #3b4252;
    --bg-tertiary: #434c5e;
    --bg-card: #3b4252;
    --text-primary: #eceff4;
    --text-secondary: #d8dee9;
    --text-muted: #7b88a1;
    --accent-primary: #88c0d0;
    --accent-secondary: #81a1c1;
    --accent-gradient: linear-gradient(135deg, #88c0d0 0%, #5e81ac 100%);
    --accent-glow: rgba(136, 192, 208, 0.25);
    --border-color: #4c566a;
}

[data-theme="monokai"] {
    --bg-primary: #272822;
    --bg-secondary: #1e1f1a;
    --bg-tertiary: #3e3d32;
    --bg-card: #2d2e27;
    --text-primary: #f8f8f2;
    --text-secondary: #cfcfc2;
    --text-muted: #75715e;
    --accent-primary: #a6e22e;
    --accent-secondary: #e6db74;
    --accent-gradient: linear-gradient(135deg, #a6e22e 0%, #66d9ef 100%);
    --accent-glow: rgba(166, 226, 46, 0.25);
    --border-color: #49483e;
}

[data-theme="solarized"] {
    --bg-primary: #002b36;
    --bg-secondary: #073642;
    --bg-tertiary: #094552;
    --bg-card: #073642;
    --text-primary: #fdf6e3;
    --text-secondary: #93a1a1;
    --text-muted: #657b83;
    --accent-primary: #2aa198;
    --accent-secondary: #268bd2;
    --accent-gradient: linear-gradient(135deg, #2aa198 0%, #268bd2 100%);
    --accent-glow: rgba(42, 161, 152, 0.25);
    --border-color: #0a4f5c;
}

[data-theme="cyberpunk"] {
    --bg-primary: #0d0221;
    --bg-secondary: #150530;
    --bg-tertiary: #1f0a42;
    --bg-card: #190735;
    --text-primary: #00f0ff;
    --text-secondary: #ff00ff;
    --text-muted: #8844aa;
    --accent-primary: #ff00ff;
    --accent-secondary: #00f0ff;
    --accent-gradient: linear-gradient(135deg, #ff00ff 0%, #00f0ff 100%);
    --accent-glow: rgba(255, 0, 255, 0.3);
    --border-color: #3d1a6a;
}

[data-theme="coffee"] {
    --bg-primary: #1b1513;
    --bg-secondary: #2a201c;
    --bg-tertiary: #3a2c26;
    --bg-card: #2f2420;
    --text-primary: #e8dcd4;
    --text-secondary: #c4b5aa;
    --text-muted: #8a7968;
    --accent-primary: #c49a6c;
    --accent-secondary: #ddb892;
    --accent-gradient: linear-gradient(135deg, #c49a6c 0%, #8b5a2b 100%);
    --accent-glow: rgba(196, 154, 108, 0.25);
    --border-color: #4a3830;
}

[data-theme="amoled"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #141414;
    --bg-card: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent-primary: #6366f1;
    --accent-secondary: #818cf8;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --accent-glow: rgba(99, 102, 241, 0.25);
    --border-color: #222222;
}

/* NEW THEMES */

[data-theme="gruvbox"] {
    --bg-primary: #1d2021;
    --bg-secondary: #282828;
    --bg-tertiary: #3c3836;
    --bg-card: #32302f;
    --text-primary: #ebdbb2;
    --text-secondary: #d5c4a1;
    --text-muted: #928374;
    --accent-primary: #fe8019;
    --accent-secondary: #fabd2f;
    --accent-gradient: linear-gradient(135deg, #fe8019 0%, #fabd2f 100%);
    --accent-glow: rgba(254, 128, 25, 0.25);
    --border-color: #504945;
}

[data-theme="onedark"] {
    --bg-primary: #21252b;
    --bg-secondary: #282c34;
    --bg-tertiary: #2c313a;
    --bg-card: #2c313a;
    --text-primary: #abb2bf;
    --text-secondary: #9da5b4;
    --text-muted: #5c6370;
    --accent-primary: #61afef;
    --accent-secondary: #56b6c2;
    --accent-gradient: linear-gradient(135deg, #61afef 0%, #c678dd 100%);
    --accent-glow: rgba(97, 175, 239, 0.25);
    --border-color: #3e4451;
}

[data-theme="tokyonight"] {
    --bg-primary: #1a1b26;
    --bg-secondary: #16161e;
    --bg-tertiary: #24283b;
    --bg-card: #1f2335;
    --text-primary: #c0caf5;
    --text-secondary: #a9b1d6;
    --text-muted: #565f89;
    --accent-primary: #7aa2f7;
    --accent-secondary: #bb9af7;
    --accent-gradient: linear-gradient(135deg, #7aa2f7 0%, #bb9af7 100%);
    --accent-glow: rgba(122, 162, 247, 0.25);
    --border-color: #3b4261;
}

[data-theme="catppuccin"] {
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-tertiary: #313244;
    --bg-card: #24273a;
    --text-primary: #cdd6f4;
    --text-secondary: #bac2de;
    --text-muted: #6c7086;
    --accent-primary: #cba6f7;
    --accent-secondary: #f5c2e7;
    --accent-gradient: linear-gradient(135deg, #cba6f7 0%, #f5c2e7 100%);
    --accent-glow: rgba(203, 166, 247, 0.25);
    --border-color: #45475a;
}

[data-theme="palenight"] {
    --bg-primary: #292d3e;
    --bg-secondary: #242837;
    --bg-tertiary: #32374c;
    --bg-card: #2f3344;
    --text-primary: #bfc7d5;
    --text-secondary: #a6accd;
    --text-muted: #676e95;
    --accent-primary: #c792ea;
    --accent-secondary: #89ddff;
    --accent-gradient: linear-gradient(135deg, #c792ea 0%, #89ddff 100%);
    --accent-glow: rgba(199, 146, 234, 0.25);
    --border-color: #4e5579;
}

[data-theme="material"] {
    --bg-primary: #263238;
    --bg-secondary: #37474f;
    --bg-tertiary: #455a64;
    --bg-card: #2e3c43;
    --text-primary: #eceff1;
    --text-secondary: #b0bec5;
    --text-muted: #78909c;
    --accent-primary: #80cbc4;
    --accent-secondary: #a7ffeb;
    --accent-gradient: linear-gradient(135deg, #80cbc4 0%, #64ffda 100%);
    --accent-glow: rgba(128, 203, 196, 0.25);
    --border-color: #546e7a;
}

[data-theme="github"] {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-card: #1c2128;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent-primary: #58a6ff;
    --accent-secondary: #79c0ff;
    --accent-gradient: linear-gradient(135deg, #58a6ff 0%, #a371f7 100%);
    --accent-glow: rgba(88, 166, 255, 0.25);
    --border-color: #30363d;
}

[data-theme="synthwave"] {
    --bg-primary: #241b2f;
    --bg-secondary: #2a2139;
    --bg-tertiary: #34294f;
    --bg-card: #2e2544;
    --text-primary: #f0e8ff;
    --text-secondary: #e8d8ff;
    --text-muted: #9d8bba;
    --accent-primary: #ff7edb;
    --accent-secondary: #72f1b8;
    --accent-gradient: linear-gradient(135deg, #ff7edb 0%, #72f1b8 100%);
    --accent-glow: rgba(255, 126, 219, 0.3);
    --border-color: #524763;
}

[data-theme="retro"] {
    --bg-primary: #2b2b2b;
    --bg-secondary: #333333;
    --bg-tertiary: #404040;
    --bg-card: #383838;
    --text-primary: #d4be98;
    --text-secondary: #c5b18a;
    --text-muted: #928374;
    --accent-primary: #e78a4e;
    --accent-secondary: #d8a657;
    --accent-gradient: linear-gradient(135deg, #e78a4e 0%, #d8a657 100%);
    --accent-glow: rgba(231, 138, 78, 0.25);
    --border-color: #5a524c;
}

[data-theme="horizon"] {
    --bg-primary: #1c1e26;
    --bg-secondary: #232530;
    --bg-tertiary: #2e303e;
    --bg-card: #272935;
    --text-primary: #e0e0e0;
    --text-secondary: #cbced0;
    --text-muted: #6c6f93;
    --accent-primary: #e95678;
    --accent-secondary: #fab795;
    --accent-gradient: linear-gradient(135deg, #e95678 0%, #fab795 100%);
    --accent-glow: rgba(233, 86, 120, 0.25);
    --border-color: #3d4059;
}

[data-theme="aurora"] {
    --bg-primary: #0e1c21;
    --bg-secondary: #142832;
    --bg-tertiary: #1c3640;
    --bg-card: #18303a;
    --text-primary: #e6f4f1;
    --text-secondary: #b8d4cf;
    --text-muted: #6b9e95;
    --accent-primary: #82aaff;
    --accent-secondary: #c3e88d;
    --accent-gradient: linear-gradient(135deg, #82aaff 0%, #c3e88d 100%);
    --accent-glow: rgba(130, 170, 255, 0.25);
    --border-color: #2a4a55;
}

[data-theme="ice"] {
    --bg-primary: #0c1929;
    --bg-secondary: #10233d;
    --bg-tertiary: #1a3352;
    --bg-card: #142944;
    --text-primary: #e0f0ff;
    --text-secondary: #b8d4f0;
    --text-muted: #5a8cbe;
    --accent-primary: #5ccfe6;
    --accent-secondary: #bae67e;
    --accent-gradient: linear-gradient(135deg, #5ccfe6 0%, #73d0ff 100%);
    --accent-glow: rgba(92, 207, 230, 0.25);
    --border-color: #234567;
}

[data-theme="volcano"] {
    --bg-primary: #1a0f0f;
    --bg-secondary: #281414;
    --bg-tertiary: #3a1c1c;
    --bg-card: #301818;
    --text-primary: #fff0e8;
    --text-secondary: #e8c8b8;
    --text-muted: #8a6050;
    --accent-primary: #ff6b35;
    --accent-secondary: #ffc045;
    --accent-gradient: linear-gradient(135deg, #ff6b35 0%, #ff3e00 100%);
    --accent-glow: rgba(255, 107, 53, 0.3);
    --border-color: #5a2d2d;
}

[data-theme="matrix"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-tertiary: #141414;
    --bg-card: #0c0c0c;
    --text-primary: #00ff00;
    --text-secondary: #00cc00;
    --text-muted: #008800;
    --accent-primary: #00ff00;
    --accent-secondary: #00dd00;
    --accent-gradient: linear-gradient(135deg, #00ff00 0%, #00aa00 100%);
    --accent-glow: rgba(0, 255, 0, 0.3);
    --border-color: #003300;
}

[data-theme="bubblegum"] {
    --bg-primary: #1f1a2e;
    --bg-secondary: #2a2240;
    --bg-tertiary: #362c52;
    --bg-card: #302848;
    --text-primary: #ffd8f4;
    --text-secondary: #e8c0dc;
    --text-muted: #9a7a9c;
    --accent-primary: #ff77aa;
    --accent-secondary: #ffaadd;
    --accent-gradient: linear-gradient(135deg, #ff77aa 0%, #aa77ff 100%);
    --accent-glow: rgba(255, 119, 170, 0.3);
    --border-color: #4a3c6c;
}

[data-theme="mint"] {
    --bg-primary: #0e1e18;
    --bg-secondary: #152820;
    --bg-tertiary: #1e3830;
    --bg-card: #1a302a;
    --text-primary: #e0fff0;
    --text-secondary: #b8e8d0;
    --text-muted: #68a888;
    --accent-primary: #4ae3b5;
    --accent-secondary: #7ff0cd;
    --accent-gradient: linear-gradient(135deg, #4ae3b5 0%, #2dd4bf 100%);
    --accent-glow: rgba(74, 227, 181, 0.25);
    --border-color: #2a5a4a;
}

[data-theme="royal"] {
    --bg-primary: #120c1c;
    --bg-secondary: #1a1228;
    --bg-tertiary: #261a3a;
    --bg-card: #201630;
    --text-primary: #f0e8ff;
    --text-secondary: #d0c0e8;
    --text-muted: #8a70a8;
    --accent-primary: #9945ff;
    --accent-secondary: #c77dff;
    --accent-gradient: linear-gradient(135deg, #9945ff 0%, #14f195 100%);
    --accent-glow: rgba(153, 69, 255, 0.3);
    --border-color: #3a2860;
}

[data-theme="aqua"] {
    --bg-primary: #0a1a1a;
    --bg-secondary: #0f2828;
    --bg-tertiary: #153838;
    --bg-card: #123030;
    --text-primary: #e0ffff;
    --text-secondary: #b8e8e8;
    --text-muted: #5aabab;
    --accent-primary: #00d4d4;
    --accent-secondary: #40e0e0;
    --accent-gradient: linear-gradient(135deg, #00d4d4 0%, #00b4b4 100%);
    --accent-glow: rgba(0, 212, 212, 0.25);
    --border-color: #2a5858;
}

[data-theme="wine"] {
    --bg-primary: #1a0c10;
    --bg-secondary: #281218;
    --bg-tertiary: #3a1c24;
    --bg-card: #30161c;
    --text-primary: #ffe8ee;
    --text-secondary: #e8c0c8;
    --text-muted: #8a606a;
    --accent-primary: #c93b5c;
    --accent-secondary: #e85c7c;
    --accent-gradient: linear-gradient(135deg, #c93b5c 0%, #8b2848 100%);
    --accent-glow: rgba(201, 59, 92, 0.25);
    --border-color: #5a2838;
}

[data-theme="olive"] {
    --bg-primary: #161710;
    --bg-secondary: #1e2018;
    --bg-tertiary: #2a2c20;
    --bg-card: #24261c;
    --text-primary: #f0f0e0;
    --text-secondary: #c8c8b8;
    --text-muted: #8a8a70;
    --accent-primary: #a8b820;
    --accent-secondary: #c8d848;
    --accent-gradient: linear-gradient(135deg, #a8b820 0%, #88a000 100%);
    --accent-glow: rgba(168, 184, 32, 0.25);
    --border-color: #4a4c38;
}

[data-theme="coral"] {
    --bg-primary: #1a1210;
    --bg-secondary: #281c18;
    --bg-tertiary: #3a2822;
    --bg-card: #30201c;
    --text-primary: #fff0e8;
    --text-secondary: #e8d0c0;
    --text-muted: #a88070;
    --accent-primary: #ff7f50;
    --accent-secondary: #ffa07a;
    --accent-gradient: linear-gradient(135deg, #ff7f50 0%, #ff6347 100%);
    --accent-glow: rgba(255, 127, 80, 0.25);
    --border-color: #5a3830;
}

[data-theme="steel"] {
    --bg-primary: #18191f;
    --bg-secondary: #22242d;
    --bg-tertiary: #2e3140;
    --bg-card: #282b38;
    --text-primary: #e8eaf0;
    --text-secondary: #b0b8c8;
    --text-muted: #6a7488;
    --accent-primary: #4f8fba;
    --accent-secondary: #7ab0d3;
    --accent-gradient: linear-gradient(135deg, #4f8fba 0%, #3a6d91 100%);
    --accent-glow: rgba(79, 143, 186, 0.25);
    --border-color: #3a4050;
}

[data-theme="candy"] {
    --bg-primary: #1a1520;
    --bg-secondary: #261e2e;
    --bg-tertiary: #34283e;
    --bg-card: #2c2236;
    --text-primary: #ffe8f8;
    --text-secondary: #e8c8e0;
    --text-muted: #9a7890;
    --accent-primary: #ff69b4;
    --accent-secondary: #ff99cc;
    --accent-gradient: linear-gradient(135deg, #ff69b4 0%, #ff1493 100%);
    --accent-glow: rgba(255, 105, 180, 0.3);
    --border-color: #4a3858;
}

[data-theme="earth"] {
    --bg-primary: #1a1612;
    --bg-secondary: #28221c;
    --bg-tertiary: #3a3028;
    --bg-card: #302820;
    --text-primary: #f0e8d8;
    --text-secondary: #d0c0a8;
    --text-muted: #8a7860;
    --accent-primary: #8b7355;
    --accent-secondary: #a89070;
    --accent-gradient: linear-gradient(135deg, #8b7355 0%, #6b5240 100%);
    --accent-glow: rgba(139, 115, 85, 0.25);
    --border-color: #4a4030;
}

[data-theme="arctic"] {
    --bg-primary: #1a2030;
    --bg-secondary: #242d40;
    --bg-tertiary: #303d55;
    --bg-card: #2a3548;
    --text-primary: #e8f0ff;
    --text-secondary: #c0d0e8;
    --text-muted: #6888a8;
    --accent-primary: #a8d8ff;
    --accent-secondary: #c8e8ff;
    --accent-gradient: linear-gradient(135deg, #a8d8ff 0%, #88c0ff 100%);
    --accent-glow: rgba(168, 216, 255, 0.25);
    --border-color: #3a4860;
}

[data-theme="sunset-beach"] {
    --bg-primary: #1c1412;
    --bg-secondary: #2a1e1a;
    --bg-tertiary: #3a2a24;
    --bg-card: #32241e;
    --text-primary: #fff0e0;
    --text-secondary: #e8d0b8;
    --text-muted: #a88868;
    --accent-primary: #ffaa55;
    --accent-secondary: #ffcc88;
    --accent-gradient: linear-gradient(135deg, #ffaa55 0%, #ff7744 100%);
    --accent-glow: rgba(255, 170, 85, 0.3);
    --border-color: #5a4030;
}

[data-theme="solarized-light"] {
    --bg-primary: #fdf6e3;
    --bg-secondary: #eee8d5;
    --bg-tertiary: #d9d2bf;
    --bg-card: #fdf6e3;
    --text-primary: #073642;
    --text-secondary: #586e75;
    --text-muted: #93a1a1;
    --accent-primary: #268bd2;
    --accent-secondary: #2aa198;
    --accent-gradient: linear-gradient(135deg, #268bd2 0%, #2aa198 100%);
    --accent-glow: rgba(38, 139, 210, 0.2);
    --border-color: #cdc5b0;
}

[data-theme="gruvbox-light"] {
    --bg-primary: #fbf1c7;
    --bg-secondary: #f2e5bc;
    --bg-tertiary: #e0d5ae;
    --bg-card: #fbf1c7;
    --text-primary: #3c3836;
    --text-secondary: #504945;
    --text-muted: #928374;
    --accent-primary: #d65d0e;
    --accent-secondary: #af3a03;
    --accent-gradient: linear-gradient(135deg, #d65d0e 0%, #b57614 100%);
    --accent-glow: rgba(214, 93, 14, 0.2);
    --border-color: #d5c4a1;
}

[data-theme="paper"] {
    --bg-primary: #f8f5f0;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e4de;
    --bg-card: #ffffff;
    --text-primary: #2d2d2d;
    --text-secondary: #5a5a5a;
    --text-muted: #8a8a8a;
    --accent-primary: #0077cc;
    --accent-secondary: #0099ff;
    --accent-gradient: linear-gradient(135deg, #0077cc 0%, #0055aa 100%);
    --accent-glow: rgba(0, 119, 204, 0.15);
    --border-color: #d0ccc4;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    font-weight: 400;
    letter-spacing: -0.01em;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cube-icon {
    width: 36px;
    height: 36px;
    background: #000000;
    border-radius: 4px;
    position: relative;
    transform: rotate(-10deg);
    box-shadow: var(--shadow-md);
    padding: 2px;
}

.cube-face {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
}

.sticker {
    border-radius: 1px;
}

.s-white { background: #ffffff; }
.s-yellow { background: #fbbf24; }
.s-red { background: #ef4444; }
.s-orange { background: #f97316; }
.s-blue { background: #3b82f6; }
.s-green { background: #22c55e; }

.logo-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-primary);
    transform: scale(1.1, 0.9);
    transform-origin: left center;
}

.logo-pro {
    font-weight: 800;
    background: linear-gradient(to right, #ef4444, #f97316, #fbbf24, #22c55e, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Global Select Styling */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0a0a0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 14px;
    padding-right: 28px !important;
}

/* Dropdown Options Styling */
select option {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 10px 12px;
    font-size: 0.9rem;
}

select option:hover,
select option:checked {
    background-color: var(--accent-primary) !important;
    color: white !important;
}

.puzzle-select,
.session-select,
.setting-group select,
.modal-select {
    height: 38px;
    padding: 0 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    outline: none;
}

.puzzle-select:hover,
.session-select:hover,
.setting-group select:hover,
.modal-select:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-card);
}

.puzzle-select:focus,
.session-select:focus,
.setting-group select:focus,
.modal-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow, rgba(99, 102, 241, 0.2));
}

/* Specific adjustments */
.modal-select {
    height: 32px;
    font-size: 0.8rem;
    background-color: var(--bg-secondary);
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn.small {
    width: 32px;
    height: 32px;
}

.icon-btn.small svg {
    width: 16px;
    height: 16px;
}

/* Main Grid Layout */
.main-grid {
    display: grid;
    grid-template-columns: 280px minmax(400px, 1fr) 260px;
    grid-template-rows: 1fr;
    grid-template-areas: "left center right";
    gap: 16px;
    padding: 16px;
    flex: 1;
    overflow-y: auto; /* Allow scrolling if content doesn't fit vertically */
    overflow-x: hidden;
    min-height: 0;
    width: 100%;
    max-width: 1800px; /* Prevent excessive stretching on ultrawide */
    margin: 0 auto;
}

.left-column { grid-area: left; }
.center-column { grid-area: center; }
.right-column { grid-area: right; }

.left-column,
.center-column,
.right-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0; /* Allow shrinking but... */
}

/* Prevent squishing by setting minimum heights for panels */
.times-panel {
    min-height: 200px; /* Ensure list is always usable */
}

.graph-panel {
    min-height: 200px;
    flex-shrink: 0;
}

.timer-panel {
    min-height: 250px;
}

/* Responsive Layouts */

/* Height-based query: If screen is short, switch to scrolling layout */
@media (max-height: 700px) {
    .main-grid {
        overflow-y: auto;
    }
    
    .left-column,
    .center-column,
    .right-column {
        overflow: visible; /* Let content expand */
        flex: 0 0 auto; /* Don't force fit */
    }
}

/* Narrow Desktop / Tablet Landscape (< 1100px) */
@media (max-width: 1100px) {
    .main-grid {
        grid-template-columns: 1fr 300px;
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "center right"
            "left right";
        max-width: 1000px;
    }
    
    .left-column {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .left-column > section {
        flex: 1;
        min-width: 250px;
    }
}

/* Tablet Portrait (< 850px) */
@media (max-width: 850px) {
    .main-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "center"
            "left"
            "right";
        padding: 12px;
    }

    .left-column,
    .center-column,
    .right-column {
        overflow: visible;
        min-height: auto;
        flex: 0 0 auto;
    }
    
    .left-column {
        flex-direction: column;
    }
    
    /* Limit height of history list in vertical layout */
    .times-list {
        min-height: 300px;
        max-height: 500px;
    }
}

/* Mobile (< 600px) */
@media (max-width: 600px) {
    .main-grid {
        padding: 8px;
        gap: 16px;
    }
    
    .header {
        padding: 8px 16px;
    }
    
    .logo-text {
        font-size: 1.2rem;
    }
    
    .nav-controls {
        gap: 8px;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
    }
}

/* Panel Base Styles */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 40px;
    overflow: hidden; /* Prevent overflow */
    gap: 12px;
    flex-wrap: nowrap; /* Force single line */
}

.panel-header h3 {
    font-size: 0.8rem;
    font-weight: 700; /* Made bolder */
    text-transform: uppercase;
    letter-spacing: 1px; /* Increased spacing */
    color: var(--text-secondary);
    flex-shrink: 0;
    white-space: nowrap;
    margin: 0;
}

.panel-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto; /* Push to right */
}

.panel-body {
    padding: 10px;
    flex: 1;
    overflow: auto;
}

/* Scramble & Preview Container */
.scramble-preview-container {
    display: flex;
    gap: 12px;
    min-height: 260px;
    max-height: 260px; /* Adjusted height */
}

/* Scramble Panel */
.scramble-panel {
    flex: 2; /* Give scramble ~60% width */
    min-width: 0;
}

.scramble-panel .panel-body {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Custom Scrollbar for Scramble Panel */
.scramble-panel .panel-body::-webkit-scrollbar {
    width: 6px;
}

.scramble-panel .panel-body::-webkit-scrollbar-track {
    background: transparent;
}

.scramble-panel .panel-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.scramble-panel .panel-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.scramble-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem; /* Reduced font size */
    font-weight: 500;
    line-height: 1.4;
    color: var(--text-primary);
    word-spacing: 2px; /* Reduced word spacing */
    letter-spacing: 0.5px;
    text-align: center; /* Ensure centered text */
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    min-width: 0;
}

.preview-panel.hidden {
    display: none;
}

.preview-body {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    overflow: hidden;
    height: 100%;
}

#cubeCanvas {
    image-rendering: crisp-edges;
    width: 100%;
    height: 100%;
    display: block;
}

/* Records Panel */
.records-panel {
    flex: 0 0 auto;
    margin-top: auto;
    display: flex;
    flex-direction: column;
    height: 260px;
}

.records-panel .panel-body {
    padding: 12px;
    overflow: hidden;
}

.records-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
    height: 100%;
}

.record-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 8px 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    text-align: center;
}

.record-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.record-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.record-value.best {
    color: var(--success);
}

/* Timer Panel */
.timer-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.timer-container {
    text-align: center;
    cursor: pointer;
    user-select: none;
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.timer {
    font-family: 'JetBrains Mono', monospace;
    font-size: clamp(4rem, 12vw, 8rem);
    font-weight: 700;
    letter-spacing: -4px;
    line-height: 1;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

[data-timer-size="small"] .timer {
    font-size: clamp(3rem, 8vw, 5rem);
}

[data-timer-size="large"] .timer {
    font-size: clamp(5rem, 15vw, 11rem);
}

[data-timer-size="xlarge"] .timer {
    font-size: clamp(6rem, 20vw, 14rem);
}

[data-timer-font="roboto"] .timer {
    font-family: 'Roboto Mono', monospace;
}

[data-timer-font="fira"] .timer {
    font-family: 'Fira Code', monospace;
}

[data-timer-font="source"] .timer {
    font-family: 'Source Code Pro', monospace;
}

[data-timer-font="inter"] .timer {
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
}

[data-timer-font="jetbrains"] .timer {
    font-family: 'JetBrains Mono', monospace;
}

.timer.ready {
    color: var(--success);
}

.timer.holding {
    color: var(--danger);
}

.timer.running {
    color: var(--text-primary);
}

.timer.inspection {
    color: #fde047; /* Yellow-300 */
}

.timer.inspection.phase-warning {
    color: var(--warning);
}

.timer.inspection.phase-danger {
    color: var(--danger);
}

.timer-state {
    margin-top: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.timer-hint {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.quick-stats {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.quick-stats.visible {
    opacity: 1;
}

.quick-stat-item {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
}

.timer-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.control-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    min-width: 60px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.control-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.control-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.control-btn.active {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.control-btn.ok-btn:not(:disabled) {
    background: var(--success);
    border-color: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.control-btn.ok-btn:not(:disabled):hover {
    background: #1db954;
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.control-btn svg {
    width: 18px;
    height: 18px;
}

/* Light theme specific improvements */
[data-theme="light"] .timer-controls {
    background: #fafafa;
    border-top-color: #ddd;
}

[data-theme="light"] .control-btn {
    background: #ffffff;
    border-color: #d0d0d0;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .control-btn:hover:not(:disabled) {
    background: #f0f0f0;
    border-color: var(--accent-primary);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Stats Panel */
.stats-panel {
    flex: 0 0 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    height: auto;
}

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 8px 6px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    text-align: center;
    transition: var(--transition);
    border: 1px solid transparent;
}

.stat-card:hover {
    border-color: var(--border-color);
}

.stat-card.highlight {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--success);
}

.stat-card.clickable {
    cursor: pointer;
}

.stat-card.clickable:hover {
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.stat-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-value.best {
    color: var(--success);
}

/* Times Panel */
.times-panel {
    flex: 1;
    min-height: 0;
}

.times-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.times-list::-webkit-scrollbar {
    width: 5px;
}

.times-list::-webkit-scrollbar-track {
    background: transparent;
}

.times-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.times-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    text-align: center;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 2px;
}

.empty-state span {
    font-size: 0.75rem;
}

.time-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 4px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid transparent; /* Hidden border to prevent layout shift on hover */
    cursor: pointer;
    transition: var(--transition);
}

.time-item:hover {
    border-color: var(--accent-primary);
}

.time-item.best {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.time-number {
    width: 36px; /* Increased width for spacing */
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 8px; /* Added margin */
}

.time-value {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
}

.time-value.dnf {
    color: var(--danger);
}

.time-value.plus2 {
    color: var(--warning);
}

.time-ao5 {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 8px;
}

.time-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: var(--transition);
}

.time-item:hover .time-actions {
    opacity: 1;
}

.time-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.time-action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.time-action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.time-action-btn svg {
    width: 12px;
    height: 12px;
}

/* Graph Panel */
.graph-panel {
    flex-shrink: 0;
    height: 260px;
    overflow: hidden;
}

.graph-body {
    display: flex;
    flex-direction: column;
    padding: 8px;
    height: calc(100% - 48px);
    position: relative;
    overflow: hidden;
}

.graph-options-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-5px);
    transition: var(--transition);
    min-width: 160px;
}

.graph-options-overlay.active {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.graph-options-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.graph-options-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.graph-mode-buttons {
    display: flex;
    gap: 4px;
}

.mode-btn {
    flex: 1;
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.mode-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.mode-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.graph-options-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.graph-option-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 0;
}

.graph-option-item:hover {
    color: var(--text-primary);
}

.graph-option-item input {
    accent-color: var(--accent-primary);
    width: 14px;
    height: 14px;
}

#graphCanvas {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: var(--radius-sm);
    cursor: crosshair;
}

.graph-stats {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.graph-stat {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2000; /* Ensure it's above bottom nav (z-index: 1000) */
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.modal-content.modal-small {
    max-width: 380px;
}

.modal-content.modal-settings {
    max-width: 900px;
    width: 95%;
    max-height: 85vh;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-settings .modal-header {
    padding: 24px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.modal-settings .modal-header h2 {
    font-size: 1.5rem;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-settings .modal-body {
    padding: 32px;
    background: var(--bg-primary);
}

.modal-settings .settings-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    background: transparent;
    padding: 0;
    border: none;
    margin-bottom: 40px;
    justify-content: center;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.modal-settings .settings-section h4 {
    grid-column: 1 / -1;
    margin-bottom: 16px;
    padding-bottom: 0;
    font-size: 1.1rem;
    border-bottom: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
}

.modal-settings .settings-section h4::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
    opacity: 0.5;
}

.modal-settings .setting-group {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 0;
}

.modal-settings .setting-group:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.modal-settings .setting-group > label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-settings .setting-group select,
.modal-settings .setting-group input[type="number"],
.modal-settings .setting-group input[type="text"] {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: var(--text-primary);
    width: 100%;
    transition: all 0.2s ease;
    height: 42px;
}

.modal-settings .setting-group select:hover,
.modal-settings .setting-group input:hover {
    border-color: var(--text-muted);
}

.modal-settings .setting-group select:focus,
.modal-settings .setting-group input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
    background: var(--bg-primary);
}

.modal-settings .checkbox-label {
    flex-direction: row-reverse;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    padding: 4px 0;
}

.modal-settings .checkbox-label span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.modal-settings .checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent-primary);
}

/* Light theme settings modal improvements */
[data-theme="light"] .modal-settings .modal-content,
[data-theme="light"] .modal-content.modal-settings {
    background: #f8f8f8;
}

[data-theme="light"] .modal-settings .modal-header {
    background: #ffffff;
    border-bottom-color: #e8e8e8;
}

[data-theme="light"] .modal-settings .modal-body {
    background: #f8f8f8;
}

[data-theme="light"] .modal-settings .setting-group {
    background: #ffffff;
    border-color: #e5e5e5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .modal-settings .setting-group:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .modal-settings .setting-group select,
[data-theme="light"] .modal-settings .setting-group input[type="number"],
[data-theme="light"] .modal-settings .setting-group input[type="text"] {
    background: #f5f5f5;
    border-color: #ddd;
    color: #333;
}

[data-theme="light"] .modal-settings .setting-group select:focus,
[data-theme="light"] .modal-settings .setting-group input:focus {
    background: #ffffff;
    border-color: var(--accent-primary);
}

@media (max-width: 768px) {
    .modal-settings .settings-section {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 16px;
        max-width: none;
        width: 100%;
        padding: 0 16px;
        box-sizing: border-box;
    }
    
    .modal-settings .settings-section h4 {
        text-align: center;
        justify-content: center;
        width: 100%;
        max-width: 340px;
    }
    
    .modal-settings .settings-section h4::after {
        display: none;
    }
    
    .modal-settings .modal-header {
        padding: 20px 24px;
        justify-content: center;
        position: relative;
    }
    
    .modal-settings .modal-header h2 {
        text-align: center;
        font-size: 1.3rem;
    }
    
    .modal-settings .modal-header .close-btn {
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .modal-settings .modal-body {
        padding: 24px 8px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    
    .modal-settings .setting-group {
        width: 100%;
        max-width: 340px;
        margin: 0 auto;
        padding: 16px 20px;
        border-radius: 16px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }
    
    .modal-settings .setting-group:hover {
        transform: none;
    }
    
    .modal-settings .setting-group > label {
        font-size: 0.75rem;
        letter-spacing: 0.8px;
    }
    
    .modal-settings .setting-group select,
    .modal-settings .setting-group input[type="number"],
    .modal-settings .setting-group input[type="text"] {
        height: 48px;
        font-size: 1rem;
        border-radius: 12px;
    }
    
    .modal-settings .checkbox-label {
        padding: 8px 0;
    }
    
    .modal-settings .checkbox-label span {
        font-size: 0.95rem;
    }
}

.modal.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* Fix for flexbox scrolling */
}

/* Custom Scrollbar for Modal Body */
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.scramble-detail-content {
    width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* Settings */
.settings-section {
    margin-bottom: 20px;
}

.settings-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-primary);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.setting-group {
    margin-bottom: 14px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group > label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.setting-group select,
.setting-group input[type="number"],
.setting-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.setting-group select:focus,
.setting-group input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.setting-group input[type="color"] {
    width: 100%;
    height: 42px;
    padding: 4px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.setting-group input[type="color"]:hover {
    border-color: var(--accent-primary);
}

.setting-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.setting-group input[type="color"]::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.checkbox-label span {
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Keybind Settings */
.keybinds-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.keybind-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.keybind-row:hover {
    background: var(--bg-secondary);
}

.keybind-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.keybind-key-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0;
    cursor: pointer;
    transition: var(--transition);
    min-width: 80px;
}

.keybind-key-btn:hover:not(.disabled) {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.keybind-key-btn:focus {
    outline: none;
    border-color: var(--warning);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
}

.keybind-key-btn.recording {
    border-color: var(--warning);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3);
    animation: pulse-keybind 1s infinite;
}

.keybind-key-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.keybind-key-btn kbd {
    display: block;
    padding: 6px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    background: transparent;
    border: none;
    text-transform: capitalize;
}

@keyframes pulse-keybind {
    0%, 100% { box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.5); }
}

/* Keybind Help Modal */
.keybind-help-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.keybind-help-section h4 {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.keybind-help-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.keybind-help-row:last-child {
    border-bottom: none;
}

.keybind-help-row kbd {
    min-width: 70px;
    padding: 6px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    text-align: center;
    box-shadow: 0 2px 0 var(--border-color);
}

.keybind-help-row span {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.keybind-help-hint {
    margin-top: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.action-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.action-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.action-btn.primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.action-btn.danger {
    color: var(--danger);
}

.action-btn.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

/* Time Detail Modal */
.time-detail-content {
    text-align: center;
}

.time-detail-content .detail-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.time-detail-content .detail-time.dnf {
    color: var(--danger);
}

.time-detail-content .detail-scramble {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    word-spacing: 2px;
    text-align: left;
}

.time-detail-content .detail-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    text-align: left;
}

.time-detail-content .detail-info div {
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

.time-detail-content .detail-info label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.time-detail-content .detail-info span {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.detail-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.detail-actions button {
    padding: 8px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.detail-actions button:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.detail-actions button.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* Averages Modal */
.averages-content {
    text-align: center;
}

.averages-content .avg-header {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--accent-primary);
}

.averages-content .avg-times {
    text-align: left;
    max-height: 300px;
    overflow-y: auto;
}

.averages-content .avg-time-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.averages-content .avg-time-item.best {
    color: var(--success);
}

.averages-content .avg-time-item.worst {
    color: var(--danger);
}

.averages-content .avg-time-item.excluded {
    opacity: 0.5;
    text-decoration: line-through;
}

/* Stats Dashboard */
.modal-content.modal-large {
    max-width: 800px;
    height: 80vh;
}

.stats-dashboard {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.stats-overview {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}

.stat-box {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-box label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-box span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
}

.stats-charts {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chart-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.chart-header-row h4 {
    margin: 0;
    font-size: 1rem;
}

.chart-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.control-group.toggles {
    display: flex;
    gap: 8px;
}

.toggle-pill {
    position: relative;
    cursor: pointer;
}

.toggle-pill input {
    display: none;
}

.toggle-pill span {
    display: block;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: var(--transition);
    user-select: none;
}

.toggle-pill input:checked + span {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.canvas-wrapper {
    height: 300px;
    width: 100%;
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    padding: 12px;
}

#modalGraphCanvas {
    width: 100%;
    height: 100%;
}

.modal-graph-footer {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.stat-pill .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.stat-pill .value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-container h4,
.stats-tables h4 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

#distCanvas {
    width: 100%;
    height: 250px;
    display: block;
}

.stats-tables {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th {
    text-align: left;
    padding: 12px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    font-family: 'JetBrains Mono', monospace;
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Responsive Design */

/* Assign Grid Areas */
.scramble-panel { grid-area: scramble; }
.preview-panel { grid-area: preview; }
.records-panel { grid-area: records; }
.timer-panel { grid-area: timer; }
.stats-panel { grid-area: stats; }
.times-panel { grid-area: times; }
.graph-panel { grid-area: graph; }

/* Tablet & Small Desktop (max-width: 1024px) */
@media (max-width: 1024px) {
    .main-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto;
        grid-template-areas: 
            "scramble scramble"
            "timer timer"
            "stats times"
            "records graph"
            "preview preview";
        gap: 12px;
        overflow-y: auto;
        padding-bottom: 32px;
    }

    /* Flatten columns */
    .left-column, .center-column, .right-column {
        display: contents;
    }

    /* Reset fixed heights for flow layout */
    .records-panel, .stats-panel, .graph-panel {
        height: auto;
        min-height: 180px;
    }

    .times-panel {
        height: 300px; /* Give it a fixed height to scroll internally */
    }

    .timer-panel {
        min-height: 300px;
    }
    
    .preview-panel {
        justify-self: center;
        width: 100%;
        max-width: 400px;
    }
}

/* Mobile Portrait (max-width: 768px) */
@media (max-width: 768px) {
    .main-grid {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "scramble"
            "timer"
            "stats"
            "times"
            "records"
            "graph"
            "preview";
    }

    .timer {
        font-size: clamp(4rem, 15vw, 6rem);
    }
    
    .scramble-text {
        font-size: 1.1rem;
        text-align: center;
    }

    .panel-header h3 {
        font-size: 0.8rem;
    }
    
    /* Adjust header for mobile */
    .header {
        padding: 8px 12px;
    }
    
    .logo h1 {
        font-size: 1.2rem;
    }
    
    .nav-controls {
        gap: 8px;
    }
    
    .session-select {
        width: 100px;
        min-width: 0;
    }
    
    .puzzle-select {
        width: 80px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile Landscape (max-height: 600px) */
@media (max-height: 600px) and (orientation: landscape) {
    .app-container {
        height: 100vh;
        overflow: hidden;
    }

    .header {
        padding: 4px 12px;
        min-height: 40px;
    }
    
    .logo h1 {
        font-size: 1rem;
    }
    
    .cube-icon {
        width: 24px;
        height: 24px;
    }

    .main-grid {
        grid-template-columns: 1fr 300px;
        grid-template-rows: auto 1fr;
        grid-template-areas: 
            "timer scramble"
            "timer stats";
        overflow: hidden;
        padding-bottom: 0;
    }

    .timer-panel {
        height: 100%;
        min-height: 0;
    }
    
    .timer {
        font-size: clamp(4rem, 20vh, 8rem);
    }

    /* Hide non-essentials in landscape focus mode */
    .preview-panel, 
    .records-panel, 
    .graph-panel, 
    .times-panel {
        display: none;
    }
    
    .scramble-panel {
        max-height: 80px;
        overflow-y: auto;
    }
    
    .stats-panel {
        flex: 1;
        height: auto;
        min-height: 0;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        overflow-y: auto;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.timer.running {
    animation: pulse 1s ease-in-out infinite;
}

/* Touch optimizations */
@media (hover: none) {
    .time-actions {
        opacity: 1;
    }
}

/* New PB indicator */
@keyframes newPB {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.new-pb {
    animation: newPB 0.5s ease-in-out;
    color: var(--success) !important;
}

/* Confetti Canvas */
#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* Compact Mode */
[data-compact="true"] .left-column {
    display: none !important;
}

[data-compact="true"] .right-column {
    display: none !important;
}

[data-compact="true"] .main-grid {
    grid-template-columns: 1fr !important;
}

[data-compact="true"] .scramble-preview-container {
    display: none !important;
}

[data-compact="true"] .timer-panel {
    height: auto;
}

[data-compact="true"] .stats-panel {
    display: none;
}

[data-compact="true"] .header {
    padding: 8px 16px;
}

[data-compact="true"] .timer {
    font-size: clamp(6rem, 25vw, 16rem);
}

/* Compact mode scramble display */
[data-compact="true"] .center-column {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

[data-compact="true"] .center-column::before {
    content: attr(data-scramble);
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.6;
    color: var(--text-primary);
    text-align: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    word-spacing: 2px;
}

#compactModeBtn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

/* Custom Theme Maker Styles */
.modal-wide {
    max-width: 900px;
}

.theme-maker-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
}

.theme-maker-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.theme-name-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.theme-name-input,
.copy-theme-input {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.theme-name-input label,
.copy-theme-input label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.theme-name-input input,
.copy-theme-input select {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
}

.theme-name-input input:focus,
.copy-theme-input select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.color-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.color-picker-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.color-picker-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.color-picker-group input[type="color"] {
    width: 100%;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
    background: var(--bg-tertiary);
}

.color-picker-group input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 2px;
}

.color-picker-group input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.color-picker-group .color-desc {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.theme-maker-actions {
    display: flex;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.theme-maker-actions .action-btn {
    flex: 1;
}

.saved-themes-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.custom-themes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.custom-theme-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.custom-theme-item .theme-colors {
    display: flex;
    gap: 3px;
}

.custom-theme-item .theme-color-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
}

.custom-theme-item .theme-name {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.custom-theme-item .theme-actions {
    display: flex;
    gap: 6px;
}

.custom-theme-item .theme-action-btn {
    padding: 4px 8px;
    font-size: 0.7rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.custom-theme-item .theme-action-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.custom-theme-item .theme-action-btn.delete:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.custom-themes-list .empty-message {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 16px;
}

/* Theme Preview Panel */
.theme-preview-panel h4 {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.theme-preview-box {
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.theme-preview-box .preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.theme-preview-box .preview-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.theme-preview-box .preview-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
}

.theme-preview-box .preview-timer {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.5rem;
    font-weight: 600;
    text-align: center;
    padding: 16px 0;
}

.theme-preview-box .preview-scramble {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    text-align: center;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.theme-preview-box .preview-card {
    display: flex;
    gap: 10px;
}

.theme-preview-box .preview-stat {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.theme-preview-box .preview-stat .label {
    display: block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.theme-preview-box .preview-stat .value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
}

.theme-preview-box .preview-times {
    display: flex;
    gap: 6px;
}

.theme-preview-box .preview-time {
    flex: 1;
    padding: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    text-align: center;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
}

.theme-preview-box .preview-time.best {
    font-weight: 600;
}

.theme-preview-box .preview-action-btn {
    padding: 10px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
}

/* Theme preview responsiveness */
@media (max-width: 768px) {
    .theme-maker-layout {
        grid-template-columns: 1fr;
    }
    
    .theme-name-row {
        grid-template-columns: 1fr;
    }
    
    .color-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .theme-preview-panel {
        order: -1;
    }
}

/* Streak Tracker Styles */
.stat-box.streak-box {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent-primary) 12%, transparent), color-mix(in srgb, var(--accent-secondary) 6%, transparent));
    border: 1px solid color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.streak-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.streak-settings input {
    width: 70px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.streak-settings input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* PB Timeline Section */
.pb-timeline-section {
    margin-top: 20px;
}

.pb-timeline-section h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.pb-timeline-section .canvas-wrapper {
    height: 180px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
}

/* Calendar Heatmap Section */
.calendar-heatmap-section {
    margin-top: 20px;
}

.calendar-heatmap-section h4 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-bottom: 10px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.legend-scale {
    display: flex;
    gap: 3px;
}

.legend-box {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-box.level-0 { background: var(--bg-tertiary); }
.legend-box.level-1 { background: color-mix(in srgb, var(--accent-primary) 25%, transparent); }
.legend-box.level-2 { background: color-mix(in srgb, var(--accent-primary) 50%, transparent); }
.legend-box.level-3 { background: color-mix(in srgb, var(--accent-primary) 75%, transparent); }
.legend-box.level-4 { background: var(--accent-primary); }

.calendar-heatmap {
    position: relative;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.heatmap-day-labels {
    position: absolute;
    left: 12px;
    top: 28px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.heatmap-day-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-align: right;
    height: 12px;
    line-height: 12px;
    width: 20px;
}

.heatmap-month-labels {
    position: relative;
    height: 16px;
    margin-left: 25px;
    margin-bottom: 4px;
}

.heatmap-month-label {
    position: absolute;
    font-size: 0.6rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.heatmap-weeks {
    display: flex;
    gap: 3px;
    margin-left: 25px;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.heatmap-cell {
    width: 11px;
    height: 11px;
    border-radius: 2px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.heatmap-cell:hover {
    outline: 2px solid var(--accent-primary);
    outline-offset: 1px;
}

.heatmap-cell.level-0 { background: var(--bg-secondary); }
.heatmap-cell.level-1 { background: color-mix(in srgb, var(--accent-primary) 25%, transparent); }
.heatmap-cell.level-2 { background: color-mix(in srgb, var(--accent-primary) 50%, transparent); }
.heatmap-cell.level-3 { background: color-mix(in srgb, var(--accent-primary) 75%, transparent); }
.heatmap-cell.level-4 { background: var(--accent-primary); }

.heatmap-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
    font-size: 0.9rem;
}

.heatmap-stats {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.heatmap-stats span {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
}

/* ================================
   Side Menu Styles
   ================================ */
.side-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 998;
}

.side-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.side-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    z-index: 999;
    display: flex;
    flex-direction: column;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.side-menu.open {
    left: 0;
}

.side-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.side-menu-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.side-menu-content {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.side-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.side-menu-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.side-menu-item.active {
    background: var(--accent-primary);
    color: white;
}

.side-menu-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.side-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 12px 0;
}

.side-menu-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.app-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.menu-btn {
    display: flex;
}

/* ================================
   Page Container Styles
   ================================ */
.page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: var(--bg-primary);
    z-index: 500;
    overflow-y: auto;
    overflow-x: hidden;
}

.page.hidden {
    display: none;
}

.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

.page-header h2 {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-content {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ================================
   Bento Grid Statistics
   ================================ */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

@media (max-width: 1000px) {
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }
}

/* Base Bento Card */
.bento-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.bento-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: color-mix(in srgb, var(--accent-primary) 50%, var(--border-color));
}

/* Card Size Variants - Clean rectangular layout */
.bento-card.bento-stat {
    grid-column: span 1;
}

.bento-card.bento-half {
    grid-column: span 2;
}

.bento-card.bento-three {
    grid-column: span 3;
}

.bento-card.bento-one {
    grid-column: span 1;
}

.bento-card.bento-full {
    grid-column: span 4;
}

@media (max-width: 1000px) {
    .bento-card.bento-stat {
        grid-column: span 1;
    }
    .bento-card.bento-half {
        grid-column: span 2;
    }
    .bento-card.bento-three {
        grid-column: span 2;
    }
    .bento-card.bento-one {
        grid-column: span 2;
    }
    .bento-card.bento-full {
        grid-column: span 2;
    }
}

@media (max-width: 500px) {
    .bento-card.bento-stat,
    .bento-card.bento-half,
    .bento-card.bento-three,
    .bento-card.bento-one,
    .bento-card.bento-full {
        grid-column: span 1;
    }
}

/* Accent Colors */
.bento-card[data-accent="purple"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #8b5cf6 15%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}
.bento-card[data-accent="purple"] .bento-icon {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

.bento-card[data-accent="gold"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #fbbf24 12%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}
.bento-card[data-accent="gold"] .bento-icon {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.bento-card[data-accent="orange"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #f97316 12%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}
.bento-card[data-accent="orange"] .bento-icon {
    background: linear-gradient(135deg, #f97316, #ef4444);
}

.bento-card[data-accent="green"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #22c55e 12%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}
.bento-card[data-accent="green"] .bento-icon {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.bento-card[data-accent="blue"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #3b82f6 10%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}

.bento-card[data-accent="red"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #ef4444 10%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}

.bento-card[data-accent="cyan"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, #06b6d4 10%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}

.bento-card[data-accent="primary"] {
    background: linear-gradient(145deg, 
        color-mix(in srgb, var(--accent-primary) 12%, var(--bg-secondary)) 0%,
        var(--bg-secondary) 60%);
}
.bento-card[data-accent="primary"] .bento-icon {
    background: var(--accent-gradient);
}

/* Stat Card Content */
.bento-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.bento-icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.bento-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.bento-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Card Header */
.bento-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 10px;
}

.bento-card-header h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Averages Layout */
.bento-averages {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    flex: 1;
}

@media (max-width: 700px) {
    .bento-averages {
        grid-template-columns: repeat(2, 1fr);
    }
}

.avg-block {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.avg-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.avg-current {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.avg-best {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--success);
    padding: 4px 8px;
    background: color-mix(in srgb, var(--success) 15%, transparent);
    border-radius: var(--radius-sm);
}

/* Streak Row */
.streak-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    flex: 1;
}

.streak-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-top: 3px solid var(--accent-primary);
}

.streak-item.current {
    border-top-color: var(--accent-primary);
}

.streak-item.best {
    border-top-color: #fbbf24;
}

.streak-item.days {
    border-top-color: #22c55e;
}

.streak-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}

.streak-item.current .streak-num {
    color: var(--accent-primary);
}

.streak-item.best .streak-num {
    color: #fbbf24;
}

.streak-item.days .streak-num {
    color: #22c55e;
}

.streak-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.streak-config {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.streak-config input {
    width: 42px;
    padding: 3px 5px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    text-align: center;
}

/* Chart Container */
.bento-chart {
    flex: 1;
    min-height: 0;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
}

.bento-chart canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 180px;
}

.bento-card.bento-three .bento-chart canvas {
    min-height: 200px;
}

/* Period Selector */
.chart-period-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 3px;
    border-radius: var(--radius-sm);
}

.period-btn {
    padding: 4px 8px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.period-btn:hover {
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent-primary);
    color: white;
}

/* Calendar Heatmap in Bento */
.bento-card .calendar-heatmap {
    flex: 1;
    overflow-x: auto;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    color: var(--text-muted);
}

.legend-scale {
    display: flex;
    gap: 2px;
}

.legend-box {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

/* PB Journey */
.pb-journey {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 16px;
    flex: 1;
    min-height: 240px;
}

@media (max-width: 800px) {
    .pb-journey {
        grid-template-columns: 1fr;
    }
    .pb-milestones {
        max-height: 150px;
    }
}

.pb-chart-container {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
    min-height: 220px;
}

.pb-chart-container canvas {
    width: 100% !important;
    height: 200px !important;
}

.pb-milestones {
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    padding: 12px;
    max-height: 240px;
    overflow-y: auto;
}

.pb-milestone {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.pb-milestone:last-child {
    border-bottom: none;
}

.pb-milestone-rank {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.pb-milestone-rank.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.pb-milestone-info {
    flex: 1;
    min-width: 0;
}

.pb-milestone-time {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.pb-milestone-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.pb-milestone-improvement {
    font-size: 0.7rem;
    color: #22c55e;
    font-weight: 500;
}

/* Period Selector */
.chart-period-selector {
    display: flex;
    gap: 2px;
    background: var(--bg-tertiary);
    padding: 3px;
    border-radius: var(--radius-sm);
}

.period-btn {
    padding: 5px 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.period-btn:hover {
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent-primary);
    color: white;
}

/* ================================
   History Page Styles
   ================================ */
.history-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.history-search {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.history-search input {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
}

.history-search input::placeholder {
    color: var(--text-muted);
}

.history-search input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.history-filters {
    display: flex;
    gap: 8px;
}

.filter-btn {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.filter-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.history-item:hover {
    border-color: var(--accent-primary);
}

.history-item.pb {
    border-left: 3px solid #fbbf24;
}

.history-item.dnf {
    opacity: 0.6;
}

.history-number {
    width: 40px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.history-time {
    font-size: 1.25rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
    min-width: 100px;
}

.history-time.pb {
    color: #fbbf24;
}

.history-scramble {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.history-actions {
    display: flex;
    gap: 8px;
}

/* Empty History */
.history-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.history-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.history-empty p {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .page-content {
        padding: 16px;
    }
    
    .stats-summary-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .summary-card {
        padding: 16px;
    }
    
    .summary-icon {
        width: 40px;
        height: 40px;
    }
    
    .summary-value {
        font-size: 1.25rem;
    }
    
    .streak-cards {
        grid-template-columns: 1fr;
    }
    
    .history-item {
        flex-wrap: wrap;
    }
    
    .history-scramble {
        order: 5;
        width: 100%;
        margin-top: 8px;
    }
}

/* ================================
   Page Header Actions
   ================================ */
.page-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ================================
   Sessions List (Manage Modal)
   ================================ */
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.session-item:hover {
    background: var(--bg-primary);
}

.session-item.current {
    border: 2px solid var(--accent-primary);
}

.session-info {
    flex: 1;
}

.session-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.session-info span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.session-actions {
    display: flex;
    gap: 8px;
}

.session-actions button {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.session-actions .rename-btn {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.session-actions .rename-btn:hover {
    background: var(--accent-primary);
    color: white;
}

.session-actions .delete-btn {
    background: color-mix(in srgb, var(--color-error) 20%, transparent);
    color: var(--color-error);
}

.session-actions .delete-btn:hover {
    background: var(--color-error);
    color: white;
}

/* ================================
   Session Comparison Modal
   ================================ */
.modal-large {
    max-width: 900px;
    width: 95%;
}

.compare-session-selectors {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
}

.compare-selector {
    flex: 1;
    max-width: 280px;
}

.compare-selector label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.compare-selector select {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
}

.compare-vs {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-primary);
    padding: 0 16px;
}

.compare-results {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.compare-card {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.compare-card.winner {
    border: 2px solid var(--color-success);
}

.compare-card .winner-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--color-success);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-lg);
    text-transform: uppercase;
}

.compare-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.compare-card-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.compare-card-header .session-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.compare-stats-grid {
    display: grid;
    gap: 12px;
}

.compare-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.compare-stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.compare-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.compare-stat-value.better {
    color: var(--color-success);
}

.compare-stat-value.worse {
    color: var(--color-error);
}

/* Comparison Chart */
.compare-chart-section {
    grid-column: 1 / -1;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.compare-chart-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.compare-chart-container {
    height: 200px;
    position: relative;
}

.compare-chart-container canvas {
    width: 100%;
    height: 100%;
}

/* Comparison Bar Chart */
.compare-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.compare-bar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.compare-bar-label {
    width: 80px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.compare-bars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.compare-bar {
    height: 24px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
    min-width: 60px;
    transition: width 0.5s ease;
}

.compare-bar.session1 {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.compare-bar.session2 {
    background: linear-gradient(135deg, #f97316, #ea580c);
}

/* Improvement indicator */
.improvement-indicator {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
}

.improvement-value {
    font-size: 2rem;
    font-weight: 700;
}

.improvement-value.positive {
    color: var(--color-success);
}

.improvement-value.negative {
    color: var(--color-error);
}

.improvement-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Empty compare state */
.compare-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.compare-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

@media (max-width: 768px) {
    .compare-session-selectors {
        flex-direction: column;
        gap: 16px;
    }
    
    .compare-vs {
        padding: 0;
    }
    
    .compare-selector {
        max-width: 100%;
        width: 100%;
    }
    
    .compare-results {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   ULTRA RESPONSIVE - Mobile & Tablet Optimized
   ============================================ */

/* Touch-friendly base styles */
@media (pointer: coarse) {
    /* Larger touch targets */
    .icon-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .action-btn, .control-btn, .time-item {
        min-height: 44px;
    }
    
    select, input, button {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch */
    .time-item:hover,
    .icon-btn:hover,
    .action-btn:hover {
        transform: none;
    }
}

/* Small phones (max-width: 380px) */
@media (max-width: 380px) {
    .header {
        padding: 6px 8px;
        gap: 6px;
    }
    
    .logo-text {
        font-size: 1rem !important;
    }
    
    .logo-pro {
        font-size: 0.5rem !important;
    }
    
    .cube-icon {
        width: 24px !important;
        height: 24px !important;
    }
    
    .nav-controls {
        gap: 4px;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
        padding: 6px;
    }
    
    .session-select, .puzzle-select {
        font-size: 0.7rem;
        padding: 6px 8px;
        min-width: 60px;
        max-width: 80px;
    }
    
    .timer {
        font-size: clamp(2.5rem, 18vw, 4rem) !important;
    }
    
    .scramble-text {
        font-size: 0.85rem !important;
        padding: 8px !important;
    }
    
    .quick-stats {
        gap: 8px;
    }
    
    .quick-stat {
        padding: 4px 8px;
        font-size: 0.7rem;
    }
    
    .control-btn {
        padding: 8px;
        font-size: 0.7rem;
    }
    
    .control-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .stats-grid {
        gap: 6px;
    }
    
    .stat-card {
        padding: 8px;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
    
    .panel {
        padding: 10px;
    }
    
    .panel-header h3 {
        font-size: 0.7rem;
    }
    
    .modal-content {
        padding: 12px;
        margin: 8px;
        max-height: calc(100vh - 16px);
    }
    
    .modal-header h2 {
        font-size: 1rem;
    }
    
    .settings-section h4 {
        font-size: 0.8rem;
    }
}

/* Regular phones (max-width: 480px) */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .main-grid {
        padding: 8px;
        gap: 8px;
    }
    
    .timer-panel {
        padding: 16px 12px;
    }
    
    .timer-controls {
        gap: 6px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .control-btn {
        flex: 0 0 auto;
        padding: 10px 14px;
    }
    
    .times-list {
        max-height: 150px;
    }
    
    .time-item {
        padding: 10px 12px;
    }
    
    /* Stack page headers vertically using Grid for better control */
    .page-header {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
        gap: 12px;
        padding: 16px;
        background: transparent;
    }
    
    .page-header h2 {
        grid-column: 1 / -1;
        grid-row: 1;
        font-size: 1.25rem;
        text-align: center;
        margin-bottom: 8px;
        font-weight: 700;
        width: 100%;
    }
    
    /* Style the back button and actions row */
    #statsBackBtn {
        grid-column: 1;
        grid-row: 2;
        width: 48px;
        height: 48px;
        border-radius: 14px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        box-shadow: var(--shadow-sm);
    }

    .page-header-actions {
        grid-column: 2;
        grid-row: 2;
        display: flex;
        gap: 8px;
        width: 100%;
        min-width: 0; /* Prevent overflow */
    }

    #compareSessionsBtn {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        box-shadow: var(--shadow-sm);
        flex-shrink: 0;
    }

    .session-select {
        flex: 1;
        height: 48px;
        border-radius: 14px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        font-size: 0.9rem;
        padding: 0 12px;
        box-shadow: var(--shadow-sm);
        width: 100%; /* Ensure it takes width */
        min-width: 0; /* Allow shrinking for text truncation */
        text-overflow: ellipsis;
    }
    
    /* Statistics page mobile */
    .stats-overview-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .overview-card {
        padding: 12px;
    }
    
    .overview-value {
        font-size: 1.3rem;
    }
    
    /* Bento grid single column on small phones */
    .bento-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    .bento-card {
        padding: 14px;
    }
    
    .bento-card h3 {
        font-size: 0.85rem;
    }
    
    /* History page mobile */
    .history-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .filter-group {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .filter-group::-webkit-scrollbar {
        display: none;
    }
    
    .history-search {
        width: 100%;
    }
    
    /* Modal full screen on mobile */
    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 16px 16px 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .modal.active .modal-content {
        animation: slideUp 0.3s ease;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    /* Keybind help grid */
    .keybind-help-grid {
        gap: 16px;
    }
    
    .keybind-help-row kbd {
        min-width: 50px;
        font-size: 0.65rem;
    }
    
    /* Settings sections */
    .settings-grid {
        gap: 12px;
    }
    
    .setting-group {
        margin-bottom: 10px;
    }
    
    .keybinds-grid {
        gap: 6px;
    }
    
    .keybind-row {
        padding: 10px;
    }
    
    .keybind-key-btn {
        min-width: 70px;
    }
    
    .keybind-key-btn kbd {
        font-size: 0.65rem;
        padding: 5px 8px;
    }
}

/* Tablets portrait (max-width: 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .main-grid {
        padding: 12px;
        gap: 12px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .bento-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .stats-overview-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Tablets landscape / Small laptops (max-width: 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr 280px;
    }
    
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Safe area insets for notched phones */
@supports (padding: max(0px)) {
    .header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-top: max(8px, env(safe-area-inset-top));
    }
    
    .main-grid {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .modal-content {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .page {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        padding: 4px 12px;
        min-height: 36px;
    }
    
    .logo-text {
        font-size: 0.9rem !important;
    }
    
    .cube-icon {
        width: 20px !important;
        height: 20px !important;
    }
    
    .main-grid {
        grid-template-columns: 1fr 200px;
        grid-template-rows: 1fr;
        grid-template-areas: "timer stats";
        padding: 6px;
        gap: 8px;
    }
    
    .timer-panel {
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
    
    .timer {
        font-size: clamp(3rem, 15vh, 5rem) !important;
    }
    
    .scramble-panel,
    .preview-panel,
    .records-panel,
    .graph-panel,
    .times-panel {
        display: none !important;
    }
    
    .quick-stats {
        position: absolute;
        bottom: 8px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .timer-controls {
        margin-top: 8px;
    }
    
    .control-btn {
        padding: 6px 10px;
        font-size: 0.7rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #888;
    }
    
    .panel, .stat-card, .bento-card {
        border-width: 2px;
    }
    
    .timer {
        text-shadow: none;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .modal.active .modal-content {
        animation: none;
    }
}

/* Print styles */
@media print {
    .header, .timer-controls, .nav-controls, .icon-btn {
        display: none !important;
    }
    
    .timer {
        color: #000 !important;
    }
    
    .panel {
        border: 1px solid #ccc;
        break-inside: avoid;
    }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
    outline: none;
}

/* Improve tap highlighting on mobile */
@media (pointer: coarse) {
    a, button, .time-item, .stat-card, .bento-card {
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
    }
}

/* Smooth scrolling with reduced motion respect */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Overscroll behavior */
html, body {
    overscroll-behavior: none;
}

.times-list, .history-list, .modal-body {
    overscroll-behavior: contain;
}

/* Time of Day Analysis */
.time-of-day-container {
    display: flex;
    gap: 24px;
    height: 200px;
    align-items: center;
}

.tod-chart {
    flex: 1;
    height: 100%;
    position: relative;
}

.tod-stats {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    padding-left: 24px;
    border-left: 1px solid var(--border-color);
}

.tod-stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tod-stat-item .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tod-stat-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tod-stat-item .value.highlight {
    color: var(--accent-primary);
}

.tod-insight {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .time-of-day-container {
        flex-direction: column;
        height: auto;
    }
    
    .tod-chart {
        width: 100%;
        height: 200px;
    }
    
    .tod-stats {
        width: 100%;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--border-color);
        padding-top: 24px;
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .tod-stat-item {
        flex: 1;
        min-width: 120px;
    }
    
    .tod-insight {
        width: 100%;
        border-top: none;
        padding-top: 0;
        margin-top: 0;
    }
}

/* Enhanced Time of Day Styles */
.tod-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
}

.tod-stat-card {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid var(--border-color);
}

.tod-icon-box {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
    font-size: 1.2rem;
}

.tod-stat-content {
    display: flex;
    flex-direction: column;
}

.tod-stat-content .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.tod-stat-content .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tod-stat-content .value.highlight {
    color: var(--accent-primary);
}

.tod-stat-content .value.success {
    color: #22c55e;
}

.tod-insight-box {
    background: var(--bg-tertiary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-primary);
}

.tod-insight-box p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.highlight-text {
    color: var(--text-primary);
}

.success-text {
    color: #22c55e;
    font-weight: 600;
}

@media (max-width: 768px) {
    .tod-stat-grid {
        grid-template-columns: 1fr;
    }
}

/* Calendar Heatmap Styles */
.calendar-heatmap-container {
    display: flex;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    gap: 12px;
    margin-top: 12px;
}

.heatmap-scroll-area {
    overflow-x: auto;
    flex: 1;
    position: relative;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.heatmap-scroll-area::-webkit-scrollbar {
    display: none;
}

.heatmap-month-labels {
    height: 24px;
    position: relative;
    min-width: max-content;
    margin-bottom: 4px;
}

.heatmap-month-label {
    position: absolute;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.heatmap-weeks {
    display: flex;
    gap: 3px;
    min-width: max-content;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.heatmap-cell {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08); /* Lighter than bg-secondary for visibility */
    transition: all 0.2s ease;
}

.heatmap-cell:hover {
    transform: scale(1.4);
    z-index: 10;
    box-shadow: 0 0 8px var(--accent-glow);
    border-radius: 3px;
    background: var(--text-muted);
}

.heatmap-cell.level-1 { background: var(--accent-primary); opacity: 0.3; }
.heatmap-cell.level-2 { background: var(--accent-primary); opacity: 0.5; }
.heatmap-cell.level-3 { background: var(--accent-primary); opacity: 0.7; }
.heatmap-cell.level-4 { background: var(--accent-primary); opacity: 1.0; }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    justify-content: flex-end;
}

.legend-scale {
    display: flex;
    gap: 3px;
}

.legend-box {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.legend-box.level-0 { background: rgba(255, 255, 255, 0.08); }
.legend-box.level-1 { background: var(--accent-primary); opacity: 0.3; }
.legend-box.level-2 { background: var(--accent-primary); opacity: 0.5; }
.legend-box.level-3 { background: var(--accent-primary); opacity: 0.7; }
.legend-box.level-4 { background: var(--accent-primary); opacity: 1.0; }


/* =========================================
   Vertical Aspect Ratio / Mobile Layout
   ========================================= */

/* Default Desktop State */
#sideDrawer {
    display: contents;
}

.mobile-menu-btn {
    display: none; /* Hidden on desktop */
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1000; /* Above everything */
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.mobile-menu-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
}

.mobile-menu-btn svg {
    width: 24px;
    height: 24px;
    display: block;
}

/* Vertical Aspect Ratio (Portrait-ish) */
@media (max-aspect-ratio: 1/1) {
    .main-grid {
        display: flex;
        flex-direction: column;
        flex: 1; /* Take remaining space */
        height: auto !important; /* Don't force 100vh */
        width: 100vw;
        padding: 0;
        margin: 0;
        overflow: hidden; /* Prevent body scroll, handle inside containers */
        max-width: none;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Side Drawer - The "Page on the Side" */
    #sideDrawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--bg-primary);
        z-index: 900; /* Below menu button */
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
        overflow-y: auto;
        padding: 70px 16px 32px; /* Top padding for menu button */
        gap: 12px; /* Reduced gap */
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none;  /* IE 10+ */
    }

    #sideDrawer::-webkit-scrollbar { 
        display: none;  /* Chrome/Safari */
    }

    #sideDrawer.open {
        transform: translateX(0);
    }

    /* Center Column - Fullscreen Timer */
    .center-column {
        height: 100%;
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-start; /* Start from top */
        align-items: center;
        padding: 0;
        position: relative;
    }

    /* Timer Panel - Centered and Large */
    .timer-panel {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background: transparent;
        box-shadow: none;
        border: none;
        min-height: 0; /* Allow shrinking */
        padding: 0;
        margin: 0; /* Remove margins, let flex handle it */
        width: 100%;
    }

    .timer-container {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .timer {
        font-size: 18vh; /* Huge timer */
        line-height: 1;
        text-shadow: 0 4px 12px rgba(0,0,0,0.3);
    }

    .timer-state {
        font-size: 1.5rem;
        margin-top: 1rem;
    }

    .timer-controls {
        margin-top: 2rem;
        transform: scale(1.2);
    }

    /* Scramble & Preview - Container */
    .scramble-preview-container {
        flex-shrink: 0;
        background: transparent;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
        border: none;
        margin-top: 0;
        display: flex;
        flex-direction: column;
        gap: 0;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* Adjust internal panels */
    .scramble-panel, .preview-panel {
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0;
        margin: 0;
    }

    .scramble-panel .panel-header,
    .preview-panel .panel-header {
        display: none; /* Hide headers to save space */
    }

    .scramble-text {
        font-size: 1.1rem;
        text-align: center;
        font-family: 'Roboto Mono', monospace;
    }

    .preview-body {
        display: flex;
        justify-content: center;
        padding: 0;
    }

    /* Ensure stats/history look good in the drawer */
    .left-column, .right-column {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 16px;
    }

    /* Override panel styles for drawer context */
    #sideDrawer .panel {
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        margin-bottom: 0;
        overflow: hidden;
        flex: 0 0 auto !important; /* Don't grow, don't shrink, auto basis */
        height: auto !important;
        min-height: 0 !important;
    }
    
    #sideDrawer .panel-header {
        padding: 10px 14px;
        background: rgba(0,0,0,0.02);
        border-bottom: 1px solid var(--border-color);
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        height: auto;
        min-height: 40px;
        gap: 8px;
    }

    #sideDrawer .panel-header h3 {
        font-size: 0.85rem;
        text-transform: uppercase;
        letter-spacing: 1px;
        color: var(--text-secondary);
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-right: auto;
        flex: 1;
        min-width: 0;
    }
    
    #sideDrawer .panel-actions {
        flex-shrink: 0;
        margin-left: 0;
    }

    #sideDrawer .panel-body {
        padding: 12px;
    }
    
    #sideDrawer .stats-grid,
    #sideDrawer .records-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        height: auto !important; /* Override 100% height */
    }
    
    #sideDrawer .stat-card,
    #sideDrawer .record-item {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        padding: 10px;
        height: auto !important; /* Override 100% height */
        min-height: auto;
    }

    #sideDrawer .stat-label,
    #sideDrawer .record-label {
        font-size: 0.7rem;
        margin-bottom: 2px;
    }

    #sideDrawer .stat-value,
    #sideDrawer .record-value {
        font-size: 1.1rem;
    }
}


/* =========================================
   Vertical Aspect Ratio / Mobile Layout Updates
   ========================================= */

/* Header in Vertical Mode */
@media (max-aspect-ratio: 1/1) {
    .header {
        display: flex !important;
        position: relative !important; /* Changed from absolute to relative */
        top: auto;
        left: auto;
        width: 100%;
        height: auto;
        min-height: 60px;
        padding: 12px 16px;
        background: transparent;
        z-index: 50;
        align-items: center;
        justify-content: center;
        border-bottom: none;
        pointer-events: none;
        flex-shrink: 0; /* Don't shrink */
    }
    
    .header > * {
        pointer-events: auto;
    }
    
    .header .logo {
        display: none;
    }
    
    .nav-controls {
        display: flex;
        gap: 0; /* Remove gap, use divider */
        align-items: center;
        justify-content: center;
        width: auto;
        max-width: 90%;
        background: var(--bg-card);
        padding: 4px;
        border-radius: 100px;
        border: 1px solid var(--border-color);
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        backdrop-filter: blur(10px);
    }
    
    /* Hide desktop-specific controls in mobile header */
    #newSessionBtn, 
    #manageSessionsBtn, 
    #keybindHelpBtn, 
    #compactModeBtn,
    #settingsBtn {
        display: none !important;
    }
    
    /* Style selectors for mobile header */
    .session-select {
        background: transparent;
        border: none;
        height: 36px;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-primary);
        min-width: 80px;
        max-width: 180px;
        padding: 0 16px;
        border-radius: 18px;
        box-shadow: none;
        text-overflow: ellipsis;
        text-align: center;
        cursor: pointer;
        -webkit-appearance: none; /* Remove default arrow */
        appearance: none;
    }
    
    .session-select:focus {
        background: var(--bg-tertiary);
    }

    /* Separator line */
    .nav-controls::after {
        content: '';
        width: 1px;
        height: 20px;
        background: var(--border-color);
        display: block;
        opacity: 0.5;
    }

    .puzzle-select {
        background: transparent;
        border: none;
        height: 36px;
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-primary);
        width: auto;
        min-width: 70px;
        padding: 0 16px;
        border-radius: 18px;
        box-shadow: none;
        cursor: pointer;
        text-align: center;
        -webkit-appearance: none;
        appearance: none;
    }
    
    .puzzle-select:focus {
        background: var(--bg-tertiary);
    }

    /* Mobile Controls in Drawer */
    .mobile-controls {
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 20px;
        background: var(--bg-card);
        border-radius: var(--radius-lg);
        border: 1px solid var(--border-color);
        box-shadow: var(--shadow-sm);
        margin-bottom: 8px;
    }

    .mobile-controls-row {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    /* Row with Stats/History buttons - keep side by side */
    .mobile-controls-row:last-child {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .mobile-controls .session-select,
    .mobile-controls .puzzle-select {
        width: 100% !important;
        max-width: none !important;
        min-height: auto;
        height: auto;
        border-radius: var(--radius-md);
        font-size: 1rem;
        padding: 8px 12px;
        white-space: normal;
        text-overflow: ellipsis;
    }

    .mobile-controls select option {
        white-space: normal;
    }

    .mobile-controls .icon-btn {
        min-height: auto;
        height: auto;
        padding: 8px;
        border-radius: var(--radius-md);
        font-size: 1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%; /* Full width buttons when stacked */
    }

    /* Buttons for + and Settings */
    #mobileNewSessionBtn, #mobileSettingsBtn {
        width: 100%;
        flex: auto;
    }

    /* Specific styling for the Stats/History buttons */
    #mobileStatsBtn, #mobileHistoryBtn {
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        font-weight: 600;
        justify-content: center;
        width: 100%;
    }
    
    #mobileStatsBtn svg, #mobileHistoryBtn svg {
        margin-right: 8px;
    }

    /* Center Column Layout: Scramble -> Timer -> Preview */
    .center-column {
        display: flex;
        flex-direction: column;
        position: relative;
        padding: 0;
        height: 100%;
        overflow: hidden;
        justify-content: flex-start;
    }

    /* Timer Panel - Full Screen Centered */
    .timer-panel {
        position: relative;
        top: auto;
        left: auto;
        width: 100%;
        height: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        padding: 20px 0 0 0;
        margin: 0;
        z-index: 1;
    }

    .timer-container {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        width: 100%;
        height: auto;
    }

    /* Fix Timer Size on Mobile */
    .timer {
        font-size: clamp(4rem, 20vw, 9rem) !important; /* Slightly reduced max size */
        line-height: 1.5; /* Increased line height to prevent clipping */
        padding: 10px 0; /* Add padding to ensure ascenders aren't cut */
        margin-top: -20px; /* Pull it up slightly to balance the padding */
    }

    /* Scramble & Preview Container */
    .scramble-preview-container {
        display: flex;
        flex-direction: column;
        width: 100%;
        order: -1; /* Ensure it's at the top */
        flex-shrink: 0;
    }

    /* Scramble Panel (Top Overlay) */
    .scramble-panel {
        position: relative;
        top: auto;
        left: auto;
        width: 100%;
        background: transparent;
        box-shadow: none;
        border: none;
        padding: 0 10px;
        text-align: center;
        z-index: 10;
        pointer-events: none; /* Let clicks pass through */
        margin-bottom: 20px;
    }

    .scramble-panel .panel-header {
        display: none;
    }

    .scramble-text {
        pointer-events: auto;
        font-size: clamp(1.2rem, 5vw, 2rem); /* Responsive size */
        line-height: 1.4;
        font-weight: 500;
        color: var(--text-primary);
        text-shadow: 0 2px 4px rgba(0,0,0,0.5);
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
    }

    /* Preview Panel (Bottom) - Hidden in vertical mode */
    .preview-panel {
        display: none !important;
    }

    /* Timer Controls (Bottom Overlay) */
    .timer-controls {
        position: absolute;
        bottom: 20px;
        left: 0;
        width: 100%;
        display: flex;
        justify-content: center;
        gap: 8px;
        flex-wrap: nowrap;
        z-index: 20;
        border-top: none;
        padding: 0;
    }

    .control-btn {
        padding: 12px 16px; /* Smaller horizontal padding */
        min-width: 60px; /* Ensure minimum width */
        flex: 0 1 auto; /* Allow shrinking if needed but prefer auto */
    }

    /* Menu Button Position */
    .mobile-menu-btn {
        top: 16px;
        left: 16px;
        width: 48px;
        height: 48px;
        background: var(--bg-card); /* Use theme color */
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        backdrop-filter: blur(4px);
    }

    /* Change Timer Hint Text */
    .timer-hint {
        font-size: 0; /* Hide original text */
    }
    
    .timer-hint::after {
        content: "Hold to start";
        font-size: 1rem; /* Restore font size */
        color: var(--text-muted);
        display: block;
    }
}

/* Hide Mobile Controls on Desktop */
@media (min-aspect-ratio: 1/1) {
    .mobile-controls {
        display: none;
    }
}

/* Wide Desktop Layout: Stack Scramble/Preview vertically on the side - REMOVED per user request */
/* @media (min-width: 1400px) { ... } */

/* Bottom Navigation */
.bottom-nav {
    display: none; /* Hidden by default */
}

@media (max-aspect-ratio: 1/1) {
    /* Old bottom nav styles removed */

    /* Adjust pages to not be covered by nav */
    .page, .main-grid {
        padding-bottom: 130px !important; /* Space for controls + nav */
    }

    /* Full Width Bottom Navigation */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 80px; /* Taller for better touch targets */
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        z-index: 1000;
        justify-content: space-around;
        align-items: flex-start; /* Align to top to give space for home indicator */
        padding-top: 12px;
        padding-bottom: env(safe-area-inset-bottom);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    }

    .nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 0.7rem;
        font-weight: 500;
        gap: 6px;
        height: 100%;
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
    }

    .nav-item::before {
        display: none;
    }

    .nav-item.active {
        color: var(--accent-primary);
    }
    
    .nav-item.active svg {
        transform: translateY(-2px);
        filter: drop-shadow(0 2px 4px var(--accent-glow));
        stroke-width: 2.5px;
    }

    .nav-item svg {
        width: 24px;
        height: 24px;
        transition: all 0.2s ease;
    }

    /* Timer Controls - Floating Pill Bar */
    .timer-controls {
        position: fixed;
        bottom: calc(90px + env(safe-area-inset-bottom)) !important;
        left: 50% !important;
        transform: translateX(-50%);
        width: auto;
        min-width: 280px;
        max-width: 90%; /* Fit on narrow screens */
        padding: 8px 24px !important;
        gap: 12px !important;
        z-index: 900;
        pointer-events: auto;
        display: flex;
        justify-content: space-between;
        align-items: center;
        
        /* Separation from background */
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 100px; /* Pill shape */
        box-shadow: 0 8px 24px rgba(0,0,0,0.15);
        backdrop-filter: blur(10px);
    }
    
    .timer-controls .control-btn {
        pointer-events: auto;
        flex: 0 0 auto;
        width: auto;
        min-width: 44px;
        height: 44px;
        border-radius: 22px;
        background: transparent;
        border: none;
        box-shadow: none;
        font-weight: 700;
        font-size: 0.95rem;
        padding: 0 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
        color: var(--text-primary); /* Increased contrast */
        text-transform: uppercase;
        letter-spacing: 0.5px;
        opacity: 0.9; /* Slight opacity for style, but readable */
    }
    
    /* Light theme mobile buttons */
    [data-theme="light"] .timer-controls .control-btn {
        background: transparent;
        border: none;
        box-shadow: none;
        color: var(--text-primary); /* Increased contrast */
    }
    
    .timer-controls .control-btn:active {
        transform: scale(0.92);
        background: var(--bg-tertiary);
        color: var(--text-primary);
        opacity: 1;
    }
    
    .timer-controls .control-btn:disabled {
        opacity: 0.3;
        box-shadow: none;
        background: transparent;
        border-color: transparent;
    }
    
    /* Preserve state colors via text color instead of background */
    .timer-controls .control-btn.active {
        background: transparent !important;
        border: none !important;
        color: var(--danger) !important;
        box-shadow: none !important;
    }
    
    .timer-controls .control-btn.ok-btn:not(:disabled) {
        background: transparent !important;
        border: none !important;
        color: var(--success) !important;
        box-shadow: none !important;
    }

    .timer-controls .control-btn svg {
        width: 24px;
        height: 24px;
        stroke-width: 2px;
    }

    /* Hide the mobile menu button since we have bottom nav */
    .mobile-menu-btn {
        display: none !important;
    }

    /* Hide the stats/history buttons in the drawer since they are in nav */
    #mobileStatsBtn, #mobileHistoryBtn {
        display: none !important;
    }
    
    /* Adjust drawer padding since menu button is gone */
    #sideDrawer {
        padding-top: 20px;
    }
}

/* =========================================
   SETTINGS REDESIGN (Sidebar Layout)
   ========================================= */

/* Modal Container */
.settings-modal-new .settings-container {
    background: var(--bg-primary);
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: row;
    width: 90vw;
    height: 85vh;
    max-width: 1100px;
    max-height: 800px;
    padding: 0;
    position: relative;
}

/* Sidebar Styling */
.settings-sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    gap: 8px;
    flex-shrink: 0;
}

.settings-sidebar-header {
    padding: 0 12px 24px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
    text-transform: none;
}

.settings-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.settings-nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: translateX(4px);
}

.settings-nav-item.active {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border-color: var(--border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.settings-nav-item svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.5px;
}

/* Main Content Area */
.settings-content {
    flex: 1;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 32px;
    scroll-behavior: smooth;
}

/* Sections */
.settings-section {
    display: none;
    animation: fadeIn 0.3s ease;
}

.settings-section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    margin-bottom: 32px;
}

.section-header h3 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Cards */
.setting-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 8px; /* Inner padding handled by rows */
    margin-bottom: 24px;
    overflow: hidden;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-row:hover {
    background: var(--bg-tertiary);
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.setting-info label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    text-transform: none;
}

.setting-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Controls */
.modern-select,
.modern-input {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 500;
    outline: none;
    transition: all 0.2s ease;
    min-width: 140px;
}

.modern-select:focus,
.modern-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: .3s;
    border-radius: 34px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-secondary);
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

input:checked + .slider:before {
    transform: translateX(24px);
    background-color: white;
}

/* Action Buttons */
.action-btn {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.action-btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

.action-btn.danger {
    color: var(--danger);
    border-color: rgba(255, 59, 48, 0.2);
}

.action-btn.danger:hover {
    background: var(--danger);
    color: white;
}

/* Keybinds */
.keybind-key-btn kbd {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    box-shadow: 0 2px 0 var(--border-color);
    display: inline-block;
    min-width: 32px;
    text-align: center;
}

/* Data Actions Grid */
.setting-actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 24px;
}

.action-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.action-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
    border-color: var(--accent-primary);
}

.icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.icon-box svg {
    width: 24px;
    height: 24px;
}

.action-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.action-title {
    font-weight: 700;
    color: var(--text-primary);
}

.action-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.action-card.danger:hover {
    border-color: var(--danger);
}

.action-card.danger .icon-box.danger {
    background: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

/* Responsive Design */
@media (max-width: 768px) {
    .settings-modal-new .settings-container {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        border: none;
        flex-direction: column;
    }

    .settings-sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 12px;
        gap: 12px;
    }

    .settings-sidebar-header {
        padding: 0 8px;
        margin-bottom: 0;
        border-bottom: none;
    }

    .settings-sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 4px;
        gap: 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .settings-sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .settings-nav-item {
        flex-direction: column;
        padding: 10px;
        min-width: 70px;
        gap: 6px;
        font-size: 0.75rem;
        justify-content: center;
        text-align: center;
        border-radius: 12px;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
    }
    
    .settings-nav-item:hover {
        transform: none;
    }
    
    .settings-nav-item.active {
        background: var(--accent-primary);
        color: white;
        border-color: var(--accent-primary);
    }
    
    .settings-nav-item.active svg {
        stroke: white;
    }

    .settings-content {
        padding: 20px;
    }

    .section-header h3 {
        font-size: 1.5rem;
    }

    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
        padding: 16px;
    }

    .setting-control {
        width: 100%;
    }

    .modern-select,
    .modern-input {
        width: 100%;
    }

    .toggle-switch {
        align-self: flex-end;
    }
    
    /* Fix toggle alignment on mobile */
    .setting-row:has(.toggle-switch) {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    
    .setting-row:has(.toggle-switch) .setting-control {
        width: auto;
    }
}


/* =========================================
   BENTO GRID REDESIGN (Visual Overhaul)
   ========================================= */

/* Global Layout Tweaks */
.main-grid {
    gap: 24px;
    padding: 24px;
    max-width: 1600px;
}

/* Panel Overhaul - The "Card" Look */
.panel {
    border: none;
    border-radius: 24px;
    background: var(--bg-secondary);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Remove internal borders for a cleaner look */
.panel-header {
    border-bottom: none;
    padding: 24px 24px 12px;
}

.panel-header h3 {
    font-size: 0.75rem;
    letter-spacing: 1.5px;
    opacity: 0.6;
    font-weight: 700;
}

.panel-body {
    padding: 0 24px 24px;
}

/* Stats & Records - Mini Cards */
.stats-grid, .records-grid {
    gap: 12px;
}

.stat-card, .record-item {
    background: var(--bg-primary); /* Inset look or just distinct */
    border: none;
    border-radius: 16px;
    padding: 16px;
    transition: all 0.2s ease;
}

.stat-card:hover, .record-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    background: var(--bg-tertiary);
}

.stat-label, .record-label {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-bottom: 6px;
}

.stat-value, .record-value {
    font-size: 1.25rem;
    font-weight: 700;
}

/* Timer Panel - The Hero Section */
.timer-panel {
    background: var(--bg-secondary);
    /* Optional: Subtle gradient for focus */
    background: linear-gradient(145deg, var(--bg-secondary), var(--bg-tertiary));
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.timer {
    font-weight: 800;
    text-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* Scramble Panel */
.scramble-panel {
    position: relative;
}



.scramble-panel .panel-body {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.scramble-text {
    font-size: 0.9rem; /* Reduced font size */
    text-align: center;
    background: transparent; /* Removed background */
    padding: 12px; /* Reduced padding */
    border-radius: 0;
    font-weight: 600;
    letter-spacing: 0.5px;
    width: 100%;
    line-height: 1.5;
}

/* Times List - Clean Table */
.times-list {
    border: none;
}

.times-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

.time-item {
    border-bottom: 1px solid transparent;
    border-radius: 8px;
    margin-bottom: 2px;
}

.time-item:hover {
    background: var(--bg-tertiary);
}

.time-number {
    opacity: 0.5;
    font-size: 0.8rem;
    width: 30px;
    display: inline-block;
}

.time-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    flex: 1;
}

.time-actions {
    opacity: 0;
    transition: opacity 0.2s;
}

.time-item:hover .time-actions {
    opacity: 1;
}

/* Graph Panel */
.graph-panel {
    min-height: 250px;
}

/* Buttons in Panels */
.icon-btn.small {
    opacity: 0.6;
    transition: opacity 0.2s;
}

.icon-btn.small:hover {
    opacity: 1;
    background: var(--bg-tertiary);
}

/* Desktop Timer Controls - Make them fit the Bento style */
@media (min-width: 769px) {
    .timer-controls {
        background: var(--bg-primary);
        padding: 12px;
        border-radius: 20px;
        gap: 12px;
        margin-top: 20px;
    }
    
    .control-btn {
        border-radius: 12px;
        font-weight: 600;
        letter-spacing: 0.5px;
    }
}

/* Dark Mode Adjustments for Depth */
[data-theme="dark"] .panel {
    border: 1px solid rgba(255,255,255,0.05); /* Subtle highlight */
}

[data-theme="dark"] .stat-card, 
[data-theme="dark"] .record-item {
    background: rgba(255,255,255,0.03);
}

/* =========================================
   Mobile Scramble Fix (Post-Bento Override)
   ========================================= */
@media (max-aspect-ratio: 1/1) {
    .scramble-panel {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        width: 90% !important;
        max-width: 400px !important;
        margin: 0 auto 8px auto !important; /* Center horizontally and reduce bottom margin */
        z-index: 40 !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
        pointer-events: none;
        display: flex !important;
        align-items: flex-start !important;
        justify-content: center !important;
        height: auto !important;
        min-height: 0 !important;
        flex-shrink: 0; /* Don't shrink */
        order: -1; /* Ensure it appears before the timer */
    }

    .scramble-panel .panel-body {
        padding: 0 !important;
        display: block !important;
        width: 100% !important;
        background: transparent !important;
    }

    .scramble-text {
        pointer-events: auto;
        font-family: 'JetBrains Mono', monospace !important;
        font-size: 1.25rem !important;
        line-height: 1.6 !important;
        font-weight: 600 !important;
        color: var(--text-primary) !important;
        
        /* Glassmorphism / Modern Card Look */
        background: var(--bg-secondary) !important;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        
        border: 1px rgba(128, 128, 128, 0.1) !important;
        border-radius: 5px !important; /* Reduced radius for cleaner corners */
        
        box-shadow: 
            0 10px 30px -5px rgba(0, 0, 0, 0.15),
            0 4px 10px rgba(0, 0, 0, 0.05) !important;
            
        width: 100% !important;
        margin: 0 !important;
        padding: 24px 28px !important;
        text-align: center !important;
        letter-spacing: 0.5px !important;
        
        /* Collapsible Logic - Default State */
        max-height: 130px !important;
        overflow: hidden !important;
        display: block !important;
        cursor: pointer;
        position: relative;
    }

    /* Visual Indication for Expandable */
    .scramble-text::after {
        content: 'Tap to expand';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        padding-bottom: 12px;
        
        /* Gradient to fade out text behind */
        background: linear-gradient(to bottom, transparent, var(--bg-secondary) 80%);
        
        font-size: 0.75rem;
        color: var(--accent-primary);
        font-weight: 700;
        opacity: 1;
        text-transform: uppercase;
        letter-spacing: 1.5px;
        pointer-events: none;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
    }
    
    /* Add padding to prevent text from overlapping with the gradient/hint */
    .scramble-text {
        padding-bottom: 50px !important;
    }
    
    /* Ensure timer is centered but doesn't overlap scramble too much */
    .timer-panel {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
        margin-top: 0 !important;
    }
}

/* Utility Classes */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

