/* ==========================================================
   K+A. Study App
   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. Modals                 10. Folder Grid (homepage)
  11. Deck Grid              12. Deck Detail
  13. Study Session          14. Study Card & MC
  15. Decomposition          16. Rewards & Streaks
  17. Knowledge Graph        18. Explorer Drawer
  19. FAB                    20. 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: 1.1rem;
    font-weight: 900;
    letter-spacing: -.02em;
    color: var(--text);
    text-decoration: none;
    font-family: Georgia, 'Times New Roman', serif;
}

.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-stats {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: .85rem;
    font-weight: 600;
}

.nav-streak { color: #f59e0b; }
.nav-level {
    color: var(--primary);
    background: rgba(79, 70, 229, .08);
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .8rem;
}
.nav-logout {
    font-weight: 400;
    font-size: .8rem;
}

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

.nav-insights-link {
    font-size: .78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: .3rem .6rem;
    border-radius: 6px;
    transition: all var(--transition);
}
.nav-insights-link:hover {
    color: var(--primary);
    background: rgba(79, 70, 229, .06);
}

.nav-user {
    display: flex;
    align-items: center;
    gap: .65rem;
    margin-left: .75rem;
}
.nav-username {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    font-size: .78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    padding: .2rem .45rem;
    border-radius: 999px;
    transition: background var(--transition);
}
.nav-username:hover {
    background: rgba(15, 23, 42, .04);
    color: var(--text);
}
.nav-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border);
}
.nav-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), #818CF8);
    color: white;
    font-size: .7rem;
    font-weight: 700;
    border: none;
}
.nav-username-text {
    line-height: 1;
}
.nav-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all var(--transition);
}
.nav-logout-btn:hover {
    color: var(--red);
    background: rgba(239, 68, 68, .08);
}

/* XP progress bar under nav */
.nav-xp-bar {
    height: 3px;
    background: var(--border);
    flex-shrink: 0;
}
.nav-xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #818CF8);
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
    border-radius: 0 3px 3px 0;
}



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

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

.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-header-left {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.page-title-back {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    text-decoration: none;
    color: var(--text);
    transition: opacity .15s ease;
}

.page-title-back svg {
    color: var(--text-muted);
    transition: transform .15s ease, color .15s ease;
    flex-shrink: 0;
}

.page-title-back:hover svg {
    transform: translateX(-2px);
    color: var(--text);
}


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

.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-input {
    width: 100%;
    padding: .65rem .85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: .95rem;
    background: var(--surface);
    outline: none;
    transition: border-color var(--transition);
}
.form-input:focus { border-color: var(--border-focus); }

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .88rem;
    color: var(--text-muted);
}
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; }
.btn-full { width: 100%; }

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .65rem;
    width: 100%;
    padding: .7rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .92rem;
    font-weight: 600;
    text-decoration: none;
    transition: all var(--transition);
    margin-bottom: 1.25rem;
}
.btn-google:hover {
    border-color: #CBD5E1;
    background: #FAFBFC;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
.btn-google svg { flex-shrink: 0; }

.auth-divider {
    display: flex;
    align-items: center;
    margin: 1rem 0 1.25rem;
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    font-weight: 600;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.auth-divider span {
    padding: 0 .85rem;
}

.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;
    width: 120px;
}
@keyframes previewIn {
    from { opacity: 0; transform: scale(.92); }
    to { opacity: 1; transform: scale(1); }
}

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

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

.modal-divider {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 1rem 0;
    color: var(--text-muted);
    font-size: .78rem;
}

.modal-divider::before,
.modal-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.modal-file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .6rem .75rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1.5px solid var(--primary);
}

.modal-file-info {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .85rem;
    font-weight: 500;
    color: var(--text);
    min-width: 0;
}

.modal-file-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.modal-file-remove {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 .25rem;
    line-height: 1;
}

.modal-file-remove:hover { color: var(--text); }



/* ==========================================================
   Folder Grid (homepage)
   ========================================================== */

.library-section {
    margin-bottom: 2.5rem;
}

.library-section-title {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 0 0 .85rem;
    padding: 0 .25rem;
}

.library-section-empty {
    font-size: .85rem;
    color: var(--text-muted);
    margin: 0;
    padding: .75rem .25rem;
    font-style: italic;
}

.library-empty-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border: 1.5px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    text-align: left;
    color: var(--text);
    transition: all var(--transition);
    font-family: inherit;
}

.library-empty-card:hover {
    border-color: var(--primary);
    background: rgba(79, 70, 229, .03);
}

.library-empty-card-static {
    cursor: default;
}
.library-empty-card-static:hover {
    border-color: var(--border);
    background: var(--surface);
}

/* Shared-class empty card uses teal accent on hover (matches My Classes section) */
.library-empty-card-shared:hover {
    border-color: #0d9488;
    background: rgba(13, 148, 136, .04);
}
.library-empty-card-shared:hover .library-empty-icon {
    background: rgba(13, 148, 136, .12);
    color: #0d9488;
}

.library-empty-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F1F3F6;
    color: var(--text-muted);
    border-radius: var(--radius);
}

.library-empty-card:not(.library-empty-card-static):not(.library-empty-card-shared):hover .library-empty-icon {
    background: rgba(79, 70, 229, .1);
    color: var(--primary);
}

.library-empty-text {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    min-width: 0;
}

.library-empty-title {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
}

.library-empty-meta {
    font-size: .8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.folder-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.folder-card {
    position: relative;
    width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    gap: .5rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
    cursor: pointer;
}

/* SortableJS states */
.sortable-ghost { opacity: .15; }
.sortable-chosen {
    box-shadow: 0 8px 24px rgba(0,0,0,.12) !important;
    transform: scale(1.04);
    z-index: 10;
}
.sortable-drag { opacity: 1 !important; }
.sortable-fallback {
    opacity: .85 !important;
    box-shadow: 0 8px 24px rgba(0,0,0,.15) !important;
}

.folder-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 12px rgba(79, 70, 229, .06);
    transform: translateY(-1px);
}

.folder-card-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    text-decoration: none;
    color: inherit;
    width: 100%;
}

.folder-card-icon { color: var(--primary); }

