/* ==========================================================
   Math Learning
   TABLE OF CONTENTS
   1. Variables & Reset      2. Typography & Layout
   3. Navigation             4. Buttons & Forms
   5. Drop Zone              6. Calculator (home)
   7. Math Input             8. Virtual Keyboard
   9. Confirm Modal         10. Deck List
  11. Deck Detail           12. Study Session
  13. Multiple Choice       14. Decomposition
  15. Rewards               16. FAB
  17. Responsive
   ========================================================== */

/* 1. Variables & Reset */

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

:root {
    --surface: #FFFFFF;
    --bg: #F5F6FA;
    --border: #E2E8F0;
    --border-focus: #818CF8;
    --text: #1E293B;
    --text-muted: #94A3B8;
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --radius: 10px;
    --transition: 120ms ease;
    --green: #22c55e;
    --red: #ef4444;

    /* Z-index scale */
    --z-sticky: 100;
    --z-fab: 200;
    --z-modal: 1000;
    --z-flash: 9000;
    --z-confetti: 9100;
    --z-hype: 9200;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}


/* ==========================================================
   Nav
   ========================================================== */

nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: 50px;
    padding: 0 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.nav-brand {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--text);
    text-decoration: none;
}

.nav-links {
    display: flex;
    gap: .75rem;
}
.nav-link {
    font-size: .88rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition);
}
.nav-link:hover { color: var(--text); }

.nav-actions { margin-left: auto; }

.kb-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}
.kb-toggle:hover { border-color: #CBD5E1; color: var(--text); }
.kb-toggle.active { background: var(--primary); border-color: var(--primary); color: #fff; }


/* ==========================================================
   Shared Page Layout
   ========================================================== */

.page-container {
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.page-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}
.page-actions {
    display: flex;
    gap: .5rem;
    flex-shrink: 0;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
}


/* ==========================================================
   Buttons
   ========================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem 1.1rem;
    font-size: .88rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 8px;
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { border-color: #CBD5E1; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }


/* ==========================================================
   Forms
   ========================================================== */

.page-title { margin-bottom: 1.25rem; }

.form-simple { max-width: 400px; }
.form-actions { display: flex; gap: .5rem; }

.form-center {
    display: flex;
    justify-content: center;
    padding: 4rem 1rem 2rem;
}
.form-card {
    width: 100%;
    max-width: 520px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 2.5rem;
}
.form-card-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.75rem;
    text-align: center;
}
.btn-full { width: 100%; }

.manual-create-row {
    display: flex;
    gap: .5rem;
}
.manual-create-row .input-text { flex: 1; }
.manual-create-row .btn { flex-shrink: 0; }

.input-text {
    display: block;
    width: 100%;
    padding: .65rem .85rem;
    font-size: .95rem;
    font-family: inherit;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    margin-bottom: 1rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-text:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(79,106,232,.18);
}

.field-group {
    margin-bottom: 1.25rem;
}
.field-group label {
    display: block;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: .35rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}


/* ==========================================================
   Drop Zone (file import)
   ========================================================== */

.drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
    margin-bottom: 1rem;
}
.drop-zone:hover { border-color: var(--primary); background: rgba(79,70,229,.02); }
.drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(79,70,229,.06);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.drop-zone-sm { padding: 1.25rem 1rem; }
.drop-icon { color: var(--text-muted); margin-bottom: .5rem; }
.drop-text { font-weight: 600; font-size: .95rem; color: var(--text); }
.drop-hint { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }

/* --- File preview card (Claude-style thumbnail) --- */

.preview-card {
    position: relative;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    animation: previewIn 200ms ease;
}
@keyframes previewIn {
    from { opacity: 0; transform: scale(.92); }
    to { opacity: 1; transform: scale(1); }
}

#file-preview {
    display: flex;
    align-items: flex-start;
}

.preview-card {
    width: 120px;
}

.preview-img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.preview-pdf {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    background: var(--bg);
    color: var(--text-muted);
}

