/* ─── CSS Variables ─────────────────────────────────────────── */
:root {
    --bg-primary: #F5F7FA;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --text-primary: #2D3748;
    --text-secondary: #718096;
    --accent-blue: #4A90D9;
    --accent-teal: #5BBFB5;
    --accent-green: #68D391;
    --accent-orange: #ED8936;
    --accent-pink: #D69E9E;
    --accent-yellow: #D4A843;
    --accent-red: #E07070;
    --accent-purple: #9B8EC4;
    --accent-cyan: #68B8D7;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 10px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.10);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --font-display: 'Fredoka', sans-serif;
    --font-body: 'Nunito', sans-serif;
    --nav-bg: #ffffff;
    --border-color: #E2E8F0;

    /* Finger colors — muted pastel */
    --finger-l-pinky: #D4A0C0;
    --finger-l-ring: #B8A9D4;
    --finger-l-middle: #8CB4D9;
    --finger-l-index: #8CD4A8;
    --finger-r-index: #D4C88C;
    --finger-r-middle: #D4A88C;
    --finger-r-ring: #D49C9C;
    --finger-r-pinky: #C4A0D4;
    --finger-thumb: #A0AEC0;

    --transition-speed: 0.3s;
}

/* ─── Dark Theme ───────────────────────────────────────────── */
[data-theme="dark"] {
    --bg-primary: #1A202C;
    --bg-card: #2D3748;
    --bg-card-hover: #353F54;
    --text-primary: #E2E8F0;
    --text-secondary: #A0AEC0;
    --nav-bg: #1A202C;
    --border-color: #4A5568;
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 10px rgba(0,0,0,0.25);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.3);
}

/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
}

a {
    text-decoration: none;
    color: inherit;
}

.content {
    animation: pageIn 0.3s ease-out;
}

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

/* ─── Navigation ───────────────────────────────────────────── */
.main-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--nav-bg);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color var(--transition-speed) ease;
    border-bottom: 1px solid var(--border-color);
}

.nav-logo {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links {
    display: flex;
    gap: 4px;
}

.nav-link {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.nav-link:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle, .sound-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-toggle:hover, .sound-toggle:hover {
    background: var(--bg-primary);
    border-color: var(--accent-blue);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-primary);
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.88rem;
}

/* ─── Content ──────────────────────────────────────────────── */
.content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ─── Home Page ────────────────────────────────────────────── */
.home-container {
    text-align: center;
}

.hero {
    padding: 32px 0 24px;
}

.hero-title {
    font-size: 2.4rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

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

.mode-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 28px 22px;
    box-shadow: var(--shadow-sm);
    transition: all 0.25s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 2px solid transparent;
    text-align: left;
}

.mode-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.mode-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.mode-training::before { background: var(--accent-blue); }
.mode-training:hover { border-color: var(--accent-blue); }
.mode-bubbles::before { background: var(--accent-cyan); }
.mode-bubbles:hover { border-color: var(--accent-cyan); }
.mode-articles::before { background: var(--accent-teal); }
.mode-articles:hover { border-color: var(--accent-teal); }
.mode-pet::before { background: var(--accent-green); }
.mode-pet:hover { border-color: var(--accent-green); }
.mode-stats::before { background: var(--accent-orange); }
.mode-stats:hover { border-color: var(--accent-orange); }
.mode-family::before { background: var(--accent-purple); }
.mode-family:hover { border-color: var(--accent-purple); }

.mode-card h2 {
    font-size: 1.2rem;
    margin-bottom: 6px;
}

.mode-card p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.mode-badge {
    display: inline-block;
    margin-top: 10px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    background: var(--bg-primary);
    color: var(--accent-blue);
}

/* ─── Finger Training ──────────────────────────────────────── */
.training-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    min-height: calc(100vh - 120px);
}

.stage-sidebar {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    align-self: start;
    position: sticky;
    top: 76px;
}

.stage-sidebar h3 {
    font-size: 1rem;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.stage-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stage-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.stage-item:hover:not(.stage-locked) {
    background: var(--bg-primary);
}

.stage-item.stage-active {
    background: #EBF4FF;
    border-color: var(--accent-blue);
}

.stage-item.stage-locked {
    opacity: 0.45;
    cursor: not-allowed;
}

.stage-item.stage-completed {
    opacity: 1;
}

.stage-num {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    flex-shrink: 0;
}

.stage-active .stage-num {
    background: var(--accent-blue);
    color: white;
}

.stage-completed .stage-num {
    background: var(--accent-green);
    color: white;
}

.stage-info {
    flex: 1;
    min-width: 0;
}

.stage-name {
    font-weight: 600;
    font-size: 0.83rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stage-stars {
    font-size: 0.72rem;
    color: var(--accent-yellow);
}

/* Training Area */
.training-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.training-header {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.training-header h2 {
    font-size: 1.3rem;
    margin-bottom: 6px;
}

.training-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.training-stats-bar {
    display: flex;
    justify-content: center;
    gap: 28px;
    margin-top: 14px;
}

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

.stat-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-blue);
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* Target display */
.target-display {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-sm);
    text-align: center;
    min-height: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.target-prompt {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 600;
}

.target-chars {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    font-family: 'Fredoka', monospace;
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: 3px;
}

.target-char {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 58px;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.target-char.current {
    background: #E8F0FE;
    color: var(--accent-blue);
    box-shadow: 0 0 12px rgba(74, 144, 217, 0.2);
}

.target-char.typed {
    color: var(--accent-green);
    opacity: 0.5;
}

.target-char.error {
    color: var(--accent-red);
    animation: shake 0.3s ease;
}

.target-char.space-char {
    width: 36px;
    border-bottom: 2px dashed #CBD5E0;
}

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

.finger-hint {
    margin-top: 14px;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 999px;
    display: inline-block;
}

/* Progress bar */
.progress-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 14px 20px;
    box-shadow: var(--shadow-sm);
}

.progress-bar-outer {
    width: 100%;
    height: 12px;
    background: #E2E8F0;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar-inner {
    height: 100%;
    border-radius: 999px;
    background: var(--accent-blue);
    transition: width 0.5s ease;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* Stage complete overlay */
.stage-complete-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.stage-complete-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.stage-complete-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 380px;
    transform: scale(0.85);
    transition: transform 0.3s ease;
}

.stage-complete-overlay.active .stage-complete-card {
    transform: scale(1);
}

.complete-emoji {
    font-size: 3rem;
    margin-bottom: 12px;
}

.complete-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.complete-stars {
    font-size: 2rem;
    margin: 12px 0;
}

.complete-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 14px 0 20px;
}

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

.complete-stat-value {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-blue);
}

