
:root {
  /* Theme: Indigo Horizon - High Contrast Refinement */
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-500: #6366f1;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;
  
  --secondary-500: #ec4899;
  
  /* Darker Slate scale for better visibility in light mode */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  --bg-body: #f8fafc; /* Lighter background for better contrast with text */
  --bg-card: #ffffff;
  --bg-translucent: rgba(255, 255, 255, 0.95);
  
  --text-main: #020617; /* Almost black for max readability */
  --text-muted: #475569; /* Darker grey for subtitles */
  
  --border-color: #cbd5e1;
  --focus-ring: rgba(79, 70, 229, 0.3);

  --radius-md: 0.5rem;   
  --radius-lg: 0.75rem;     
  --radius-xl: 1rem;   
  --radius-pill: 9999px;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --header-height: 4rem;
  --max-width: 1200px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.05);
}

/* System Dark Mode Preference Override (Fixes Loading Flash) */
@media (prefers-color-scheme: dark) {
  :root {
      --bg-body: #0f172a;
      --bg-card: #1e293b;
      --bg-translucent: rgba(30, 41, 59, 0.9);
      
      --text-main: #f8fafc;
      --text-muted: #94a3b8;
      
      --border-color: #334155;
      --primary-500: #818cf8;
      --primary-600: #6366f1;
      
      --slate-100: #1e293b; 
      --slate-300: #475569;
  }
}

/* Explicit Light Theme (Overrides System Dark if user selects Light) */
[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-translucent: rgba(255, 255, 255, 0.95);
  
  --text-main: #020617;
  --text-muted: #475569;
  
  --border-color: #cbd5e1;
  --primary-500: #6366f1;
  --primary-600: #4f46e5;
  
  --slate-100: #f1f5f9;
  --slate-300: #cbd5e1;
}

/* Explicit Dark Theme (Overrides System Light if user selects Dark) */
[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-translucent: rgba(30, 41, 59, 0.9);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --border-color: #334155;
  --primary-500: #818cf8;
  --primary-600: #6366f1;
  
  --slate-100: #1e293b; 
  --slate-300: #475569;
}

/* --- Resets & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; height: 100%; }

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

img, svg { display: block; max-width: 100%; }
button, input, textarea { font-family: inherit; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--slate-300); border-radius: 5px; border: 2px solid var(--bg-body); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background-color: var(--slate-600); border-color: var(--bg-body); }

/* --- Loader --- */
.loader-overlay {
    position: fixed; inset: 0; background: var(--bg-body); z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.4s ease-out, visibility 0.4s;
}
.loader-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-spinner {
    width: 48px; height: 48px; border: 4px solid var(--primary-100);
    border-top-color: var(--primary-600); border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Typography --- */
h1, h2, h3, h4 {
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--text-main);
    line-height: 1.2;
}

h1 {
    font-size: clamp(2rem, 4vw, 3rem);
    margin-bottom: 1rem;
    color: var(--primary-700);
}
[data-theme="dark"] h1 { color: var(--text-main); }

h2 { font-size: 1.5rem; margin-bottom: 0.75rem; }
p { margin-bottom: 1.5rem; color: var(--text-muted); font-size: 1rem; }

a { color: var(--primary-600); text-decoration: none; font-weight: 600; transition: color 0.2s; }
a:hover { color: var(--primary-700); text-decoration: underline; }
[data-theme="dark"] a { color: var(--primary-500); }
[data-theme="dark"] a:hover { color: var(--primary-500); }