.preview-name {
    display: block;
    padding: .4rem .6rem;
    font-size: .72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-top: 1px solid var(--border);
}

.preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity 150ms ease;
}
.preview-card:hover .preview-remove { opacity: 1; }
.preview-remove:hover { background: rgba(0,0,0,.7); }

.file-error {
    font-size: .85rem;
    color: #dc2626;
    padding: .5rem 0;
}

/* --- Import status --- */
.import-status {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem 1.1rem;
    border-radius: var(--radius);
    font-size: .9rem;
    font-weight: 500;
    margin-bottom: 1rem;
}
.import-loading {
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text);
}
.import-success {
    background: #f0fdf4;
    border: 1.5px solid #bbf7d0;
    color: #16a34a;
}
.import-error {
    background: #fef2f2;
    border: 1.5px solid #fecaca;
    color: #dc2626;
}

.import-spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .6s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Divider --- */
.divider {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: .8rem;
    font-weight: 500;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}


/* ==========================================================
   Calculator Layout (home page only)
   ========================================================== */

.calculator {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    /* fill remaining viewport height */
    height: calc(100vh - 50px);
}


/* ==========================================================
   Math Input (shared across pages)
   ========================================================== */

.input-area {
    position: relative;
    cursor: text;
}
.input-area-calc {
    margin: 1.5rem 1rem 0;
}

.math-field { width: 100%; }

/* MathQuill adds .mq-editable-field to the span itself (same element). */
.mq-editable-field,
.mq-editable-field.mq-focused,
.mq-math-mode .mq-editable-field,
.mq-math-mode .mq-editable-field.mq-focused {
    border: 1.5px solid var(--border) !important;
    box-shadow: none !important;
    outline: none !important;
    margin: 0 !important;
    padding: .85rem 1rem !important;
    border-radius: 8px !important;
    background: var(--surface) !important;
    font-size: 1.3rem !important;
    min-height: 54px !important;
}

.mq-editable-field.mq-focused,
.mq-math-mode .mq-editable-field.mq-focused {
    border-color: #4F6AE8 !important;
    box-shadow: 0 0 0 2px rgba(79,106,232,.18) !important;
}

.placeholder {
    position: absolute;
    left: 1.1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 1.1rem;
    pointer-events: none;
    opacity: .45;
    z-index: 1;
}


/* ==========================================================
   Virtual Keyboard
   ========================================================== */

.keyboard-panel {
    flex-shrink: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: none;
    margin-top: auto;
}
.keyboard-panel.open {
    display: block;
}

.kb-inner {
    max-width: 760px;
    margin: 0 auto;
    padding: .5rem .75rem .75rem;
}

.kb-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: .5rem;
}
.kb-tab {
    flex: 1;
    padding: .4rem 0;
    font-size: .75rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}
.kb-tab:hover { color: var(--text); }
.kb-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.kb-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}

