/* NowCards — design tokens & base */
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,400;0,14..32,500;0,14..32,600;0,14..32,700;1,14..32,400&display=swap');

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

:root {
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --primary-color: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --secondary-color: #6366f1;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --study-frame-known: #059669;
    --study-frame-unknown: #dc2626;
    --text-color: #1e293b;
    --text-light: #64748b;
    --text-muted: #94a3b8;
    --bg-color: #f8fafc;
    --bg-subtle: #f1f5f9;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --border-light: #f1f5f9;
    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --shadow-focus: 0 0 0 3px rgba(79, 70, 229, 0.2);
    --nav-blur: 16px;
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    color-scheme: light;
}

/* ================================================================
   DARK MODE
   ================================================================ */
html[data-theme="dark"] {
    color-scheme: dark;
    --primary-color: #a5b4fc;
    --primary-dark: #c7d2fe;
    --primary-light: rgba(99, 102, 241, 0.15);
    --secondary-color: #818cf8;
    --success-color: #34d399;
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --text-color: #f1f5f9;
    --text-light: #94a3b8;
    --text-muted: #64748b;
    --text-on-light-surface: #0f172a;
    --text-on-dark-surface: #f1f5f9;
    --bg-color: #0f172a;
    --bg-subtle: #1e293b;
    --card-bg: #1e293b;
    --border-color: rgba(148, 163, 184, 0.15);
    --border-light: rgba(148, 163, 184, 0.08);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.35);
    --shadow-xl: 0 20px 30px rgba(0, 0, 0, 0.4);
    --shadow-focus: 0 0 0 3px rgba(129, 140, 248, 0.3);
}

html[data-theme="dark"] body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(ellipse 1000px 500px at 10% -5%, rgba(99, 102, 241, 0.12), transparent 60%),
        radial-gradient(ellipse 800px 400px at 95% 5%, rgba(14, 165, 233, 0.08), transparent 55%);
}

html[data-theme="dark"] .navbar {
    background: rgba(15, 23, 42, 0.85);
    border-bottom-color: var(--border-color);
}

html[data-theme="dark"] .logo { color: #e0e7ff; }
html[data-theme="dark"] .logo-byline { color: var(--text-muted); }
html[data-theme="dark"] .logo-byline a { color: var(--primary-color); }

html[data-theme="dark"] .username {
    background: rgba(241, 245, 249, 0.06);
    color: var(--text-light);
}

html[data-theme="dark"] .btn-outline {
    background: rgba(30, 41, 59, 0.6);
    border-color: var(--border-color);
    color: var(--text-color);
}

html[data-theme="dark"] .btn-outline:hover {
    background: rgba(129, 140, 248, 0.1);
    border-color: rgba(165, 180, 252, 0.4);
    color: var(--primary-color);
}

html[data-theme="dark"] .form-group input,
html[data-theme="dark"] .form-group textarea,
html[data-theme="dark"] .form-group select {
    background-color: rgba(15, 23, 42, 0.6);
    color: var(--text-color);
    border-color: var(--border-color);
}

html[data-theme="dark"] .form-group input:focus,
html[data-theme="dark"] .form-group textarea:focus,
html[data-theme="dark"] .form-group select:focus {
    background-color: rgba(30, 41, 59, 0.8);
}

html[data-theme="dark"] .info-message {
    background: rgba(59, 130, 246, 0.12);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.25);
}

html[data-theme="dark"] .error-message {
    background: rgba(127, 29, 29, 0.25);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.25);
}

html[data-theme="dark"] .success-message {
    background: rgba(6, 78, 59, 0.3);
    color: #a7f3d0;
    border-color: rgba(52, 211, 153, 0.25);
}

html[data-theme="dark"] .card-back {
    background: linear-gradient(165deg, #1e293b 0%, #0f172a 100%);
}

html[data-theme="dark"] #cardFront .card-title,
html[data-theme="dark"] #cardFront .card-text,
html[data-theme="dark"] #cardFront .study-rich-text {
    color: var(--text-on-light-surface);
}

html[data-theme="dark"] #cardFront .study-rich-text strong,
html[data-theme="dark"] #cardFront .study-rich-text b {
    color: #020617;
}

html[data-theme="dark"] #cardBack .card-title { color: #e0e7ff; }
html[data-theme="dark"] #cardBack .card-text,
html[data-theme="dark"] #cardBack .study-rich-text { color: var(--text-on-dark-surface); }
html[data-theme="dark"] #cardBack .study-rich-text strong,
html[data-theme="dark"] #cardBack .study-rich-text b { color: #fff; }

html[data-theme="dark"] .card-preview h4 { color: var(--primary-color); }
html[data-theme="dark"] .card-preview p { color: var(--text-on-dark-surface); }

html[data-theme="dark"] .card-preview--full-tint .card-preview-front h4,
html[data-theme="dark"] .card-preview--full-tint .card-preview-front p { color: var(--text-on-light-surface); }
html[data-theme="dark"] .card-preview--full-tint .card-preview-back h4,
html[data-theme="dark"] .card-preview--full-tint .card-preview-back p { color: var(--text-on-dark-surface); }
html[data-theme="dark"] .card-preview--full-tint .card-preview-front .card-preview-text-scroll,
html[data-theme="dark"] .card-preview--full-tint .card-preview-front .card-preview-text-scroll p { color: var(--text-on-light-surface); }
html[data-theme="dark"] .card-preview--full-tint .card-preview-back .card-preview-text-scroll,
html[data-theme="dark"] .card-preview--full-tint .card-preview-back .card-preview-text-scroll p { color: var(--text-on-dark-surface); }

