@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;700&family=Inter:wght@400;600;700;800&display=swap');

:root {
    --bg: #F5F6FB;
    --surface: #FFFFFF;
    --ink: #1B1F3B;
    --muted: #767B99;
    --line: #E4E6F2;
    --primary: #5B4FE9;
    --primary-dark: #4038B8;
    --primary-tint: #EEECFD;
    --mint: #16B8A6;
    --mint-tint: #E4F8F5;
    --coral: #FF6B57;
    --coral-tint: #FFEBE8;
    --amber: #F5A623;
    --amber-tint: #FEF3E1;
    --shadow: rgba(27, 31, 59, 0.08);
    --teal: #16B8A6;
    --teal-dark: #0E8B7D;
    --gold: #F5A623;
    --navy: #1B1F3B;
    --danger: #FF6B57;
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 8% 8%, rgba(91, 79, 233, 0.07) 0%, transparent 32%),
        radial-gradient(circle at 92% 18%, rgba(22, 184, 166, 0.08) 0%, transparent 30%),
        radial-gradient(circle at 15% 85%, rgba(255, 107, 87, 0.06) 0%, transparent 30%),
        radial-gradient(circle at 90% 90%, rgba(245, 166, 35, 0.06) 0%, transparent 28%);
    background-attachment: fixed;
    color: var(--ink);
    min-height: 100vh;
}

.wrap { max-width: 780px; margin: 0 auto; min-height: 100vh; }

.board {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    padding: 26px 22px 30px;
    position: relative;
    border-radius: 0 0 28px 28px;
}
.board-title { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 27px; margin: 8px 0 2px; }
.board-sub { font-size: 14px; opacity: 0.85; }
.board .back-link { color: rgba(255,255,255,0.85); background: none; border: none; font-family: 'Inter', sans-serif; font-weight: 700; font-size: 13px; cursor: pointer; padding: 0; }
.board .back-link:hover { color: #fff; }
.logo-badge { width: 68px; height: 68px; border-radius: 18px; box-shadow: 0 6px 18px rgba(0,0,0,0.22); margin-bottom: 10px; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,0.16); animation: popIn 0.4s ease; }

.content { padding: 22px 22px 60px; }

.mode-grid { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.mode-tile {
    background: var(--surface);
    border-radius: 16px;
    border-left: 5px solid var(--tile-color);
    padding: 16px 16px;
    text-decoration: none;
    color: var(--ink);
    box-shadow: 0 4px 14px var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    border-top: none; border-right: none; border-bottom: none;
    width: 100%; text-align: left; font-family: 'Inter', sans-serif;
}
.mode-tile .mode-icon {
    width: 46px; height: 46px; border-radius: 13px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 22px;
    background: var(--tile-color);
    color: #fff;
    box-shadow: 0 4px 10px color-mix(in srgb, var(--tile-color) 45%, transparent);
}
.mode-tile .mode-icon svg { width: 24px; height: 24px; }
.mode-title { font-weight: 800; font-size: 15px; }
.mode-desc { font-size: 12.5px; color: var(--muted); line-height: 1.4; margin-top: 2px; }
.mode-tile .mode-arrow { margin-left: auto; color: var(--muted); flex-shrink: 0; }

.shelf { display: flex; flex-direction: column; gap: 12px; }
.book-card {
    background: var(--surface); border-radius: 14px; padding: 15px 17px;
    box-shadow: 0 4px 14px var(--shadow);
    cursor: pointer; border: none; text-align: left; width: 100%; font-family: 'Inter', sans-serif; color: var(--ink);
}
.book-subject { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary); font-weight: 800; }
.book-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.book-title { font-weight: 800; font-size: 15px; margin-top: 2px; }
.book-bar { height: 6px; border-radius: 4px; background: var(--line); margin-top: 10px; overflow: hidden; }
.book-bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1); }

