:root {
    /* Dark Theme (Default) */
    --bg: #050505;
    --surface: #111111;
    --border: #333333;
    --text: #ffffff;
    --text-dim: #888888;
    --accent: #ffffff;
    --error: #ff3333;
    --success: #00ff00;
}

[data-theme="light"] {
    /* Light Theme */
    --bg: #f9f9f9;
    --surface: #ffffff;
    --border: #dddddd;
    --text: #111111;
    --text-dim: #666666;
    --accent: #000000;
    --error: #d63031;
    --success: #00b894;
}

* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; font-family: 'Inter', 'Segoe UI', sans-serif; }

body { background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; display: flex; flex-direction: column; transition: background 0.3s, color 0.3s; }

/* Top Bar */
.top-bar { height: 60px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; padding: 0 2rem; background: var(--bg); z-index: 10; }
.brand { font-weight: 800; font-size: 1.2rem; letter-spacing: 1px; font-family: 'Segoe UI'}
.nav-right { display: flex; gap: 15px; align-items: center; }
.nav-item { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 8px 16px; font-size: 0.8rem; cursor: pointer; transition: 0.2s; text-transform: uppercase; letter-spacing: 1px; }
.nav-item:hover { border-color: var(--text); }
.icon-btn { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text); filter: grayscale(100%); opacity: 0.7; transition: 0.2s; }
.icon-btn:hover { opacity: 1; }

/* Info Panel */
.info-panel { position: absolute; top: 70px; right: 2rem; width: 300px; background: var(--surface); border: 1px solid var(--border); padding: 20px; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.info-header { font-size: 0.7rem; color: var(--text-dim); letter-spacing: 2px; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.info-panel p { font-size: 0.9rem; line-height: 1.5; color: var(--text); }

/* Layout & Scrolling Fixes */
.layout { display: flex; flex: 1; height: calc(100vh - 100px); }
.sidebar { width: 250px; border-right: 1px solid var(--border); padding: 20px; background: var(--bg); overflow-y: auto; }
.menu-label { color: var(--text-dim); font-size: 0.7rem; margin-bottom: 15px; letter-spacing: 2px; }
.menu-btn { display: block; width: 100%; padding: 12px 0; text-align: left; background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 0.95rem; border-bottom: 1px solid transparent; transition: 0.2s; }
.menu-btn:hover { color: var(--text); padding-left: 5px; }
.menu-btn.active { color: var(--text); border-bottom: 1px solid var(--text); font-weight: 700; }

/* Stage styling updated to allow proper top scrolling */
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; overflow-y: auto; padding: 40px 20px; }

/* Center these dynamically */
.welcome-screen, #game-mount { margin: auto; text-align: center; }

/* Footer */
.footer { height: 40px; border-top: 1px solid var(--border); background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 0.75rem; color: var(--text-dim); }
.text-link { cursor: pointer; color: var(--text); margin-left: 5px; text-decoration: underline transparent; transition: 0.2s; }
.text-link:hover { text-decoration-color: var(--text); }

/* Welcome Screen Dots */
.dots-container { display: flex; justify-content: center; align-items: center; gap: 15px; margin-bottom: 40px; flex-wrap: wrap;}
.big-dot { width: 80px; height: 80px; border-radius: 50%; background-color: var(--text); opacity: 100; transition: 0.3s; }
.welcome-screen p { color: var(--text-dim); font-size: 1.1rem; margin-right: 20%; margin-left: 20%; }

/* Buttons */
.btn { padding: 15px 40px; font-size: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; border: 1px solid var(--text); transition: 0.2s; margin: 5px; }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.primary:hover { opacity: 0.8; }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { border-color: var(--text); }

/* Privacy Policy Formatting */
.policy-doc { max-width: 800px; width: 100%; margin: 0 auto; padding-bottom: 60px; text-align: left; line-height: 1.6; user-select: text; }
.policy-doc h1 { font-size: 2rem; margin-bottom: 5px; }
.policy-doc h2 { font-size: 1.2rem; margin-top: 30px; margin-bottom: 10px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.policy-doc ul { margin-left: 20px; margin-bottom: 15px; color: var(--text-dim); }
.policy-doc p { color: var(--text-dim); margin-bottom: 10px; }

/* Game Specifics */
.target-box { width: 300px; height: 300px; border: 2px solid var(--border); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 2rem; font-weight: 800; cursor: pointer; transition: 0.1s; background: var(--surface); color: var(--text); }
.target-box.wait { border-color: var(--border); color: var(--text-dim); }
.target-box.ready { background: var(--error); border-color: var(--error); color: #fff; }
.target-box.go { background: var(--success); border-color: var(--success); color: #000; box-shadow: 0 0 40px rgba(0,255,0,0.2); }

.grid-system { display: grid; gap: 8px; margin: 20px auto; }
.cell { width: 80px; height: 80px; background: var(--surface); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 700; cursor: pointer; }
.cell.active { background: var(--text); color: var(--bg); }
.cell.good { background: var(--text); opacity: 0.8; }
.cell.bad { background: var(--error); border-color: var(--error); }

.typing-area { max-width: 600px; text-align: left; margin: auto; }
.typing-text { font-family: 'Courier New', monospace; font-size: 1.4rem; line-height: 1.6; color: var(--text-dim); margin-bottom: 20px; }
.typing-input { width: 100%; background: transparent; border: none; border-bottom: 2px solid var(--text); color: var(--text); font-family: 'Courier New', monospace; font-size: 1.4rem; padding: 10px 0; outline: none; user-select: text !important; }
.c-correct { color: var(--text); }
.c-wrong { color: var(--error); text-decoration: underline; }

.number-display { font-size: 5rem; letter-spacing: 10px; font-weight: 800; }
.stroop-word { font-size: 5rem; font-weight: 900; text-transform: uppercase; margin-bottom: 30px; letter-spacing: 2px; }

/* Professional Theme Switch */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    margin-right: 10px;
}

.theme-switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--surface);
    border: 1px solid var(--border);
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-dim);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: var(--text); }
input:checked + .slider:before {
    transform: translateX(22px);
    background-color: var(--bg);
}