/* --- Shared / class folders --- */
.folder-card-class .folder-card-icon { color: #0d9488; }

.folder-card-class:hover {
    border-color: #0d9488;
    box-shadow: 0 2px 12px rgba(13, 148, 136, .08);
}

.folder-card-class .folder-card-fill {
    background: linear-gradient(90deg, #14b8a6, #5eead4);
}

/* Section title color tinting */
.library-section:has(#class-grid) .library-section-title { color: #0d9488; }
.library-section:has(#folder-grid) .library-section-title { color: var(--primary); }

/* --- Library toggle (modal) --- */
.library-toggle {
    display: flex;
    gap: .4rem;
    margin-top: .85rem;
    padding: .25rem;
    background: #f1f5f9;
    border-radius: 10px;
}

.library-toggle-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem .75rem;
    background: transparent;
    border: none;
    border-radius: 7px;
    font-family: inherit;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all .18s ease;
}

.library-toggle-btn:hover {
    color: var(--text);
}

.library-toggle-btn-personal.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.library-toggle-btn-shared.active {
    background: var(--surface);
    color: #0d9488;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}

.folder-card-name {
    font-size: .9rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
}

.folder-card-meta {
    font-size: .75rem;
    color: var(--text-muted);
}

.folder-card-bar {
    align-self: stretch;
    height: 5px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin: 0 0 .25rem;
}

.folder-card-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4ade80);
    border-radius: 999px;
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
}


.folder-card-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);
    text-decoration: none;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease;
    z-index: 2;
}

.folder-card:hover .folder-card-gear { opacity: 1; }
.folder-card-gear:hover { background: var(--bg); color: var(--text); }

/* ==========================================================
   Deck Grid (inside folders)
   ========================================================== */

.deck-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.grid-card {
    position: relative;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.grid-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, .04);
}


.grid-deck {
    display: flex;
    flex-direction: column;
}

.grid-deck-body {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    padding: 1.5rem 1.75rem 1.25rem;
    gap: 1rem;
}

.grid-deck-left {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: .3rem;
    min-width: 0;
}

.grid-deck-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: space-between;
    gap: .75rem;
    flex-shrink: 0;
}

.grid-card-name {
    font-size: 1.15rem;
    font-weight: 800;
    line-height: 1.3;
    text-decoration: none;
    color: var(--text);
}

.grid-deck-meta {
    font-size: .75rem;
    color: var(--text-muted);
}

/* Instagram-style attribution: gradient ring + bold username, no underline */
.grid-deck-creator,
.grid-deck-creator:hover,
.grid-deck-creator:focus,
.grid-deck-creator:active,
.grid-deck-creator:visited,
.grid-deck-creator * {
    text-decoration: none !important;
}

.grid-deck-creator {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin-top: .5rem;
    padding: 0;
    background: none;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    width: fit-content;
    transition: opacity var(--transition);
}
.grid-deck-creator:hover {
    opacity: .8;
}

.grid-deck-creator-ring {
    display: inline-flex;
    flex-shrink: 0;
}

.grid-deck-creator-avatar-img {
    display: block;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    object-fit: cover;
    background: transparent;
}

.grid-deck-creator-initial {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    line-height: 1;
}

.grid-deck-creator-name {
    line-height: 1;
    color: var(--text);
}

.grid-deck-manage {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: .3rem;
    font-size: .78rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    transition: color .15s ease;
}

.grid-deck-manage:hover { color: var(--text); }

.grid-deck-study-btn {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .45rem 1.1rem;
    background: var(--primary);
    color: #fff;
    font-size: .8rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, background .15s ease;
}

.grid-deck-study-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(79, 70, 229, .3);
}

.grid-deck-study-btn:active {
    transform: scale(0.97);
}

.grid-deck-bar {
    height: 4px;
    background: var(--border);
}

.grid-deck-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4ade80);
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
}


/* Cell-division FAB */
.cell-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: var(--z-fab);
}

.cell-fab-btn {
    position: fixed !important;
    bottom: 2rem;
    right: 2rem;
    z-index: var(--z-fab);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(79, 70, 229, .35), 0 2px 6px rgba(79, 70, 229, .2);
    opacity: 1;
    transition: background .2s ease, transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s ease;
}
.cell-fab-btn:hover {
    background: #4338ca;
    box-shadow: 0 8px 24px rgba(79, 70, 229, .45), 0 3px 8px rgba(79, 70, 229, .25);
    transform: scale(1.06);
}
.cell-fab-btn:active { transform: scale(0.94); }

.cell-fab-icon {
    transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.cell-fab.open .cell-fab-icon {
    transform: rotate(45deg);
}

/* Options: split out like cell division */
.cell-fab-options {
    position: absolute;
    bottom: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: .5rem;
    pointer-events: none;
}

.cell-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem 1rem .6rem .75rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.08);
    opacity: 0;
    transform: scale(0.3) translateY(0);
    transition: opacity .25s ease, transform .35s cubic-bezier(.34, 1.56, .64, 1);
    pointer-events: none;
    white-space: nowrap;
}
.cell-option:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Cell division animation: options split outward */
.cell-fab.open .cell-fab-options { pointer-events: auto; }

.cell-fab.open .cell-option {
    opacity: 1;
    pointer-events: auto;
}

.cell-fab.open .cell-option-deck {
    transform: scale(1) translateY(-70px);
    transition-delay: .05s;
}
.cell-fab.open .cell-option-folder {
    transform: scale(1) translateY(-130px);
    transition-delay: .1s;
}

/* Backdrop */
.cell-fab-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.08);
    z-index: calc(var(--z-fab) - 1);
    opacity: 0;
    transition: opacity .2s ease;
    pointer-events: none;
}
.cell-fab-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Folder selector on deck detail */
.folder-selector {
    margin-bottom: 1.5rem;
    max-width: 300px;
}

/* Back link */
.back-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.back-link:hover { background: var(--border); color: var(--text); }

/* ==========================================================
   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; }

/* Settings pages */
.settings-section {
    margin-bottom: 2rem;
}

.settings-label {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .5rem;
}

.settings-row {
    display: flex;
    gap: .5rem;
    align-items: center;
}

.rename-saved-pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .75rem;
    background: rgba(34, 197, 94, .12);
    color: var(--green);
    border-radius: 999px;
    font-size: .82rem;
    font-weight: 600;
    pointer-events: none;
}
.rename-saved-pill svg { flex-shrink: 0; }