.card { background: var(--surface); border-radius: 16px; padding: 18px 18px; box-shadow: 0 4px 14px var(--shadow); margin-bottom: 14px; }
.section-title { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 19px; margin: 28px 0 12px; }
.section-title:first-child { margin-top: 0; }
.empty-note { text-align: center; color: var(--muted); font-size: 14px; margin-top: 40px; line-height: 1.6; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; padding: 11px 20px; font-weight: 800; font-size: 14px; cursor: pointer; font-family: 'Inter', sans-serif; border: none; text-decoration: none; text-align: center; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger-link { background: none; border: none; color: var(--coral); font-weight: 700; font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn-block { width: 100%; }
.back-link { color: var(--muted); text-decoration: none; font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; gap: 4px; margin-bottom: 4px; background: none; border: none; cursor: pointer; padding: 0; font-family: 'Inter', sans-serif; }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 800; font-size: 13px; margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px;
    font-size: 14px; font-family: 'Inter', sans-serif; background: var(--surface); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.hint { font-size: 12px; color: var(--muted); margin-top: -8px; margin-bottom: 16px; line-height: 1.5; }
.radio-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.radio-row label { flex: 1; min-width: 44px; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; font-weight: 700; font-size: 13px; cursor: pointer; }
.radio-row input { margin-right: 4px; }
.radio-row input:checked + span, .radio-row label:has(input:checked) { color: var(--primary-dark); }
.radio-row label:has(input:checked) { background: var(--primary-tint); border-color: var(--primary); }

/* Quiz */
.progress-dots { display: flex; gap: 7px; justify-content: center; margin-bottom: 22px; }
.progress-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.progress-dot.active { background: var(--primary); width: 22px; border-radius: 5px; }
.progress-dot.done { background: var(--mint); }
.quiz-card { background: var(--surface); border-radius: 18px; padding: 22px 20px; box-shadow: 0 4px 14px var(--shadow); }
.quiz-q { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 18px; margin-bottom: 18px; line-height: 1.4; }
.option-row { display: block; width: 100%; text-align: left; background: var(--surface); border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 15px; margin-bottom: 10px; font-family: 'Inter', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink); cursor: pointer; }
.option-row:hover:not(:disabled) { border-color: var(--primary); }
.option-row.correct { background: var(--mint-tint); border-color: var(--teal); color: var(--teal-dark); animation: popIn 0.35s ease; }
.option-row.wrong { background: var(--coral-tint); border-color: var(--coral); color: #C2432F; animation: shake 0.35s ease; }
.option-row:disabled { cursor: default; }
.feedback-box { border-radius: 12px; padding: 13px 15px; margin-top: 6px; font-size: 13px; animation: fadeInUp 0.3s ease both; }
.feedback-box.correct { background: var(--mint-tint); color: #0E8B7D; }
.feedback-box.wrong { background: var(--coral-tint); color: #C2432F; }
.feedback-box b { display: block; margin-bottom: 3px; font-size: 15px; }

/* Results */
.result-hero { text-align: center; margin: 10px 0 26px; }
.result-score { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 46px; color: var(--primary); }
.result-msg { font-weight: 700; font-size: 18px; margin-top: 2px; }

.mastery-chip { display: inline-block; border-radius: 20px; padding: 3px 12px; font-size: 12px; font-weight: 800; }
.mastery-chip.mastered { background: var(--mint-tint); color: var(--teal-dark); }
.mastery-chip.learning { background: var(--line); color: var(--muted); }

.pill { display: inline-block; background: var(--primary-tint); color: var(--primary-dark); border-radius: 20px; padding: 3px 10px; font-size: 11px; font-weight: 800; }
.pill-mint { background: var(--mint-tint); color: #0E8B7D; }
.pill-amber { background: var(--amber-tint); color: #B8790F; }
.pill-coral { background: var(--coral-tint); color: #C2432F; }
.pill-muted { background: var(--line); color: var(--muted); }

.error-box { background: var(--coral-tint); color: #C2432F; border-radius: 12px; padding: 12px 14px; font-size: 13px; font-weight: 700; margin-top: 12px; }
.success-box { background: var(--mint-tint); color: #0E8B7D; border-radius: 12px; padding: 12px 14px; font-size: 13px; font-weight: 700; margin-top: 12px; margin-bottom: 16px; }

.loading-note { text-align: center; padding: 50px 20px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 14px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stat-grid { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-box { background: var(--surface); border-radius: 14px; padding: 14px 18px; flex: 1; min-width: 100px; text-align: center; box-shadow: 0 2px 8px var(--shadow); }
.stat-num { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 24px; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

.teach-card { background: var(--surface); border-radius: 18px; padding: 22px 20px; box-shadow: 0 4px 14px var(--shadow); line-height: 1.8; font-size: 16px; }
.teach-card h3 { font-family: 'Space Grotesk', sans-serif; margin-top: 0; }

/* Avatars */
.avatar-circle { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 19px; color: #fff; flex-shrink: 0; }

/* ============================================================
   Motion & liveliness
   ============================================================ */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { 0% { transform: scale(0.9); } 55% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-6px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes celebrateIn { 0% { transform: scale(0.85) translateY(6px); opacity: 0; } 60% { transform: scale(1.04) translateY(0); opacity: 1; } 100% { transform: scale(1); } }
@keyframes sparklePulse { 0%, 100% { transform: scale(1) rotate(0deg); } 50% { transform: scale(1.15) rotate(-6deg); } }

.book-card, .mode-tile, .badge-card, .stat-box, .quiz-card { animation: fadeInUp 0.35s ease both; }
.shelf .book-card:nth-child(1), .mode-grid .mode-tile:nth-child(1), .badge-grid .badge-card:nth-child(1) { animation-delay: 0.02s; }
.shelf .book-card:nth-child(2), .mode-grid .mode-tile:nth-child(2), .badge-grid .badge-card:nth-child(2) { animation-delay: 0.06s; }
.shelf .book-card:nth-child(3), .mode-grid .mode-tile:nth-child(3), .badge-grid .badge-card:nth-child(3) { animation-delay: 0.10s; }
.shelf .book-card:nth-child(4), .mode-grid .mode-tile:nth-child(4), .badge-grid .badge-card:nth-child(4) { animation-delay: 0.14s; }
.shelf .book-card:nth-child(5), .mode-grid .mode-tile:nth-child(5), .badge-grid .badge-card:nth-child(5) { animation-delay: 0.18s; }
.shelf .book-card:nth-child(n+6), .badge-grid .badge-card:nth-child(n+6) { animation-delay: 0.2s; }

.btn, .mode-tile, .book-card, .option-row, .stat-box { transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease; }
.btn:active, .mode-tile:active, .book-card:active, .option-row:not(:disabled):active { transform: scale(0.96); }
.mode-tile:hover, .book-card:hover { box-shadow: 0 8px 22px var(--shadow); transform: translateY(-2px); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.success-box.celebrate { animation: celebrateIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.badge-card:not(.locked) .badge-icon { animation: sparklePulse 2.2s ease-in-out infinite; }

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

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.badge-card { background: var(--surface); border-radius: 14px; padding: 16px 12px; text-align: center; box-shadow: 0 4px 14px var(--shadow); }
.badge-card.locked { opacity: 0.5; filter: grayscale(1); }
.badge-icon { font-size: 34px; margin-bottom: 8px; }
.badge-name { font-weight: 800; font-size: 13px; }
.badge-desc { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.badge-icon-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.badge-icon-chip { width: 60px; height: 60px; justify-self: center; background: var(--surface); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 30px; box-shadow: 0 4px 14px var(--shadow); }
.badge-icon-chip.locked { background: var(--line); filter: grayscale(1); opacity: 0.55; font-size: 22px; }