html[data-theme="dark"] .subject-card .subject-description,
html[data-theme="dark"] .subject-card .subject-stats { color: #64748b; }

html[data-theme="dark"] .study-group-picker-subtitle { color: var(--text-color); }
html[data-theme="dark"] .study-group-picker-hint { color: var(--text-light); }
html[data-theme="dark"] .study-group-picker-row-label { color: var(--text-color); }
html[data-theme="dark"] .inline-rich-scroll { color: var(--text-color); }
html[data-theme="dark"] .modal-content { color: var(--text-color); }
html[data-theme="dark"] .modal-content .form-group label { color: var(--text-color); }
html[data-theme="dark"] .auth-hint,
html[data-theme="dark"] .auth-switch { color: var(--text-light); }
html[data-theme="dark"] .surface-panel ul { color: var(--text-light); }
html[data-theme="dark"] .surface-panel > p,
html[data-theme="dark"] .surface-panel > h3 { color: var(--text-color); }

html[data-theme="dark"] .ql-editor.ql-blank::before { color: var(--text-muted); }
html[data-theme="dark"] .ql-snow .ql-picker.ql-expanded .ql-picker-options {
    background-color: #1e293b;
    border-color: var(--border-color);
}
html[data-theme="dark"] .ql-snow .ql-picker-options .ql-picker-item { color: var(--text-color); }
html[data-theme="dark"] .ql-snow .ql-tooltip {
    background-color: #334155;
    border-color: var(--border-color);
    color: var(--text-color);
}
html[data-theme="dark"] .ql-snow .ql-tooltip input[type='text'] {
    background-color: #0f172a;
    color: var(--text-color);
    border-color: var(--border-color);
}

html[data-theme="dark"] .no-cards h2,
html[data-theme="dark"] .no-cards h3,
html[data-theme="dark"] .study-complete h2 { color: var(--text-color); }
html[data-theme="dark"] .page-header h2 { color: var(--text-color); }
html[data-theme="dark"] .edit-subject-heading { color: var(--text-color); }
html[data-theme="dark"] .edit-subject-card-count { color: var(--text-light); }
html[data-theme="dark"] .result-stat-value { color: var(--primary-color); }
html[data-theme="dark"] .result-stat-label { color: var(--text-light); }
html[data-theme="dark"] .progress-text { color: var(--text-light); }
html[data-theme="dark"] .results-container h2 { color: var(--text-color); }
html[data-theme="dark"] .results-container .study-actions .btn-outline { color: var(--primary-color); }
html[data-theme="dark"] .feature-card h3 { color: var(--text-color); }
html[data-theme="dark"] .feature-card p { color: var(--text-light); }
html[data-theme="dark"] .hero h2 { color: var(--text-color); }
html[data-theme="dark"] .hero p { color: var(--text-light); }
html[data-theme="dark"] .card-side h3 { color: var(--primary-color); }
html[data-theme="dark"] .card-side .form-hint,
html[data-theme="dark"] .form-hint { color: var(--text-light); }

html[data-theme="dark"] .card-image-upload {
    background: rgba(15, 23, 42, 0.45);
    border-color: var(--border-color);
    color: var(--text-light);
}

html[data-theme="dark"] .card-side-image:hover .card-image-upload {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

html[data-theme="dark"] a:not(.btn) { color: var(--primary-color); }
html[data-theme="dark"] a:not(.btn):hover { color: var(--primary-dark); }

html[data-theme="dark"] .study-container .card-content { scrollbar-color: #475569 #1e293b; }
html[data-theme="dark"] .study-container .card-content::-webkit-scrollbar-track { background: #1e293b; }
html[data-theme="dark"] .study-container .card-content::-webkit-scrollbar-thumb { background: #64748b; border-color: #1e293b; }
html[data-theme="dark"] .study-container .card-content::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
html[data-theme="dark"] .card-preview-text-scroll { scrollbar-color: #475569 #1e293b; }
html[data-theme="dark"] .card-preview-text-scroll::-webkit-scrollbar-track { background: #1e293b; }
html[data-theme="dark"] .card-preview-text-scroll::-webkit-scrollbar-thumb { background: #64748b; }

html[data-theme="dark"] .inline-rich-scroll {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    border-color: var(--border-color);
    scrollbar-color: #475569 #1e293b;
}

html[data-theme="dark"] .card-preview-back {
    background: linear-gradient(160deg, #334155 0%, #1e293b 100%);
}

html[data-theme="dark"] .card-actions {
    background: rgba(15, 23, 42, 0.4);
    border-top-color: var(--border-color);
}

html[data-theme="dark"] .first-card-preview {
    background: rgba(15, 23, 42, 0.3);
    border-color: var(--border-color);
}

html[data-theme="dark"] .subject-group-tab:not(.subject-group-tab--accent) {
    background: var(--bg-subtle);
    border-color: var(--border-color);
    color: var(--text-color);
}

html[data-theme="dark"] .subject-group-tab.subject-group-tab--active:not(.subject-group-tab--accent) {
    background: var(--primary-color);
    color: #0f172a;
    font-weight: 700;
}

html[data-theme="dark"] .subject-group-tab:not(.subject-group-tab--accent):hover {
    background: rgba(129, 140, 248, 0.1);
}

html[data-theme="dark"] .modal {
    background-color: rgba(0, 0, 0, 0.65);
}

html[data-theme="dark"] .modal-content {
    box-shadow: var(--shadow-xl);
}

html[data-theme="dark"] .modal-close:hover {
    background: rgba(241, 245, 249, 0.08);
    color: var(--text-color);
}

html[data-theme="dark"] .progress-bar {
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--border-color);
}

html[data-theme="dark"] .result-stat {
    background: var(--bg-subtle);
    border-color: var(--border-color);
}

html[data-theme="dark"] .code-block {
    background: #020617;
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.15);
}

html[data-theme="dark"] .ql-toolbar { background: rgba(15, 23, 42, 0.6); }
html[data-theme="dark"] .ql-container { background: rgba(30, 41, 59, 0.8); }
html[data-theme="dark"] .ql-editor { color: var(--text-color); }
html[data-theme="dark"] .ql-snow .ql-stroke { stroke: #94a3b8; }
html[data-theme="dark"] .ql-snow .ql-fill { fill: #94a3b8; }

html[data-theme="dark"] .card-drag-handle {
    color: #e2e8f0;
    background: rgba(30, 41, 59, 0.85);
    border-color: var(--border-color);
}

html[data-theme="dark"] .card-drag-handle--grouped {
    border-color: var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .btn-ai {
    color: #ecfdf5 !important;
    border-color: rgba(52, 211, 153, 0.35) !important;
}

html[data-theme="dark"] .study-group-picker-row:hover {
    background: rgba(129, 140, 248, 0.1);
}

html[data-theme="dark"] .demo-subject-row {
    border-bottom-color: var(--border-color);
}

/* ================================================================
   BASE
   ================================================================ */
body {
    font-family: var(--font-sans);
    color: var(--text-color);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(ellipse 1000px 500px at 15% -8%, rgba(79, 70, 229, 0.04), transparent 60%),
        radial-gradient(ellipse 700px 400px at 90% 0%, rgba(14, 165, 233, 0.03), transparent 50%);
    background-attachment: fixed;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 clamp(1rem, 3vw, 2rem);
}

main.container {
    padding-bottom: 4rem;
}

/* ================================================================
   NAVBAR
   ================================================================ */
.navbar {
    position: sticky;
    top: 0;
    z-index: 200;
    background: rgba(255, 255, 255, 0.82);
    border-bottom: 1px solid var(--border-color);
    padding: 0.625rem 0;
    box-shadow: var(--shadow-xs);
    backdrop-filter: saturate(180%) blur(var(--nav-blur));
    -webkit-backdrop-filter: saturate(180%) blur(var(--nav-blur));
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--primary-dark);
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.logo-byline {
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--text-muted);
}

.logo-byline a {
    color: var(--secondary-color);
    text-decoration: none;
}

.logo-byline a:hover { text-decoration: underline; }

.nav-links {
    display: flex;
    gap: 0.375rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.username {
    color: var(--text-light);
    margin-right: 0.25rem;
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.3rem 0.65rem;
    background: var(--bg-subtle);
    border-radius: 999px;
}

.navbar-trail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
}

.theme-toggle .theme-toggle-icon {
    font-size: 1rem;
    line-height: 1;
}

.theme-toggle .theme-toggle-label {
    font-size: 0.8125rem;
}

@media (max-width: 640px) {
    .theme-toggle .theme-toggle-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    .theme-toggle { padding: 0.4rem 0.55rem; }
}

/* ================================================================
   BUTTONS — clean, flat with subtle depth
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    line-height: 1.35;
    box-shadow: var(--shadow-xs);
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--secondary-color);
    color: #fff;
    border-color: rgba(79, 70, 229, 0.3);
}

.btn-secondary:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-success {
    background: var(--success-color);
    color: #fff;
    border-color: rgba(5, 150, 105, 0.3);
}

.btn-success:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger-color);
    color: #fff;
    border-color: rgba(185, 28, 28, 0.3);
}

.btn-danger:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-outline {
    background: var(--card-bg);
    color: var(--text-color);
    border-color: var(--border-color);
    box-shadow: none;
}

.btn-outline:hover {
    background: var(--bg-subtle);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-block { width: 100%; }

.btn-large {
    padding: 0.65rem 1.5rem;
    font-size: 0.9375rem;
    border-radius: var(--radius-md);
}

.btn-small {
    padding: 0.3rem 0.65rem;
    font-size: 0.75rem;
    border-radius: var(--radius-xs);
}

/* Accent buttons */
.btn-ai {
    background: var(--success-color) !important;
    color: #fff !important;
    border-color: rgba(5, 150, 105, 0.3) !important;
}

.btn-ai:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-warn-ai {
    background: var(--warning-color) !important;
    color: #fff !important;
    border-color: rgba(180, 83, 9, 0.3) !important;
}

.btn-warn-ai:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.btn-generate-bg {
    background: #7c3aed !important;
    color: #fff !important;
    border-color: rgba(91, 33, 182, 0.3) !important;
}

.btn-generate-bg:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* ================================================================
   HERO
   ================================================================ */
.hero {
    text-align: center;
    padding: clamp(3rem, 7vw, 5rem) 0;
}

.hero h2 {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.15;
    margin-bottom: 1rem;
    color: var(--text-color);
    max-width: 20ch;
    margin-left: auto;
    margin-right: auto;
}

.hero p {
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    color: var(--text-light);
    margin-bottom: 2rem;
    max-width: 36rem;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.7;
}

.hero-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ================================================================
   FEATURES
   ================================================================ */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.25rem;
    margin: 3rem 0 2.5rem;
}

.feature-card {
    background: var(--card-bg);
    padding: 2rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.feature-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.feature-card h3 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.feature-card p {
    color: var(--text-light);
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ================================================================
   AUTH
   ================================================================ */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 2rem 0;
}

.auth-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.auth-card h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    font-weight: 700;
    letter-spacing: -0.03em;
    font-size: 1.35rem;
}

.auth-hint {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover { text-decoration: underline; }

/* ================================================================
   FORMS
   ================================================================ */
.form-group {
    margin-bottom: 1rem;
}

.card-form .form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    background-color: var(--card-bg);
    color: var(--text-color);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-focus);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
}

.card-form .form-actions {
    margin-top: 1rem;
}

.info-message {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin: 1rem 0;
    border: 1px solid rgba(79, 70, 229, 0.15);
    font-size: 0.875rem;
}

.error-message {
    background: rgba(254, 226, 226, 0.8);
    color: #991b1b;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid rgba(239, 68, 68, 0.15);
    font-size: 0.875rem;
}

.success-message {
    background: rgba(209, 250, 229, 0.8);
    color: #065f46;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid rgba(16, 185, 129, 0.2);
    font-size: 0.875rem;
}

/* ================================================================
   CARD CREATION
   ================================================================ */
.card-form {
    max-width: 1040px;
    margin: 1.5rem auto 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-group-half {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
}

.card-sides {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
    align-items: start;
}

@media (max-width: 900px) {
    .card-sides { grid-template-columns: 1fr; }
}

.card-side {
    background: var(--card-bg);
    padding: 1.25rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    min-width: 0;
    overflow: visible;
    height: auto;
}

.card-side > .form-group {
    margin-bottom: 0.85rem;
}

.card-side > .form-group:last-child {
    margin-bottom: 0;
}

.card-side h3 {
    margin-bottom: 0;
    color: var(--text-color);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.image-preview:empty {
    display: none;
}

.image-preview img {
    max-width: 100%;
    max-height: 180px;
    margin-top: 8px;
    border-radius: var(--radius-sm);
}

/* Image upload button — always fully visible */
.card-side-image {
    margin-top: 0.25rem;
    margin-bottom: 0 !important;
    position: relative;
}

.card-image-input {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    opacity: 0 !important;
    cursor: pointer !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    z-index: 2;
    font-size: 0;
}

.card-image-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    min-height: 2.75rem;
    box-sizing: border-box;
    padding: 0.65rem 1rem;
    border: 1.5px dashed var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-subtle);
    color: var(--text-light);
    font-size: 0.8125rem;
    font-weight: 500;
    pointer-events: none; /* clicks go to the overlay file input */
}

.card-side-image:hover .card-image-upload {
    border-color: var(--primary-color);
    background: var(--primary-light);
    color: var(--primary-color);
}

.card-image-upload-icon {
    font-size: 1rem;
    line-height: 1;
}

/* ================================================================
   QUILL EDITOR — compact single-row toolbar
   ================================================================ */
.card-side .ql-toolbar.ql-snow,
.card-side .ql-container.ql-snow {
    border: none !important;
}

.card-side .ql-toolbar.ql-snow {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color) !important;
    border-bottom: none !important;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0;
    padding: 4px 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.card-side .ql-toolbar.ql-snow::-webkit-scrollbar {
    display: none;
}

.card-side .ql-toolbar.ql-snow .ql-formats {
    display: inline-flex;
    flex-wrap: nowrap;
    margin-right: 6px !important;
    margin-left: 0 !important;
    gap: 0;
}

.card-side .ql-toolbar.ql-snow .ql-formats:last-child {
    margin-right: 0 !important;
}

.card-side .ql-toolbar.ql-snow button,
.card-side .ql-toolbar.ql-snow .ql-picker {
    width: 28px;
    height: 28px;
}

.card-side .ql-toolbar.ql-snow .ql-picker-label {
    padding: 2px 4px;
}

.card-side .ql-container.ql-snow {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    border: 1px solid var(--border-color) !important;
    background: var(--card-bg);
    font-size: 0.9375rem;
    font-family: inherit;
}

.card-side .ql-editor {
    min-height: 120px;
    max-height: 280px;
    overflow-y: auto;
    padding: 0.75rem 0.9rem;
    line-height: 1.55;
}

.card-side .ql-editor.ql-blank::before {
    font-style: normal;
    color: var(--text-muted);
    left: 1rem;
}

.ql-container {
    font-size: 0.9375rem;
    font-family: inherit;
}

.ql-editor {
    min-height: 150px;
}

.ql-toolbar.ql-snow {
    border-top-left-radius: var(--radius-sm);
    border-top-right-radius: var(--radius-sm);
    background: var(--bg-subtle);
    border-color: var(--border-color) !important;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 6px 8px;
}

.ql-toolbar.ql-snow .ql-formats {
    display: inline-flex;
    flex-wrap: nowrap;
    margin-right: 8px;
    gap: 1px;
}

.ql-container.ql-snow {
    border-bottom-left-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    border-color: var(--border-color) !important;
    background: var(--card-bg);
}

/* ================================================================
   PAGE HEADER
   ================================================================ */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin: 1.75rem 0 1.25rem;
    flex-wrap: wrap;
}

.page-header h2 {
    font-size: clamp(1.35rem, 2.5vw, 1.65rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.page-header-lead {
    margin: 0.5rem 0 0;
    max-width: 42rem;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text-light);
}

.page-header--edit-subject {
    align-items: flex-start;
}

.page-header-title-block {
    flex: 1;
    min-width: 0;
}

.edit-subject-heading {
    font-size: 1.75rem;
    line-height: 1.3;
    margin: 0;
}

.edit-subject-card-count {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
    vertical-align: baseline;
}

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

/* ================================================================
   SUBJECT GROUP TABS
   ================================================================ */
.subject-group-tabs-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: -0.5rem 0 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.subject-group-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
}

.subject-group-tabs-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    flex-shrink: 0;
}

.subject-group-tabs-actions[hidden] { display: none !important; }

.subject-group-tabs-side-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
}

.subject-group-bulk-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
}

#bulkAddToGroupBtn[hidden] { display: none !important; }

#bulkSelectModeBtn.subject-bulk-mode--on {
    box-shadow: 0 0 0 2px var(--primary-color);
    background: var(--primary-light);
}

.subject-group-tab {
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.subject-group-tab:not(.subject-group-tab--accent):hover {
    background: var(--bg-subtle);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.subject-group-tab.subject-group-tab--accent {
    background-color: var(--sg-accent);
    color: var(--sg-ink);
    border-color: var(--sg-accent);
}

.subject-group-tab.subject-group-tab--accent:hover { filter: brightness(0.93); }

.subject-group-tab.subject-group-tab--accent.subject-group-tab--active {
    background-color: var(--sg-accent);
    color: var(--sg-ink);
    border-color: var(--sg-accent);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
    filter: none;
}

.subject-group-tab.subject-group-tab--accent.subject-group-tab--active:hover { filter: none; }

.subject-group-tab.subject-group-tab--active:not(.subject-group-tab--accent) {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.subject-group-tab.subject-group-tab--dragover:not(.subject-group-tab--accent) {
    box-shadow: 0 0 0 2px var(--primary-color);
    background: var(--primary-light);
}

.subject-group-tab.subject-group-tab--accent.subject-group-tab--dragover {
    box-shadow: 0 0 0 3px var(--sg-accent);
    filter: brightness(0.88);
}

/* Card drag & bulk select */
.card-preview-top-left {
    position: absolute;
    left: 0.4rem;
    top: 0.45rem;
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.card-preview-top-left .card-drag-handle {
    position: relative;
    left: auto;
    top: auto;
}

.card-bulk-select {
    display: flex;
    align-items: center;
    margin: 0;
    cursor: pointer;
}

.card-bulk-select[hidden] { display: none !important; }

.card-bulk-checkbox {
    width: 1rem;
    height: 1rem;
    margin: 0;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.card-drag-handle {
    position: absolute;
    left: 0.4rem;
    top: 0.45rem;
    z-index: 12;
    padding: 0.15rem 0.3rem;
    font-size: 0.8rem;
    line-height: 1;
    letter-spacing: -0.05em;
    color: rgba(0, 0, 0, 0.4);
    cursor: grab;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.5);
    user-select: none;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.card-drag-handle--grouped {
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.card-drag-handle:active { cursor: grabbing; }

/* ================================================================
   STUDY PAGE
   ================================================================ */
.study-container {
    max-width: 800px;
    margin: 2rem auto;
}

.study-stats {
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-light);
    letter-spacing: -0.02em;
}

.card-container {
    perspective: 1000px;
    margin-bottom: 2rem;
    position: relative;
}

.card {
    width: 100%;
    height: auto;
    min-height: 0;
    position: relative;
    margin: 0 auto;
    display: block;
}

.card-inner {
    position: relative;
    width: 100%;
    min-height: 120px;
    height: auto;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card-inner.flipped { transform: rotateY(180deg); }

.card-front,
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    backface-visibility: hidden;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 1.5rem;
    box-sizing: border-box;
    overflow: hidden;
}

.card-back {
    transform: rotateY(180deg);
    background: linear-gradient(165deg, var(--bg-subtle) 0%, var(--bg-color) 100%);
}

.card-inner:not(.flipped) .card-back { pointer-events: none; }
.card-inner.flipped .card-front { pointer-events: none; }

.study-container .card-content {
    text-align: center;
    width: 100%;
    max-width: 100%;
    display: block;
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(78vh, 920px);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) var(--bg-subtle);
    touch-action: pan-y;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.study-container .card-content::-webkit-scrollbar { width: 8px; }
.study-container .card-content::-webkit-scrollbar-track { background: var(--bg-subtle); border-radius: 4px; }
.study-container .card-content::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 4px; border: 2px solid var(--bg-subtle); }
.study-container .card-content::-webkit-scrollbar-thumb:hover { background: var(--text-light); }

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.75rem;
    color: var(--primary-dark);
}

.card-image {
    max-width: 100%;
    max-height: 250px;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    box-shadow: var(--shadow-md);
}

.card-text {
    font-size: clamp(1rem, 1.4rem, 1.6rem);
    line-height: 1.8;
    color: var(--text-color);
    word-wrap: break-word;
    overflow-wrap: break-word;
    width: 100%;
    max-width: 100%;
}

.card-text br { display: block; margin: 0.2rem 0; }
.card-text ul, .card-text ol { text-align: left; display: inline-block; margin: 0.5rem 0; max-width: 100%; }

.study-container .study-rich-text { white-space: pre-line; }
.study-rich-text ul, .study-rich-text ol { padding-left: 1.5rem; list-style-position: outside; }
.card-text p { margin: 0.4rem 0; }

.study-actions,
.flipped-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.study-complete {
    text-align: center;
    padding: clamp(2rem, 5vw, 3rem);
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.study-complete h2 {
    font-size: 2.25rem;
    margin-bottom: 0.75rem;
}

.study-complete p {
    font-size: 1.125rem;
    color: var(--text-light);
    margin-bottom: 2rem;
}

/* ================================================================
   NO CARDS / EMPTY STATE
   ================================================================ */
.no-cards {
    text-align: center;
    padding: clamp(3rem, 7vw, 4.5rem) 2rem;
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.no-cards h2,
.no-cards h3 { margin-bottom: 0.75rem; }

.no-cards p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
}

.no-cards-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
}

/* Demo cards modal */
.demo-modal-content { max-width: 520px; }

.demo-modal-lead {
    color: var(--text-light);
    font-size: 0.875rem;
    margin: 0.25rem 0 1.25rem;
}

.demo-subject-row {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.demo-subject-row:last-child { border-bottom: none; }

/* ================================================================
   DASHBOARD — cards grid
   ================================================================ */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0;
}

.card-preview {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.cards-grid .card-preview {
    border: 3px solid transparent;
}

.card-preview:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.clickable-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.card-preview.card-preview--study-known,
.card-preview.clickable-card.card-preview--study-known,
.first-card-preview.clickable-card.card-preview--study-known {
    box-shadow: var(--shadow);
    border: 3px solid var(--study-frame-known);
}

.card-preview.card-preview--study-known:hover,
.card-preview.clickable-card.card-preview--study-known:hover,
.first-card-preview.clickable-card.card-preview--study-known:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--study-frame-known);
}

.card-preview.card-preview--study-unknown,
.card-preview.clickable-card.card-preview--study-unknown,
.first-card-preview.clickable-card.card-preview--study-unknown {
    box-shadow: var(--shadow);
    border: 3px solid var(--study-frame-unknown);
}

.card-preview.card-preview--study-unknown:hover,
.card-preview.clickable-card.card-preview--study-unknown:hover,
.first-card-preview.clickable-card.card-preview--study-unknown:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--study-frame-unknown);
}

.card-preview-inner {
    position: relative;
    height: 200px;
    perspective: 1000px;
    overflow: hidden;
}

.card-preview-text-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 6.5rem;
    margin-top: 0.3rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) var(--bg-subtle);
    text-align: left;
}

