/* ===== Brain Age — DS-Style Theme ===== */
:root {
    --bg:         #1a1a2e;
    --surface:    #16213e;
    --surface2:   #1e2a4a;
    --accent:     #667eea;
    --accent2:    #764ba2;
    --correct:    #2ed573;
    --error:      #ff4757;
    --text:       #e0e0e0;
    --text-muted: #8899bb;
    --border:     #2a2a4a;
    --hinge:      #0e0e1e;
    --radius:     14px;
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 12px 60px;
    user-select: none;
    -webkit-user-select: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Typography ===== */
.page-title {
    font-size: 2rem;
    letter-spacing: 5px;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}
.page-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ===== DS-Style Console Shell ===== */
.ds-console {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.ds-screen {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    position: relative;
    overflow: hidden;
}
.ds-screen.top { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.ds-screen.bottom { border-top-left-radius: 0; border-top-right-radius: 0; min-height: 220px; }
.ds-hinge {
    width: 100%;
    height: 8px;
    background: var(--hinge);
    border-left: 2px solid var(--border);
    border-right: 2px solid var(--border);
    position: relative;
}
.ds-hinge::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
}

/* ===== Top Bar (timer + progress) ===== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.timer { font-variant-numeric: tabular-nums; font-weight: 600; }
.progress-label { font-weight: 500; }

/* ===== Problem Display ===== */
.problem-text {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--text);
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.answer-display {
    font-size: 2.4rem;
    font-weight: 700;
    min-height: 50px;
    min-width: 80px;
    text-align: center;
    border-bottom: 3px solid var(--accent);
    margin-top: 8px;
    padding: 4px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
}
.answer-display.correct { border-bottom-color: var(--correct); color: var(--correct); }
.answer-display.wrong   { border-bottom-color: var(--error);   color: var(--error); }

/* ===== Numeric Keypad ===== */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 320px;
}
.numpad-btn {
    padding: 16px 0;
    font-size: 1.5rem;
    font-weight: 600;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    touch-action: manipulation;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.numpad-btn:hover { border-color: var(--accent); background: #22305a; }
.numpad-btn:active { transform: scale(0.95); background: #1a2848; }
.numpad-btn.action {
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}
.numpad-btn.action:hover { color: var(--text); }

/* ===== Stroop — Color Word ===== */
.stroop-word {
    font-size: 3.4rem;
    font-weight: 800;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}

/* ===== Stroop — Color Buttons (2×2 grid) ===== */
.color-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}
.color-btn {
    position: relative;
    padding: 20px 0;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 2px;
    border: 3px solid transparent;
    border-radius: 12px;
    color: #fff;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    min-height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.color-btn:hover { opacity: 0.9; transform: scale(1.03); }
.color-btn:active { transform: scale(0.95); }
.color-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.color-btn-label { font-size: 1.1rem; }
.color-btn-key {
    font-size: 0.65rem;
    opacity: 0.6;
    font-weight: 400;
    letter-spacing: 0;
}
.color-btn.correct-flash {
    border-color: #fff;
    box-shadow: 0 0 20px rgba(46,213,115,0.6);
    animation: btnPop 0.3s ease;
}
.color-btn.wrong-flash {
    border-color: var(--error);
    box-shadow: 0 0 20px rgba(255,71,87,0.6);
    animation: btnShake 0.35s ease;
}
@keyframes btnPop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}
@keyframes btnShake {
    0%   { transform: translateX(0); }
    20%  { transform: translateX(-6px); }
    40%  { transform: translateX(6px); }
    60%  { transform: translateX(-3px); }
    80%  { transform: translateX(3px); }
    100% { transform: translateX(0); }
}

/* ===== Countdown Overlay ===== */
.countdown-overlay {
    position: absolute;
    inset: 0;
    background: rgba(22, 33, 62, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    font-weight: 800;
    color: var(--accent);
    z-index: 10;
    animation: countPulse 0.8s ease-out;
}
@keyframes countPulse {
    0%   { transform: scale(1.6); opacity: 0.3; }
    50%  { opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== Flash Animations ===== */
.flash-correct {
    animation: flashGreen 0.35s ease;
}
@keyframes flashGreen {
    0%   { background: var(--surface); }
    30%  { background: rgba(46,213,115,0.2); }
    100% { background: var(--surface); }
}
.flash-wrong {
    animation: shakeRed 0.4s ease;
}
@keyframes shakeRed {
    0%   { transform: translateX(0);    background: var(--surface); }
    15%  { transform: translateX(-8px); background: rgba(255,71,87,0.2); }
    30%  { transform: translateX(8px);  }
    45%  { transform: translateX(-4px); }
    60%  { transform: translateX(4px);  background: rgba(255,71,87,0.1); }
    100% { transform: translateX(0);    background: var(--surface); }
}

/* ===== Buttons ===== */
.btn {
    padding: 12px 28px;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 1px;
}
.btn:hover { border-color: var(--accent); background: var(--surface2); transform: translateY(-2px); }
.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-color: transparent;
    color: #fff;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-2px); }
.btn-sm { padding: 8px 18px; font-size: 0.85rem; }

/* ===== Results Screen ===== */
.results {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}
.results h2 { font-size: 1.2rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 3px; }
.brain-age-display {
    font-size: 4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: revealAge 0.6s ease-out;
}
@keyframes revealAge {
    0%   { transform: scale(0.5); opacity: 0; }
    60%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.results-stats {
    display: flex;
    gap: 24px;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.results-stats span { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.results-stats strong { color: var(--text); font-size: 1.2rem; }
.results-actions { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.save-msg { font-size: 0.85rem; color: var(--text-muted); }
.save-msg.success { color: var(--correct); }
.save-msg.error { color: var(--error); }

/* ===== Game Cards (Index) ===== */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 520px;
    margin-top: 16px;
}
.game-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 18px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.game-card:hover { border-color: var(--accent); transform: translateY(-3px); text-decoration: none; }
.game-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
.game-card .card-icon { font-size: 2.4rem; }
.game-card .card-title { font-size: 1.1rem; font-weight: 700; }
.game-card .card-desc { font-size: 0.8rem; color: var(--text-muted); }
.game-card .card-badge {
    font-size: 0.7rem;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--surface2);
    color: var(--text-muted);
    align-self: center;
}

/* ===== Daily Stamps ===== */
.stamp-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 12px 0;
}
.stamp-day {
    width: 42px;
    height: 50px;
    border-radius: 8px;
    background: var(--surface);
    border: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: var(--text-muted);
    gap: 2px;
}
.stamp-day .day-label { font-weight: 600; text-transform: uppercase; }
.stamp-day .stamp-icon { font-size: 1rem; }
.stamp-day.completed {
    border-color: var(--error);
    background: rgba(255,71,87,0.1);
}
.stamp-day.completed .stamp-icon { color: var(--error); }
.stamp-day.today { border-color: var(--accent); }

/* ===== Dashboard Tabs ===== */
.dash-tabs {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin: 12px 0 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    max-width: 400px;
    width: 100%;
}
.dash-tab {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.dash-tab:hover { color: var(--text); background: var(--surface2); }
.dash-tab.active {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
}

/* ===== Dashboard ===== */
.dashboard-section {
    width: 100%;
    max-width: 600px;
    margin-bottom: 24px;
}
.dashboard-section h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 10px;
    text-align: center;
}
.stat-card .stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.stat-card .stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    position: relative;
    height: 280px;
}

.score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.score-table th, .score-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}
.score-table th {
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 1px;
}
.score-table tr:hover td { background: rgba(102,126,234,0.05); }

/* ===== Mini Stats (Index) ===== */
.mini-stats {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.mini-stats strong { color: var(--accent); }

/* ===== Back Link ===== */
.back-link {
    position: absolute;
    top: 18px;
    left: 18px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
    body { padding: 12px 8px 40px; }
    .page-title { font-size: 1.5rem; letter-spacing: 3px; }
    .problem-text { font-size: 2.4rem; }
    .answer-display { font-size: 2rem; }
    .numpad { gap: 6px; max-width: 280px; }
    .numpad-btn { padding: 14px 0; font-size: 1.3rem; min-height: 50px; }
    .ds-screen { padding: 14px; min-height: 150px; }
    .ds-screen.bottom { min-height: 200px; }
    .brain-age-display { font-size: 3rem; }
    .stamp-day { width: 36px; height: 44px; }
    .chart-container { height: 220px; }
    .stroop-word { font-size: 2.6rem; letter-spacing: 4px; }
    .color-buttons { gap: 8px; max-width: 280px; }
    .color-btn { padding: 16px 0; min-height: 60px; font-size: 1rem; }
}