/* Custom Confirmation Box Styling */
.confirm-box {
    max-width: 400px !important;
    border: 1px solid var(--error) !important;
}

.target-box.locked {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-dim);
    opacity: 0.6;
}

/* Modal & Tables */
.stats-table { width: 100%; max-width: 700px; border-collapse: collapse; margin-top: 20px; }
.stats-table th { text-align: left; color: var(--text-dim); padding: 10px; border-bottom: 1px solid var(--border); font-size: 0.8rem; }
.stats-table td { padding: 15px 10px; border-bottom: 1px solid var(--border); }
.hidden { display: none !important; }
.modal { position: absolute; inset: 0; background: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(5px); }
.modal-content { width: 100%; max-width: 500px; text-align: center; border: 1px solid var(--border); padding: 40px; background: var(--bg); }
.modal-header { color: var(--text-dim); font-size: 0.8rem; letter-spacing: 2px; margin-bottom: 20px; }
.score-display { font-size: 5rem; font-weight: 800; line-height: 1; margin-bottom: 40px; }
.score-display .unit { font-size: 1.5rem; color: var(--text-dim); font-weight: 400; }
.data-grid { display: flex; justify-content: space-between; margin-bottom: 40px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 20px 0; }
.label { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 5px; }
.value { font-size: 1.2rem; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* =========================================
   RESPONSIVE DESIGN (MOBILE & TABLET FIXES)
   ========================================= */
@media (max-width: 768px) {
    /* Layout & Navigation */
    body { height: auto; min-height: 100vh; overflow-y: auto; }
    .layout { flex-direction: column; height: auto; min-height: calc(100vh - 60px); }
    
    /* Make Sidebar a Horizontal Scrollable Menu */
    .sidebar { width: 100%; height: auto; padding: 10px 15px; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
    .menu-label { display: none; }
    #menu-list { display: flex; gap: 10px; padding-bottom: 5px; }
    .menu-btn { width: auto; white-space: nowrap; padding: 8px 12px; font-size: 0.85rem; border-bottom: 2px solid transparent; }
    .menu-btn:hover { padding-left: 12px; }
    .menu-btn.active { padding-left: 12px; border-bottom: 2px solid var(--text); }
    
    /* Header Fixes */
    .top-bar { padding: 0 1rem; }
    .brand { font-size: 1rem; }
    .nav-right { gap: 10px; }
    .nav-item { padding: 6px 10px; font-size: 0.7rem; }
    
    /* Main Stage & Globals */
    .stage { padding: 20px 10px; flex: 1; justify-content: flex-start; }
    .welcome-screen p { margin-right: 5%; margin-left: 5%; font-size: 1rem; }
    .target-box { width: 85vw; height: 85vw; max-width: 300px; max-height: 300px; font-size: 1.5rem; }
    
    /* Game Specific Adjustments */
    .typing-area { max-width: 100%; padding: 0 10px; }
    .typing-text, .typing-input { font-size: 1.1rem; }
    .number-display { font-size: 3.5rem; letter-spacing: 5px; }
    .stroop-word { font-size: 3.5rem; margin-bottom: 20px; }
    .grid-system { justify-content: center; }
    .cell { width: 100% !important; height: auto !important; aspect-ratio: 1/1; font-size: 1.2rem; }
    .est-opt { width: 100%; margin: 5px 0; }
    
    /* UI Elements */
    .info-panel { right: 5%; top: 60px; width: 90%; }
    .modal-content { padding: 25px 15px; width: 95%; margin: 10px; }
    .score-display { font-size: 4rem; }
    .data-grid { gap: 10px; padding: 15px 0; }
    .value { font-size: 1rem; }
    .modal-actions { flex-direction: column; }
    .btn { width: 100%; margin: 5px 0; }
    
    /* Stats Table */
    .stats-table th, .stats-table td { padding: 10px 5px; font-size: 0.75rem; }
    .stats-table { width: 100%; overflow-x: auto; display: block; }
}

/* Extra small screens (e.g. older/narrow iPhones) */
@media (max-width: 480px) {
    .brand { font-size: 0.85rem; letter-spacing: 0; }
    .nav-item { font-size: 0.65rem; padding: 5px 8px; }
    .score-display { font-size: 3rem; }
    .stats-table th, .stats-table td { font-size: 0.65rem; }
}