.card-preview-text-scroll::-webkit-scrollbar { width: 6px; }
.card-preview-text-scroll::-webkit-scrollbar-track { background: var(--bg-subtle); border-radius: 3px; }
.card-preview-text-scroll::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }

.inline-rich-scroll {
    background: var(--bg-subtle);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-top: 0.5rem;
    min-height: 100px;
    max-height: min(45vh, 420px);
    overflow-y: auto;
    overflow-x: hidden;
    word-wrap: break-word;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--text-muted) var(--bg-subtle);
}

.card-preview-front,
.card-preview-back {
    position: absolute;
    width: 100%;
    height: 100%;
    padding: 1rem;
    backface-visibility: hidden;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-preview-front > *,
.card-preview-back > * { flex-shrink: 0; }

.card-preview-front > p,
.card-preview-back > p { flex-shrink: 1; flex-grow: 0; }

.card-preview-front > .card-preview-text-scroll,
.card-preview-back > .card-preview-text-scroll { flex-shrink: 1; min-height: 0; }

.card-preview.card-preview--full-tint .card-preview-front > .card-preview-text-scroll,
.card-preview.card-preview--full-tint .card-preview-back > .card-preview-text-scroll {
    flex: 1 1 auto;
    max-height: none;
}

.card-preview-back {
    transform: rotateY(180deg);
    background: linear-gradient(160deg, var(--bg-subtle) 0%, var(--border-color) 100%);
}

.card-preview h4 {
    font-size: 1rem;
    margin-bottom: 0.4rem;
    color: var(--primary-color);
}

.card-preview img {
    max-width: 100%;
    max-height: 120px;
    border-radius: 4px;
    margin: 0.4rem 0;
}

.card-preview p {
    color: var(--text-color);
    font-size: 0.9375rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow: hidden;
    margin: 0;
    flex: 0 1 auto;
    min-height: 0;
    max-height: calc(1.5em * 5);
    box-sizing: border-box;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
}

.card-preview .card-preview-text-scroll p {
    overflow: visible;
    display: block;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
    max-height: none;
    text-overflow: unset;
    flex: none;
}

.card-actions {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 0.375rem;
}

/* ================================================================
   SUBJECTS
   ================================================================ */
.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin: 1.5rem 0;
}