.settings-hint {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.settings-danger {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}


/* ==========================================================
   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;
}

/* XP breakdown on completion screen */
.done-xp {
    margin-top: 1.25rem;
    text-align: center;
}
.done-xp-total {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: .5rem;
}
.done-xp-bar {
    width: 200px;
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    margin: 0 auto .35rem;
    overflow: hidden;
}
.done-xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #818CF8);
    border-radius: 999px;
    transition: width .8s cubic-bezier(.22, 1, .36, 1);
}
.done-xp-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.near-miss {
    margin-top: .75rem;
    font-size: .9rem;
    font-weight: 600;
    color: #f59e0b;
    text-align: center;
}
.near-miss.perfect { color: var(--green); }

/* Floating +XP animation */
@keyframes xp-float-up {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    60% { opacity: 1; transform: translateY(-40px) scale(1.1); }
    100% { opacity: 0; transform: translateY(-60px) scale(0.9); }
}
.xp-float {
    position: absolute;
    top: -10px;
    right: 10px;
    font-size: .95rem;
    font-weight: 800;
    color: var(--primary);
    animation: xp-float-up 1.1s ease-out forwards;
    pointer-events: none;
    z-index: var(--z-hype);
}

.study-card {
    position: relative;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    margin-bottom: 1rem;
    overflow: visible;
}

/* Wrong answer action buttons */
.wrong-actions {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: .75rem 1.25rem 1.25rem;
}

.wrong-action-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 1rem 1.25rem;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s ease;
}

.wrong-action-primary:hover { background: var(--primary-hover); }

.wrong-action-content {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.wrong-action-content svg { flex-shrink: 0; }

.wrong-action-label {
    display: block;
    font-size: .92rem;
    font-weight: 700;
}

.wrong-action-desc {
    display: block;
    font-size: .72rem;
    opacity: .75;
    margin-top: .1rem;
}

.wrong-action-row {
    display: flex;
    gap: .5rem;
}

.wrong-action-secondary {
    flex: 1;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .7rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: transparent;
    font-family: inherit;
    cursor: pointer;
    color: var(--text-muted);
    text-align: left;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.wrong-action-secondary svg { flex-shrink: 0; }

.wrong-action-label-sm {
    display: block;
    font-size: .82rem;
    font-weight: 600;
}

.wrong-action-desc-sm {
    display: block;
    font-size: .65rem;
    opacity: .7;
}

.wrong-action-drill:hover {
    border-color: #f59e0b;
    color: #f59e0b;
}

.wrong-action-next:hover {
    border-color: var(--green);
    color: var(--green);
}

/* Break it Down transition overlay */
.breakdown-overlay {
    position: fixed;
    inset: 0;
    background: rgba(245, 246, 250, .92);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: var(--z-hype);
    pointer-events: none;
}

.breakdown-ripple-container {
    position: relative;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.breakdown-ripple {
    position: absolute;
    border-radius: 50%;
    border: 2px solid var(--primary);
    opacity: 0;
    animation: rippleOut 1.8s ease-out infinite;
}

.breakdown-ripple.r1 { width: 60px; height: 60px; animation-delay: 0s; }
.breakdown-ripple.r2 { width: 60px; height: 60px; animation-delay: 0.4s; }
.breakdown-ripple.r3 { width: 60px; height: 60px; animation-delay: 0.8s; }

@keyframes rippleOut {
    0% { width: 60px; height: 60px; opacity: .6; }
    100% { width: 160px; height: 160px; opacity: 0; }
}

.breakdown-icon {
    position: relative;
    z-index: 1;
    color: var(--primary);
    animation: iconPulse 1s ease-in-out infinite alternate;
}

@keyframes iconPulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.breakdown-overlay-text {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    animation: textFadeIn 0.5s ease 0.3s both;
}

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

.correct-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: .5rem 1.25rem 1rem;
}

.btn-next-correct {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.3rem;
    background: var(--green);
    color: #fff;
    font-size: .88rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    transition: background .15s ease;
}

.btn-next-correct:hover { background: #16a34a; }

.breakdown-link {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    padding: .3rem 0;
    transition: color .15s ease;
}

.breakdown-link:hover { color: var(--primary); }

.drill-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .75rem;
    background: #fef3c7;
    color: #92400e;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.study-card-explorer {
    position: absolute;
    top: .75rem;
    right: .75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 8px;
    opacity: .4;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
}

.study-card-explorer:hover {
    opacity: 1;
    background: var(--bg);
    color: var(--text);
}

/* Calc button on keyboard */
.kb-key-calc {
    background: rgba(79, 70, 229, .08);
    color: var(--primary);
}
.kb-key-calc:hover { background: rgba(79, 70, 229, .15); }

.kb-key-mode {
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--primary);
    font-size: .7rem;
    font-weight: 700;
    flex: 0 0 auto;
    width: 50px;
}
.kb-key-mode:hover { background: var(--bg); }



.study-card-divider {
    height: 1px;
    background: var(--border);
    margin: 0 1.5rem;
}

/* Hide divider when followed by math input (not MC) */
.study-card-divider:has(+ .study-input) {
    display: none;
}

.study-question {
    text-align: center;
    padding: 2rem 2rem 1.5rem;
    background: transparent;
    border: none;
    min-height: 60px;
    overflow-wrap: break-word;
    word-wrap: break-word;
    overflow: visible;
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text);
    line-height: 1.6;
}
.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: 0 1.25rem 1rem;
    cursor: text;
}

.study-card .mq-editable-field,
.study-card .mq-editable-field.mq-focused,
.study-card .mq-math-mode .mq-editable-field {
    border: 1.5px solid var(--border) !important;
    border-radius: 10px !important;
    background: var(--bg) !important;
}

.study-actions {
    display: flex;
    justify-content: center;
    gap: .5rem;
    padding: 1rem 1.5rem 1.25rem;
}

/* --- 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
   ========================================================== */

/* --- Break it Down stepper --- */
.depth-indicator {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: .55rem .85rem .65rem;
    margin-bottom: .75rem;
    background: #EFF6FF;
    border: 1px solid #BFDBFE;
    border-radius: 8px;
    font-size: .8rem;
    font-weight: 500;
    color: #1D4ED8;
}

.depth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: .5rem;
}

.depth-label {
    display: flex;
    align-items: center;
    gap: .35rem;
    color: #1D4ED8;
    font-weight: 500;
    font-size: .75rem;
    min-width: 0;
}

.depth-q-preview {
    font-weight: 600;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.depth-counter {
    color: #60A5FA;
    font-weight: 600;
    font-size: .72rem;
    white-space: nowrap;
}

.depth-stepper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 2px 2px;
    min-height: 24px;
}

