/* ========================================
   Flashcard Section - Full Width
======================================== */
.flashcard-section {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    background: transparent;
    padding: var(--space-6);
    overflow-y: auto;
}

/* ========================================
   Global Keyframes for Flashcard Animations
======================================== */
@keyframes fc-fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fc-fadeInScale {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

@keyframes fc-slideInRight {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes fc-slideInLeft {
    from { opacity: 0; transform: translateX(-40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes fc-slideOutLeft {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-40px); }
}

@keyframes fc-slideOutRight {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

@keyframes fc-scaleIn {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}

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

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

@keyframes fc-ripple {
    0%   { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(2.5); opacity: 0; }
}

@keyframes fc-hintReveal {
    from { opacity: 0; max-height: 0; padding: 0 var(--space-3); margin-top: 0; }
    to   { opacity: 1; max-height: 200px; padding: var(--space-3); margin-top: var(--space-2); }
}

/* ========================================
   Setup Container
======================================== */
.flashcard-panel {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.flashcard-setup {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 24%),
        var(--bg-panel);
    padding: clamp(24px, 4vw, 36px);
    max-width: 780px;
    width: 100%;
    border-radius: var(--radius-2xl);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-floating);
}

/* Setup Steps */
.flashcard-setup {
    position: relative;
}

.setup-step {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.setup-step.fc-step-exit {
    animation: fc-slideOutLeft 0.2s cubic-bezier(0.4, 0, 1, 1) both;
}

.setup-step.fc-step-enter {
    animation: fc-slideInRight 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.setup-step h2 {
    font-size: clamp(1.7rem, 3vw, 2.2rem);
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
    letter-spacing: -0.03em;
}

.setup-selection {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin: -10px 0 6px 0;
    font-weight: 600;
}

.setup-back-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    border: 1px solid var(--border-default);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    align-self: flex-start;
    margin-bottom: -8px;
    transition: var(--transition-spring);
}

.setup-back-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.setup-back-btn svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   Grade Selection Grid
======================================== */
.grade-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-3);
}

.grade-btn {
    padding: 18px var(--space-3);
    border-radius: var(--radius-lg);
    background: var(--bg-glass);
    border: 1px solid var(--border-default);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    overflow: hidden;
}

.grade-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: inherit;
}

.grade-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
    transform: translateY(-2px) scale(1.03);
    box-shadow: var(--shadow-md);
}

.grade-btn:active {
    background: var(--bg-active);
    transform: translateY(0) scale(0.98);
    transition-duration: 0.1s;
}

/* ========================================
   Subject Selection Grid
======================================== */
.subject-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: var(--space-3);
    max-height: 400px;
    overflow-y: auto;
}

.subject-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-3);
    border-radius: var(--radius-xl);
    background: var(--bg-glass);
    border: 1px solid var(--border-default);
    transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.subject-btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    transform: translateY(-3px) scale(1.04);
    box-shadow: var(--shadow-md);
}

.subject-btn:active {
    transform: translateY(0) scale(0.97);
    transition-duration: 0.1s;
}

.subject-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(245, 184, 0, 0.08);
    border-radius: var(--radius-lg);
    transition: var(--transition-fast);
}

.subject-icon svg {
    width: 28px;
    height: 28px;
    stroke: var(--text-tertiary);
    transition: var(--transition-fast);
}

.subject-btn:hover .subject-icon svg {
    stroke: var(--accent);
}

.subject-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.3;
}

/* ========================================
   Topic Input
======================================== */
.topic-input-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.topic-input {
    width: 100%;
    padding: 18px var(--space-5);
    border-radius: var(--radius-xl);
    background: var(--bg-inset);
    border: 1px solid var(--border-default);
    font-size: 15px;
    color: var(--text-primary);
    transition: var(--transition-spring);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.topic-input:focus {
    background: rgba(245, 184, 0, 0.04);
    border-color: rgba(245, 184, 0, 0.24);
    box-shadow: 0 0 0 4px rgba(245, 184, 0, 0.08), var(--shadow-md);
}

.topic-input::placeholder {
    color: var(--text-placeholder);
}

.generate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-4);
    border-radius: var(--radius-xl);
    background: var(--brand-gradient);
    font-size: 15px;
    font-weight: 600;
    color: var(--accent-text);
    transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    position: relative;
    overflow: hidden;
}

.generate-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.generate-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: var(--shadow-glow);
}