.subject-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
    position: relative;
    overflow: hidden;
}

.subject-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.subject-card h3 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.4rem;
    color: var(--primary-color);
}

.subject-description {
    color: var(--text-light);
    margin-bottom: 0.75rem;
    font-size: 0.8125rem;
}

.subject-stats {
    margin-bottom: 0.75rem;
    color: var(--text-light);
    font-size: 0.8125rem;
}

.subject-actions {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
}

.subject-icon {
    width: 200px;
    height: 100px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    position: absolute;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 1;
}

.card-delete-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow);
}

.card-delete-btn:hover {
    filter: brightness(1.1);
    transform: scale(1.1);
}

.subject-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-count-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    box-shadow: var(--shadow-xs);
}

.first-card-preview {
    margin: 0.75rem 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.4);
}

.first-card-preview .card-preview-inner { height: 150px; }

.first-card-preview .card-preview-front,
.first-card-preview .card-preview-back {
    padding: 0.75rem;
    font-size: 0.8125rem;
}

.first-card-preview.clickable-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.first-card-preview h4 {
    font-size: 0.9375rem;
    margin-bottom: 0.35rem;
}

.first-card-preview img { max-height: 80px; }

/* ================================================================
   MODAL
   ================================================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 2rem;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-xl);
    position: relative;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.modal-content h2 {
    font-weight: 700;
    letter-spacing: -0.02em;
    font-size: 1.25rem;
    padding-right: 2rem;
}

.modal-close {
    position: absolute;
    right: 0.75rem;
    top: 0.75rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-color);
    background: var(--bg-subtle);
}

/* Study: group picker modal */
.study-group-picker-modal .study-group-picker-subtitle {
    font-weight: 600;
    color: var(--text-color);
    margin: 0.25rem 0 0;
    font-size: 1rem;
}