.kb-key {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    font-size: .88rem;
    font-weight: 500;
    font-family: inherit;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    cursor: pointer;
    transition: background 80ms ease, transform 80ms ease;
    user-select: none;
    -webkit-user-select: none;
}
.kb-key:hover { background: #E9EBF2; }
.kb-key:active { background: #DDE0EA; transform: scale(.94); }

.key-struct { color: var(--primary); font-weight: 600; }
.key-nav { color: var(--text-muted); font-size: 1.1rem; }

.kb-actions {
    display: flex;
    gap: 4px;
    margin-top: 4px;
}
.kb-key-wide { flex: 1; }
.kb-key-action { color: var(--text-muted); }
.kb-key-action:hover { background: #FEF2F2; color: #EF4444; border-color: #FECACA; }
.kb-key-clear {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
}
.kb-key-clear:hover { background: #FEF2F2; color: #EF4444; border-color: #FECACA; }


/* ==========================================================
   Confirm Modal
   ========================================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: modalFadeIn 150ms ease;
}
@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: var(--surface);
    border-radius: 14px;
    padding: 1.5rem;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15), 0 2px 8px rgba(0,0,0,.08);
    animation: modalSlideIn 150ms ease;
}
@keyframes modalSlideIn {
    from { opacity: 0; transform: scale(.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-message {
    font-size: .95rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
}


/* ==========================================================
   Deck List
   ========================================================== */

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: .75rem;
}

.deck-canvas {
    position: relative;
    min-height: 200px;
}

.deck-card {
    position: absolute;
    width: 220px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow 150ms ease;
    user-select: none;
}
.deck-card:hover { border-color: var(--primary); }
.deck-card-dragging {
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    border-color: var(--primary);
    cursor: grabbing;
}

.deck-card-body {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    text-decoration: none;
    color: var(--text);
}
.deck-name { font-weight: 600; }
.deck-count { font-size: .82rem; color: var(--text-muted); margin-top: .25rem; }

.deck-gear {
    position: absolute;
    top: .5rem;
    right: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: var(--text-muted);
    opacity: .35;
    transition: opacity var(--transition), color var(--transition), background var(--transition);
}
.deck-card:hover .deck-gear { opacity: .7; }
.deck-gear:hover { opacity: 1 !important; color: var(--text); background: var(--bg); }



/* ==========================================================
   Card List (deck detail)
   ========================================================== */

.card-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

/* --- Card row (deck detail — stacked Q/A layout) --- */

.card-row-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
}

.card-row-q {
    display: flex;
    gap: .6rem;
    align-items: baseline;
    margin-bottom: .4rem;
}
.card-num {
    font-size: .75rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 1.2rem;
}
.card-q-text {
    flex: 1;
    min-width: 0;
}
.card-q-text .katex { white-space: normal; }

.card-row-a {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding-left: 1.8rem;
}
.card-a-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}
.card-a-text {
    flex: 1;
    min-width: 0;
}
.card-a-text .katex { white-space: normal; }

.card-row-detail .card-delete-form { margin-left: auto; flex-shrink: 0; }
.card-row-detail .btn-icon { opacity: 0; transition: opacity var(--transition); }
.card-row-detail:hover .btn-icon { opacity: 1; }

.card-delete-form { flex-shrink: 0; }
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover { background: #fef2f2; color: var(--red); }

/* --- Deck manager --- */

.deck-rename-form {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.input-rename {
    font-size: 1.25rem;
    font-weight: 700;
    font-family: inherit;
    color: var(--text);
    border: none;
    border-bottom: 1.5px solid transparent;
    border-radius: 0;
    padding: .15rem 0;
    background: transparent;
    outline: none;
    transition: border-color 200ms ease;
    cursor: text;
}
.input-rename:hover {
    border-bottom-color: var(--border);
}
.input-rename:focus {
    border-bottom-color: var(--primary);
}

.btn-sm { font-size: .78rem; padding: .35rem .75rem; }

.danger-zone {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
.btn-danger {
    background: transparent;
    color: var(--red);
    border: 1.5px solid var(--red);
    font-size: .82rem;
    padding: .45rem .9rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-danger:hover { background: #fef2f2; }


/* ==========================================================
   Study Session
   ========================================================== */

.study {
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    overflow: hidden;
}

.study-progress {
    text-align: center;
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .5rem;
}

.study-score {
    display: flex;
    justify-content: center;
    gap: 1rem;
    font-size: .82rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.score-correct { color: var(--green); }
.score-wrong { color: var(--red); }
.score-remaining { color: var(--text-muted); }

.done-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    margin-top: .75rem;
}

.study-question {
    text-align: center;
    padding: 1.5rem 1.5rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    min-height: 60px;
    overflow-wrap: break-word;
    word-wrap: break-word;
    overflow: visible;
}
.study-question .katex-display { margin: 0; overflow: visible; }
.study-question .katex-display > .katex { white-space: normal !important; text-align: center; }
.study-question .katex-html { white-space: normal !important; flex-wrap: wrap; justify-content: center; }
.study-question .katex { white-space: normal !important; word-wrap: break-word; }

.study-input {
    position: relative;
    margin-bottom: 1rem;
    cursor: text;
}

.study-actions {
    display: flex;
    justify-content: center;
    gap: .5rem;
    margin-bottom: 1rem;
}

/* --- Diff display --- */

.study-diff {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.diff-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem 0;
}
.diff-row + .diff-row {
    border-top: 1px solid var(--border);
}

.diff-label {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    width: 56px;
    flex-shrink: 0;
}
.diff-math {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}
.diff-math .katex { font-size: 1.25rem; }

.diff-match-banner {
    text-align: center;
    padding: .6rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: .9rem;
    margin-bottom: 1rem;
}
.diff-correct {
    background: #f0fdf4;
    color: var(--green);
    border: 1px solid #bbf7d0;
}

.banner-pop {
    animation: bannerPop 400ms ease;
}
@keyframes bannerPop {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================
   Decomposition — depth indicator + loading
   ========================================================== */

.depth-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .85rem;
    margin-bottom: .75rem;
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    border-radius: 8px;
    font-size: .8rem;
    font-weight: 500;
    color: #1D4ED8;
}

.depth-crumbs {
    display: flex;
    align-items: center;
    gap: .25rem;
}

.depth-arrow {
    color: #93C5FD;
    font-weight: 700;
}

.depth-level {
    color: #60A5FA;
    font-size: .75rem;
    font-weight: 600;
}

.study-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    padding: 2.5rem 1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .95rem;
    font-weight: 500;
    color: var(--text);
}

/* --- Skeleton loader (streaming) --- */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem 0;
}

.skeleton-bar {
    background: linear-gradient(90deg, var(--border) 25%, #f1f5f9 50%, var(--border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 8px;
}

.skeleton-question {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.skeleton-question .skeleton-bar:nth-child(1) { height: 14px; width: 85%; }
.skeleton-question .skeleton-bar:nth-child(2) { height: 14px; width: 60%; }
.skeleton-question .skeleton-bar:nth-child(3) { height: 14px; width: 72%; animation-delay: .1s; }

.skeleton-input {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.skeleton-input .skeleton-bar { height: 24px; width: 40%; animation-delay: .15s; }

.skeleton-choices {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.skeleton-choice {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.skeleton-choice-label {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-choice-text {
    height: 14px;
    flex: 1;
}

.skeleton-choice:nth-child(1) .skeleton-choice-text { width: 70%; }
.skeleton-choice:nth-child(2) .skeleton-choice-text { width: 55%; animation-delay: .1s; }
.skeleton-choice:nth-child(2) .skeleton-choice-label { animation-delay: .1s; }
.skeleton-choice:nth-child(3) .skeleton-choice-text { width: 65%; animation-delay: .2s; }
.skeleton-choice:nth-child(3) .skeleton-choice-label { animation-delay: .2s; }
.skeleton-choice:nth-child(4) .skeleton-choice-text { width: 48%; animation-delay: .3s; }
.skeleton-choice:nth-child(4) .skeleton-choice-label { animation-delay: .3s; }

.skeleton-status {
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding-top: .5rem;
}

/* --- Multiple choice --- */
.mc-choices {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 1rem;
}

.mc-choice {
    display: flex;
    align-items: center;
    gap: .75rem;
    width: 100%;
    padding: .85rem 1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: .95rem;
    color: var(--text);
    text-align: left;
    transition: border-color 150ms, background 150ms;
}

.mc-choice:hover:not(:disabled) {
    border-color: var(--primary);
    background: #F0F5FF;
}

.mc-label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    border: 1.5px solid var(--border);
    font-weight: 700;
    font-size: .8rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.mc-text {
    flex: 1;
    line-height: 1.4;
}

.mc-choice:disabled {
    cursor: default;
    opacity: .85;
}

.mc-choice.mc-correct {
    border-color: var(--green);
    background: #F0FDF4;
}
.mc-choice.mc-correct .mc-label {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.mc-choice.mc-wrong {
    border-color: var(--red);
    background: #FEF2F2;
}
.mc-choice.mc-wrong .mc-label {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}

/* ==========================================================
   Reward Effects
   ========================================================== */

/* --- Confetti particles (CSS-based) --- */
.confetti-particle {
    position: fixed;
    pointer-events: none;
    z-index: var(--z-confetti);
    animation: confetti-fall var(--cd, 1.2s) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}
@keyframes confetti-fall {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(var(--cx), var(--cy)) rotate(var(--cr)) scale(0.4); }
}

/* --- Screen flash --- */
.screen-flash {
    position: fixed;
    inset: 0;
    z-index: var(--z-flash);
    pointer-events: none;
    animation: flash-fade 400ms ease-out forwards;
}
@keyframes flash-fade {
    0% { opacity: 0.35; }
    100% { opacity: 0; }
}

/* --- Hype message --- */
.hype-message {
    position: fixed;
    top: 30%;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-hype);
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: .04em;
    color: var(--primary);
    text-shadow: 0 2px 12px rgba(79,70,229,.25);
    pointer-events: none;
    animation: hype-pop 1.1s ease forwards;
}
@keyframes hype-pop {
    0% { opacity: 0; transform: translateX(-50%) scale(0.3) translateY(20px); }
    25% { opacity: 1; transform: translateX(-50%) scale(1.15) translateY(-5px); }
    45% { transform: translateX(-50%) scale(1) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) scale(0.8) translateY(-40px); }
}

/* --- Streak badge --- */
.streak-badge {
    position: fixed;
    top: 62px;
    right: 1rem;
    z-index: var(--z-sticky);
    padding: .35rem .85rem;
    border-radius: 99px;
    font-size: .88rem;
    font-weight: 700;
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

.streak-pop { animation: bannerPop 400ms ease; }

.streak-ember {
    background: linear-gradient(135deg, #FFFBEB, #FEF3C7);
    border-color: #FCD34D;
    color: #B45309;
}
.streak-storm {
    background: linear-gradient(135deg, #EFF6FF, #DBEAFE);
    border-color: #60A5FA;
    color: #1D4ED8;
}
.streak-inferno {
    background: linear-gradient(135deg, #FEF2F2, #FEE2E2);
    border-color: #F87171;
    color: #DC2626;
}
.streak-legendary {
    background: linear-gradient(135deg, #FFFBEB, #FDE68A);
    border-color: #F59E0B;
    color: #92400E;
    box-shadow: 0 0 12px rgba(245,158,11,.3);
}
.streak-broken {
    background: #FEF2F2;
    border-color: #FECACA;
    color: var(--red);
    animation: bannerPop 400ms ease;
}
.streak-muted {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: .8rem;
}

/* --- Session complete --- */

.study-done {
    text-align: center;
    padding: 3rem 1rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
}
.study-done h2 { margin-bottom: .5rem; }
.study-done p { color: var(--text-muted); margin-bottom: 1.25rem; }
.study-done .btn + .btn { margin-left: .5rem; }


/* ==========================================================
   Floating Action Button
   ========================================================== */

.fab-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: var(--z-fab);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .75rem;
}

.fab {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(79,70,229,.35);
    transition: transform 200ms ease, box-shadow 200ms ease;
}
.fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(79,70,229,.4);
}
.fab.fab-open {
    transform: rotate(45deg);
}
.fab.fab-open:hover {
    transform: rotate(45deg) scale(1.08);
}

.fab-panel {
    width: 300px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    box-shadow: 0 8px 30px rgba(0,0,0,.12);
    animation: fabSlideIn 200ms ease;
}
@keyframes fabSlideIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.fab-panel-header {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .75rem;
}

.fab-panel .drop-zone-sm {
    padding: 1rem .75rem;
}


/* ==========================================================
   Responsive
   ========================================================== */

@media (max-width: 600px) {
    .calculator { max-width: 100%; }
    .input-area { margin: 1rem .5rem 0; }
    .kb-grid { gap: 3px; }
    .kb-key { height: 38px; font-size: .82rem; }

    .page-header { flex-direction: column; align-items: flex-start; }
    .deck-grid { grid-template-columns: 1fr; }
}