.generate-btn:hover::before {
    transform: translateX(100%);
}

.generate-btn:active {
    transform: translateY(0) scale(0.98);
    transition-duration: 0.1s;
}

.generate-btn svg {
    width: 18px;
    height: 18px;
}

/* ========================================
   Card Count Selector
======================================== */
.fc-card-count {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-2);
    padding: var(--space-4);
    border-radius: var(--radius-xl);
    background: var(--bg-inset);
    border: 1px solid var(--border-subtle);
}

.fc-card-count-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.fc-card-count-options {
    display: flex;
    gap: var(--space-2);
}

.fc-count-btn {
    padding: 10px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-glass);
    border: 1px solid var(--border-default);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    min-width: 44px;
    text-align: center;
}

.fc-count-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.fc-count-btn.active {
    background: var(--brand-gradient);
    border-color: rgba(245, 184, 0, 0.2);
    color: var(--accent-text);
    box-shadow: 0 10px 24px rgba(245, 184, 0, 0.18);
}

/* ========================================
   Sources Card
======================================== */
.fc-sources-card {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    padding: var(--space-5);
    margin-top: var(--space-2);
    background: var(--bg-inset);
}

[data-theme="dark"] .fc-sources-card {
    border-color: var(--border-default);
}

.fc-sources-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.fc-sources-header svg {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.fc-sources-optional {
    font-weight: 400;
    color: var(--text-tertiary);
    font-size: 12px;
}

.fc-source-inputs {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.fc-file-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-5);
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-xl);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    color: var(--text-tertiary);
    font-size: 13px;
    background: var(--bg-glass);
}

.fc-file-drop:hover,
.fc-file-drop.dragover {
    border-color: var(--accent);
    background: var(--accent-subtle);
    transform: scale(1.01);
    box-shadow: 0 0 0 4px var(--accent-subtle);
}

.fc-file-drop svg {
    color: var(--text-tertiary);
}

.fc-file-drop strong {
    color: var(--accent);
    cursor: pointer;
}

.fc-file-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.fc-file-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--bg-hover);
    font-size: 12px;
}

[data-theme="dark"] .fc-file-item {
    background: rgba(255, 255, 255, 0.05);
}

.fc-file-name {
    font-weight: 600;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.fc-file-remove-btn {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-tertiary);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    line-height: 1;
}

.fc-file-remove-btn:hover {
    background: var(--destructive-subtle);
    color: var(--destructive);
}

.fc-url-input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.fc-url-input-group label {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.fc-url-input {
    width: 100%;
    padding: 14px var(--space-4);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-default);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    transition: all var(--transition-spring);
}

.fc-url-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(245, 184, 0, 0.08);
}

.fc-url-input::placeholder {
    color: var(--text-placeholder);
}

.fc-source-error {
    margin-top: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--destructive-subtle);
    color: var(--destructive);
    font-size: 13px;
    border: 1px solid rgba(239, 68, 68, 0.18);
}

/* ========================================
   Topic Suggestions
======================================== */
.topic-suggestions {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
}

.suggestion-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.suggestion-chip {
    padding: 10px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-glass);
    border: 1px solid var(--border-default);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.suggestion-chip:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px) scale(1.04);
}

.suggestion-chip:active {
    transform: scale(0.96);
    transition-duration: 0.1s;
}

/* ========================================
   Loading State
======================================== */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-8);
    animation: fc-fadeInUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.loading-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    border-radius: var(--radius-xl);
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    position: relative;
}

.loading-icon::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid var(--accent);
    opacity: 0;
    animation: fc-ripple 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.loading-icon svg {
    width: 36px;
    height: 36px;
    stroke: var(--accent);
    animation: bounce 1.2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.08); opacity: 0.85; }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.loading-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    margin: 0;
    animation: fc-fadeInUp 0.5s 0.15s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.loading-progress-container {
    width: 100%;
    max-width: 280px;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
    animation: fc-fadeInUp 0.5s 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.loading-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-hover), var(--accent));
    background-size: 200% 100%;
    border-radius: var(--radius-full);
    transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    animation: fc-shimmer 2s linear infinite;
}

.loading-progress-text {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    margin: 0;
    font-variant-numeric: tabular-nums;
    animation: fc-fadeInUp 0.5s 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* ========================================
   Flashcard Display - Modernized
======================================== */
.flashcard-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
}

/* Top bar */
.flashcard-progress {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    background: transparent;
}