.study-group-picker-modal .study-group-picker-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.study-group-picker-modal .study-group-picker-fieldset {
    border: none;
    margin: 1rem 0 0;
    padding: 0;
}

.study-group-picker-modal .study-group-picker-fieldset legend {
    font-weight: 600;
    margin-bottom: 0.5rem;
    padding: 0;
}

.study-group-picker-modal .study-group-picker-hint {
    color: var(--text-light);
    font-size: 0.8125rem;
    margin: 0 0 0.75rem;
    line-height: 1.45;
}

.study-group-picker-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    width: 100%;
    max-height: min(50vh, 320px);
    overflow-y: auto;
}

.study-group-picker-row {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--radius-xs);
    margin: 0;
}

.study-group-picker-row input[type="checkbox"] {
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.study-group-picker-row-label {
    flex: 1;
    min-width: 0;
    line-height: 1.35;
    word-break: break-word;
}

.study-group-picker-row:hover {
    background: var(--primary-light);
}

.study-group-picker-modal #studyGroupPickerSelectedBtn {
    margin-top: 1rem;
    width: 100%;
}

/* ================================================================
   PROGRESS BAR
   ================================================================ */
.progress-container { margin: 1.5rem 0; }

.progress-bar {
    width: 100%;
    height: 28px;
    background: var(--bg-subtle);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}

