/* Fredoka — child-friendly Google Font (loaded locally, no CDN) */
@font-face {
    font-family: 'Fredoka';
    src: url('fonts/fredoka-latin-ext.woff2') format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Fredoka';
    src: url('fonts/fredoka-latin.woff2') format('woff2');
    font-weight: 300 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================
   THEME SYSTEM: CSS Custom Properties
   ============================================ */

:root,
[data-theme="island"] {
    --bg-gradient: linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #96CEB4, #FFEAA7, #FD79A8);
    --bg-anim-duration: 18s;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    --text-primary: #222;
    --text-secondary: #444;
    --text-muted: #64748b;
    --text-heading: #1e293b;
    --text-subheading: #334155;
    --surface: #f8fafc;
    --surface-alt: #f1f5f9;
    --surface-muted: #e2e8f0;
    --input-border: #ffd93d;
    --input-focus: #ff9f1c;
    --focus-ring: rgba(255, 159, 28, 0.3);
    --option-bg: #e2e8f0;
    --option-hover: #cbd5f5;
    --option-correct-bg: #bbf7d0;
    --option-correct-border: #22c55e;
    --option-incorrect-bg: #fee2e2;
    --option-incorrect-border: #ef4444;
    --feedback-correct-bg: #ecfdf3;
    --feedback-correct-text: #166534;
    --feedback-correct-border: rgba(34, 197, 94, 0.5);
    --feedback-incorrect-bg: #fef2f2;
    --feedback-incorrect-text: #991b1b;
    --feedback-incorrect-border: rgba(239, 68, 68, 0.5);
    --bubble-bg: rgba(255, 255, 255, 0.5);
    --star-bg: radial-gradient(circle, #fff 0%, rgba(255,255,255,0) 60%);
    --toggle-bg: #0f172a;
    --btn-mode-bg: linear-gradient(135deg, #fff, #FFEAA7);
    --btn-mode-text: #333;
    --tab-bg: #fff;
    --tab-border: #e2e8f0;
    --tab-text: #64748b;
    --tab-active-border: #FF9F1C;
    --tab-active-bg: #fff7e6;
    --tab-active-text: #92400e;
    --leaderboard-bg: #f8fafc;
    --leaderboard-highlight: #fef9c3;
    --card-white: #ffffff;
    --column-display-bg: linear-gradient(135deg, #ffffff, #f8fafc);
    --column-display-border: #e2e8f0;
    --numpad-bg: linear-gradient(135deg, #f8fafc, #e2e8f0);
    --numpad-text: #334155;
    --numpad-hover: linear-gradient(135deg, #ffffff, #f1f5f9);
    --tl-card-bg: rgba(255, 255, 255, 0.92);
    --tl-preview-bg: linear-gradient(135deg, #f8fafc, #f1f5f9);
    --tl-preview-border: #e2e8f0;
    --fraction-bar: #334155;
    --fraction-part-bg: #f1f5f9;
    --motivational-bg: #fef9c3;
    --motivational-border: #facc15;
    --results-lb-bg: linear-gradient(135deg, #ffedd5, #fef3c7);
    --decimal-box-bg: #f1f5f9;
    --decimal-box-border: #e2e8f0;
    --decimal-box-text: #1e293b;
}

[data-theme="deepsea"] {
    --bg-gradient: linear-gradient(45deg, #0f172a, #1e293b, #0c4a6e, #164e63, #1e3a5f, #0f172a);
    --bg-anim-duration: 30s;
    --card-bg: rgba(15, 23, 42, 0.95);
    --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --text-heading: #e2e8f0;
    --text-subheading: #cbd5e1;
    --surface: #1e293b;
    --surface-alt: #1e293b;
    --surface-muted: #334155;
    --input-border: #475569;
    --input-focus: #38bdf8;
    --focus-ring: rgba(56, 189, 248, 0.3);
    --option-bg: #334155;
    --option-hover: #475569;
    --option-correct-bg: #064e3b;
    --option-correct-border: #10b981;
    --option-incorrect-bg: #450a0a;
    --option-incorrect-border: #f87171;
    --feedback-correct-bg: #064e3b;
    --feedback-correct-text: #a7f3d0;
    --feedback-correct-border: rgba(16, 185, 129, 0.6);
    --feedback-incorrect-bg: #450a0a;
    --feedback-incorrect-text: #fecaca;
    --feedback-incorrect-border: rgba(248, 113, 113, 0.6);
    --bubble-bg: rgba(56, 189, 248, 0.15);
    --star-bg: radial-gradient(circle, rgba(56, 189, 248, 0.5) 0%, rgba(56, 189, 248, 0) 60%);
    --toggle-bg: #334155;
    --btn-mode-bg: linear-gradient(135deg, #1e293b, #334155);
    --btn-mode-text: #e2e8f0;
    --tab-bg: #1e293b;
    --tab-border: #334155;
    --tab-text: #94a3b8;
    --tab-active-border: #38bdf8;
    --tab-active-bg: #0c4a6e;
    --tab-active-text: #bae6fd;
    --leaderboard-bg: #1e293b;
    --leaderboard-highlight: #1e3a5f;
    --card-white: #1e293b;
    --column-display-bg: linear-gradient(135deg, #1e293b, #0f172a);
    --column-display-border: #334155;
    --numpad-bg: linear-gradient(135deg, #1e293b, #334155);
    --numpad-text: #e2e8f0;
    --numpad-hover: linear-gradient(135deg, #334155, #475569);
    --tl-card-bg: rgba(30, 41, 59, 0.92);
    --tl-preview-bg: linear-gradient(135deg, #1e293b, #0f172a);
    --tl-preview-border: #334155;
    --fraction-bar: #94a3b8;
    --fraction-part-bg: #334155;
    --motivational-bg: #1e3a5f;
    --motivational-border: #38bdf8;
    --results-lb-bg: linear-gradient(135deg, #1e293b, #0c4a6e);
    --decimal-box-bg: #334155;
    --decimal-box-border: #475569;
    --decimal-box-text: #e2e8f0;
}

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

/* ACCESSIBILITY: Skip to main content link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toggle-bg);
    color: #fff;
    padding: 12px 24px;
    border-radius: 0 0 12px 12px;
    z-index: 9999;
    text-decoration: none;
    font-weight: bold;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* ACCESSIBILITY: Focus indicators for keyboard navigation */
*:focus-visible {
    outline: 3px solid var(--input-focus);
    outline-offset: 2px;
}

button:focus-visible,
.btn:focus-visible,
.option:focus-visible,
.avatar-option:focus-visible,
.diff-btn:focus-visible {
    outline: 3px solid var(--input-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px var(--focus-ring);
}

input:focus-visible {
    outline: none;
    border-color: var(--input-focus);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

body {
    font-family: 'Fredoka', 'Comic Sans MS', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-gradient);
    background-size: 400% 400%;
    animation: gradientShift var(--bg-anim-duration) ease infinite;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--text-primary);
}

/* Background animation */

.background-animation {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: -1;
}

.bubble,
.star {
    position: absolute;
    border-radius: 50%;
    opacity: 0.35;
    animation: floatUp 20s linear infinite;
}

.bubble {
    background: var(--bubble-bg);
    width: 80px;
    height: 80px;
}

.bubble:nth-child(1) { left: 10%; animation-duration: 24s; }
.bubble:nth-child(2) { left: 30%; animation-duration: 17s; }
.bubble:nth-child(3) { left: 50%; animation-duration: 21s; }
.bubble:nth-child(4) { left: 70%; animation-duration: 19s; }
.bubble:nth-child(5) { left: 85%; animation-duration: 23s; }

.star {
    background: var(--star-bg);
    width: 50px;
    height: 50px;
    animation: twinkle 5s ease-in-out infinite alternate;
}

.star:nth-child(6) { top: 10%; left: 20%; }
.star:nth-child(7) { top: 35%; left: 75%; }
.star:nth-child(8) { top: 65%; left: 40%; }

@keyframes gradientShift {
    0% { background-position: 0 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

@keyframes floatUp {
    0% { transform: translateY(100vh) scale(0.7); }
    100% { transform: translateY(-120px) scale(1.1); }
}

@keyframes twinkle {
    0% { opacity: 0.1; transform: scale(0.8); }
    50% { opacity: 0.7; transform: scale(1); }
    100% { opacity: 0.3; transform: scale(0.9); }
}

/* Layout */

.game-wrapper {
    max-width: 1100px;
    width: 100%;
}

.game-card {
    background: var(--card-bg);
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    padding: 24px;
    position: relative;
    overflow: hidden;
}

/* Screens */

.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Typography */

.rainbow-text {
    background: linear-gradient(to right, #FF6B6B, #FFD93D, #6BCF7F, #4ECDC4, #A8E6CF, #FF8B94);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    font-size: 3rem;
    margin-bottom: 10px;
    animation: rainbow 3s linear infinite;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.tagline {
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

@keyframes rainbow {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

/* Inputs and form bits */

.player-setup {
    margin-bottom: 16px;
}

.label {
    display: block;
    font-weight: bold;
    margin-bottom: 6px;
}

.input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 2px solid var(--input-border);
    font-size: 1rem;
    outline: none;
    transition: box-shadow 0.2s, border-color 0.2s;
    background: var(--surface);
    color: var(--text-primary);
}

.input:focus {
    border-color: #ff9f1c;
    box-shadow: 0 0 0 3px rgba(255,159,28,0.3);
}

/* Avatar picker */

.avatar-section {
    margin-bottom: 20px;
}

.avatar-heading {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.avatar-picker {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
    gap: 10px;
}

.avatar-option {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: radial-gradient(circle at top left, #FFEAA7, #FF6B6B);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}

.avatar-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 10px rgba(0,0,0,0.2);
}

.avatar-option.selected {
    border-color: #ffd93d;
    box-shadow: 0 0 0 3px rgba(255,217,61,0.7);
}

/* Mode buttons */

.mode-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.btn {
    border: none;
    border-radius: 999px;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.2s ease;
    background: #4ECDC4;
    color: #fff;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 10px rgba(0,0,0,0.18);
}

.btn-primary {
    background: linear-gradient(135deg, #FF9F1C, #FF6B6B);
}

.btn-secondary {
    background: linear-gradient(135deg, #4ECDC4, #2AB7CA);
}

.btn-success {
    background: linear-gradient(135deg, #6BCB77, #38A169);
}

.btn-mode {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    border-radius: 18px;
    padding: 12px 16px;
    background: var(--btn-mode-bg);
    color: var(--btn-mode-text);
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.btn-mode .btn-emoji {
    font-size: 1.6rem;
}

.btn-mode .btn-subtext {
    font-size: 0.85rem;
    opacity: 0.8;
}

.big-btn {
    width: 100%;
    font-size: 1.1rem;
    margin: 6px 0 18px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 14px;
}

.btn-icon {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 1.2rem;
    background: #FFD93D;
    color: #333;
}

.btn-emoji {
    font-size: 1.4rem;
}

.read-btn {
    font-size: 28px !important;
}

button.option.correct {
    color: #111;
}

/* Difficulty selector */

.difficulty-selector {
    margin-bottom: 14px;
}

.difficulty-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.diff-btn {
    flex: 1;
    min-width: 180px;
    border-radius: 14px;
    background: var(--surface-alt);
    border: 2px solid transparent;
    color: var(--text-primary);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.diff-btn .diff-emoji {
    font-size: 1.2rem;
}

.diff-btn .diff-desc {
    font-size: 0.8rem;
    opacity: 0.7;
}

.diff-btn.active {
    border-color: var(--tab-active-border);
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

/* Leaderboard preview */

.leaderboard-section {
    margin-top: 10px;
}

/* Home screen leaderboard tabs */
.leaderboard-tabs-section {
    margin-top: 20px;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.leaderboard-tab {
    padding: 8px 16px;
    border: 2px solid var(--tab-border);
    border-radius: 20px;
    background: var(--tab-bg);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--tab-text);
}

.leaderboard-tab:hover {
    border-color: var(--surface-muted);
    background: var(--surface);
}

.leaderboard-tab.active {
    border-color: var(--tab-active-border);
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

.home-leaderboard-panel {
    display: none;
}

.home-leaderboard-panel.active {
    display: block;
}

.empty-message {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
}

.leaderboard {
    background: var(--leaderboard-bg);
    border-radius: 14px;
    padding: 8px 10px;
    max-height: 220px;
    overflow-y: auto;
    font-size: 0.9rem;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px dashed rgba(148,163,184,0.4);
}

.leaderboard-entry:last-child {
    border-bottom: none;
}

.leaderboard-entry span:first-child {
    display: flex;
    align-items: center;
    gap: 6px;
}

.leaderboard-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff7e6;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Screen header and player badge */

.screen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

/* Home button for game screens */
.btn-icon.home-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    font-size: 1.4rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #e2e8f0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-icon.home-btn:hover {
    background: #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-icon.home-btn:active {
    transform: scale(0.95);
}

.screen-title {
    font-size: 1.6rem;
}

.screen-subtitle {
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.player-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: radial-gradient(circle at top left, #FFEAA7, #FF6B6B);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25);
}

.player-avatar.large {
    width: 60px;
    height: 60px;
    font-size: 2.1rem;
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.player-name-label {
    font-size: 0.8rem;
    opacity: 0.7;
}

.player-name {
    font-weight: bold;
}

.player-mode {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Score panel */

.score-panel {
    display: flex;
    gap: 14px;
    align-items: center;
}

.score-item {
    text-align: right;
    font-size: 0.85rem;
}

.stars-display {
    font-size: 1.2rem;
}

.coins-count {
    font-size: 1.2rem;
}

/* Question area */

.question-area {
    margin-top: 8px;
}

.question-progress {
    margin-bottom: 8px;
}

.progress-label {
    font-size: 0.9rem;
}

.progress-bar-fancy {
    width: 100%;
    height: 14px;
    border-radius: 999px;
    background: var(--surface-muted);
    overflow: hidden;
    margin-top: 4px;
    position: relative;
}

.progress-fill-fancy {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #34D399, #22C55E, #16A34A);
    border-radius: inherit;
    transition: width 0.25s ease-out;
    position: relative;
}

.progress-sparkle {
    position: absolute;
    top: -4px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, #fef9c3 0%, rgba(254,249,195,0) 70%);
    pointer-events: none;
}

/* Question / options */

.question-container {
    margin-top: 8px;
}

.question-box {
    background: var(--surface);
    border-radius: 18px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.question-text {
    font-size: 1.2rem;
    flex: 1;
}

.options-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.option {
    padding: 8px 10px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: var(--option-bg);
    color: var(--text-primary);
    cursor: pointer;
    text-align: center;
    font-size: 1rem;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
}

.option:hover {
    transform: translateY(-1px);
    background: var(--option-hover);
}

.option.correct {
    background: var(--option-correct-bg);
    border-color: var(--option-correct-border);
}

.option.incorrect {
    background: var(--option-incorrect-bg);
    border-color: var(--option-incorrect-border);
}

.option.disabled {
    opacity: 0.6;
    cursor: default;
}

/* Feedback */

.feedback {
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 0.95rem;
    margin-bottom: 6px;
}

.feedback.correct {
    background: var(--feedback-correct-bg);
    color: var(--feedback-correct-text);
    border: 1px solid var(--feedback-correct-border);
}

.feedback.incorrect {
    background: var(--feedback-incorrect-bg);
    color: var(--feedback-incorrect-text);
    border: 1px solid var(--feedback-incorrect-border);
}

.hidden {
    display: none !important;
}

/* Power-ups */

.powerups {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.powerup-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #FDE68A;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
}

.powerup-count {
    font-size: 0.8rem;
}

.powerup-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Times Tables Zone */

.tables-main {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}

.tables-panel {
    background: var(--surface);
    border-radius: 16px;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.tables-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0;
}

.table-btn-small {
    border-radius: 999px;
    border: none;
    padding: 4px 10px;
    font-size: 0.9rem;
    cursor: pointer;
    background: #e2e8f0;
}

.table-btn-small.active {
    background: #ffedd5;
    border: 1px solid #fdba74;
}

.table-display {
    margin-top: 6px;
    background: var(--surface-muted);
    border-radius: 10px;
    padding: 6px 8px;
    font-family: 'JetBrains Mono', 'DM Mono', monospace;
    font-size: 0.9rem;
}

.table-display-line {
    display: flex;
    justify-content: space-between;
}

/* Mixed tables */

.tables-checkbox-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin: 6px 0;
}

.tables-checkbox-grid label {
    font-size: 0.85rem;
}

.question-count-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    font-size: 0.9rem;
    margin: 6px 0;
}

/* Leaderboards screen */

.leaderboard-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-bottom: 10px;
}

.leaderboard-switch .leaderboard-tab {
    border-radius: 999px;
    border: none;
    padding: 6px 14px;
    font-size: 0.85rem;
    cursor: pointer;
    background: #e2e8f0;
    transition: all 0.2s ease;
}

.leaderboard-switch .leaderboard-tab.active {
    background: #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}

.leaderboard-panel {
    display: none;
    margin-top: 6px;
}

.leaderboard-panel.active {
    display: block;
}

.table-tabs-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.table-tab-btn {
    border-radius: 999px;
    border: none;
    padding: 3px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    background: #e2e8f0;
}

.table-tab-btn.active {
    background: #ffedd5;
    border: 1px solid #fdba74;
}

/* Results screen */

.results-header {
    margin-bottom: 10px;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
    margin-bottom: 10px;
}

.results-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 10px 12px;
    font-size: 0.9rem;
}

.score-circle-wrapper {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 4px auto 8px;
}

.score-circle {
    width: 150px;
    height: 150px;
    transform: rotate(-90deg);
}

.score-bg {
    fill: none;
    stroke: #e5e7eb;
    stroke-width: 16;
}

.score-progress {
    fill: none;
    stroke: #22c55e;
    stroke-width: 16;
    stroke-linecap: round;
    stroke-dasharray: 565;
    stroke-dashoffset: 565;
    transition: stroke-dashoffset 0.8s ease-out;
}

.score-percentage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: bold;
}

.stars-earned {
    font-size: 1.4rem;
}

.motivational-message {
    font-size: 0.95rem;
}

.results-actions {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

/* Victory animation layer */

.victory-animation-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: -1;
}

/* Fireworks */

.firework {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, rgba(255,255,255,0) 70%);
    animation: fireworkExplode 900ms ease-out forwards;
}

@keyframes fireworkExplode {
    0% { transform: translate(0, 0) scale(0.3); opacity: 1; }
    100% { transform: translate(var(--dx), var(--dy)) scale(1.3); opacity: 0; }
}

/* Sparkles */

.sparkle {
    position: absolute;
    width: 12px;
    height: 12px;
    font-size: 1rem;
    animation: sparkleFloat 2.4s ease-out forwards;
}

@keyframes sparkleFloat {
    0% { transform: translateY(0) scale(0.7); opacity: 1; }
    100% { transform: translateY(-80px) scale(1.1); opacity: 0; }
}

/* Avatar bounce */

.avatar-celebrate {
    animation: avatarBounce 1.6s ease-out;
}

.avatar-celebrate-epic {
    animation: avatarBounceEpic 2.5s ease-out;
}

@keyframes avatarBounce {
    0% { transform: scale(1) translateY(0); }
    20% { transform: scale(1.2) translateY(-6px); }
    40% { transform: scale(0.9) translateY(2px); }
    60% { transform: scale(1.05) translateY(-3px); }
    100% { transform: scale(1) translateY(0); }
}

@keyframes avatarBounceEpic {
    0% { transform: scale(1) translateY(0) rotate(0deg); }
    10% { transform: scale(1.3) translateY(-10px) rotate(-5deg); }
    20% { transform: scale(1.1) translateY(0) rotate(5deg); }
    30% { transform: scale(1.25) translateY(-8px) rotate(-3deg); }
    40% { transform: scale(1) translateY(2px) rotate(3deg); }
    50% { transform: scale(1.15) translateY(-5px) rotate(-2deg); }
    60% { transform: scale(1.05) translateY(0) rotate(2deg); }
    80% { transform: scale(1.1) translateY(-3px) rotate(0deg); }
    100% { transform: scale(1) translateY(0) rotate(0deg); }
}

/* Confetti */

.confetti {
    position: absolute;
    font-size: 2rem;
    animation: confettiFall 2.5s ease-out forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-20px) rotate(0deg) scale(0.5);
        opacity: 1;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translateY(300px) rotate(720deg) scale(1);
        opacity: 0;
    }
}

/* Star particles */

.star-particle {
    position: absolute;
    font-size: 1.5rem;
    animation: starFloat 2s ease-out forwards;
    pointer-events: none;
    z-index: 10;
}

@keyframes starFloat {
    0% {
        transform: translate(0, 0) scale(0.3);
        opacity: 1;
    }
    50% {
        opacity: 1;
    }
    100% {
        transform: translate(var(--float-x, 50px), var(--float-y, -80px)) scale(1.2);
        opacity: 0;
    }
}

/* Enhanced message card */

.results-message-card {
    background: linear-gradient(135deg, #fff9e6 0%, #fff3cd 100%);
    border-left: 4px solid #ffc107;
}

.results-message-card .motivational-message {
    font-size: 1.1rem;
    line-height: 1.5;
    color: #5d4e37;
    margin: 0;
    padding: 0;
    border: none;
    font-style: normal;
    text-align: center;
}

/* Sound toggle */

.sound-toggle {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--toggle-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(15,23,42,0.5);
}

/* Responsive */

@media (max-width: 768px) {
    .rainbow-text {
        font-size: 2.3rem;
    }

    .options-container {
        grid-template-columns: 1fr;
    }

    .tables-main {
        grid-template-columns: 1fr;
    }

    .score-panel {
        flex-direction: column;
        align-items: flex-end;
    }
}

/* ============================================================
   FINAL PATCH — REQUIRED FIXES ONLY (SAFE, NON-DESTRUCTIVE)
   Adds ONLY the new elements your updated script + HTML needs.
============================================================ */

/* ------------------------------
   FIX: SOUND TOGGLE (TOP RIGHT)
------------------------------ */
#soundToggle,
.sound-toggle {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 2000 !important;
}

/* ------------------------------
   FIX: POWER-UPS (BOTTOM RIGHT)
------------------------------ */
.powerups {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    display: flex !important;
    flex-direction: row !important;
    gap: 14px !important;
    z-index: 2000 !important;
}

.powerups .powerup-btn {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    font-size: 1.6rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 6px 16px rgba(0,0,0,0.25) !important;
}

/* ------------------------------
   NEW: TIMES TABLE VIEWER CARD
------------------------------ */
.times-table-card {
    background: var(--card-white);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 6px 14px rgba(0,0,0,0.15);
    animation: fadeInTables 0.25s ease-out;
}

.times-table-card-header h3 {
    text-align: center;
    margin-bottom: 12px;
    color: var(--text-heading);
    font-weight: bold;
}

.times-table-card-body ul.times-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.times-table-card-body .times-list li {
    background: var(--surface-alt);
    margin-bottom: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    font-family: "JetBrains Mono", monospace;
    font-size: 0.95rem;
}

/* Smooth fade-in for the new card */
@keyframes fadeInTables {
    0% { opacity: 0; transform: translateY(6px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ------------------------------
   NEW: TIMES TABLE CHECKBOX GRID
------------------------------ */
.tables-checkbox-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)) !important;
    gap: 8px !important;
    margin: 10px 0 !important;
}

.tables-checkbox-grid label {
    background: #f1f5f9;
    padding: 6px 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
}

/* ------------------------------
   NEW: PRACTISE SHORTCUT BUTTONS
------------------------------ */
#practiceTablesRow .table-btn-small {
    background: #e2e8f0;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.85rem;
}

#practiceTablesRow .table-btn-small.active {
    background: #ffeed5;
    border: 1px solid #fbbf24;
}

/* ------------------------------
   FIX: UNIFIED START PRACTISE BUTTON
------------------------------ */
#startSingleTableBtn {
    margin-top: 10px;
    width: 100%;
}

/* Ensure no panel collapses */
.tables-panel {
    min-height: 100px;
}

/* === Results page enhancements === */

.results-card {
    position: relative;
    overflow: hidden;
}

/* Score pulse */
.score-circle-wrapper.score-pulse {
    animation: scorePulse 1.2s ease-out;
}

@keyframes scorePulse {
    0%   { transform: scale(0.9); }
    30%  { transform: scale(1.07); }
    60%  { transform: scale(0.97); }
    100% { transform: scale(1); }
}

/* Stars pop */
.stars-earned.stars-pop {
    animation: starsPop 0.9s ease-out;
    transform-origin: left center;
}

@keyframes starsPop {
    0%   { transform: scale(0.6); opacity: 0; }
    40%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

/* Badge circle */
.badge-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
}

.badge-circle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: radial-gradient(circle at top left, #FFEAA7, #FF6B6B);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.badge-circle.badge-pop {
    animation: badgePop 0.9s ease-out;
}

@keyframes badgePop {
    0%   { transform: scale(0.5); opacity: 0; }
    40%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

.badge-label {
    font-size: 0.9rem;
    font-weight: bold;
    text-align: center;
}

/* Message as big blockquote */
.results-message-card .motivational-message {
    margin-top: 4px;
    padding: 10px 12px;
    background: #fef9c3;
    border-left: 4px solid #facc15;
    border-radius: 12px;
    font-size: 1rem;
    line-height: 1.4;
}

/* Leaderboard card on results */
.results-leaderboard-card {
    background: var(--results-lb-bg);
    box-shadow: 0 6px 14px rgba(0,0,0,0.12);
}

.results-leaderboard-card p {
    margin-bottom: 8px;
}

/* Highlighted row on full leaderboard */
.leaderboard-entry.highlight {
    background: #fef9c3;
    border-radius: 12px;
    box-shadow: 0 0 0 2px rgba(250,204,21,0.6);
}

/* Ensure no panel collapses */
.tables-panel {
    min-height: 100px;
}

/* ===== Progress Bar Milestones ===== */
.progress-milestones {
  position: relative;
  height: 0;
  margin-top: -2px;
}

.milestone {
  position: absolute;
  top: -14px;
  transform: translateX(-50%);
  font-size: 0.9rem;
  opacity: 0.4;
  transition: opacity 0.4s ease, transform 0.4s ease;
  line-height: 1;
}

.milestone.reached {
  opacity: 1;
  animation: milestoneReached 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes milestoneReached {
  0% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.5); }
  100% { transform: translateX(-50%) scale(1); }
}

@media (max-width: 480px) {
  .milestone { font-size: 0.7rem; top: -10px; }
}

/* ===== Answer Feedback Animations ===== */

/* Correct answer pop effect */
.option.correct-pop {
  animation: correctPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes correctPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* Wrong answer shake effect */
.option.wrong-shake {
  animation: wrongShake 0.5s ease;
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  90% { transform: translateX(2px); }
}

/* ===== Streak Counter ===== */
.streak-counter {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  z-index: 100;
  font-size: 2rem;
  font-weight: bold;
  color: #ff9f1c;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
}

.streak-counter.show {
  animation: streakPop 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes streakPop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  40% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { transform: translate(-50%, -50%) scale(1) translateY(-30px); opacity: 0.8; }
  100% { transform: translate(-50%, -50%) scale(0.8) translateY(-60px); opacity: 0; }
}

/* Streak fire effect for 5+ */
.streak-counter.fire {
  color: #ff4500;
  text-shadow: 0 0 20px rgba(255, 69, 0, 0.5);
}

/* ===== Mascot - Game Screen ===== */
.game-mascot {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 80px;
  height: 80px;
  z-index: 50;
  pointer-events: none;
  transition: transform 0.3s ease;
  display: none;
}

.game-mascot.visible {
  display: block;
}

.mascot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.3s ease, filter 0.3s ease;
}

/* Mascot reactions */
.mascot-happy {
  animation: mascotHappy 0.6s ease;
}

.mascot-encourage {
  animation: mascotEncourage 0.8s ease;
}

.mascot-celebrate {
  animation: mascotCelebrate 1.2s ease;
}

.mascot-thinking {
  animation: mascotThinking 2s ease infinite;
}

@keyframes mascotHappy {
  0% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.2) rotate(-5deg); }
  50% { transform: scale(1.15) rotate(5deg); }
  75% { transform: scale(1.1) rotate(-3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes mascotEncourage {
  0% { transform: scale(1) translateY(0); }
  30% { transform: scale(1.05) translateY(-5px); }
  60% { transform: scale(1) translateY(0); }
  100% { transform: scale(1) translateY(0); }
}

@keyframes mascotCelebrate {
  0% { transform: scale(1) rotate(0deg) translateY(0); }
  15% { transform: scale(1.3) rotate(-10deg) translateY(-15px); }
  30% { transform: scale(1.2) rotate(8deg) translateY(-10px); }
  45% { transform: scale(1.25) rotate(-6deg) translateY(-12px); }
  60% { transform: scale(1.15) rotate(4deg) translateY(-5px); }
  80% { transform: scale(1.05) rotate(-2deg) translateY(-2px); }
  100% { transform: scale(1) rotate(0deg) translateY(0); }
}

@keyframes mascotThinking {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-3px) rotate(2deg); }
  75% { transform: translateY(-3px) rotate(-2deg); }
}

@media (max-width: 480px) {
  .game-mascot {
    width: 50px;
    height: 50px;
    bottom: 10px;
    left: 10px;
  }
}

/* ACCESSIBILITY: Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .background-animation,
  .background-animation .bubble,
  .background-animation .star,
  .firework,
  .sparkle {
    animation: none !important;
    transform: none !important;
  }

  .avatar-celebrate {
    animation: none !important;
  }

  .mascot-happy,
  .mascot-encourage,
  .mascot-celebrate,
  .mascot-thinking {
    animation: none !important;
  }

  .milestone.reached { animation: none !important; }
  .option.correct-pop { animation: none !important; }
  .option.wrong-shake { animation: none !important; }
  .streak-counter.show {
    animation: none !important;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* BUGFIX: Ensure fireworks are visible and animate properly */
.victory-animation-layer {
  position: fixed !important;
  inset: 0 !important;
  pointer-events: none !important;
  overflow: hidden !important;
  z-index: 1000 !important;
}

.firework {
  position: absolute !important;
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
  opacity: 1 !important;
}

/* Enhance firework visibility with multiple colors */
.firework:nth-child(3n) {
  background: radial-gradient(circle, #FFD93D 0%, rgba(255,217,61,0) 70%) !important;
}

.firework:nth-child(3n+1) {
  background: radial-gradient(circle, #FF6B6B 0%, rgba(255,107,107,0) 70%) !important;
}

.firework:nth-child(3n+2) {
  background: radial-gradient(circle, #4ECDC4 0%, rgba(78,205,196,0) 70%) !important;
}

@keyframes fireworkExplode {
  0% {
    transform: translate(0, 0) scale(0.5);
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(1.5);
    opacity: 0;
  }
}

/* ===========================================
   COLUMN SUMS ZONE STYLES
   =========================================== */

/* Column Sums Setup Screen */
.columns-setup {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.columns-panel {
    background: var(--surface);
    border-radius: 16px;
    padding: 16px;
}

.columns-panel h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    color: var(--text-subheading);
}

/* Operation Buttons */
.columns-operation-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.columns-op-btn {
    flex: 1;
    min-width: 100px;
    padding: 12px 16px;
    border: 2px solid transparent;
    border-radius: 14px;
    background: #e2e8f0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.columns-op-btn .op-emoji {
    font-size: 1.8rem;
}

.columns-op-btn:hover {
    background: #cbd5e1;
    transform: translateY(-2px);
}

.columns-op-btn.active {
    background: #dbeafe;
    border-color: #3b82f6;
}

/* Difficulty Buttons */
.columns-difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.columns-diff-btn {
    padding: 12px;
    border: 2px solid transparent;
    border-radius: 14px;
    background: #f1f5f9;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.15s ease;
}

.columns-diff-btn .diff-emoji {
    font-size: 1.4rem;
}

.columns-diff-btn .diff-desc {
    font-size: 0.75rem;
    color: #64748b;
}

.columns-diff-btn:hover {
    background: #e2e8f0;
    transform: translateY(-1px);
}

.columns-diff-btn.active {
    background: #fff7ed;
    border-color: #f97316;
}

/* ===========================================
   COLUMN GAME SCREEN - Interactive Display
   =========================================== */

.column-question-container {
    text-align: center;
    padding: 10px 0;
}

.column-instruction {
    font-size: 1rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Visual Column Sum Display */
.column-sum-display {
    display: inline-block;
    background: var(--column-display-bg);
    border-radius: 20px;
    padding: 24px 32px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    margin: 0 auto 20px;
    font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    font-size: 2.2rem;
    font-weight: bold;
    border: 3px solid var(--column-display-border);
    color: var(--text-primary);
}

.column-row {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    min-height: 2.8rem;
    align-items: center;
}

.column-digit {
    width: 2.4rem;
    height: 2.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s ease;
}

.column-operator-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-operator {
    width: 2rem;
    text-align: center;
    color: #6366f1;
}

.column-bottom {
    display: flex;
    gap: 4px;
}

.column-line {
    height: 4px;
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    border-radius: 2px;
    margin: 8px 0;
}

/* Answer Digits */
.column-answer-digit {
    background: #f1f5f9;
    border: 2px dashed #cbd5e1;
    color: #64748b;
}

.column-answer-digit.current {
    background: #fef3c7;
    border: 2px solid #f59e0b;
    color: #92400e;
    animation: glow-throb 1.2s ease-in-out infinite;
}

/* Focus animation when moving to a new column */
.column-answer-digit.focus-in {
    animation: focus-pop 0.3s ease-out forwards;
}

.column-answer-digit.filled {
    background: #dbeafe;
    border: 2px solid #3b82f6;
    color: #1e40af;
}

.column-answer-digit.correct {
    background: #dcfce7 !important;
    border-color: #22c55e !important;
    color: #166534 !important;
}

.column-answer-digit.wrong-shake {
    animation: shake 0.4s ease-in-out;
    background: #fee2e2;
    border-color: #ef4444;
}

/* Spacer for answer slots when answer has fewer digits than operands */
.column-answer-digit.spacer {
    background: transparent;
    border: none;
    visibility: hidden;
}

/* Gentle glow throb - no movement, just glow intensity changes */
@keyframes glow-throb {
    0%, 100% {
        box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
        border-color: #f59e0b;
    }
    50% {
        box-shadow: 0 0 20px rgba(245, 158, 11, 0.6), 0 0 30px rgba(245, 158, 11, 0.3);
        border-color: #fbbf24;
    }
}

/* Pop animation when focus moves to new column */
@keyframes focus-pop {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 rgba(245, 158, 11, 0);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 25px rgba(245, 158, 11, 0.7);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* Carry/Borrow indicators - positioned above the answer line */
.column-carry-row {
    min-height: 1.8rem;
    position: relative;
    margin-top: 8px;
    margin-bottom: 0;
}

.column-carry-digit {
    width: 2.4rem;
    height: 2rem;
    font-size: 1.1rem;
    font-weight: 900;
    opacity: 0;
    transform: scale(0) translateY(8px);
    transition: all 0.4s ease;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 2px;
}

.column-carry-digit.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    animation: carry-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Faded state when user has moved past this column */
.column-carry-digit.faded {
    opacity: 0.35;
    transform: scale(0.9) translateY(0);
    animation: none;
}

/* Green for addition carries */
.column-carry-digit.carry-add {
    color: #16a34a;
    text-shadow: 0 0 10px rgba(22, 163, 74, 0.5);
}

/* Blue for subtraction borrows */
.column-carry-digit.carry-subtract {
    color: #2563eb;
    text-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
}

/* Carry text styling - bigger and bolder */
.column-carry-digit span {
    font-size: 1.1rem;
    font-weight: 900;
    line-height: 1;
}

/* Carry pop-in animation */
@keyframes carry-pop {
    0% {
        opacity: 0;
        transform: scale(0) translateY(8px);
    }
    50% {
        transform: scale(1.4) translateY(-4px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ===========================================
   NUMBER PAD
   =========================================== */

.column-numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 280px;
    margin: 20px auto;
}

.numpad-btn {
    width: 100%;
    aspect-ratio: 1;
    max-width: 80px;
    border: none;
    border-radius: 16px;
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    background: var(--numpad-bg);
    color: var(--numpad-text);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.1s ease;
}

.numpad-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    background: var(--numpad-hover);
}

.numpad-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.numpad-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.numpad-clear {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
}

.numpad-submit {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #166534;
}

.numpad-btn.hint-flash {
    animation: hint-pulse 0.5s ease-in-out 3;
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
}

@keyframes hint-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); box-shadow: 0 0 20px rgba(245, 158, 11, 0.6); }
}

/* Column powerups positioning */
.column-powerups {
    position: fixed !important;
    bottom: 20px !important;
    left: 20px !important;
    right: auto !important;
}

/* ===========================================
   RESPONSIVE ADJUSTMENTS
   =========================================== */

@media (max-width: 480px) {
    .column-sum-display {
        padding: 16px 20px;
        font-size: 1.6rem;
    }

    .column-digit {
        width: 1.8rem;
        height: 2.2rem;
    }

    .column-numpad {
        max-width: 240px;
        gap: 8px;
    }

    .numpad-btn {
        font-size: 1.4rem;
        max-width: 70px;
    }

    .columns-difficulty-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===========================================
   NEW MODULE STYLES — VISUAL DELIGHT
   =========================================== */

/* Themed accent colours on setup screen titles */
.decimals-title { border-bottom: 3px solid #6366f1; padding-bottom: 4px; display: inline-block; }
.shapes-title { border-bottom: 3px solid #10b981; padding-bottom: 4px; display: inline-block; }
.triangles-title { border-bottom: 3px solid #f59e0b; padding-bottom: 4px; display: inline-block; }
.fractions-title { border-bottom: 3px solid #f43f5e; padding-bottom: 4px; display: inline-block; }
.timeline-title { border-bottom: 3px solid #4f46e5; padding-bottom: 4px; display: inline-block; }

/* Active difficulty buttons with module accent colours */
.decimals-diff-btn.active { border-color: #6366f1 !important; background: #eef2ff; }
.shapes-diff-btn.active { border-color: #10b981 !important; background: #ecfdf5; }
.triangles-diff-btn.active { border-color: #f59e0b !important; background: #fffbeb; }
.fractions-diff-btn.active { border-color: #f43f5e !important; background: #fff1f2; }
.timeline-diff-btn.active { border-color: #4f46e5 !important; background: #eef2ff; }

/* Decimals operation & mode buttons */
.decimals-op-btn {
    flex: 1;
    min-width: 80px;
    padding: 10px 12px;
    border: 2px solid transparent;
    border-radius: 14px;
    background: #e2e8f0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}
.decimals-op-btn .op-emoji { font-size: 1.6rem; }
.decimals-op-btn:hover { background: #cbd5e1; transform: translateY(-2px); }
.decimals-op-btn.active { background: #eef2ff; border-color: #6366f1; }

.decimals-mode-btn.active { border-color: #6366f1 !important; background: #eef2ff; }

/* Formula display box (used in Shapes & Triangles) */
.formula-box {
    background: #fefce8;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.05rem;
    display: inline-block;
    margin: 6px 0;
}

/* ===========================================
   DECIMALS INTERACTIVE PLACEMENT STYLES
   =========================================== */

.decimal-digit-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    margin: 20px auto;
    flex-wrap: wrap;
}

.decimal-digit-box {
    width: 48px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    font-family: 'JetBrains Mono', monospace;
    background: var(--decimal-box-bg);
    border-radius: 10px;
    border: 2px solid var(--decimal-box-border);
    color: var(--decimal-box-text);
}

.decimal-gap {
    width: 32px;
    height: 56px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    background: transparent;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    color: transparent;
    transition: all 0.2s ease;
    padding-bottom: 4px;
}

.decimal-gap:hover:not(:disabled) {
    background: #eef2ff;
    border-color: #6366f1;
}

.decimal-gap:focus-visible {
    outline: 3px solid #ff9f1c;
    outline-offset: 2px;
}

.decimal-point-placed {
    color: #1e293b;
    cursor: default;
    font-size: 2.5rem;
    line-height: 1;
}

.decimal-point-correct {
    background: #dcfce7;
    border-color: #22c55e;
    border-style: solid;
    animation: dropIn 0.4s ease-out;
}

.decimal-point-wrong {
    background: #fee2e2;
    border-color: #ef4444;
    border-style: solid;
    animation: shake 0.4s ease-in-out;
}

.decimal-hint-flash {
    animation: hint-pulse 0.5s ease-in-out 3;
    background: #fef3c7 !important;
    border-color: #f59e0b !important;
}

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

/* ===========================================
   FRACTION VISUAL STYLES
   =========================================== */

.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
    line-height: 1;
}

.frac-num {
    font-size: 1.1rem;
    font-weight: bold;
    padding: 2px 6px;
}

.fraction-bar {
    width: 100%;
    height: 2px;
    background: var(--fraction-bar);
    margin: 1px 0;
}

.frac-den {
    font-size: 1.1rem;
    font-weight: bold;
    padding: 2px 6px;
}

.fraction-visual {
    display: flex;
    border-radius: 12px;
    overflow: hidden;
    height: 40px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin: 10px auto;
    max-width: 300px;
    animation: scaleIn 0.4s ease-out;
    transform-origin: left;
}

.fraction-part {
    flex: 1;
    transition: background 0.3s;
    background: var(--fraction-part-bg);
    border-right: 1px solid rgba(0,0,0,0.1);
}

.fraction-part:last-child {
    border-right: none;
}

.fraction-part.shaded {
    background: linear-gradient(135deg, #f472b6, #ec4899);
}

@keyframes scaleIn {
    0% { transform: scaleX(0); }
    100% { transform: scaleX(1); }
}

/* Pizza scenario visuals */
.pizza-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 10px 0;
    flex-wrap: wrap;
}

.pizza-circle {
    border-radius: 50%;
    background: linear-gradient(135deg, #fbbf24, #f97316);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 0.8rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.pizza-label {
    text-align: center;
    font-size: 0.85rem;
    margin-top: 4px;
    color: #64748b;
}

/* ===========================================
   RESPONSIVE FOR NEW MODULES
   =========================================== */

@media (max-width: 480px) {
    .decimal-digit-box {
        width: 36px;
        height: 44px;
        font-size: 1.5rem;
    }

    .decimal-gap {
        width: 28px;
        height: 44px;
        min-width: 36px;
        font-size: 1.8rem;
    }

    .fraction-visual {
        height: 32px;
        max-width: 240px;
    }
}

/* ===========================================
   QUESTION ILLUSTRATION CONTAINER
   =========================================== */

.question-illustration {
    text-align: center;
    margin: 12px 0;
}

/* ===========================================
   DECIMAL COLUMN LAYOUT (for add/subtract)
   =========================================== */

.decimal-column-display {
    display: inline-block;
    font-family: 'Courier New', Courier, monospace;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: 16px 24px;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.15);
    border: 2px solid #e0e7ff;
}

.decimal-column-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
    min-height: 2.4rem;
}

.decimal-column-op-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
}

.decimal-column-operator {
    color: #6366f1;
    font-weight: bold;
    font-size: 1.4rem;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.decimal-column-bottom {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
}

.dcol-digit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2.4rem;
    font-size: 1.3rem;
    font-weight: bold;
    color: #1e293b;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.dcol-point {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 0.8rem;
    height: 2.4rem;
    font-size: 1.4rem;
    font-weight: bold;
    color: #6366f1;
}

.dcol-pad {
    visibility: hidden;
}

.decimal-column-line {
    height: 3px;
    background: linear-gradient(90deg, #818cf8, #6366f1, #4f46e5);
    border-radius: 2px;
    margin: 6px 0;
}

.decimal-column-answer {
    justify-content: center;
    border: 2px dashed #c7d2fe;
    border-radius: 8px;
    color: #a5b4fc;
    font-size: 1.3rem;
    font-weight: bold;
    min-height: 2.4rem;
    margin-top: 4px;
}

@media (max-width: 480px) {
    .decimal-column-display {
        padding: 12px 16px;
    }
    .dcol-digit {
        width: 1.6rem;
        height: 2rem;
        font-size: 1.1rem;
    }
    .dcol-point {
        width: 0.6rem;
        height: 2rem;
        font-size: 1.2rem;
    }
    .decimal-column-operator {
        width: 1.6rem;
        font-size: 1.2rem;
    }
}

/* ===========================================
   SHAPE ILLUSTRATION SVGs
   =========================================== */

.shape-svg-container {
    display: inline-block;
    max-width: 280px;
    margin: 8px auto;
}

.shape-svg-container svg {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.1));
}

@media (max-width: 480px) {
    .shape-svg-container { max-width: 200px; }
}

/* Wikipedia thumbnail in timeline feedback */
.feedback-wiki-img {
    display: block;
    max-width: 120px;
    max-height: 90px;
    object-fit: cover;
    border-radius: 8px;
    margin: 8px auto 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    animation: feedback-img-in 0.3s ease;
}

@keyframes feedback-img-in {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@media (min-width: 481px) {
    .feedback-wiki-img {
        float: right;
        margin: 0 0 6px 10px;
    }
}

/* ===========================================
   TIMELINE EXPLORER STYLES
   =========================================== */

.timeline-explorer-container {
    position: relative;
    padding: 20px 0 40px 60px;
    max-height: 70vh;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Vertical line */
.tl-line {
    position: absolute;
    left: 30px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to bottom, #818cf8, #6366f1, #4f46e5, #4338ca);
    border-radius: 2px;
}

/* Era dividers */
.tl-era-divider {
    position: relative;
    padding: 8px 16px;
    margin: 16px 0 8px -40px;
    font-weight: bold;
    font-size: 1rem;
    color: #fff;
    border-radius: 20px;
    display: inline-block;
    z-index: 2;
}
.tl-era-divider.era-ancient { background: linear-gradient(135deg, #92400e, #b45309); }
.tl-era-divider.era-classical { background: linear-gradient(135deg, #7c3aed, #8b5cf6); }
.tl-era-divider.era-medieval { background: linear-gradient(135deg, #dc2626, #ef4444); }
.tl-era-divider.era-early-modern { background: linear-gradient(135deg, #0891b2, #06b6d4); }
.tl-era-divider.era-modern { background: linear-gradient(135deg, #059669, #10b981); }

/* Event cards */
.tl-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    margin-bottom: 12px;
    background: var(--tl-card-bg);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border-left: 4px solid #6366f1;
    animation: tl-fade-in 0.4s ease forwards;
    opacity: 0;
    transform: translateX(20px);
}

.tl-card.era-ancient { border-left-color: #b45309; }
.tl-card.era-classical { border-left-color: #8b5cf6; }
.tl-card.era-medieval { border-left-color: #ef4444; }
.tl-card.era-early-modern { border-left-color: #06b6d4; }
.tl-card.era-modern { border-left-color: #10b981; }

@keyframes tl-fade-in {
    to { opacity: 1; transform: translateX(0); }
}

/* Dot on timeline */
.tl-dot {
    position: absolute;
    left: -42px;
    top: 20px;
    width: 16px;
    height: 16px;
    background: #6366f1;
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.5);
    z-index: 2;
}

/* Big emoji */
.tl-emoji {
    font-size: 2.5rem;
    flex-shrink: 0;
    line-height: 1;
}

/* Content */
.tl-content {
    flex: 1;
    min-width: 0;
}

.tl-year {
    font-size: 0.85rem;
    font-weight: bold;
    color: #6366f1;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tl-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin: 2px 0 4px;
    color: var(--text-heading);
}

.tl-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0 0 8px;
    line-height: 1.4;
}

.tl-wiki-link {
    display: inline-block;
    padding: 6px 14px;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    color: #4338ca;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.tl-wiki-link:hover {
    background: linear-gradient(135deg, #c7d2fe, #a5b4fc);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* Scrollbar styling */
.timeline-explorer-container::-webkit-scrollbar {
    width: 8px;
}
.timeline-explorer-container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 4px;
}
.timeline-explorer-container::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, #818cf8, #6366f1);
    border-radius: 4px;
}

/* Wikipedia preview (lazy loaded) */
.tl-preview {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 8px 0;
    padding: 10px;
    background: var(--tl-preview-bg);
    border-radius: 10px;
    border: 1px solid var(--tl-preview-border);
    animation: tl-preview-in 0.3s ease;
}

@keyframes tl-preview-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.tl-preview-img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.tl-preview-text {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0;
}

/* Loading shimmer */
.tl-preview-shimmer {
    width: 100%;
    height: 48px;
    border-radius: 6px;
    background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
    background-size: 200% 100%;
    animation: tl-shimmer 1.2s ease-in-out infinite;
}

@keyframes tl-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Mobile responsive */
@media (max-width: 480px) {
    .timeline-explorer-container { padding-left: 40px; }
    .tl-line { left: 16px; }
    .tl-dot { left: -30px; width: 12px; height: 12px; }
    .tl-emoji { font-size: 1.8rem; }
    .tl-card { padding: 12px; }
    .tl-era-divider { margin-left: -24px; }
    .tl-preview { flex-direction: column; }
    .tl-preview-img { width: 100%; height: 120px; }
}

/* ===========================================
   THEME TOGGLE BUTTON
   =========================================== */

.theme-toggle {
    position: fixed !important;
    top: 20px !important;
    right: 76px !important;
    z-index: 2000 !important;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--toggle-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.5);
    transition: transform 0.15s ease;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

/* ===========================================
   COLOUR-BLIND SAFE ANSWER ICONS
   =========================================== */

.answer-icon {
    font-weight: bold;
    margin-left: 4px;
    font-size: 1.1em;
}

.option.correct .answer-icon {
    color: var(--option-correct-border);
}

.option.incorrect .answer-icon {
    color: var(--option-incorrect-border);
}

/* ===========================================
   QUESTION ILLUSTRATIONS (DECORATIVE)
   =========================================== */

.q-illus {
    display: inline-block;
    vertical-align: middle;
    opacity: 0.7;
    margin: 0 4px;
}

[data-theme="deepsea"] .q-illus {
    opacity: 0.85;
    filter: brightness(1.2);
}

/* ===========================================
   DEEP SEA THEME OVERRIDES
   =========================================== */

[data-theme="deepsea"] .btn-icon.home-btn {
    background: rgba(30, 41, 59, 0.9);
    border-color: #475569;
    color: #e2e8f0;
}

[data-theme="deepsea"] .btn-icon.home-btn:hover {
    background: #334155;
}

[data-theme="deepsea"] .leaderboard-switch .leaderboard-tab {
    background: var(--surface-muted);
    color: var(--text-muted);
}

[data-theme="deepsea"] .leaderboard-switch .leaderboard-tab.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

[data-theme="deepsea"] .leaderboard-entry.highlight {
    background: var(--leaderboard-highlight);
}

[data-theme="deepsea"] .table-btn-small {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .table-tab-btn {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .columns-op-btn {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .columns-diff-btn {
    background: var(--surface-alt);
    color: var(--text-primary);
}

[data-theme="deepsea"] .columns-diff-btn .diff-desc {
    color: var(--text-muted);
}

[data-theme="deepsea"] .pizza-label {
    color: var(--text-muted);
}

[data-theme="deepsea"] .dcol-digit {
    color: var(--text-primary);
    background: var(--surface);
    border-color: var(--surface-muted);
}

[data-theme="deepsea"] .decimal-column-display {
    background: var(--column-display-bg);
    border-color: var(--column-display-border);
}

[data-theme="deepsea"] .results-message-card .motivational-message {
    background: var(--motivational-bg);
    border-left-color: var(--motivational-border);
    color: var(--text-primary);
}

[data-theme="deepsea"] .results-message-card {
    background: var(--surface);
    border-left-color: var(--motivational-border);
}

[data-theme="deepsea"] .tables-checkbox-grid label {
    background: var(--surface-alt);
    color: var(--text-primary);
}

[data-theme="deepsea"] .powerup-btn {
    background: #334155;
}

[data-theme="deepsea"] .btn-icon {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .decimal-column-answer {
    border-color: var(--surface-muted);
    color: var(--text-muted);
}

[data-theme="deepsea"] .formula-box {
    background: var(--surface);
    color: var(--text-primary);
}

[data-theme="deepsea"] .decimals-op-btn {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] #practiceTablesRow .table-btn-small {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .score-bg {
    stroke: var(--surface-muted);
}

/* --- Buttons & icons --- */
[data-theme="deepsea"] .btn-icon {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .leaderboard-avatar {
    background: var(--surface-muted);
}

[data-theme="deepsea"] button.option.correct {
    color: var(--feedback-correct-text);
}

/* --- Column Sums --- */
[data-theme="deepsea"] .columns-op-btn {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .columns-op-btn:hover {
    background: var(--option-hover);
}

[data-theme="deepsea"] .columns-op-btn.active {
    background: #1e3a5f;
    border-color: #38bdf8;
}

[data-theme="deepsea"] .columns-diff-btn {
    background: var(--surface-alt);
    color: var(--text-primary);
}

[data-theme="deepsea"] .columns-diff-btn .diff-desc {
    color: var(--text-muted);
}

[data-theme="deepsea"] .columns-diff-btn:hover {
    background: var(--surface-muted);
}

[data-theme="deepsea"] .columns-diff-btn.active {
    background: #3b1f0b;
    border-color: #f97316;
}

[data-theme="deepsea"] .column-operator {
    color: #818cf8;
}

[data-theme="deepsea"] .column-line {
    background: linear-gradient(90deg, #818cf8, #a78bfa);
}

[data-theme="deepsea"] .column-answer-digit {
    background: var(--surface);
    border-color: var(--surface-muted);
    color: var(--text-muted);
}

[data-theme="deepsea"] .column-answer-digit.current {
    background: #422006;
    border-color: #f59e0b;
    color: #fbbf24;
}

[data-theme="deepsea"] .column-answer-digit.filled {
    background: #1e3a5f;
    border-color: #60a5fa;
    color: #bfdbfe;
}

[data-theme="deepsea"] .column-answer-digit.correct {
    background: #064e3b !important;
    border-color: #10b981 !important;
    color: #a7f3d0 !important;
}

[data-theme="deepsea"] .column-answer-digit.wrong-shake {
    background: #450a0a;
    border-color: #f87171;
}

[data-theme="deepsea"] .column-carry-digit.carry-add {
    color: #34d399;
    text-shadow: 0 0 10px rgba(52, 211, 153, 0.5);
}

[data-theme="deepsea"] .column-carry-digit.carry-subtract {
    color: #60a5fa;
    text-shadow: 0 0 10px rgba(96, 165, 250, 0.5);
}

[data-theme="deepsea"] .numpad-clear {
    background: linear-gradient(135deg, #422006, #78350f);
    color: #fbbf24;
}

[data-theme="deepsea"] .numpad-submit {
    color: #a7f3d0;
}

/* --- Decimals --- */
[data-theme="deepsea"] .decimals-op-btn {
    background: var(--surface-muted);
    color: var(--text-primary);
}

[data-theme="deepsea"] .decimals-op-btn:hover {
    background: var(--option-hover);
}

[data-theme="deepsea"] .decimals-op-btn.active {
    background: #1e1b4b;
    border-color: #818cf8;
}

[data-theme="deepsea"] .decimals-mode-btn.active {
    border-color: #818cf8 !important;
    background: #1e1b4b !important;
}

[data-theme="deepsea"] .decimals-diff-btn.active { border-color: #818cf8 !important; background: #1e1b4b !important; }
[data-theme="deepsea"] .shapes-diff-btn.active { border-color: #34d399 !important; background: #064e3b !important; }
[data-theme="deepsea"] .triangles-diff-btn.active { border-color: #fbbf24 !important; background: #422006 !important; }
[data-theme="deepsea"] .fractions-diff-btn.active { border-color: #fb7185 !important; background: #4c0519 !important; }
[data-theme="deepsea"] .timeline-diff-btn.active { border-color: #818cf8 !important; background: #1e1b4b !important; }

[data-theme="deepsea"] .decimal-gap {
    border-color: var(--surface-muted);
}

[data-theme="deepsea"] .decimal-gap:hover:not(:disabled) {
    background: #1e1b4b;
    border-color: #818cf8;
}

[data-theme="deepsea"] .decimal-point-placed {
    color: var(--text-primary);
}

[data-theme="deepsea"] .decimal-point-correct {
    background: #064e3b;
    border-color: #10b981;
}

[data-theme="deepsea"] .decimal-point-wrong {
    background: #450a0a;
    border-color: #f87171;
}

[data-theme="deepsea"] .decimal-hint-flash {
    background: #422006 !important;
    border-color: #f59e0b !important;
}

[data-theme="deepsea"] .decimal-column-display {
    background: var(--column-display-bg);
    border-color: var(--column-display-border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

[data-theme="deepsea"] .decimal-column-operator {
    color: #818cf8;
}

[data-theme="deepsea"] .decimal-column-line {
    background: linear-gradient(90deg, #818cf8, #a78bfa);
}

[data-theme="deepsea"] .decimal-column-answer {
    border-color: var(--surface-muted);
    color: var(--text-muted);
}

[data-theme="deepsea"] .dcol-digit {
    color: var(--text-primary);
    background: var(--surface);
    border-color: var(--surface-muted);
}

[data-theme="deepsea"] .dcol-point {
    color: #818cf8;
}

/* --- Timeline --- */
[data-theme="deepsea"] .tl-dot {
    border-color: var(--surface);
}

[data-theme="deepsea"] .tl-year {
    color: #a5b4fc;
}

[data-theme="deepsea"] .tl-wiki-link {
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    color: #c7d2fe;
}

[data-theme="deepsea"] .tl-wiki-link:hover {
    background: linear-gradient(135deg, #312e81, #3730a3);
}

/* --- Results message --- */
[data-theme="deepsea"] .results-message-card {
    background: var(--surface);
    border-left-color: var(--motivational-border);
}

[data-theme="deepsea"] .results-message-card .motivational-message {
    background: var(--motivational-bg);
    border-left-color: var(--motivational-border);
    color: var(--text-primary);
}

/* --- Results leaderboard card --- */
[data-theme="deepsea"] .results-leaderboard-card {
    background: var(--results-lb-bg);
}

/* --- Table buttons active states --- */
[data-theme="deepsea"] .table-btn-small.active {
    background: #422006;
    border-color: #f59e0b;
    color: #fbbf24;
}

[data-theme="deepsea"] #practiceTablesRow .table-btn-small.active {
    background: #422006;
    border-color: #f59e0b;
    color: #fbbf24;
}

[data-theme="deepsea"] .table-tab-btn.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

/* --- Dark mode: question box & answer button contrast --- */
[data-theme="deepsea"] .question-box {
    background: #0f172a;
    border: 1px solid #334155;
}

[data-theme="deepsea"] .question-text {
    color: #f8fafc;
    font-size: 1.3rem;
}

[data-theme="deepsea"] button.option {
    border: 1px solid #475569;
}

[data-theme="deepsea"] button.option:hover:not(:disabled) {
    border-color: #60a5fa;
    background: #475569;
}

[data-theme="deepsea"] .builder-option {
    background: #334155;
    color: #f1f5f9;
}

[data-theme="deepsea"] .builder-option.color-swatch {
    border: 2px solid #475569;
}

[data-theme="deepsea"] .builder-option.active {
    border-color: #ffd93d;
}

[data-theme="deepsea"] .shop-item {
    border-color: #334155;
}

[data-theme="deepsea"] .shop-item-desc {
    color: #94a3b8;
}

/* ===== Skin System ===== */
.skin-dark .game-card {
  color: #dfe6e9;
}

.skin-dark .game-card h1,
.skin-dark .game-card h2,
.skin-dark .game-card h3 {
  color: #ADE8F4;
}

.skin-dark .option {
  background: rgba(30, 40, 60, 0.8);
  color: #dfe6e9;
  border-color: #3d5a80;
}

.skin-dark .input {
  background: rgba(30, 40, 60, 0.8);
  color: #dfe6e9;
  border-color: #3d5a80;
}

.skin-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 10px 0 20px;
  padding-right: 60px;
}

@media (min-width: 768px) {
  .skin-picker-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.skin-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: 12px;
  border: 2px solid transparent;
  background: var(--option-bg, #f8f9fa);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  font-size: 0.85rem;
}

.skin-option:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.skin-option.active {
  border-color: #ffd93d;
  box-shadow: 0 0 0 3px rgba(255, 217, 61, 0.3);
}

.skin-option-icon {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.background-animation .bubble,
.background-animation .star {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

[data-skin] body {
  background: linear-gradient(
    135deg,
    var(--skin-gradient-1, #FF6B6B),
    var(--skin-gradient-2, #4ECDC4),
    var(--skin-gradient-3, #45B7D1),
    var(--skin-gradient-4, #96CEB4),
    var(--skin-gradient-5, #FFEAA7),
    var(--skin-gradient-6, #FD79A8)
  );
  background-size: 400% 400%;
  animation: gradientShift 18s ease infinite;
}

/* ===========================================
   SYSTEM DARK MODE
   Only applies when system prefers dark AND the Island theme is active.
   Deep Sea theme is already dark, so we skip it.
   =========================================== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="deepsea"]) .game-card {
    background: rgba(45, 52, 54, 0.95);
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .game-card h1,
  :root:not([data-theme="deepsea"]) .game-card h2,
  :root:not([data-theme="deepsea"]) .game-card h3 {
    color: #ffeaa7;
  }

  :root:not([data-theme="deepsea"]) .input {
    background: #3d3d3d;
    border-color: #555;
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .option {
    background: #3d3d3d;
    border-color: #555;
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .option:hover:not(:disabled) {
    background: #4a4a5a;
  }

  :root:not([data-theme="deepsea"]) .option.correct {
    background: #1a4d2e;
    border-color: #27ae60;
    color: #a3d9a5;
  }

  :root:not([data-theme="deepsea"]) .option.incorrect {
    background: #4d1a1a;
    border-color: #e74c3c;
    color: #f5b7b1;
  }

  :root:not([data-theme="deepsea"]) .feedback.correct {
    background: #1a4d2e;
    color: #a3d9a5;
  }

  :root:not([data-theme="deepsea"]) .feedback.incorrect {
    background: #4d1a1a;
    color: #f5b7b1;
  }

  :root:not([data-theme="deepsea"]) .btn-mode {
    background: rgba(45, 52, 54, 0.9);
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .diff-btn {
    background: #3d3d3d;
    color: #dfe6e9;
    border-color: #555;
  }

  :root:not([data-theme="deepsea"]) .leaderboard-entry {
    background: rgba(45, 52, 54, 0.9);
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .leaderboard-tab {
    background: #3d3d3d;
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .leaderboard-tab.active {
    background: #4a4a5a;
  }

  :root:not([data-theme="deepsea"]) .screen-subtitle,
  :root:not([data-theme="deepsea"]) .tagline,
  :root:not([data-theme="deepsea"]) .player-name-label,
  :root:not([data-theme="deepsea"]) .btn-subtext,
  :root:not([data-theme="deepsea"]) .diff-desc {
    color: #b2bec3;
  }

  :root:not([data-theme="deepsea"]) .question-box {
    background: #2d3436 !important;
    border: 1px solid #555;
  }

  :root:not([data-theme="deepsea"]) .question-text,
  :root:not([data-theme="deepsea"]) .game-card .question-text {
    color: #f1f5f9 !important;
  }

  :root:not([data-theme="deepsea"]) .builder-option {
    background: #3d3d3d;
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .builder-option.color-swatch {
    border: 2px solid #555;
  }

  :root:not([data-theme="deepsea"]) .skin-option {
    background: rgba(45, 52, 54, 0.9);
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .shop-item {
    border-color: #555;
  }

  :root:not([data-theme="deepsea"]) .shop-item-desc {
    color: #b2bec3;
  }

  :root:not([data-theme="deepsea"]) .avatar-option {
    background: rgba(45, 52, 54, 0.8);
  }

  :root:not([data-theme="deepsea"]) .tables-checkbox-grid label {
    background: #3d3d3d;
    color: #dfe6e9;
  }

  :root:not([data-theme="deepsea"]) .bubble {
    opacity: 0.08;
  }

  :root:not([data-theme="deepsea"]) .star {
    opacity: 0.1;
  }
}

/* ===== Coin Shop ===== */
.coin-display-header {
  font-size: 1.2rem;
  font-weight: bold;
  color: #ff9f1c;
}

.shop-grid {
  padding: 12px 0;
}

.shop-section-header {
  grid-column: 1 / -1;
  margin: 16px 0 8px;
  font-size: 1.1rem;
}

.shop-grid .shop-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  border-radius: 16px;
  background: var(--card-bg, rgba(255,255,255,0.8));
  border: 2px solid #e9ecef;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  width: 140px;
  margin: 6px;
}

.shop-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.shop-item-emoji { font-size: 2.5rem; margin-bottom: 8px; }
.shop-item-name { font-weight: bold; margin-bottom: 4px; }
.shop-item-cost { color: #ff9f1c; font-weight: bold; margin-bottom: 4px; }
.shop-item-desc { font-size: 0.8rem; color: #636e72; margin-bottom: 8px; }
.shop-item-owned { color: #27ae60; font-weight: bold; }

.btn-buy {
  background: linear-gradient(135deg, #ff9f1c, #ff6b6b);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  font-family: inherit;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.btn-buy:hover:not(:disabled) {
  transform: scale(1.05);
}

.btn-buy:disabled {
  background: #ccc;
  cursor: not-allowed;
  color: #666;
}

@media (max-width: 480px) {
  .shop-grid .shop-item { width: 120px; padding: 12px 8px; }
  .shop-item-emoji { font-size: 2rem; }
}

/* ===== Difficulty Suggestion ===== */
.difficulty-suggestion {
  background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  animation: slideDown 0.3s ease;
}

.difficulty-suggestion .suggestion-text {
  flex: 1;
  font-size: 0.95rem;
  min-width: 200px;
  color: #2d3436;
}

@keyframes slideDown {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .difficulty-suggestion { animation: none !important; }
}

/* ===== Avatar Creator ===== */
.avatar-creator-section {
  margin: 20px 0;
  text-align: center;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  margin: 10px auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  transition: background-color 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.avatar-builder {
  margin: 12px 0;
}

.builder-row {
  margin: 8px 0;
}

.builder-label {
  display: block;
  font-size: 0.85rem;
  font-weight: bold;
  margin-bottom: 4px;
}

.builder-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.builder-option {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: #f8f9fa;
  cursor: pointer;
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-family: inherit;
}

.builder-option:hover {
  transform: scale(1.1);
}

.builder-option.active {
  border-color: #ffd93d;
  box-shadow: 0 0 0 2px rgba(255, 217, 61, 0.4);
}

.builder-option.color-swatch {
  font-size: 0;
}

@media (max-width: 480px) {
  .builder-option { width: 38px; height: 38px; font-size: 1.1rem; }
}

/* ===== Times Tables Array Visualisation ===== */
.array-visualisation {
  text-align: center;
  margin: 10px auto;
}

.array-viz-svg {
  max-width: 280px;
  width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}

@media (max-width: 480px) {
  .array-viz-svg { max-width: 200px; }
}

/* ===== Screen Transitions ===== */
.screen.entering {
  display: block !important;
  animation: screenEnter 0.3s ease forwards;
}

.screen.leaving {
  display: block !important;
  animation: screenLeave 0.2s ease forwards;
}

@keyframes screenEnter {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes screenLeave {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); }
}

@media (prefers-reduced-motion: reduce) {
  .screen.entering,
  .screen.leaving {
    animation: none !important;
  }
  .screen.entering {
    opacity: 1;
    transform: none;
  }
}

/* ===== Background Creatures ===== */
.background-creatures {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.creature {
  position: absolute;
  font-size: 1.5rem;
  opacity: 0.3;
  top: var(--top, 50%);
}

.creature-bird {
  animation: flyAcross 20s linear infinite;
  animation-delay: var(--delay, 0s);
  left: -5%;
}

@keyframes flyAcross {
  0% { left: -5%; transform: translateY(0); }
  25% { transform: translateY(-15px); }
  50% { left: 50%; transform: translateY(5px); }
  75% { transform: translateY(-10px); }
  100% { left: 105%; transform: translateY(0); }
}

.creature-butterfly {
  animation: butterflyFloat 15s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  left: -5%;
}

@keyframes butterflyFloat {
  0% { left: -5%; transform: translateY(0) rotate(0deg); }
  15% { transform: translateY(-20px) rotate(5deg); }
  30% { transform: translateY(10px) rotate(-5deg); }
  45% { transform: translateY(-15px) rotate(3deg); }
  60% { left: 60%; transform: translateY(5px) rotate(-3deg); }
  75% { transform: translateY(-10px) rotate(2deg); }
  100% { left: 105%; transform: translateY(0) rotate(0deg); }
}

.creature-fish {
  animation: swimAcross 25s linear infinite;
  animation-delay: var(--delay, 0s);
  left: -5%;
}

@keyframes swimAcross {
  0% { left: -5%; transform: translateY(0); }
  25% { transform: translateY(-8px); }
  50% { left: 50%; transform: translateY(8px); }
  75% { transform: translateY(-5px); }
  100% { left: 105%; transform: translateY(0); }
}

@media (max-width: 480px) {
  .creature { font-size: 1rem; opacity: 0.2; }
  .creature:nth-child(even) { display: none; }
}

/* ===========================================
   COMPREHENSIVE REDUCED MOTION (safety net)
   =========================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .background-animation {
    display: none;
  }
  .background-creatures {
    display: none;
  }
}