.flashcard-progress-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.flashcard-progress span {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Card Type Badge */
.card-type-badge {
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.card-type-badge.card-type-definition {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.card-type-badge.card-type-formula {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.card-type-badge.card-type-example {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.card-type-badge.card-type-concept {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.card-type-badge.card-type-mistake {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.flashcard-progress-right {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.back-to-topics {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: var(--transition-fast);
}

.back-to-topics:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.back-to-topics svg {
    width: 16px;
    height: 16px;
}

/* ========================================
   Progress Dots
======================================== */
.flashcard-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    padding: var(--space-2) 0;
    flex-wrap: wrap;
    max-width: 100%;
}

.fc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bg-hover);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    cursor: pointer;
}

.fc-dot:hover {
    transform: scale(1.4);
}

[data-theme="dark"] .fc-dot {
    background: rgba(255, 255, 255, 0.08);
}

.fc-dot.active {
    width: 24px;
    border-radius: 4px;
    background: var(--accent);
}

.fc-dot.rated-easy {
    background: #22c55e;
}

.fc-dot.rated-good {
    background: #3b82f6;
}

.fc-dot.rated-hard {
    background: #f59e0b;
}

.fc-dot.rated-again {
    background: #ef4444;
}

/* ========================================
   Flashcard - Modern Design
======================================== */
.flashcard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
}

.flashcard {
    width: 100%;
    min-height: 320px;
    max-height: 55vh;
    perspective: 1200px;
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 320px;
    max-height: 55vh;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-style: preserve-3d;
}

/* Card slide wrapper — animate the outer .flashcard, not inner (which handles flip) */
.flashcard.fc-card-slide-left {
    animation: fc-cardSlideLeft 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.flashcard.fc-card-slide-right {
    animation: fc-cardSlideRight 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes fc-cardSlideLeft {
    0%   { opacity: 0; transform: translateX(40px); }
    100% { opacity: 1; transform: translateX(0); }
}

@keyframes fc-cardSlideRight {
    0%   { opacity: 0; transform: translateX(-40px); }
    100% { opacity: 1; transform: translateX(0); }
}

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

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    min-height: 320px;
    max-height: 55vh;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-6) var(--space-5);
    text-align: center;
    overflow: hidden;
    -webkit-transform: translateZ(0);
}

.flashcard-front {
    transform: rotateY(0deg);
}

.flashcard-back {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
}

/* Front - type-specific gradient backgrounds */
.flashcard-front {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #334155 100%);
    color: #f8fafc;
    box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .flashcard-front {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.5);
}

/* Type-specific front gradients */
.flashcard.card-front-definition .flashcard-front {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}
.flashcard.card-front-formula .flashcard-front {
    background: linear-gradient(135deg, #064e3b 0%, #059669 100%);
}
.flashcard.card-front-example .flashcard-front {
    background: linear-gradient(135deg, #78350f 0%, #d97706 100%);
}
.flashcard.card-front-concept .flashcard-front {
    background: linear-gradient(135deg, #3b0764 0%, #9333ea 100%);
}
.flashcard.card-front-mistake .flashcard-front {
    background: linear-gradient(135deg, #7f1d1d 0%, #dc2626 100%);
}

/* Front decorative elements */
.flashcard-front::before {
    content: '';
    position: absolute;
    top: -40%;
    right: -30%;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, transparent 70%);
    pointer-events: none;
}

.flashcard-front::after {
    content: '';
    position: absolute;
    bottom: -20%;
    left: -20%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, transparent 70%);
    pointer-events: none;
}

/* Front card type icon */
.flashcard-type-icon {
    position: absolute;
    top: var(--space-4);
    left: var(--space-4);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.flashcard-type-icon svg {
    width: 16px;
    height: 16px;
    stroke: rgba(255, 255, 255, 0.8);
}

/* Front card number */
.flashcard-card-num {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    font-size: 12px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 0.5px;
}

/* Back */
.flashcard-back {
    background: var(--bg-primary);
    color: var(--text-primary);
    transform: rotateY(180deg);
    box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--bg-hover);
    justify-content: flex-start;
    padding-top: var(--space-6);
}

[data-theme="dark"] .flashcard-back {
    background: #111827;
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.5);
}

/* Back header label */
.flashcard-back-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-4);
    background: var(--accent-subtle);
    color: var(--accent);
}

/* Hint section */
.flashcard-hint-section {
    width: 100%;
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid var(--bg-hover);
}

[data-theme="dark"] .flashcard-hint-section {
    border-color: rgba(255, 255, 255, 0.06);
}

.flashcard-hint-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: var(--transition-fast);
    width: 100%;
    justify-content: center;
}

.flashcard-hint-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.flashcard-hint-toggle svg {
    width: 14px;
    height: 14px;
}

.flashcard-hint-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    padding: 0 var(--space-3);
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    margin-top: 0;
    text-align: left;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="dark"] .flashcard-hint-text {
    background: rgba(255, 255, 255, 0.03);
}

.flashcard-hint-text.visible {
    max-height: 200px;
    opacity: 1;
    padding: var(--space-3);
    margin-top: var(--space-2);
}

.flashcard-question {
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.45;
    margin: 0;
    position: relative;
    z-index: 1;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.flashcard-question .md-content,
.flashcard-answer .md-content {
    text-align: inherit;
    width: 100%;
}

.flashcard-question .katex-display,
.flashcard-answer .katex-display {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    margin: 0.5em 0;
}

.flashcard-question .katex,
.flashcard-answer .katex {
    font-size: 1em;
    max-width: 100%;
}

.flashcard-answer {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.65;
    color: var(--text-primary);
    white-space: pre-wrap;
    text-align: left;
    width: 100%;
    word-break: break-word;
    overflow-wrap: break-word;
}

.flip-instruction {
    color: var(--text-tertiary);
    font-size: 12px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.flip-instruction kbd {
    display: inline-flex;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-hover);
    font-size: 11px;
    font-family: inherit;
    color: var(--text-tertiary);
}

[data-theme="dark"] .flip-instruction kbd {
    background: rgba(255, 255, 255, 0.06);
}

/* ========================================
   Self-Rating Buttons
======================================== */
.flashcard-rating {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}

.flashcard-rating.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.rating-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-lg);
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    min-width: 80px;
    border: 1.5px solid transparent;
    position: relative;
    overflow: hidden;
}