.depth-stepper-track {
    position: absolute;
    top: 50%;
    left: 8px;
    right: 8px;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    transform: translateY(-50%);
    overflow: hidden;
}

.depth-stepper-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width .3s ease;
}

.depth-step {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.depth-step-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .5rem;
    font-weight: 700;
    color: transparent;
    transition: all .25s ease;
}

.depth-step.completed .depth-step-dot {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.depth-step.current .depth-step-dot {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.depth-step.goal .depth-step-dot {
    width: 20px;
    height: 20px;
    font-size: .55rem;
}

.depth-step.goal.completed .depth-step-dot,
.depth-step.goal.current .depth-step-dot {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.depth-step.goal.current .depth-step-dot {
    box-shadow: none;
}

.depth-shimmer .depth-stepper-track {
    background: linear-gradient(90deg, var(--border) 0%, rgba(79, 70, 229, .12) 50%, var(--border) 100%);
    background-size: 200% 100%;
    animation: depth-shimmer 1.5s ease infinite;
}

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

/* --- Pop-level celebration --- */
.pop-celebration {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    padding: 2rem 1rem;
}

.pop-check-ring {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 3px solid;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
}

.pop-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    margin: 0;
}

.pop-sub {
    font-size: .85rem;
    color: var(--text-muted);
    margin: 0;
}

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

/* --- Stream loader (animated loading experience) --- */

@keyframes pulse-glow {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.08); opacity: .85; }
}
@keyframes ring-expand {
    0% { transform: scale(.8); opacity: .6; }
    100% { transform: scale(2.2); opacity: 0; }
}
@keyframes float-up {
    0% { opacity: 0; transform: translateY(20px) scale(.95); }
    15% { opacity: 1; transform: translateY(0) scale(1); }
    85% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-30px) scale(.95); }
}
@keyframes count-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.btn-skip-card {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .4rem .9rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all .15s ease;
}

.btn-skip-card:hover {
    border-color: var(--text-muted);
    color: var(--text);
}
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

.stream-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    min-height: 50vh;
    text-align: center;
    animation: fade-in-up .5s ease-out;
}

.stream-loader-icon {
    position: relative;
    width: 80px;
    height: 80px;
    margin-bottom: 2rem;
}

.stream-loader-icon svg {
    width: 80px;
    height: 80px;
    animation: pulse-glow 2s ease-in-out infinite;
    filter: drop-shadow(0 0 12px rgba(79, 70, 229, .25));
}

.stream-loader-icon::before,
.stream-loader-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--primary);
    animation: ring-expand 2.5s ease-out infinite;
}
.stream-loader-icon::after {
    animation-delay: 1.25s;
}

.stream-loader-status {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .5rem;
    min-height: 1.6em;
    transition: opacity .4s ease;
}

.stream-loader-progress {
    width: 260px;
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    margin-bottom: .75rem;
    overflow: hidden;
    position: relative;
}

.stream-loader-progress-bar {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), #818CF8, var(--primary));
    background-size: 200% 100%;
    animation: progress-shimmer 1.2s linear infinite;
    width: 0%;
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
}

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

.stream-loader-milestones {
    display: flex;
    justify-content: space-between;
    width: 260px;
    margin-bottom: 2rem;
    position: relative;
}

.stream-milestone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .25rem;
    opacity: .3;
    transition: opacity .4s ease, transform .4s ease;
}

.stream-milestone.active {
    opacity: 1;
    transform: scale(1.1);
}

.stream-milestone.done {
    opacity: .6;
    transform: scale(1);
}

.stream-milestone-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: background .3s ease, box-shadow .3s ease;
}

.stream-milestone.active .stream-milestone-dot {
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, .2);
}

.stream-milestone.done .stream-milestone-dot {
    background: var(--green);
}

.stream-milestone-label {
    font-size: .65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}

.stream-milestone.active .stream-milestone-label {
    color: var(--primary);
}

/* Particle burst */
@keyframes particle-burst {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--px), var(--py)) scale(0); opacity: 0; }
}

.stream-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: particle-burst .7s ease-out forwards;
}

/* Milestone check animation */
@keyframes check-draw {
    from { stroke-dashoffset: 20; }
    to { stroke-dashoffset: 0; }
}

.stream-milestone.done .stream-milestone-dot {
    position: relative;
}

.milestone-check {
    position: absolute;
    top: -3px;
    left: -3px;
    width: 16px;
    height: 16px;
}

.stream-loader-count {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(79, 70, 229, .08);
    padding: .5rem 1.25rem;
    border-radius: 999px;
    opacity: 0;
    transition: opacity .3s ease;
}
.stream-loader-count.visible { opacity: 1; }

.stream-loader-count .count-num {
    font-size: 1.3rem;
    font-weight: 700;
    display: inline-block;
}
.stream-loader-count .count-num.pop {
    animation: count-pop .3s ease;
}

.stream-card-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem 1.25rem;
    font-size: .85rem;
    color: var(--text-muted);
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    animation: float-up 2s ease forwards;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: var(--z-flash);
}

.stream-loader-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

/* --- Progress HUD (study page) --- */
.progress-hud {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.hud-deck-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: .4rem;
}
.hud-deck-title {
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}
.hud-deck-pct {
    font-size: 1rem;
    font-weight: 800;
    color: var(--green);
}

.hud-deck-bar {
    height: 10px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: .75rem;
    position: relative;
}
.hud-deck-fill {
    height: 100%;
    background: linear-gradient(90deg, #22c55e, #4ade80, #86efac);
    border-radius: 999px;
    transition: width .8s cubic-bezier(.22, 1, .36, 1);
    position: relative;
}
.hud-deck-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.4));
    border-radius: 999px;
}

.hud-levels {
    display: flex;
    gap: .5rem;
    margin-bottom: .5rem;
}

