:root {
  /* Color Palette - Light Mode */
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --secondary: #ec4899;
  --accent: #8b5cf6;
  --success: #10b981;
  --danger: #ef4444;
  
  --bg-page: #f0f2f5;
  --bg-surface: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.8);
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border: #e2e8f0;
  --divider: #f1f5f9;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 0 transparent; /* No glow in light mode */
  
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 9999px;
  
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --header-height: 72px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  /* Color Palette - Dark Mode */
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --secondary: #f472b6;
  --accent: #a78bfa;
  
  --bg-page: #0f172a;
  --bg-surface: #1e293b;
  --bg-glass: rgba(30, 41, 59, 0.8);
  
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-light: #94a3b8;
  
  --border: #334155;
  --divider: #1e293b;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; outline-color: var(--primary); -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-main);
  background: var(--bg-page);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

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

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 { color: var(--text-main); font-weight: 800; letter-spacing: -0.025em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); line-height: 1.1; margin-bottom: 1.5rem; }
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
p { margin-bottom: 1.5rem; color: var(--text-muted); }
a { color: var(--primary); text-decoration: none; font-weight: 600; transition: var(--transition); }
a:hover { color: var(--primary-hover); }

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

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

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

.logo { 
    font-size: 1.5rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 0.5rem; 
}
.logo span { color: var(--primary); }

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

nav ul { display: flex; gap: 1rem; list-style: none; align-items: center; }
nav a { 
    color: var(--text-muted); font-weight: 600; font-size: 0.95rem; 
    padding: 0.5rem 1rem; border-radius: var(--radius-full);
}
nav a:hover { color: var(--primary); background: rgba(99, 102, 241, 0.08); }
nav a.active { color: var(--primary); background: rgba(99, 102, 241, 0.1); }

/* Theme Toggle Button */
.theme-toggle {
    background: transparent; border: none; cursor: pointer;
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: var(--text-main);
    transition: var(--transition);
}
.theme-toggle:hover { background: var(--border); transform: rotate(15deg); }

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

/* --- Main Grid --- */
.app-grid { 
  display: grid; grid-template-columns: 1fr 400px; gap: 4rem; 
  padding: 3rem 0; align-items: flex-start; 
}

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

.wheel-container { 
  position: relative; width: 100%; max-width: 650px; aspect-ratio: 1; 
  display: flex; justify-content: center; align-items: center;
  filter: drop-shadow(0 25px 40px rgba(0,0,0,0.15));
  margin-bottom: 2rem;
  transition: transform 0.3s ease;
}
.wheel-container:hover { transform: scale(1.01); }

canvas { width: 100%; height: 100%; border-radius: 50%; cursor: grab; touch-action: none; }
canvas:active { cursor: grabbing; }

/* Pointer */
.pointer {
    position: absolute; top: 50%; right: -25px; transform: translateY(-50%);
    width: 60px; height: 60px; z-index: 20; pointer-events: none;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}
.pointer::before {
    content: ''; position: absolute; top: 50%; left: 18px; transform: translateY(-50%);
    width: 44px; height: 44px; background: radial-gradient(circle at 30% 30%, #f1f5f9, #94a3b8);
    border-radius: 50%; border: 3px solid #cbd5e1; z-index: 1;
    box-shadow: inset 0 -2px 5px rgba(0,0,0,0.1);
}
.pointer::after {
    content: ''; position: absolute; top: 50%; left: -5px; transform: translateY(-50%);
    border-style: solid; border-width: 16px 45px 16px 0; 
    border-color: transparent #ef4444 transparent transparent; z-index: 2;
}

/* Spin Button */
.center-spin-btn {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 90px; height: 90px; border-radius: 50%;
    background: var(--bg-surface);
    border: 6px solid var(--bg-surface);
    color: var(--primary); font-weight: 900; font-size: 1.3rem; letter-spacing: 1px;
    cursor: pointer; z-index: 30;
    box-shadow: 0 0 0 4px var(--border), 0 15px 35px rgba(0,0,0,0.2);
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    animation: pulse 3s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 4px var(--border), 0 15px 35px rgba(0,0,0,0.2); }
    50% { box-shadow: 0 0 0 8px var(--primary-hover), 0 15px 45px rgba(99, 102, 241, 0.4); }
    100% { box-shadow: 0 0 0 4px var(--border), 0 15px 35px rgba(0,0,0,0.2); }
}
.center-spin-btn:hover { 
    transform: translate(-50%, -50%) scale(1.1); color: var(--primary-hover); 
    background: var(--bg-page);
}
.center-spin-btn:disabled { 
    cursor: not-allowed; opacity: 0.8; animation: spin-load 1s linear infinite; 
    border-top-color: var(--primary); border-right-color: var(--border);
    border-bottom-color: var(--border); border-left-color: var(--border);
    background: transparent; color: transparent;
}
@keyframes spin-load { 0% { transform: translate(-50%, -50%) rotate(0deg); } 100% { transform: translate(-50%, -50%) rotate(360deg); } }

/* Toolbar */
.toolbar { display: flex; gap: 0.8rem; flex-wrap: wrap; justify-content: center; }
.icon-btn {
    background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-muted);
    border-radius: var(--radius-md); width: 48px; height: 48px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
    transition: var(--transition); box-shadow: var(--shadow-sm);
}
.icon-btn:hover { 
    background: var(--primary); color: #fff; border-color: var(--primary); 
    transform: translateY(-3px); box-shadow: var(--shadow-glow);
}
.icon-btn.active { background: var(--success); color: #fff; border-color: var(--success); }

/* --- Controls Panel --- */
.controls-panel {
    background: var(--bg-surface); padding: 1.5rem; border-radius: var(--radius-lg);
    border: 1px solid var(--border); box-shadow: var(--shadow-xl);
    position: sticky; top: 100px; max-height: calc(100vh - 120px); overflow-y: auto;
    transition: var(--transition);
}

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }

