/* ============================================
   MUSIC THEORY PRACTICE - SHARED STYLES
   Common components for all apps
   ============================================ */

/* Font fallback with size-adjust to prevent CLS during font swap */
@font-face {
    font-family: 'Inter Fallback';
    src: local('Arial');
    size-adjust: 107%;
    ascent-override: 90%;
    descent-override: 22%;
    line-gap-override: 0%;
}

:root {
    /* Light mode colors */
    --primary: #14b8a6;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #e2e8f0;
    
    --blue: #3b82f6;
    --purple: #8b5cf6;
    --green: #10b981;
    --red: #ef4444;
    --orange: #f59e0b;
    --yellow: #eab308;
    --gray: #6b7280;
    --cyan: #06b6d4;
    
    /* Shadows */
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* Dark mode */
body.dark-mode {
    --primary: #5eead4; /* Brighter teal for visibility */
    --bg: #0f172a; /* Dark navy */
    --card: #1e293b; /* Slate card */
    --text: #f1f5f9; /* Almost white */
    --text-light: #cbd5e1; /* Lighter gray for better readability */
    --border: #475569; /* More visible borders */
    
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
}

/* Dark mode component overrides */
body.dark-mode .header {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .stat.success {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

body.dark-mode .stat.error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

body.dark-mode .stat.info {
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.3);
}

body.dark-mode .feedback-alert {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .feedback-alert.success {
    background: rgba(16, 185, 129, 0.15);
    border-color: #10b981;
    color: #6ee7b7;
}

body.dark-mode .feedback-alert.success .highlight-var {
    background: #10b981;
    color: white;
}

body.dark-mode .feedback-alert.error {
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
    color: #fca5a5;
}

body.dark-mode .feedback-alert.error .highlight-var {
    background: #ef4444;
    color: white;
}

body.dark-mode .feedback-alert.warning {
    background: rgba(234, 179, 8, 0.15);
    border-color: #eab308;
    color: #fde047;
}

body.dark-mode .feedback-alert.warning .highlight-var {
    background: #eab308;
    color: #1e293b;
    font-weight: 900;
}

body.dark-mode .flashcard {
    /* Must be --bg (not --card) so clipped corners show correct background */
    background: var(--bg);
    border-color: var(--border);
}

body.dark-mode .flashcard-back {
    background: var(--card);
    /* Use inset box-shadow instead of border so it follows clip-path */
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 40px rgba(0, 0, 0, 0.08),
        inset 0 0 0 2px #10b981;
}

body.dark-mode .answers {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .pill {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

body.dark-mode .pill:hover:not(:disabled) {
    background: var(--border);
    border-color: var(--primary);
}

body.dark-mode .mistakes {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .mistake {
    background: var(--bg);
}

body.dark-mode .btn-reset {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .icon-btn {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .mode-toggle {
    background: var(--bg);
}

body.dark-mode .modal {
    background: var(--card);
}

body.dark-mode .modal-stats {
    background: var(--bg);
}

body.dark-mode .modal-btn-secondary {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .modal-message.success {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

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

body {
    font-family: 'Inter', 'Inter Fallback', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 20px 0 20px; /* Remove bottom padding so footer sits at bottom */
    transition: background 0.3s, color 0.3s;
}

.app {
    max-width: 900px;
    width: 100%;
    flex: 1;
}

.footer {
    width: 100%;
    max-width: 100%;
}

.main-content {
    min-width: 0;
}

/* ============================================
   HEADER - Clean & Spacious
   ============================================ */
.header {
    background: var(--card);
    border-radius: 16px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.home-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text-light);
    transition: all 0.2s;
    text-decoration: none;
    flex-shrink: 0;
}

.home-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    transform: translateY(-2px);
}

.home-btn svg {
    width: 20px;
    height: 20px;
}

.title {
    font-size: 28px;
    font-weight: 900;
    color: var(--primary);
    margin: 0;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

.icon-btn.muted {
    opacity: 0.5;
}

.mode-toggle {
    display: inline-flex;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 4px;
}

.mode-btn {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    /* text-transform: uppercase; */
    letter-spacing: 0.5px;
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(20, 184, 166, 0.25);
}

/* Stats Bar - Integrated Bottom Row */
.stats-bar {
    display: flex;
    gap: 16px;
    align-items: center;
}

/* Reserve space for injected header elements to prevent CLS */
#header-controls:empty {
    min-height: 40px;
}

#stats-bar:empty {
    min-height: 40px;
}

.stats {
    display: flex;
    gap: 20px;
    flex: 1;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
    min-width: 0;
    flex-shrink: 1;
}

.stat {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-radius: 12px;
    flex: 1;
}

.stat-icon {
    font-size: 24px;
    line-height: 1;
}

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
    color: var(--text-light);
    opacity: 0.9;
    margin-bottom: 2px;
}

body.dark-mode .stat-label {
    opacity: 1;
    font-weight: 800;
}

body.dark-mode .stat.success .stat-label {
    color: #86efac;
}

body.dark-mode .stat.error .stat-label {
    color: #fca5a5;
}

body.dark-mode .stat.info .stat-label {
    color: #c4b5fd;
}

.stat-value {
    font-variant-numeric: tabular-nums;
    font-weight: 900;
    font-size: 28px;
    line-height: 1;
}

.stat.success { 
    background: #d1fae5;
}
.stat.success .stat-icon { color: var(--green); }
.stat.success .stat-label { color: #065f46; }
.stat.success .stat-value { color: var(--green); }

.stat.error { 
    background: #fee2e2;
}
.stat.error .stat-icon { color: var(--red); }
.stat.error .stat-label { color: #991b1b; }
.stat.error .stat-value { color: var(--red); }

.stat.info { 
    background: #ede9fe;
}
.stat.info .stat-icon { color: #8b5cf6; }
.stat.info .stat-label { color: #6b21a8; }
.stat.info .stat-value { color: #8b5cf6; }

/* ============================================
   BUTTONS
   ============================================ */
.login-btn {
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 700;
    border: 2px solid var(--primary);
    border-radius: 12px;
    background: white;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.login-btn:hover {
    background: var(--primary);
    color: white;
}

.btn-reset {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: white;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-reset:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

/* Login button - matches stat card style */
.btn-login {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 12px;
    border: none;
    background: #dbeafe;
    color: #1d4ed8;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-login:hover {
    background: #bfdbfe;
    transform: translateY(-1px);
}

.btn-login svg {
    width: 20px;
    height: 20px;
    color: #3b82f6;
    flex-shrink: 0;
}

/* Logged-in state - subtle, neutral */
.btn-login.logged-in {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-login.logged-in:hover {
    border-color: var(--primary);
}

.btn-login.logged-in svg {
    color: var(--primary);
}

/* Dark mode login button */
body.dark-mode .btn-login {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

body.dark-mode .btn-login:hover {
    background: rgba(59, 130, 246, 0.3);
}

body.dark-mode .btn-login svg {
    color: #60a5fa;
}

body.dark-mode .btn-login.logged-in {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
}

/* ============================================
   TIMER BADGE - On Flashcard
   ============================================ */
.timer-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--orange);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 800;
    font-size: 20px;
    z-index: 5;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    animation: slideInRight 0.3s ease-out;
}

.timer-badge-value {
    font-variant-numeric: tabular-nums;
}

.timer-badge.warning {
    background: var(--orange);
    animation: pulse 1s infinite;
}

.timer-badge.danger {
    background: var(--red);
    animation: pulse 0.5s infinite;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes flashcardRefresh {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.7;
        transform: scale(0.98);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Flashcard refresh animation class */
/* .flashcard.refreshing {
    animation: flashcardRefresh 0.4s ease-in-out;
} */

.flashcard.refreshing {
  animation: cardPop 0.25s ease-out;
}

@keyframes cardPop {
  0% { transform: scale(0.95); opacity: 0.5; }
  60% { transform: scale(1.03); opacity: 1; }
  100% { transform: scale(1); }
}


/* ============================================
   FEEDBACK ALERT - Always Visible
   ============================================ */
.feedback-alert-container {
    margin-bottom: 12px;
}

.feedback-alert {
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    box-shadow: var(--shadow);
    background: var(--card);
    color: var(--text);
    border: 2px solid var(--border);
    transition: all 0.3s;
}

.feedback-alert .highlight-var {
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
    margin: 0 2px;
}

.feedback-alert.success {
    background: #d1fae5;
    color: #065f46;
    border-color: #10b981;
}

.feedback-alert.success .highlight-var {
    background: #10b981;
    color: white;
}

.feedback-alert.error {
    background: #fee2e2;
    color: #991b1b;
    border-color: #ef4444;
}

.feedback-alert.error .highlight-var {
    background: #ef4444;
    color: white;
}

.feedback-alert.warning {
    background: #fef3c7;
    color: #92400e;
    border-color: #eab308;
}

.feedback-alert.warning .highlight-var {
    background: #eab308;
    color: white;
}

/* ============================================
   SIDEBAR - LEADERBOARD
   ============================================ */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.leaderboard {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.leaderboard-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border);
}

.leaderboard-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-size: 14px;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.rank {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-light);
    min-width: 24px;
}

.rank.top { color: var(--orange); }

.player-info {
    flex: 1;
}

.player-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.player-score {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

/* ============================================
   GAME FOOTER
   ============================================ */
.game-footer {
    display: flex;
    gap: 16px;
    margin-top: 20px;
}

.game-footer .btn-reset {
    flex-shrink: 0;
}

/* ============================================
   MISTAKES LOG - Elegant Integration
   ============================================ */
.mistakes {
    flex: 1;
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.3s;
}

.mistakes summary {
    list-style: none;
}

.mistakes summary::-webkit-details-marker {
    display: none;
}

.mistakes-header {
    padding: 14px 18px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.mistakes-header:hover {
    background: var(--bg);
}

.mistakes-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.mistakes-toggle {
    font-size: 14px;
    color: var(--text-light);
    transition: transform 0.2s;
}

.mistakes[open] .mistakes-toggle {
    transform: rotate(180deg);
}

.mistakes-content {
    max-height: 240px;
    overflow-y: auto;
    padding: 12px;
}

.mistake {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
    border-left: 3px solid var(--red);
}

.mistake-info {
    flex: 1;
}

.mistake-q {
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
}

.mistake-details {
    font-size: 12px;
    margin-bottom: 3px;
}

.mistake-answered {
    color: var(--red);
    font-weight: 600;
}

.mistake-answered.enharmonic {
    color: var(--yellow);
}

.mistake-correct {
    color: var(--green);
    font-weight: 600;
}

.mistake-count {
    background: var(--red);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-weight: 800;
    font-size: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty {
    text-align: center;
    padding: 30px;
    color: var(--text-light);
    font-size: 14px;
}

/* ============================================
   COMMON FLASHCARD STYLES
   Shared across all flashcard apps
   ============================================ */

/* Flashcard Container */
.flashcard-container {
    perspective: 1000px;
    margin: 0 auto 12px;
    max-width: 600px;
    min-height: 240px;
    /* Background to fill the clipped corner area */
    background: var(--bg);
    border-radius: 12px;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 240px;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    /* Background to show through clipped corners */
    background: var(--bg);
    border-radius: 12px;
}

/* Reserve exact space for VexFlow notation to prevent CLS */
.notation-container {
    min-height: 160px; /* Match VexFlow renderer.resize(380, 160) */
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background: var(--card);
    border-radius: 12px;
    padding: 32px;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 40px rgba(0, 0, 0, 0.08),
        inset 0 0 0 2px var(--border);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: background 0.3s;
    /* Dog-ear corner clip */
    clip-path: polygon(0 0, calc(100% - 28px) 0, 100% 28px, 100% 100%, 0 100%);
    border-radius: 12px 0 12px 12px;
}

/* Fold shadow - Light mode (front only - back has its own) */
body:not(.dark-mode) .flashcard-front::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 28px 0 0 28px;
    border-color: transparent transparent transparent rgba(0, 0, 0, 0.05);
    z-index: 1;
}

/* Fold shadow - Dark mode (front only - back has its own) */
body.dark-mode .flashcard-front::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 28px 0 0 28px;
    border-color: transparent transparent transparent rgba(255, 255, 255, 0.03);
    z-index: 1;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, #d1fae5 0%, #ccfbf1 100%);
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.05),
        0 10px 40px rgba(0, 0, 0, 0.08),
        inset 0 0 0 2px var(--green);
    /* Dog-ear on LEFT side for back (since card is flipped) */
    clip-path: polygon(28px 0, 100% 0, 100% 100%, 0 100%, 0 28px);
    border-radius: 0 12px 12px 12px;
}

/* Fold shadow for back - on LEFT side */
body:not(.dark-mode) .flashcard-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: auto;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 28px 28px 0 0;
    border-color: rgba(0, 0, 0, 0.05) transparent transparent transparent;
    z-index: 1;
}

body.dark-mode .flashcard-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: auto;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 28px 28px 0 0;
    border-color: rgba(255, 255, 255, 0.03) transparent transparent transparent;
    z-index: 1;
}

.flashcard.blank .question-text,
.flashcard.blank .highlight {
    opacity: 0;
}

/* Countdown Overlay */
.countdown-overlay {
    position: absolute;
    inset: 0;
    background: rgba(20, 184, 166, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 12px;
    z-index: 10;
}

.countdown-number {
    font-size: 120px;
    font-weight: 900;
    color: white;
    animation: countdownPulse 1s ease-in-out;
}

.countdown-label {
    font-size: 20px;
    font-weight: 700;
    color: white;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Hint Button */
.hint-controls {
    text-align: center;
    margin-bottom: 12px;
}

.hint-btn {
    padding: 10px 28px;
    font-size: 14px;
    font-weight: 700;
    border-radius: 20px;
    border: 2px solid var(--orange);
    background: white;
    color: var(--orange);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: var(--shadow);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body.dark-mode .hint-btn {
    background: var(--card);
}

.hint-btn:hover:not(:disabled) {
    background: var(--orange);
    color: white;
    transform: translateY(-1px);
}

.hint-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--text-light);
    color: var(--text-light);
}

/* Answer Section */
.answers {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

body.dark-mode .answers {
    background: var(--card);
    border-color: var(--border);
}

.section-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text);
    margin-bottom: 16px;
    text-align: center;
}

/* Answer Feedback States */
.pill.correct {
    background: #10b981 !important;
    border-color: #10b981 !important;
    color: white !important;
    animation: pop 0.3s;
}

.pill.incorrect {
    background: #ef4444 !important;
    border-color: #ef4444 !important;
    color: white !important;
    animation: shake 0.3s;
}

.pill.enharmonic {
    background: #f59e0b !important;
    border-color: #f59e0b !important;
    color: white !important;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes countdownPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
}

@keyframes pop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.8); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes slideDown {
    0% {
        transform: translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
    padding: 20px;
}

.modal {
    background: white;
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease-out;
    text-align: center;
}

.modal-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 16px;
}

.modal-score {
    font-size: 64px;
    font-weight: 900;
    color: var(--primary);
    margin: 20px 0;
    font-variant-numeric: tabular-nums;
}

.modal-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 24px 0;
    padding: 20px;
    background: var(--bg);
    border-radius: 12px;
}

.modal-stat {
    text-align: center;
}

.modal-stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.modal-stat-value {
    font-size: 32px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.modal-stat.correct .modal-stat-value { color: var(--green); }
.modal-stat.incorrect .modal-stat-value { color: var(--red); }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 32px;
}

.modal-btn {
    flex: 1;
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-btn-primary {
    background: var(--primary);
    color: white;
}

.modal-btn-primary:hover {
    background: #0f9984;
    transform: translateY(-2px);
}

.modal-btn-secondary {
    background: white;
    color: var(--text);
    border: 2px solid var(--border);
}

.modal-btn-secondary:hover {
    border-color: var(--primary);
}

.modal-leaderboard-prompt {
    margin: 24px 0;
}

.modal-message {
    background: var(--bg);
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.modal-message.success {
    background: rgba(16, 185, 129, 0.15);
    color: #065f46;
    border: 2px solid #10b981;
}

body.dark-mode .modal-message.success {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
}

.modal-icon {
    font-size: 20px;
}

.modal-btn-login {
    width: 100%;
    background: #4285f4;
    color: white;
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.modal-btn-login:hover:not(:disabled) {
    background: #3367d6;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(66, 133, 244, 0.3);
}

.modal-btn-login:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-icon {
    font-size: 18px;
}

body.dark-mode .modal {
    background: var(--card);
}

body.dark-mode .modal-stats {
    background: var(--bg);
}

body.dark-mode .modal-btn-secondary {
    background: var(--card);
    border-color: var(--border);
}

@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes slideUp {
    0% {
        transform: translateY(30px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.controls {
    text-align: center;
    margin-bottom: 20px;
}

/* ============================================
   UTILITIES
   ============================================ */
.hidden { 
    display: none !important; 
}

.controls {
    text-align: center;
    margin-bottom: 20px;
}

/* ============================================
   RESPONSIVE - MOBILE FIRST
   ============================================ */
@media (max-width: 1024px) {
    body {
        padding: 12px;
    }
    
    .sidebar {
        order: 2;
    }
}


@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .app {
        gap: 12px;
    }

    /* --- Header layout: two rows --- */
    .header {
        padding: 16px 20px;
    }
    /* Row 1: title row stays as-is */
    .header-content {
        display: flex;
        flex-direction: column;
        gap: 10px;
        align-items: center;  /* center the logo+title line */
    }

    .header-left {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
    }

    .title {
        font-size: 24px;
    }

    .header-right {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;   /* <--- THE IMPORTANT PART */
        gap: 12px;

        width: 100%;
        margin-top: 4px;
    }

    /* keep icons tidy */
    .icon-btn {
        width: 38px;
        height: 38px;
        font-size: 18px;
        flex-shrink: 0;
    }

    /* mode-toggle no longer floats far right */
    .mode-toggle {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;

        flex: 0 0 auto;
        white-space: nowrap;
        width: auto;
    }


 .mode-btn {
        flex: 0 0 auto;
        padding: 8px 14px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* --- Stats bar & buttons --- */
    .stats-bar {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .stats {
        display: flex;
        flex: 1 1 0;
        min-width: 0;
        gap: 6px;
    }

    .stat {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 10px;
        gap: 6px;
    }

    .stat-icon {
        font-size: 16px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 9px;
    }

    /* Compact pill Login on tablets */
    .btn-login {
        padding: 8px 12px;
        font-size: 12px;
        gap: 6px;
        border-radius: 10px;
    }

    .btn-login svg {
        width: 16px;
        height: 16px;
    }

    /* Prevent mode-toggle from stretching too wide */
    .mode-toggle {
        flex: 0 0 auto;
        width: auto;
    }

    /* Make buttons size themselves to their text only */
    .mode-btn {
        flex: 0 0 auto;
        width: auto;
        font-size: 12px;
        padding: 8px 12px;
    }
}



/* Mobile - Small screens (iPhone SE, etc) */
@media (max-width: 480px) {
    body {
        padding: 12px;
    }
    
    .app {
        max-width: 100%;
    }
    
    .title {
        font-size: 20px;
    }
    
    .header {
        padding: 12px 16px;
        margin-bottom: 12px;
    }

    /* Icon-only login on small phones */
    .btn-login {
        padding: 6px;
        font-size: 0;
        border-radius: 8px;
        min-width: 32px;
        min-height: 32px;
        justify-content: center;
    }

    .btn-login svg {
        width: 18px;
        height: 18px;
    }

    .header-content {
        gap: 10px;
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .home-btn {
        width: 34px;
        height: 34px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        font-size: 16px;
    }

    .mode-toggle {
        padding: 2px;
    }

    .mode-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .stat {
        padding: 6px 8px;
        gap: 4px;
    }

    .stat-icon {
        font-size: 14px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 8px;
        letter-spacing: 0.3px;
    }
    
    .feedback-alert {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    .flashcard {
        height: 200px;
    }
    
    .question-text {
        font-size: 15px;
    }
    
    .highlight {
        font-size: 32px;
    }
    
    .hint-btn {
        padding: 8px 20px;
        font-size: 13px;
    }
    
    .answers {
        padding: 16px;
    }
    
    .section-label {
        font-size: 11px;
        margin-bottom: 12px;
    }
    
    .pill {
        padding: 10px 14px;
        font-size: 14px;
        min-width: 52px;
    }
    
    .row-label {
        font-size: 14px;
        min-width: 20px;
    }
    
    .game-footer {
        flex-direction: column;
        gap: 12px;
    }
    
    .mistakes {
        width: 100%;
    }
    
    .modal {
        padding: 24px;
    }
    
    .modal-title {
        font-size: 24px;
    }
    
    .modal-score {
        font-size: 48px;
    }
}

/* Mobile landscape optimization */
@media (max-height: 600px) and (orientation: landscape) {
    .header {
        padding: 12px 16px;
    }

    .flashcard {
        height: 160px;
    }

    .stats-bar {
        display: none; /* Hide stats in landscape to save space */
    }

    .feedback-alert {
        padding: 8px 16px;
        font-size: 13px;
    }
}

/* ============================================
   FOOTER (Compact)
   ============================================ */
.footer {
    margin-top: 32px;
    padding: 16px 24px 20px; /* Extra bottom padding since body has none */
    border-top: 1px solid var(--border);
    background: var(--card);
    width: 100vw; /* Full viewport width */
    margin-left: calc(-50vw + 50%); /* Center and extend to edges */
    margin-right: calc(-50vw + 50%);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.footer-brand {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.footer-nav {
    display: flex;
    gap: 24px;
}

.footer-nav a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.2s;
}

.footer-nav a:hover {
    color: var(--primary);
}

.footer-copyright {
    font-size: 12px;
    color: var(--text-light);
}

@media (max-width: 768px) {
    .footer {
        padding: 16px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .footer-nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 16px;
    }
}

/* ============================================
   LEADERBOARD TABLE
   ============================================ */
.leaderboard-section {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.3s;
    margin-top: 16px;
}

.leaderboard-section summary {
    list-style: none;
}

.leaderboard-section summary::-webkit-details-marker {
    display: none;
}

.leaderboard-header {
    padding: 14px 18px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.leaderboard-header:hover {
    background: var(--bg);
}

.leaderboard-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.leaderboard-toggle {
    font-size: 14px;
    color: var(--text-light);
    transition: transform 0.2s;
}

.leaderboard-section[open] .leaderboard-toggle {
    transform: rotate(180deg);
}

.leaderboard-content {
    padding: 0;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.leaderboard-table thead {
    background: var(--bg);
}

.leaderboard-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    border-bottom: 1px solid var(--border);
}

.leaderboard-table th:first-child {
    width: 50px;
    text-align: center;
}

.leaderboard-table th:last-child,
.leaderboard-table th:nth-child(3) {
    text-align: right;
}

.leaderboard-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.leaderboard-table tbody tr:last-child td {
    border-bottom: none;
}

.leaderboard-table tbody tr:hover {
    background: var(--bg);
}

.leaderboard-table .rank-cell {
    text-align: center;
    font-weight: 700;
    font-size: 16px;
}

.leaderboard-table .player-cell {
    font-weight: 600;
    color: var(--text);
}

.leaderboard-table .accuracy-cell {
    text-align: right;
    font-weight: 700;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.leaderboard-table .score-cell {
    text-align: right;
    color: var(--text-light);
    font-variant-numeric: tabular-nums;
}

/* Rank styling */
.leaderboard-table tr.rank-1 {
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.1) 0%, transparent 100%);
}

.leaderboard-table tr.rank-2 {
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.1) 0%, transparent 100%);
}

.leaderboard-table tr.rank-3 {
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.1) 0%, transparent 100%);
}

/* Current user highlight */
.leaderboard-table tr.current-user {
    background: rgba(20, 184, 166, 0.1);
    border-left: 3px solid var(--primary);
}

.leaderboard-table tr.current-user .player-cell {
    color: var(--primary);
}

.leaderboard-table tr.current-user .player-cell::after {
    content: ' (You)';
    font-size: 11px;
    color: var(--text-light);
    font-weight: 500;
}

/* Empty state */
.leaderboard-table .leaderboard-empty td {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
    font-style: italic;
}

.leaderboard-footer {
    padding: 12px 16px;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

/* Subtle Login CTA for Leaderboard */
.leaderboard-login-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.05) 0%, rgba(79, 70, 229, 0.02) 100%);
    border-top: 1px solid var(--border);
}

.leaderboard-login-cta .cta-text {
    font-size: 13px;
    color: var(--text-light);
}

.leaderboard-login-cta .cta-login-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.leaderboard-login-cta .cta-login-btn:hover {
    background: var(--bg);
    border-color: var(--primary);
    color: var(--primary);
}

.leaderboard-login-cta .cta-login-btn svg {
    flex-shrink: 0;
}

body.dark-mode .leaderboard-login-cta {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1) 0%, rgba(79, 70, 229, 0.03) 100%);
}

body.dark-mode .leaderboard-login-cta .cta-login-btn {
    background: var(--bg);
    border-color: var(--border);
}

body.dark-mode .leaderboard-login-cta .cta-login-btn:hover {
    background: var(--card);
    border-color: var(--primary);
}

.view-all-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: opacity 0.2s;
}

.view-all-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Dark mode leaderboard */
body.dark-mode .leaderboard-section {
    background: var(--card);
    border-color: var(--border);
}

body.dark-mode .leaderboard-header {
    background: var(--card);
}

body.dark-mode .leaderboard-header:hover {
    background: var(--bg);
}

body.dark-mode .leaderboard-table thead {
    background: var(--bg);
}

body.dark-mode .leaderboard-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .leaderboard-table tr.current-user {
    background: rgba(20, 184, 166, 0.15);
}

body.dark-mode .leaderboard-footer {
    background: var(--bg);
}

/* ============================================
   MODAL RANK & PERSONAL BEST
   ============================================ */
.modal-rank-section {
    margin: 16px 0;
}

.modal-rank {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin: 12px 0;
}

.modal-personal-best {
    font-size: 16px;
    font-weight: 600;
    color: var(--orange);
    margin: 8px 0;
    animation: pop 0.5s ease-out;
}

.modal-message.saving {
    background: var(--bg);
    border: none;
}

.modal-message.saving .spinner,
.modal-btn-login .spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

.modal-message.error {
    background: rgba(239, 68, 68, 0.15);
    color: #991b1b;
    border: 2px solid #ef4444;
}

body.dark-mode .modal-message.error {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Login button logged-in state */
.btn-login.logged-in {
    background: rgba(66, 133, 244, 0.1);
    border-color: #4285F4;
    color: #4285F4;
}

.btn-login.logged-in:hover {
    background: rgba(66, 133, 244, 0.15);
}

body.dark-mode .btn-login.logged-in {
    background: rgba(66, 133, 244, 0.2);
}

/* ============================================
   TOAST NOTIFICATIONS
   Slide-in notifications for login/logout feedback
   ============================================ */

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    padding: 12px 24px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
    z-index: 10000;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast-success {
    background: #10b981;
    color: white;
}

.toast-error {
    background: #ef4444;
    color: white;
}

.toast-info {
    background: #3b82f6;
    color: white;
}

.toast-icon {
    font-size: 16px;
    font-weight: 700;
}

.toast-message {
    white-space: nowrap;
}

/* Dark mode toast adjustments */
body.dark-mode .toast {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 480px) {
    .toast {
        left: 16px;
        right: 16px;
        transform: translateX(0) translateY(-100px);
        justify-content: center;
    }

    .toast.show {
        transform: translateX(0) translateY(0);
    }
}

/* ============================================
   LOGIN HINT (Subtle Header CTA)
   Inline row in header to encourage sign-in
   ============================================ */

.login-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-light);
    border-top: 1px solid var(--border);
    background: var(--bg);
    margin-top: 5px;
}

.login-hint-text {
    display: inline;
}

.login-hint-text a {
    color: var(--primary);
    font-weight: 500;
    text-decoration: none;
}

.login-hint-text a:hover {
    text-decoration: underline;
}

.login-hint-dismiss {
    background: none;
    border: none;
    font-size: 16px;
    color: var(--text-light);
    cursor: pointer;
    opacity: 0.5;
    padding: 2px 6px;
    line-height: 1;
    transition: opacity 0.2s;
}

.login-hint-dismiss:hover {
    opacity: 1;
}

/* Dark mode login hint */
body.dark-mode .login-hint {
    background: var(--card);
}

/* Mobile responsive */
@media (max-width: 600px) {
    .login-hint {
        font-size: 11px;
        padding: 6px 12px;
        gap: 8px;
    }
}

/* ============================================
   AD CONTAINER
   Styling for AdSense placements
   ============================================ */

.ad-container {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg);
    border-radius: 12px;
    text-align: center;
    min-height: 100px;
}

.ad-container::before {
    content: 'Advertisement';
    display: block;
    font-size: 10px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    opacity: 0.7;
}

/* Dark mode ad container */
body.dark-mode .ad-container {
    background: var(--card);
    border: 1px solid var(--border);
}

/* Hide empty ad containers (when ads fail to load) */
.ad-container:empty::before {
    display: none;
}

.ad-container:empty {
    display: none;
}