/* --- Layout --- */
.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* --- Header --- */
header {
    height: var(--header-height);
    background: var(--bg-translucent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; z-index: 1000;
}

.nav-flex { display: flex; align-items: center; justify-content: space-between; height: 100%; }

.logo {
    font-size: 1.25rem; font-weight: 900;
    display: flex; align-items: center; gap: 0.5rem;
    color: var(--text-main);
    letter-spacing: -0.03em;
    text-decoration: none !important;
}
.logo span { color: var(--primary-600); }

.main-nav { margin-left: auto; margin-right: 1.5rem; }
.nav-list { display: flex; gap: 0.25rem; list-style: none; align-items: center; }

.nav-link {
    display: block;
    padding: 0.5rem 0.85rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: transparent; border: none;
    transition: all 0.2s;
}
.nav-link:hover, .nav-link.active { color: var(--primary-700); background: var(--primary-50); text-decoration: none; }
[data-theme="dark"] .nav-link:hover, [data-theme="dark"] .nav-link.active { color: var(--text-main); background: var(--slate-800); }

/* Mega Menu */
.has-dropdown { position: relative; }
.mega-menu {
    position: absolute;
    top: calc(100% + 0.5rem); right: -80px;
    width: 650px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    opacity: 0; visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1001;
}
.has-dropdown:hover .mega-menu { opacity: 1; visibility: visible; transform: translateY(0); }

.mega-col h4 {
    font-size: 0.75rem; text-transform: uppercase;
    color: var(--primary-600); margin-bottom: 0.75rem; letter-spacing: 0.05em;
    font-weight: 700; border-bottom: 2px solid var(--primary-50); padding-bottom: 0.25rem; display: inline-block;
}
[data-theme="dark"] .mega-col h4 { border-color: var(--slate-800); }

.mega-col ul { list-style: none; }
.mega-col li { margin-bottom: 0.25rem; }
.mega-col a {
    color: var(--text-muted); font-size: 0.85rem; font-weight: 500;
    display: block; padding: 0.35rem 0.5rem; border-radius: var(--radius-md);
    text-decoration: none;
}
.mega-col a:hover { color: var(--primary-700); background: var(--primary-50); }
[data-theme="dark"] .mega-col a:hover { background: var(--slate-800); color: var(--text-main); }

.nav-actions { display: flex; align-items: center; gap: 0.75rem; }

.theme-toggle {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--primary-500); color: var(--primary-500); transform: rotate(15deg); }

.mobile-menu-btn { display: none; background: none; border: none; font-size: 1.5rem; color: var(--text-main); cursor: pointer; padding: 0.25rem; }
.mobile-menu { display: none; }

/* --- App Grid --- */
.app-grid {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 3rem;
    margin-top: 2rem;
    margin-bottom: 2rem;
    align-items: start;
}

/* --- Wheel Area --- */
.wheel-section { display: flex; flex-direction: column; align-items: center; width: 100%; position: relative; }

.wheel-container {
    position: relative;
    width: 100%; max-width: 550px;
    aspect-ratio: 1/1;
    margin-bottom: 2rem;
}
canvas { width: 100%; height: 100%; filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.12)); transition: transform 0.1s; }

.pointer {
    position: absolute; top: 50%; right: -25px; transform: translateY(-50%);
    width: 50px; height: 60px; z-index: 20; pointer-events: none;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.15));
}
.pointer::after {
    content: ''; position: absolute; top: 50%; left: 0; transform: translateY(-50%);
    width: 0; height: 0;
    border-top: 18px solid transparent; border-bottom: 18px solid transparent;
    border-right: 40px solid var(--primary-600); border-radius: 4px;
}
.pointer::before {
    content: ''; position: absolute; top: 50%; right: -5px; transform: translateY(-50%);
    width: 12px; height: 12px; background: white; border-radius: 50%; z-index: 21;
}

/* Idle Pulse Animation */
@keyframes idle-pulse {
  0% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4); }
  50% { transform: translate(-50%, -50%) scale(1.05); box-shadow: 0 0 0 10px rgba(79, 70, 229, 0); }
  100% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}