.tabs { 
    display: flex; background: var(--bg-page); padding: 5px; 
    border-radius: var(--radius-md); margin-bottom: 1.5rem; 
}
.tab-btn {
    flex: 1; background: transparent; border: none; padding: 0.8rem;
    color: var(--text-muted); font-weight: 700; border-radius: var(--radius-sm);
    cursor: pointer; transition: var(--transition);
}
.tab-btn.active { background: var(--bg-surface); color: var(--primary); box-shadow: var(--shadow-sm); }

.tab-content { display: none; animation: slideUp 0.3s ease; }
.tab-content.active { display: block; }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.action-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.btn-text {
    background: transparent; border: none; color: var(--primary); 
    font-weight: 700; font-size: 0.9rem; cursor: pointer; padding: 0.5rem;
    border-radius: var(--radius-sm); transition: var(--transition);
}
.btn-text:hover { background: rgba(99, 102, 241, 0.1); }

textarea {
    width: 100%; height: 320px; padding: 1rem; border-radius: var(--radius-md);
    border: 2px solid var(--border); background: var(--bg-page); color: var(--text-main);
    font-family: 'JetBrains Mono', monospace; font-size: 0.95rem; resize: vertical;
    transition: var(--transition); margin-bottom: 1.5rem;
}
textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1); }

/* Range Slider */
input[type=range] {
    width: 100%; height: 6px; background: var(--border); border-radius: var(--radius-full);
    outline: none; -webkit-appearance: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 20px; height: 20px; background: var(--primary);
    border-radius: 50%; box-shadow: 0 0 0 4px var(--bg-surface); transition: transform 0.2s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* History List */
.history-list { list-style: none; max-height: 350px; overflow-y: auto; }
.history-item {
    padding: 1rem; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    transition: background 0.2s;
}
.history-item:hover { background: var(--bg-page); }
.history-val { font-weight: 700; color: var(--text-main); }
.history-time { font-size: 0.8rem; color: var(--text-muted); }

/* --- Modal --- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(8px);
    z-index: 200; display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: all 0.4s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--bg-surface); padding: 3rem 2rem; border-radius: var(--radius-lg);
    text-align: center; width: 90%; max-width: 500px;
    box-shadow: var(--shadow-xl); border: 1px solid var(--border);
    transform: scale(0.9) translateY(20px); transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.winner-text {
    font-size: clamp(2.5rem, 8vw, 4rem); font-weight: 900; margin: 1.5rem 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    line-height: 1.1; word-wrap: break-word; text-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.modal-actions { display: flex; gap: 1rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }
.btn-primary, .btn-secondary {
    padding: 0.8rem 1.5rem; font-weight: 700; border-radius: var(--radius-md);
    cursor: pointer; border: none; transition: var(--transition); font-size: 1rem;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4); }
.btn-secondary { background: var(--bg-page); color: var(--text-main); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* --- Footer --- */
footer { background: var(--bg-surface); border-top: 1px solid var(--border); padding: 4rem 0 2rem; margin-top: auto; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 3rem; margin-bottom: 3rem; }
.footer-col h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-light); margin-bottom: 1.5rem; }
.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: 0.8rem; }
.footer-col a { color: var(--text-muted); font-weight: 500; font-size: 0.95rem; }
.footer-col a:hover { color: var(--primary); padding-left: 5px; }

/* --- Content Section --- */
.content-section { margin-top: 4rem; max-width: 800px; }
.content-section h1 { font-size: 2.5rem; margin-bottom: 1.5rem; background: linear-gradient(to right, var(--text-main), var(--text-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.content-section p { font-size: 1.1rem; line-height: 1.7; }

/* --- Breadcrumbs --- */
.breadcrumbs { 
    padding: 1rem 0; color: var(--text-light); font-size: 0.9rem; font-weight: 500;
}
.breadcrumbs span { margin: 0 0.5rem; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .app-grid { grid-template-columns: 1fr; max-width: 800px; margin: 0 auto; }
    .controls-panel { position: relative; top: 0; max-height: none; }
}

@media (max-width: 768px) {
    .nav-actions { display: none; } /* Hide desktop nav items */
    .mobile-menu-btn { display: block; }
    
    /* Mobile Menu */
    .nav-flex nav ul {
        position: fixed; top: var(--header-height); left: 0; width: 100%;
        background: var(--bg-surface); flex-direction: column; padding: 2rem;
        gap: 0; border-bottom: 1px solid var(--border);
        transform: translateY(-100%); opacity: 0; transition: all 0.3s ease;
        z-index: 90; pointer-events: none;
    }
    .nav-flex nav ul.open { transform: translateY(0); opacity: 1; pointer-events: all; box-shadow: var(--shadow-xl); }
    .nav-flex nav a { width: 100%; display: block; padding: 1rem; text-align: center; border-radius: var(--radius-sm); }
    
    .logo { font-size: 1.2rem; }
    .pointer { right: -15px; width: 45px; height: 45px; }
    .pointer::before { left: 12px; width: 34px; height: 34px; }
    .pointer::after { border-width: 12px 35px 12px 0; }
    
    h1 { font-size: 2rem; }
}

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

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