@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);

    /* Aliases used across pages for the mode colors and status states */
    --teal: #16B8A6;
    --teal-dark: #0E8B7D;
    --gold: #F5A623;
    --navy: #1B1F3B;
    --danger: #FF6B57;
}

* { box-sizing: border-box; }

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; }

/* Header band — every page opens with one of these */
.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); }
.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: block; animation: popIn 0.4s ease; }

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

/* Mode grid — the five home-screen modes */
.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;
}
.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; }

/* Study lists ("shelf" of topics/materials) */
.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);
}
.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; }

/* Tabs (paste text vs upload file) */
.tab-row { display: flex; gap: 8px; margin-bottom: 14px; }
.tab-btn { flex: 1; text-align: center; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line); font-weight: 700; font-size: 13px; cursor: pointer; color: var(--muted); }
.tab-btn.active { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-dark); }

/* Knowledge map tree (admin) */
.tree-item { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); margin-bottom: 4px; }
.tree-label { font-weight: 700; font-size: 14px; }
.tree-meta { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.5; }

/* Mastery chip shown after an answer */
.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); }

/* Cards & lists */
.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; }

/* Buttons */
.btn { display: inline-block; 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; }
.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; }
.back-link { color: var(--muted); text-decoration: none; font-weight: 700; font-size: 13px; display: inline-block; margin-bottom: 4px; }

/* Forms */
.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 textarea { min-height: 160px; resize: vertical; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.field input[type=file] { padding: 9px; }
.hint { font-size: 12px; color: var(--muted); margin-top: -8px; margin-bottom: 16px; line-height: 1.5; }
.radio-row { display: flex; gap: 10px; margin-bottom: 16px; }
.radio-row label { flex: 1; 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: 6px; }

/* PIN pad */
.pin-wrap { display: flex; flex-direction: column; align-items: center; margin-top: 10px; }
.pin-dots { display: flex; gap: 14px; margin: 18px 0 26px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; }
.pin-dot.filled { background: var(--ink); }
.pin-grid { display: grid; grid-template-columns: repeat(3, 64px); gap: 14px; }
.pin-key { width: 64px; height: 64px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface); font-size: 20px; font-weight: 800; color: var(--ink); cursor: pointer; }
.pin-key:active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pin-error { color: var(--coral); font-weight: 700; font-size: 13px; margin-top: 14px; min-height: 16px; }

/* 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.done { background: var(--mint); }
.progress-dot.current { background: var(--primary); }
.quiz-card { background: var(--surface); border-radius: 18px; padding: 24px 20px; box-shadow: 0 4px 14px var(--shadow); }
.quiz-topic { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary); font-weight: 800; margin-bottom: 8px; }
.quiz-question { font-weight: 800; font-size: 18px; line-height: 1.4; margin-bottom: 18px; font-family: 'Space Grotesk', sans-serif; }
.option-row { display: block; width: 100%; text-align: left; background: var(--bg); border: 1.5px solid var(--line); border-radius: 12px; padding: 13px 16px; margin-bottom: 10px; font-size: 15px; font-weight: 700; font-family: 'Inter', sans-serif; cursor: pointer; color: var(--ink); }
.option-row:hover { border-color: var(--primary); }
.option-row.correct { background: var(--mint-tint); border-color: var(--mint); }
.option-row.wrong { background: var(--coral-tint); border-color: var(--coral); }
.option-row:disabled { cursor: default; }
.feedback-box { margin-top: 14px; padding: 14px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5; }
.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; }
.miss-item { background: var(--surface); border-radius: 12px; border-left: 4px solid var(--coral); padding: 13px 16px; margin-bottom: 10px; box-shadow: 0 2px 8px var(--shadow); }
.miss-q { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.miss-correct { font-size: 13px; color: #0E8B7D; font-weight: 700; }
.miss-topic { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 6px; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.data-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; }
.manage-row { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border-radius: 12px; padding: 11px 15px; margin-bottom: 8px; font-size: 14px; font-weight: 700; box-shadow: 0 2px 8px var(--shadow); }

.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; }

mark { background: var(--amber-tint); color: #7A5300; font-weight: 800; padding: 1px 3px; border-radius: 4px; }
.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.7; font-size: 15px; }
.teach-card h3 { font-family: 'Space Grotesk', sans-serif; margin-top: 0; }

.concept-checkbox { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 2px 8px var(--shadow); font-weight: 700; font-size: 14px; }
.concept-checkbox input { width: 18px; height: 18px; }

.upload-drop {
    border: 2px dashed var(--line); border-radius: 16px; padding: 30px 20px; text-align: center;
    color: var(--muted); background: var(--surface);
}

/* ============================================================
   Motion & liveliness pass
   ============================================================ */

@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); }
}

/* Cards animate in with a gentle cascade */
.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; }

/* Tactile feedback on anything tappable */
.btn, .mode-tile, .book-card, .option-row, .pin-key, .badge-card, .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, .pin-key:active {
    transform: scale(0.96);
}
.mode-tile:hover, .book-card:hover {
    box-shadow: 0 8px 22px var(--shadow);
    transform: translateY(-2px);
}
.btn-primary:hover { filter: brightness(1.06); }

/* Quiz answer feedback with real motion */
.option-row.correct { animation: popIn 0.35s ease; }
.option-row.wrong { animation: shake 0.35s ease; }
.feedback-box { animation: fadeInUp 0.3s ease both; }

/* Celebration moments (new badge / level up) get a proper entrance */
.success-box:has(.badge-icon), .success-box.celebrate {
    animation: celebrateIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.badge-icon, .badge-card:not(.locked) .badge-icon {
    display: inline-block;
}
.badge-card:not(.locked) .badge-icon {
    animation: sparklePulse 2.2s ease-in-out infinite;
}

/* Progress bars fill in smoothly rather than snapping */
.book-bar-fill, [style*="background:#fff;height:100%"] {
    transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

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

/* Badge grid — full detail view (achievements page) */
.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; }

/* Icon-only chips — compact home screen preview, 4 per row */
.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; }