.progress-text {
    text-align: center;
    margin-top: 0.4rem;
    color: var(--text-light);
    font-size: 0.8125rem;
}

.progress-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-top: 0.4rem;
    gap: 0.5rem;
}

.progress-row .progress-text {
    grid-column: 2;
    margin-top: 0;
    justify-self: center;
}

.progress-row #backToSubjectLink {
    grid-column: 3;
    justify-self: end;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .progress-row { grid-template-columns: 1fr; }
    .progress-row .progress-text { grid-column: 1; }
    .progress-row #backToSubjectLink {
        grid-column: 1;
        justify-self: center;
        white-space: normal;
        text-align: center;
    }
}

/* Focused card highlight */
.edit-subject-card--focused {
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.35), var(--shadow-lg);
    border-radius: var(--radius-lg);
    transition: box-shadow var(--transition-base);
}

/* ================================================================
   RESULTS
   ================================================================ */
.results-container {
    text-align: center;
    padding: clamp(1.75rem, 4vw, 2.5rem);
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    margin: 2rem 0;
}

.results-container h2 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin: 1.5rem 0;
}

.result-stat {
    padding: 1rem;
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.result-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

.result-stat-label {
    color: var(--text-light);
    font-size: 0.8125rem;
    margin-top: 0.35rem;
}

/* ================================================================
   SURFACE PANEL (import, help)
   ================================================================ */
.surface-panel {
    max-width: 640px;
    margin: 2rem auto;
    padding: 1.75rem;
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.surface-panel h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.6rem;
    font-size: 1.05rem;
}

.surface-panel ul {
    margin: 0.6rem 0 0.6rem 1.25rem;
    color: var(--text-light);
    line-height: 1.55;
    font-size: 0.875rem;
}

.code-block {
    background: #0f172a;
    color: #e2e8f0;
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.5;
    margin: 0.6rem 0;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.form-hint {
    display: block;
    margin-top: 0.4rem;
    color: var(--text-light);
    font-size: 0.8125rem;
    line-height: 1.45;
}

/* ================================================================
   CARD NAVIGATION (create_card arrows)
   ================================================================ */
.card-nav-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.card-nav-row--end { justify-content: flex-end; }

.card-nav-grow {
    flex: 1;
    min-width: 0;
}

.card-nav-arrow {
    padding: 0.35rem;
    flex-shrink: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), opacity var(--transition-fast);
}

.card-nav-arrow:hover:not(:disabled) {
    background: var(--primary-light);
}

.card-nav-arrow:disabled {
    opacity: 0.25;
    cursor: not-allowed;
}

.card-nav-arrow.btn { box-shadow: none; }

.card-nav-arrow img {
    height: 36px;
    width: auto;
    display: block;
    border-radius: var(--radius-xs);
}

.image-preview-wrap {
    position: relative;
    display: inline-block;
    margin-top: 8px;
}

.image-preview-wrap img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
}