.complete-stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 3px 12px rgba(74, 144, 217, 0.3);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    margin-left: 8px;
}

.btn-secondary:hover {
    background: #E2E8F0;
}

/* ─── Toast Notifications ──────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: white;
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    animation: slideIn 0.3s ease;
    border-left: 3px solid var(--accent-blue);
}

.toast.success { border-left-color: var(--accent-green); }
.toast.error { border-left-color: var(--accent-red); }
.toast.achievement { border-left-color: var(--accent-yellow); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── Confetti ─────────────────────────────────────────────── */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 3000;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    animation: confettiFall linear forwards;
}

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

/* ─── Achievement Toast ────────────────────────────────────── */
.achievement-unlock {
    border-left: 3px solid var(--accent-yellow) !important;
    padding: 14px 18px !important;
    min-width: 260px;
    background: linear-gradient(135deg, #FFFBEB, #FEF3C7, white) !important;
}

.achievement-toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.achievement-toast-icon {
    font-size: 1.8rem;
}

.achievement-toast-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    color: var(--accent-yellow);
    font-weight: 800;
    letter-spacing: 0.5px;
}

.achievement-toast-name {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.achievement-toast-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ─── Badge Gallery ────────────────────────────────────────── */
.badge-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
}

.badge-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.badge-card.badge-earned {
    border-color: var(--accent-yellow);
}

.badge-card.badge-earned:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.badge-card.badge-locked {
    opacity: 0.4;
    filter: grayscale(0.4);
}

.badge-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}

.badge-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 3px;
}

.badge-desc {
    font-size: 0.68rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.badge-date {
    font-size: 0.62rem;
    color: var(--accent-blue);
    font-weight: 700;
    margin-top: 4px;
}

/* ─── Loading Spinner ──────────────────────────────────────── */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ─── Global Hover ─────────────────────────────────────────── */
button, .btn, .mode-card, .badge-card, a.nav-link {
    transition: all 0.2s ease;
}

button:not(:disabled):hover, .btn:hover {
    transform: translateY(-1px);
}

button:not(:disabled):active, .btn:active {
    transform: translateY(0) scale(0.98);
}

/* ─── Dark theme overrides ─────────────────────────────────── */
[data-theme="dark"] .stage-complete-card,
[data-theme="dark"] .toast,
[data-theme="dark"] .rename-modal {
    background: var(--bg-card);
    color: var(--text-primary);
}

[data-theme="dark"] .achievement-unlock {
    background: linear-gradient(135deg, #422006, #451a03, var(--bg-card)) !important;
}

[data-theme="dark"] .badge-card.badge-earned {
    background: linear-gradient(135deg, #422006, var(--bg-card));
}

[data-theme="dark"] input {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

[data-theme="dark"] .stage-item.stage-active {
    background: #2A3B52;
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .training-container {
        grid-template-columns: 1fr;
    }
    .stage-sidebar {
        position: static;
    }
    .stage-list {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .stage-item {
        flex: 1;
        min-width: 100px;
    }
}

@media (max-width: 600px) {
    .nav-links {
        display: none;
    }
    .hero-title {
        font-size: 1.8rem;
    }
    .mode-grid {
        grid-template-columns: 1fr;
    }
    .target-chars {
        font-size: 1.6rem;
    }
    .target-char {
        width: 38px;
        height: 44px;
    }
    .training-stats-bar {
        gap: 14px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .content {
        padding: 16px;
    }
    .mode-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .training-container {
        grid-template-columns: 200px 1fr;
    }
}

/* Donate heart button in nav */
.donate-heart {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #F6C255;
    background: rgba(246, 194, 85, 0.12);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 20px;
    margin-right: 8px;
    transition: all 0.3s ease;
    animation: donateGlow 3s ease-in-out infinite;
}
.donate-heart:hover {
    background: rgba(246, 194, 85, 0.25);
    transform: scale(1.08);
    color: #E5A800;
}
@keyframes donateGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(246, 194, 85, 0); }
    50% { box-shadow: 0 0 12px 2px rgba(246, 194, 85, 0.3); }
}
/* Heartbeat pulse on the emoji */
.donate-heart::before {
    content: '';
    display: none;
}