.hud-level {
    flex: 1;
    min-width: 0;
}
.hud-level-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: .2rem;
}
.hud-level-name {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hud-level-count {
    font-size: .65rem;
    font-weight: 600;
    color: var(--text-muted);
}

.hud-level-bar {
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.hud-level-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .8s cubic-bezier(.22, 1, .36, 1);
}
.hud-level:nth-child(1) .hud-level-fill { background: #4F46E5; }
.hud-level:nth-child(2) .hud-level-fill { background: #f59e0b; }
.hud-level:nth-child(3) .hud-level-fill { background: #ef4444; }

.hud-milestone {
    text-align: center;
    font-size: .8rem;
    font-weight: 700;
    color: #f59e0b;
    min-height: 1.2em;
}

@keyframes hud-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
.hud-milestone.pulse {
    animation: hud-pulse .4s ease;
}

/* --- Mastery progress --- */
.mastery-section {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.mastery-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: .5rem;
}
.mastery-pct { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.mastery-count { font-size: .8rem; color: var(--text-muted); font-weight: 500; }

.mastery-bar {
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 1rem;
}
.mastery-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4ade80);
    border-radius: 999px;
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
}

.mastery-levels {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}


.mastery-level-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: .25rem;
}
.mastery-level-name { font-size: .8rem; font-weight: 600; color: var(--text); }
.mastery-level-count { font-size: .75rem; color: var(--text-muted); font-weight: 500; }

.mastery-level-bar {
    height: 5px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.mastery-level-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width .6s cubic-bezier(.22, 1, .36, 1);
}

.mastery-milestone {
    margin-top: 1rem;
    text-align: center;
    font-size: .88rem;
    font-weight: 600;
    color: #f59e0b;
}

/* Compact mastery bar on deck list cards */
.deck-mastery-bar {
    width: 100%;
    height: 4px;
    background: rgba(0,0,0,.06);
    border-radius: 999px;
    overflow: hidden;
    margin-top: .35rem;
}
.deck-mastery-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4ade80);
    border-radius: 999px;
}

/* --- Multiple choice --- */
.mc-choices {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: .75rem 1.25rem;
}

.mc-choice {
    display: flex;
    align-items: center;
    gap: .85rem;
    width: 100%;
    padding: .85rem 1rem;
    background: var(--bg);
    border: 1.5px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-size: .92rem;
    color: var(--text);
    text-align: left;
    transition: border-color .15s ease, background .15s ease;
}

.mc-choice:hover:not(:disabled) {
    border-color: var(--primary);
    background: rgba(79, 70, 229, .04);
}

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

.mc-choice:hover:not(:disabled) .mc-label {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(79, 70, 229, .06);
}

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

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

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

.mc-choice.mc-wrong {
    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
   ========================================================== */

/* --- Mascot companion (placeholder for future Rive/Lottie integration) --- */
/* To add animated mascot: replace this section with Rive player styles */

/* (mascot CSS removed — will be re-added with Rive/Lottie integration) */


/* --- Shuffle FAB --- */
.study-actions-left {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: var(--z-fab);
    display: flex;
    gap: .5rem;
}

.study-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    border: 1.5px solid var(--border);
    box-shadow: 0 2px 10px rgba(0,0,0,.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: transform .2s ease, box-shadow .2s ease, color .15s ease, border-color .15s ease;
}

.study-action-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    color: var(--primary);
    border-color: var(--primary);
}

.study-action-btn:active { transform: scale(0.95); }



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


/* Explorer Drawer */
.explorer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .3);
    backdrop-filter: blur(2px);
    z-index: var(--z-modal);
}

.explorer-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 340px;
    height: 100vh;
    background: var(--surface);
    z-index: calc(var(--z-modal) + 1);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 24px rgba(0,0,0,.08);
    transform: translateX(100%);
}

.explorer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem .75rem;
    flex-shrink: 0;
}

.explorer-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.explorer-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: .25rem;
}

.explorer-close:hover { color: var(--text); }

.explorer-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem 1rem;
}

.explorer-loading {
    display: flex;
    justify-content: center;
    padding: 3rem 0;
}

.explorer-concept {
    margin-bottom: .25rem;
}

.explorer-concept-btn {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: .7rem .5rem;
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
    transition: background .15s ease;
}

.explorer-concept-btn:hover {
    background: var(--bg);
}

.explorer-concept-info {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: .35rem;
}

.explorer-concept-name {
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
}

.explorer-concept-meta {
    font-size: .72rem;
    color: var(--text-muted);
}

.explorer-concept-bar {
    height: 4px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}

.explorer-concept-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--green), #4ade80);
    border-radius: 999px;
}

.explorer-cards {
    padding: .25rem 0 .5rem .5rem;
}

.explorer-card {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: .5rem .5rem;
    cursor: pointer;
    border-radius: 6px;
    font-family: inherit;
    transition: background .15s ease;
}

.explorer-card:hover {
    background: var(--bg);
}