.rating-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.rating-btn:active {
    transform: scale(0.93) !important;
    transition-duration: 0.1s;
}

.rating-btn .rating-label {
    font-size: 12px;
    font-weight: 500;
    opacity: 0.7;
}

.rating-btn.rating-again {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.05);
}
.rating-btn.rating-again:hover {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.4);
    transform: translateY(-2px);
}

.rating-btn.rating-hard {
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.2);
    background: rgba(245, 158, 11, 0.05);
}
.rating-btn.rating-hard:hover {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.4);
    transform: translateY(-2px);
}

.rating-btn.rating-good {
    color: #3b82f6;
    border-color: rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.05);
}
.rating-btn.rating-good:hover {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

.rating-btn.rating-easy {
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.2);
    background: rgba(34, 197, 94, 0.05);
}
.rating-btn.rating-easy:hover {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.4);
    transform: translateY(-2px);
}

/* ========================================
   Flashcard Navigation
======================================== */
.flashcard-nav {
    display: flex;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) 0;
    background: transparent;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn.primary {
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

.nav-btn.primary:hover:not(:disabled) {
    opacity: 0.9;
}

.nav-btn svg {
    width: 16px;
    height: 16px;
}

/* Keyboard hint in nav */
.nav-kbd {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0,0,0,0.1);
    margin-left: 4px;
    font-family: inherit;
    opacity: 0.6;
}

.nav-btn.primary .nav-kbd {
    background: rgba(0,0,0,0.15);
}

/* ========================================
   Session Summary
======================================== */
.flashcard-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-6);
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
    padding: var(--space-8) var(--space-4);
    text-align: center;
    animation: fc-fadeInUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.summary-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-subtle);
    animation: summaryPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes summaryPop {
    0% { transform: scale(0) rotate(-20deg); opacity: 0; }
    60% { transform: scale(1.15) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.summary-icon svg {
    width: 40px;
    height: 40px;
    stroke: var(--accent);
}

.summary-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.02em;
    animation: fc-fadeInUp 0.5s 0.15s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.summary-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: -8px 0 0 0;
    animation: fc-fadeInUp 0.5s 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Stats grid */
.summary-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-3);
    width: 100%;
    animation: fc-fadeInUp 0.5s 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.summary-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    background: var(--bg-hover);
    animation: fc-scaleIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.summary-stat:nth-child(1) { animation-delay: 0.35s; }
.summary-stat:nth-child(2) { animation-delay: 0.42s; }
.summary-stat:nth-child(3) { animation-delay: 0.49s; }
.summary-stat:nth-child(4) { animation-delay: 0.56s; }

.summary-stat:hover {
    transform: scale(1.04);
}

[data-theme="dark"] .summary-stat {
    background: rgba(255, 255, 255, 0.03);
}

.summary-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.summary-stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
}