.image-preview-wrap .btn-danger {
    position: absolute;
    top: 6px;
    right: 6px;
}

/* ================================================================
   SUBSCRIBE / ABONNEMANG
   ================================================================ */
.subscribe-page {
    max-width: 880px;
    margin: 2rem auto 3rem;
}

.subscribe-hero {
    text-align: center;
    margin-bottom: 1.75rem;
}

.subscribe-hero h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.subscribe-hero p {
    color: var(--text-light);
    font-size: 1.05rem;
}

.subscribe-expired {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 1.25rem;
}

.subscribe-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.25rem;
    align-items: start;
}

.subscribe-plan .subscribe-price {
    font-size: 1.15rem;
    color: var(--text-light);
    margin: 0.75rem 0 1rem;
}

.subscribe-plan .subscribe-price span {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
}

.subscribe-perks {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem;
}

.subscribe-perks li {
    padding: 0.4rem 0;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
}

.subscribe-perks li:last-child {
    border-bottom: none;
}

.subscribe-swish {
    margin: 1.25rem 0;
}

.subscribe-swish h4 {
    margin: 0 0 0.35rem;
    color: var(--text-color);
}

.subscribe-swish > p {
    color: var(--text-light);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}

.subscribe-swish-box {
    background: var(--bg-color);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

.subscribe-swish-qr {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
}

.subscribe-swish-qr img {
    width: 180px;
    height: 180px;
    border-radius: var(--radius-sm, 6px);
    background: #fff;
    padding: 0.4rem;
    box-sizing: border-box;
}

.subscribe-swish-open {
    font-size: 0.85rem;
}

.subscribe-swish-details {
    flex: 1;
    min-width: 160px;
}

.subscribe-swish-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-light);
    margin: 0;
}