.explorer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.explorer-card-text {
    font-size: .8rem;
    color: var(--text);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.explorer-enriching {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .65rem .85rem;
    margin-bottom: .75rem;
    background: var(--bg-subtle, #f8fafc);
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: .82rem;
    color: var(--text-muted);
    font-weight: 500;
}



/* Generic loading spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spinnerSpin .8s linear infinite;
}

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


/* ==========================================================
   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; }
    .folder-card { width: calc(50% - 6px); }
    .deck-grid { grid-template-columns: 1fr; }

    .depth-step-dot { width: 14px; height: 14px; }
    .depth-step.goal .depth-step-dot { width: 17px; height: 17px; }
    .depth-q-preview { max-width: 140px; }
}


/* ==========================================================
   Insights Dashboard
   ========================================================== */

.insights-page {
    max-width: 1080px;
    margin: 0 auto;
    padding: 3rem 2rem 6rem;
}

.insights-header {
    margin-bottom: 4rem;
}

.insights-header-compact {
    margin-bottom: 2rem;
}

.insights-title {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.insights-title-meta {
    font-size: .82rem;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0;
}

.insights-section {
    margin-bottom: 3.5rem;
}

.insights-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.insights-section-title {
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--text);
    margin: 0;
}

.insights-section-meta {
    font-size: .78rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Pulse hero metrics --- */

.insights-hero {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

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

.metric-card {
    background: var(--surface);
    padding: 1.75rem 1.5rem;
}

.metric-label {
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.metric-value {
    font-size: 2.6rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}

.metric-unit {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-left: .15rem;
}

.metric-delta {
    font-size: .78rem;
    font-weight: 500;
    margin-top: .85rem;
}

.metric-delta.positive { color: var(--green); }
.metric-delta.neutral { color: var(--text-muted); }

/* --- Per-user activity table --- */

.user-activity-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.user-activity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .87rem;
}

.user-activity-table th,
.user-activity-table td {
    padding: .85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.user-activity-table thead th {
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: #FAFBFC;
}

.user-activity-table tbody tr:last-child td { border-bottom: none; }
.user-activity-table tbody tr:hover { background: #FAFBFC; }

.user-activity-table .col-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.user-activity-table .col-name { width: 28%; }

.user-name {
    font-weight: 600;
    color: var(--text);
}

.user-badge {
    display: inline-block;
    margin-left: .4rem;
    padding: .08rem .4rem;
    background: rgba(79, 70, 229, .1);
    color: var(--primary);
    font-size: .65rem;
    font-weight: 600;
    border-radius: 4px;
    letter-spacing: .03em;
    text-transform: uppercase;
    vertical-align: 1px;
}

.cell-muted { color: var(--text-muted); }

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: .55rem;
    vertical-align: 2px;
}

.status-dot.status-active { background: var(--green); box-shadow: 0 0 0 2px rgba(34, 197, 94, .15); }
.status-dot.status-recent { background: #f59e0b; }
.status-dot.status-dormant { background: #CBD5E1; }

.empty-row {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem !important;
}

/* --- Daily activity heatmap --- */

.heatmap-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    overflow-x: auto;
}

.heatmap {
    display: grid;
    grid-template-rows: repeat(7, 11px);
    grid-auto-flow: column;
    grid-auto-columns: 11px;
    gap: 3px;
    width: max-content;
}

.heatmap-cell {
    width: 11px;
    height: 11px;
    border-radius: 2px;
    background: #EDF0F4;
}

.heatmap-cell.empty { background: transparent; }
.heatmap-cell.intensity-0 { background: #EDF0F4; }
.heatmap-cell.intensity-1 { background: #C7D0F8; }
.heatmap-cell.intensity-2 { background: #94A3F0; }
.heatmap-cell.intensity-3 { background: #6573E5; }
.heatmap-cell.intensity-4 { background: var(--primary); }

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 1rem;
    justify-content: flex-end;
}

.legend-label {
    font-size: .7rem;
    color: var(--text-muted);
    margin: 0 .35rem;
}

/* --- Live total time counter --- */

.total-time-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
}

.total-time-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .85rem;
}

.total-time-live {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, .55);
    animation: live-pulse 1.6s ease-out infinite;
}

@keyframes live-pulse {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .55); }
    70% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.total-time-value {
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: baseline;
    gap: .15rem;
    flex-wrap: wrap;
}

.tt-num {
    color: var(--text);
}

.tt-unit {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: .45rem;
    margin-left: .05rem;
}

/* --- Funnel --- */

.funnel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
}

.funnel-row {
    display: grid;
    grid-template-columns: 240px 1fr 110px;
    gap: 1.25rem;
    align-items: center;
    padding: .65rem 0;
}

.funnel-row + .funnel-row { border-top: 1px solid #F1F3F6; }

.funnel-label {
    font-size: .87rem;
    color: var(--text);
    font-weight: 500;
}

.funnel-bar-track {
    height: 8px;
    background: #F1F3F6;
    border-radius: 999px;
    overflow: hidden;
}

.funnel-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width .4s ease;
}

.funnel-count {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.funnel-pct {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
}

.funnel-num {
    font-size: .78rem;
    color: var(--text-muted);
    margin-left: .4rem;
}

/* --- Responsive --- */

@media (max-width: 900px) {
    .insights-page { padding: 2rem 1rem 4rem; }
    .insights-hero { grid-template-columns: repeat(2, 1fr); }
    .funnel-row { grid-template-columns: 1fr; gap: .35rem; padding: .85rem 0; }
    .funnel-count { text-align: left; }
    .insights-title { font-size: 1.8rem; }
    .metric-value { font-size: 2rem; }
}

@media (max-width: 540px) {
    .user-activity-table { font-size: .78rem; }
    .user-activity-table th,
    .user-activity-table td { padding: .65rem .55rem; }
}


/* ==========================================================
   Collaborative Folders — Members + Invite UI
   ========================================================== */

.page-header-actions {
    display: flex;
    align-items: center;
    gap: .65rem;
}

.members-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .4rem .7rem;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s ease;
}
.members-badge:hover {
    background: var(--bg-subtle, #f1f5f9);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: .4rem .85rem;
    font-size: .82rem;
}

/* Invite modal */
.invite-link-row {
    display: flex;
    gap: .5rem;
    align-items: center;
}
.invite-link-input {
    flex: 1;
    padding: .55rem .75rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: .85rem;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    background: var(--bg-subtle, #f8fafc);
    color: var(--text);
}
.invite-regen-btn {
    margin-top: .75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: .8rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0;
}
.invite-regen-btn:hover { color: var(--primary); }

/* Members list */
.members-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    max-height: 360px;
    overflow-y: auto;
}
.member-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}
.member-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #818CF8);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.member-ig {
    display: inline-flex;
    align-items: center;
    font-size: .75rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    margin-top: .15rem;
}
.member-ig:hover { text-decoration: underline; }
.member-info {
    flex: 1;
    min-width: 0;
}
.member-name {
    font-weight: 600;
    font-size: .9rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: .4rem;
}
.member-role {
    font-size: .72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-top: .1rem;
}
.member-active-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.2);
}
.member-remove-btn {
    background: none;
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 600;
    padding: .35rem .7rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s ease;
}
.member-remove-btn:hover {
    border-color: var(--red);
    color: var(--red);
}


/* ==========================================================
   Folder invite preview (public, unauthenticated)
   ========================================================== */

.preview-container {
    min-height: calc(100vh - 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.preview-card {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
}

.preview-badge {
    display: inline-block;
    padding: .3rem .7rem;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(129, 140, 248, 0.1));
    color: var(--primary);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    border-radius: 999px;
    margin-bottom: .75rem;
}

.preview-title {
    margin: 0 0 .35rem 0;
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text);
}

.preview-meta {
    margin: 0 0 1.5rem 0;
    color: var(--text-muted);
    font-size: .9rem;
}

.preview-decks {
    display: flex;
    flex-direction: column;
    gap: .55rem;
    margin-bottom: 1.5rem;
    max-height: 320px;
    overflow-y: auto;
}

.preview-deck {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .8rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-subtle, #f8fafc);
}

.preview-deck-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.preview-deck-name {
    font-weight: 600;
    font-size: .95rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.preview-deck-meta {
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: .1rem;
}

.preview-empty {
    color: var(--text-muted);
    font-size: .9rem;
    text-align: center;
    padding: 1.5rem 0;
}

.preview-cta {
    margin-top: 1.5rem;
}

.preview-login {
    margin: .85rem 0 0 0;
    text-align: center;
    color: var(--text-muted);
    font-size: .85rem;
}
.preview-login a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}
.preview-login a:hover { text-decoration: underline; }


/* ==========================================================
   Insights — User Detail Page
   ========================================================== */

.insights-back {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 1.5rem;
    transition: color var(--transition);
}
.insights-back:hover { color: var(--text); }

.user-row {
    cursor: pointer;
    transition: background var(--transition);
}
.user-row:hover { background: #FAFBFC; }

.user-badge-lg {
    font-size: .68rem;
    margin-left: .55rem;
    padding: .2rem .55rem;
    vertical-align: 6px;
}

.insights-hero.hero-6 {
    grid-template-columns: repeat(6, 1fr);
}

/* --- Personal funnel --- */

.user-funnel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    overflow: hidden;
}

.user-funnel-step {
    display: grid;
    grid-template-columns: 30px 1fr 90px;
    gap: 1rem;
    align-items: center;
    padding: .85rem 1.5rem;
}

.user-funnel-step + .user-funnel-step { border-top: 1px solid #F1F3F6; }

.funnel-step-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-funnel-step.hit .funnel-step-icon {
    background: rgba(34, 197, 94, .12);
    color: var(--green);
}
.user-funnel-step.miss .funnel-step-icon {
    background: #F1F3F6;
    color: #CBD5E1;
}

.user-funnel-step.hit .funnel-step-label { color: var(--text); font-weight: 500; }
.user-funnel-step.miss .funnel-step-label { color: var(--text-muted); font-weight: 400; }

.funnel-step-label { font-size: .9rem; }
.funnel-step-when {
    font-size: .78rem;
    color: var(--text-muted);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --- Timeline --- */

.timeline {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.75rem;
}

.timeline-session {
    display: grid;
    grid-template-columns: 90px 4px 1fr;
    gap: 1rem;
    align-items: stretch;
    padding: .9rem 0;
}
.timeline-session + .timeline-session { border-top: 1px solid #F1F3F6; }

.session-time {
    text-align: right;
}
.session-date {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.session-clock {
    font-size: .72rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-top: .15rem;
}

.session-bar {
    background: var(--primary);
    border-radius: 4px;
    width: 4px;
    align-self: stretch;
    min-height: 28px;
}

.session-body { padding-top: .1rem; }

.session-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .35rem;
    font-size: .85rem;
}

.session-stat-num {
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.session-stat-label {
    color: var(--text-muted);
    font-size: .8rem;
}

.session-divider {
    color: #CBD5E1;
    margin: 0 .15rem;
}

.session-tag {
    display: inline-block;
    margin-left: .65rem;
    padding: .12rem .55rem;
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 4px;
}
.wrong-tag {
    background: rgba(239, 68, 68, .1);
    color: var(--red);
}

.session-decks {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: .4rem;
}
.session-deck {
    font-size: .72rem;
    color: var(--text-muted);
    background: #F4F5F7;
    padding: .12rem .55rem;
    border-radius: 4px;
}

/* Gap markers between sessions */
.timeline-gap {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .55rem 0;
    margin-left: 90px;
    padding-left: 1rem;
}

.timeline-gap-line {
    flex: 1;
    height: 1px;
    background: #E2E8F0;
}

.timeline-gap-label {
    font-size: .68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #94A3B8;
    background: var(--surface);
    padding: 0 .55rem;
}

.empty-timeline {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    font-size: .85rem;
}

/* --- Recent attempts table --- */

.recent-attempts .nowrap { white-space: nowrap; }
.recent-attempts .attempt-q {
    color: var(--text);
    max-width: 380px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recent-attempts .attempt-a {
    color: var(--text);
    font-family: 'SF Mono', Monaco, 'Cascadia Mono', Menlo, monospace;
    font-size: .8rem;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recent-attempts .attempt-a.wrong-a { color: var(--red); }

.result-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    font-size: .85rem;
    font-weight: 700;
}
.result-correct { background: rgba(34, 197, 94, .12); color: var(--green); }
.result-wrong { background: rgba(239, 68, 68, .12); color: var(--red); }

@media (max-width: 900px) {
    .insights-hero.hero-6 { grid-template-columns: repeat(2, 1fr); }
    .user-funnel-step { grid-template-columns: 30px 1fr 70px; padding: .75rem 1rem; gap: .65rem; }
    .timeline { padding: 1rem 1.25rem; }
    .timeline-session { grid-template-columns: 70px 4px 1fr; gap: .65rem; }
    .timeline-gap { margin-left: 70px; padding-left: .65rem; }
    .recent-attempts .attempt-q { max-width: 200px; }
    .recent-attempts .attempt-a { max-width: 100px; }
}



/* ==========================================================
   Profile settings page
   ========================================================== */

.profile-page {
    max-width: 480px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

.profile-page-header {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
}

.profile-card {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 18px;
    padding: 2.5rem 2rem 2rem;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.05);
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* --- Avatar (focal point) --- */

.profile-avatar-stage {
    position: relative;
    align-self: center;
    margin-bottom: 1.25rem;
}

.profile-avatar-circle {
    position: relative;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    background: linear-gradient(135deg, var(--primary), #818CF8);
    box-shadow: 0 6px 20px rgba(79, 70, 229, .18);
    transition: transform .25s ease, box-shadow .25s ease;
    display: block;
    font-family: inherit;
}

.profile-avatar-circle:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(79, 70, 229, .25);
}

.profile-avatar-content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar-content img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-initial {
    color: white;
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.profile-avatar-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .25rem;
    background: rgba(15, 23, 42, .55);
    color: white;
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    opacity: 0;
    transition: opacity .2s ease;
    pointer-events: none;
}

.profile-avatar-circle:hover .profile-avatar-overlay,
.profile-avatar-circle:focus-visible .profile-avatar-overlay {
    opacity: 1;
}

.profile-avatar-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    background: var(--text);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .2);
    transition: transform .15s ease, background .15s ease;
    z-index: 2;
}

.profile-avatar-remove:hover {
    transform: scale(1.08);
    background: var(--red);
}

/* --- Identity (username + stats) --- */

.profile-identity {
    text-align: center;
    margin-bottom: 1.75rem;
}

.profile-username {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 .5rem 0;
    letter-spacing: -.01em;
}

.profile-stats {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .35rem .85rem;
    font-size: .78rem;
    color: var(--text-muted);
}

.profile-stat {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-weight: 500;
}

.profile-stat svg {
    color: var(--primary);
    opacity: .8;
}

/* --- Divider --- */

.profile-divider {
    height: 1px;
    background: var(--border);
    margin: 0 -.5rem 1.75rem;
}

/* --- Form fields --- */

.profile-field {
    margin-bottom: 1.5rem;
}

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

.profile-field-hint {
    font-size: .75rem;
    color: var(--text-muted);
    margin: .5rem 0 0 0;
}

/* --- Instagram input (handle prefix) --- */

.instagram-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.instagram-input-prefix {
    position: absolute;
    left: 1rem;
    font-size: .95rem;
    color: var(--text-muted);
    pointer-events: none;
    font-weight: 500;
}
.instagram-input {
    padding-left: 1.85rem;
    width: 100%;
}

/* --- Save row --- */

.profile-save-row {
    margin-top: .25rem;
    position: relative;
}

.profile-save-row .btn-full {
    width: 100%;
}

.profile-save-row .rename-saved-pill {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(15, 23, 42, .12);
    border: 1px solid rgba(34, 197, 94, .25);
}

/* --- Crop modal (Cropper.js) --- */

.crop-modal-overlay {
    z-index: 9999;
}

.modal-crop {
    max-width: 480px;
    width: calc(100vw - 2rem);
    padding: 1.5rem 1.5rem 1.25rem;
}

.crop-title {
    margin: 0 0 .25rem 0;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
}

.crop-hint {
    margin: 0 0 1rem 0;
    text-align: center;
    color: var(--text-muted);
    font-size: .8rem;
}

.crop-stage {
    width: 100%;
    height: 360px;
    background: #0f172a;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: .85rem;
    position: relative;
}

.crop-stage img {
    /* Cropper.js requires the source image inside its container; visibility
       is managed by Cropper itself once initialized. */
    display: block;
    max-width: 100%;
}

/* Make Cropper's crop box circular (the underlying crop is still square,
   this is just visual). */
.crop-stage .cropper-view-box,
.crop-stage .cropper-face {
    border-radius: 50%;
}

.crop-stage .cropper-view-box {
    outline: 2px solid white;
    outline-color: rgba(255, 255, 255, .85);
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, .55);
}

.crop-stage .cropper-line,
.crop-stage .cropper-point {
    display: none !important;
}

.crop-zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    margin-bottom: 1rem;
}

.crop-zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .15s ease;
}

.crop-zoom-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: scale(1.05);
}

.crop-actions {
    display: flex;
    gap: .65rem;
    justify-content: flex-end;
}

.crop-actions .btn {
    min-width: 110px;
}

@media (max-width: 540px) {
    .crop-stage { height: 280px; }
    .crop-actions .btn { flex: 1; min-width: 0; }
}


/* ==========================================================
   Instagram-style User Profile Page
   ========================================================== */

.ig-profile-page {
    max-width: 940px;
    margin: 0 auto;
    padding: 2rem 2rem 5rem;
}

.ig-profile-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.ig-profile-empty h1 {
    font-size: 1.5rem;
    margin-bottom: .5rem;
    color: var(--text);
}

/* --- Header --- */

.ig-profile-header {
    display: flex;
    align-items: center;
    gap: 4rem;
    padding: 1.5rem 0 2.5rem;
}

.ig-profile-avatar {
    width: 150px;
    height: 150px;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    background: #F1F3F6;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ig-profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ig-profile-avatar-initial {
    font-size: 4rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.ig-profile-meta {
    flex: 1;
    min-width: 0;
}

.ig-profile-top {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.ig-profile-username {
    font-size: 1.75rem;
    font-weight: 400;
    color: var(--text);
    margin: 0;
    letter-spacing: -.01em;
}

.ig-profile-edit {
    display: inline-flex;
    align-items: center;
    padding: .4rem 1rem;
    background: #F1F3F6;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    transition: background var(--transition);
}
.ig-profile-edit:hover {
    background: #E2E8F0;
}

.ig-profile-stats {
    display: flex;
    gap: 2.5rem;
    margin-bottom: 1.25rem;
}

.ig-stat {
    display: flex;
    gap: .35rem;
    font-size: 1rem;
    color: var(--text);
}
.ig-stat-num {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.ig-stat-label {
    color: var(--text);
}

.ig-profile-bio {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    font-size: .95rem;
    color: var(--text);
}

.ig-profile-name {
    font-weight: 600;
    color: var(--text);
    min-height: 1.2em;
}

.ig-profile-streak {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: #f59e0b;
    font-weight: 500;
    width: fit-content;
}

.ig-profile-link {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    width: fit-content;
}
.ig-profile-link:hover {
    text-decoration: underline;
}

.ig-profile-divider {
    border-top: 1px solid var(--border);
    margin: 1rem 0 2rem;
}

/* --- Subject grid --- */

.ig-subject-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.ig-subject-card {
    display: block;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: all var(--transition);
}
.ig-subject-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .04);
}

.ig-subject-name {
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: .35rem;
    line-height: 1.3;
}

.ig-subject-meta {
    font-size: .78rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.ig-subject-bar {
    height: 4px;
    background: #F1F3F6;
    border-radius: 999px;
    overflow: hidden;
}
.ig-subject-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
}

.ig-subject-empty {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}
.ig-subject-empty p {
    margin-bottom: 1rem;
    font-size: .95rem;
}

/* --- Responsive --- */

@media (max-width: 720px) {
    .ig-profile-page { padding: 1.5rem 1rem 4rem; }
    .ig-profile-header {
        gap: 1.75rem;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .ig-profile-avatar { width: 110px; height: 110px; }
    .ig-profile-avatar-initial { font-size: 2.75rem; }
    .ig-profile-top { justify-content: center; }
    .ig-profile-stats { gap: 1.5rem; justify-content: center; }
    .ig-profile-bio { align-items: center; }
    .ig-profile-streak,
    .ig-profile-link { margin: 0 auto; }
    .ig-subject-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 460px) {
    .ig-subject-grid { grid-template-columns: 1fr; }
    .ig-profile-stats { gap: 1.25rem; font-size: .9rem; }
}