.summary-stat.stat-easy .summary-stat-value { color: #22c55e; }
.summary-stat.stat-good .summary-stat-value { color: #3b82f6; }
.summary-stat.stat-hard .summary-stat-value { color: #f59e0b; }
.summary-stat.stat-again .summary-stat-value { color: #ef4444; }

/* Mastery ring */
.summary-mastery {
    position: relative;
    width: 120px;
    height: 120px;
    animation: fc-scaleIn 0.5s 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.summary-mastery svg {
    transform: rotate(-90deg);
}

.summary-mastery-bg {
    fill: none;
    stroke: var(--bg-hover);
    stroke-width: 8;
}

[data-theme="dark"] .summary-mastery-bg {
    stroke: rgba(255, 255, 255, 0.06);
}

.summary-mastery-fill {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 314;
    stroke-dashoffset: 314;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.summary-mastery-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.summary-mastery-pct {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.summary-mastery-label {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* Summary actions */
.summary-actions {
    display: flex;
    gap: var(--space-3);
    width: 100%;
    animation: fc-fadeInUp 0.5s 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.summary-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    transition: all 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.summary-btn:active {
    transform: scale(0.96) !important;
    transition-duration: 0.1s;
}

.summary-btn svg {
    width: 18px;
    height: 18px;
}

.summary-btn.primary {
    background: var(--accent);
    color: var(--accent-text);
}

.summary-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.summary-btn.secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
}

[data-theme="dark"] .summary-btn.secondary {
    background: rgba(255, 255, 255, 0.06);
}

.summary-btn.secondary:hover {
    background: var(--bg-active);
    transform: translateY(-1px);
}

/* Cards to review badge */
.summary-review-note {
    font-size: 13px;
    color: var(--text-tertiary);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.15);
    width: 100%;
}

.summary-review-note strong {
    color: #f59e0b;
}

/* ========================================
   Shuffle Toggle
======================================== */
.flashcard-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
}

.fc-toolbar-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    transition: var(--transition-fast);
}

.fc-toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.fc-toolbar-btn.active {
    color: var(--accent);
    background: var(--accent-subtle);
}

.fc-toolbar-btn svg {
    width: 14px;
    height: 14px;
}

/* ========================================
   Responsive
======================================== */
@media (max-width: 640px) {
    .flashcard-section {
        padding: var(--space-4);
    }

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

    .grade-btn {
        min-height: 52px;
    }

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

    .subject-btn {
        min-height: 80px;
    }

    .flashcard-setup {
        padding: var(--space-5);
        border-radius: var(--radius-lg);
    }

    .flashcard,
    .flashcard-inner,
    .flashcard-front,
    .flashcard-back {
        min-height: 280px;
        max-height: 50vh;
    }

    .flashcard-front,
    .flashcard-back {
        padding: var(--space-5);
    }

    .flashcard-question {
        font-size: 1rem;
    }

    .flashcard-answer {
        font-size: 0.8rem;
        line-height: 1.55;
    }

    .flashcard-rating {
        gap: var(--space-1);
    }

    .rating-btn {
        padding: var(--space-2) var(--space-3);
        min-width: 64px;
        font-size: 12px;
        min-height: 48px;
    }

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

    .summary-actions {
        flex-direction: column;
    }

    .summary-btn {
        min-height: 48px;
    }

    .flashcard-dots {
        gap: 4px;
    }

    .fc-dot {
        width: 6px;
        height: 6px;
    }

    .fc-dot.active {
        width: 18px;
    }

    .topic-input {
        font-size: 16px;
        padding: 16px var(--space-4);
    }

    .generate-btn {
        min-height: 52px;
    }

    .fc-count-btn {
        min-height: 44px;
        min-width: 48px;
    }

    .fc-file-drop {
        padding: var(--space-4);
    }

    .fc-url-input {
        font-size: 16px;
    }

    .setup-step h2 {
        font-size: 1.5rem;
    }

    .back-to-topics {
        min-height: 44px;
    }

    .setup-back-btn {
        min-height: 44px;
    }

    .nav-btn {
        min-height: 44px;
    }
}