.center-spin-btn {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 76px; height: 76px; border-radius: 50%;
    background: white; border: 4px solid var(--slate-100);
    color: var(--primary-600); font-weight: 800; font-size: 0.9rem; letter-spacing: 0.05em;
    cursor: pointer; z-index: 30; box-shadow: var(--shadow-lg); transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.center-spin-btn:not(:disabled) {
    animation: idle-pulse 2s infinite;
}
.center-spin-btn:hover { transform: translate(-50%, -50%) scale(1.1); border-color: var(--primary-100); color: var(--primary-700); }
.center-spin-btn:active { transform: translate(-50%, -50%) scale(0.95); }
.center-spin-btn:disabled { opacity: 0.8; cursor: not-allowed; animation: none; }


/* Confetti (Fix) */
.confetti-canvas {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 2147483647; /* Max z-index to be on top of everything */
}

/* Toolbar */
.controls-panel .toolbar {
    display: flex; gap: 0.5rem; 
    flex-wrap: wrap; justify-content: flex-start;
    padding-bottom: 1rem; margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.icon-btn {
    width: 40px; height: 40px; border: 1px solid transparent; background: transparent;
    border-radius: 50%; color: var(--text-muted); font-size: 1.1rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.icon-btn:hover { background: var(--slate-200); color: var(--text-main); }
[data-theme="dark"] .icon-btn:hover { background: var(--slate-700); }
.icon-btn.active { background: var(--primary-100); color: var(--primary-700); }
[data-theme="dark"] .icon-btn.active { background: rgba(99, 102, 241, 0.3); color: var(--primary-500); }

/* --- Sidebar (Controls) --- */
.controls-panel {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-xl); padding: 1.5rem; box-shadow: var(--shadow-md);
    display: flex; flex-direction: column; gap: 0.5rem;
    position: sticky; top: calc(var(--header-height) + 1.5rem);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.panel-header h2 { font-size: 1.1rem; margin: 0; color: var(--text-main); }

.tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem;
    background: var(--slate-200); padding: 0.25rem; border-radius: var(--radius-lg);
    margin-bottom: 0.5rem;
}
[data-theme="dark"] .tabs { background: var(--slate-800); }
.tab-btn {
    background: transparent; border: none; padding: 0.5rem; font-size: 0.85rem; font-weight: 600;
    color: var(--text-muted); border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s;
}
.tab-btn.active { background: var(--bg-card); color: var(--primary-700); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .tab-btn.active { color: var(--primary-500); }

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }

.action-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.btn-text {
    background: var(--bg-body); border: 1px solid var(--border-color); color: var(--text-main);
    font-size: 0.75rem; font-weight: 700; padding: 0.4rem 0.8rem;
    border-radius: var(--radius-md); cursor: pointer; text-transform: uppercase; letter-spacing: 0.05em;
    transition: all 0.2s;
}
.btn-text:hover { border-color: var(--primary-500); color: var(--primary-600); }

textarea {
    width: 100%; height: 320px; padding: 1rem;
    background: var(--slate-50); border: 1px solid var(--border-color); border-radius: var(--radius-md);
    color: var(--text-main); font-family: var(--font-mono); font-size: 0.9rem; line-height: 1.6;
    resize: none; outline: none; transition: all 0.2s;
}
[data-theme="dark"] textarea { background: var(--slate-900); }
textarea:focus { border-color: var(--primary-500); box-shadow: 0 0 0 3px var(--focus-ring); background: var(--bg-card); }

.history-list { 
    list-style: none; height: 320px; overflow-y: auto; 
    border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--slate-50);
}
[data-theme="dark"] .history-list { background: var(--slate-900); }

.history-item {
    padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; font-size: 0.9rem;
}
.history-item:last-child { border-bottom: none; }
.history-val { font-weight: 600; color: var(--text-main); }
.history-time { font-size: 0.75rem; color: var(--text-muted); }

/* --- Modals --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(5px);
    z-index: 2000; display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--bg-card); padding: 2.5rem; border-radius: var(--radius-xl);
    text-align: center; width: 95%; max-width: 480px;
    box-shadow: var(--shadow-lg); border: 1px solid var(--border-color);
    transform: translateY(20px); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 90vh; overflow-y: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }

.winner-text { 
    font-size: 2.5rem; font-weight: 800; color: var(--primary-600); 
    margin: 1rem 0 2rem; line-height: 1.1; word-break: break-word; 
}

/* Celebration Animation */
@keyframes pop-celebrate {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  80% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.winner-text.pop-anim {
    animation: pop-celebrate 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.modal-actions { display: flex; gap: 0.75rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }
.btn-primary {
    background: var(--primary-600); color: white; border: none; padding: 0.75rem 1.75rem;
    border-radius: var(--radius-pill); font-weight: 700; cursor: pointer; font-size: 1rem;
    box-shadow: 0 4px 6px rgba(79, 70, 229, 0.3); transition: transform 0.1s, background 0.2s;
    min-width: 140px;
}
.btn-primary:hover { background: var(--primary-700); transform: translateY(-1px); }
.btn-secondary {
    background: transparent; color: var(--text-main); border: 1px solid var(--border-color);
    padding: 0.75rem 1.75rem; border-radius: var(--radius-pill); font-weight: 600; cursor: pointer;
    transition: all 0.2s; font-size: 1rem;
    min-width: 100px;
}
.btn-secondary:hover { border-color: var(--text-main); background: var(--slate-100); }
[data-theme="dark"] .btn-secondary:hover { background: var(--slate-800); }

/* Settings Inputs */
.settings-group { margin-bottom: 1.5rem; text-align: left; }
.settings-group label { display: block; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-main); font-size: 0.95rem; }
.settings-group small { display: block; color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; }
input[type=range] { width: 100%; cursor: pointer; accent-color: var(--primary-600); margin-top: 0.5rem; height: 6px; border-radius: 3px; background: var(--slate-200); }
[data-theme="dark"] input[type=range] { background: var(--slate-700); }

/* Toggle Switch */
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 0; border-bottom: 1px solid var(--border-color); }
.switch-row:last-child { border-bottom: none; }
.switch-label { font-weight: 600; color: var(--text-main); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--slate-300); transition: .3s; border-radius: 24px;
}
.slider:before {
  position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
input:checked + .slider { background-color: var(--primary-600); }
input:checked + .slider:before { transform: translateX(20px); }
[data-theme="dark"] .slider { background-color: var(--slate-600); }

/* Content Section */
.content-section { max-width: 800px; margin: 0 auto; padding: 0 1.5rem 2rem; }
.breadcrumbs { margin-top: 1rem; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.breadcrumbs a { color: var(--text-muted); font-weight: 500; }
.breadcrumbs a:hover { color: var(--primary-600); }
.breadcrumbs span { margin: 0 0.5rem; opacity: 0.5; }

/* Footer */
footer {
    background: var(--bg-card); 
    border-top: 1px solid var(--border-color);
    padding: 2rem 0 1rem;
    margin-top: auto;
}
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2rem; margin-bottom: 2rem; }
.footer-col h3 {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--text-main); margin-bottom: 1rem; font-weight: 800;
}
.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: 0.5rem; }
.footer-col a { font-weight: 500; color: var(--text-muted); font-size: 0.9rem; text-decoration: none; }
.footer-col a:hover { color: var(--primary-600); }