.subscribe-swish-value {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0.25rem 0 0.65rem;
    color: var(--text-color);
    letter-spacing: 0.02em;
}

.subscribe-swish-hint {
    margin: 0 0 0.35rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.subscribe-status {
    text-align: center;
    max-width: 420px;
    margin: 0 auto;
}

.auth-optional {
    font-weight: 400;
    color: var(--text-light);
    font-size: 0.9em;
}

.password-label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}

.password-label-row label {
    margin-bottom: 0;
}

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary-color);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

.btn-link:hover {
    text-decoration: underline;
}

.password-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.password-input-wrap input {
    width: 100%;
    padding-right: 2.75rem;
}

.password-toggle-btn {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.35rem;
    opacity: 0.7;
}

.password-toggle-btn:hover {
    opacity: 1;
}

.password-suggest-hint {
    margin-top: 0.45rem;
}

.password-suggest-hint .btn-link {
    margin-left: 0.35rem;
}

.trial-offer {
    margin: 1rem 0 0.25rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: rgba(79, 70, 229, 0.04);
}

.trial-offer-title {
    margin: 0 0 0.35rem;
    font-weight: 700;
    color: var(--text-color);
}

.trial-offer-slots {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-color);
}

.trial-offer-btn.is-selected,
.trial-offer-btn.btn-primary {
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.25);
}

.trial-offer-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .subscribe-grid {
        grid-template-columns: 1fr;
    }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
    .hero h2 { font-size: 1.75rem; }
    .nav-links { flex-wrap: wrap; }
    .study-actions,
    .flipped-actions { flex-direction: column; }
    .study-actions .btn,
    .flipped-actions .btn { width: 100%; }
}


/* ================================================================
   ADMIN
   ================================================================ */
.admin-page {
    max-width: 1200px;
    margin: 1.5rem auto 3rem;
}
.admin-header {
    margin-bottom: 1.25rem;
}
.admin-header h2 {
    margin: 0 0 0.35rem;
    font-size: 1.75rem;
}
.admin-header p {
    margin: 0;
    color: var(--text-light);
}
.admin-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}
.admin-stat {
    padding: 1rem 1.1rem;
}
.admin-stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 0.35rem;
}
.admin-stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-color);
}
.admin-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}
.admin-section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.admin-section-head h3,
.admin-section h3 {
    margin: 0 0 0.75rem;
}
.admin-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg, #fff);
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.admin-table th,
.admin-table td {
    padding: 0.7rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}
.admin-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-light);
    background: rgba(0,0,0,0.02);
    white-space: nowrap;
}
.admin-table tr:last-child td {
    border-bottom: none;
}
.admin-table tr.is-free {
    background: rgba(16, 185, 129, 0.04);
}
.admin-table tr.is-used {
    background: transparent;
}
.admin-table tr.is-due-soon {
    background: rgba(245, 158, 11, 0.08);
}
.admin-table tr.is-overdue {
    background: rgba(239, 68, 68, 0.08);
}
.admin-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    background: rgba(0,0,0,0.04);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}
.admin-muted {
    color: var(--text-light);
    font-size: 0.85rem;
}
.admin-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 11rem;
}
.admin-inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.admin-inline-form input[type="text"],
.admin-inline-form input[type="number"] {
    min-width: 0;
    flex: 1;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm, 6px);
    font-size: 0.85rem;
}
.admin-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: rgba(79, 70, 229, 0.12);
    color: var(--primary-color);
}
.admin-badge-warn {
    background: rgba(239, 68, 68, 0.12);
    color: #b91c1c;
}
.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}
@media (max-width: 900px) {
    .admin-stats {
        grid-template-columns: 1fr 1fr;
    }
}
@media (max-width: 600px) {
    .admin-stats {
        grid-template-columns: 1fr;
    }
}