.copyright-row {
    text-align:center; padding-top:1.5rem; border-top:1px solid var(--border-color); 
    color:var(--text-muted); font-size:0.85rem;
}
.copyright-row p { margin-bottom: 0; }

/* Fullscreen Controls */
.fs-control-btn { display: none; }
body.fullscreen .fs-control-btn { display: none !important; }

.fs-exit-btn {
    display: none;
    position: fixed; top: 1.5rem; left: 1.5rem;
    width: 48px; height: 48px; border-radius: 50%;
    background: var(--bg-card); border: 1px solid var(--border-color);
    color: var(--text-main); font-size: 1.25rem; font-weight: 700;
    align-items: center; justify-content: center;
    cursor: pointer; box-shadow: var(--shadow-md); z-index: 1100;
    transition: all 0.2s;
}
body.fullscreen .fs-exit-btn { display: flex; }
.fs-exit-btn:hover { background: var(--slate-100); transform: scale(1.05); }
[data-theme="dark"] .fs-exit-btn:hover { background: var(--slate-800); }

/* Responsive */
@media (max-width: 1024px) {
    .app-grid { grid-template-columns: 1fr; max-width: 700px; margin: 2rem auto; gap: 2.5rem; }
    .controls-panel { position: relative; top: 0; }
    .main-nav { display: none; }
    .mobile-menu-btn { display: block; }
    
    .mobile-menu {
        position: fixed; top: var(--header-height); left: 0; right: 0; bottom: 0;
        background: var(--bg-card); padding: 2rem; z-index: 999;
        display: none; overflow-y: auto;
    }
    .mobile-menu.open { display: block; }
    .mobile-menu h4 { margin-top: 1.5rem; color: var(--primary-600); font-size: 0.85rem; text-transform: uppercase; font-weight: 700; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
    .mobile-menu a { display: block; padding: 0.75rem 0; border-bottom: 1px solid var(--border-color); color: var(--text-main); font-weight: 600; font-size: 1rem; }
    
    .wheel-container { max-width: 100%; }
}

@media (max-width: 600px) {
    h1 { font-size: 2rem; }
    .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
    .app-grid { gap: 2rem; margin-top: 1.5rem; }
    .controls-panel { padding: 1rem; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

body.fullscreen header, body.fullscreen footer, body.fullscreen .controls-panel, 
body.fullscreen .breadcrumbs, body.fullscreen .content-section { display: none !important; }
body.fullscreen .app-grid { grid-template-columns: 1fr; margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; }
body.fullscreen .wheel-section { height: 100%; justify-content: center; }
body.fullscreen .wheel-container { max-width: 90vh; }
