/* ═══════════════════════════════════════════════════════════════════
   PracticeFlashcard - Premium Dark Theme
   Inspired by Anki "406" note type styling
   ═══════════════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --bg-card: #1a1f2b;
    --bg-elevated: #21262d;
    --bg-hover: #262c36;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-yellow: #d29922;
    --accent-red: #f85149;
    --accent-purple: #a371f7;
    --accent-cyan: #56d4dd;

    --border-primary: #30363d;
    --border-subtle: #21262d;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px rgba(88,166,255,0.15);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --font-main: 'Vazirmatn', 'Inter', 'Segoe UI', sans-serif;
    --font-code: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

    --sidebar-width: 380px;
    --topbar-height: 56px;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ───────────────────────────────────────────────── */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100dvh;
    overflow-x: hidden;
    direction: rtl;
}

/* ─── Scrollbar ──────────────────────────────────────────────────── */

::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Buttons ────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: #fff;
    box-shadow: 0 2px 8px rgba(88,166,255,0.3);
}
.btn-primary:hover {
    box-shadow: 0 4px 16px rgba(88,166,255,0.4);
    filter: brightness(1.1);
}
.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: none;
    box-shadow: none;
}

.btn-outline {
    background: transparent;
    color: var(--accent-blue);
    border: 1px solid var(--border-primary);
}
.btn-outline:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
}

.btn-danger {
    background: rgba(248,81,73,0.12);
    color: var(--accent-red);
    border: 1px solid rgba(248,81,73,0.25);
}
.btn-danger:hover {
    background: rgba(248,81,73,0.2);
}

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-icon { font-size: 1.1em; }

/* ─── Sidebar ────────────────────────────────────────────────────── */

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-smooth);
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: min(var(--sidebar-width), 90vw);
    height: 100dvh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: right var(--transition-smooth);
    box-shadow: var(--shadow-lg);
}
.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.sidebar-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ─── Sidebar Tabs ───────────────────────────────────────────────── */

.sidebar-tabs {
    display: flex;
    padding: 8px 12px;
    gap: 4px;
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    padding: 8px 12px;
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.tab-btn.active {
    color: var(--accent-blue);
    background: rgba(88,166,255,0.1);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.tab-content.active {
    display: block;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.logout-btn {
    text-decoration: none;
    width: 100%;
    color: var(--text-muted);
}
.logout-btn:hover {
    color: var(--accent-red);
    border-color: rgba(248, 81, 73, 0.4);
}

.topbar-actions {
    margin-right: auto;
    margin-left: 0;
    display: flex;
    align-items: center;
}

.topbar-logout {
    text-decoration: none;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}
.topbar-logout:hover {
    background: var(--bg-hover);
    transform: scale(1.1);
}

/* ─── Deck Tree ──────────────────────────────────────────────────── */

.deck-tree {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.deck-node {
    border-radius: var(--radius-sm);
}

.deck-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
    min-height: 30px;
}
.deck-row:hover {
    background: var(--bg-hover);
}

.deck-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}
.deck-toggle.expanded {
    transform: rotate(90deg);
}
.deck-toggle.no-children {
    visibility: hidden;
}

.deck-checkbox {
    width: 15px;
    height: 15px;
    accent-color: var(--accent-blue);
    cursor: pointer;
    flex-shrink: 0;
}

.deck-name {
    flex: 1;
    min-width: 0;
    font-size: 0.82rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.deck-count {
    font-size: 0.68rem;
    font-family: var(--font-code);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 1px 5px;
    border-radius: 4px;
    flex-shrink: 0;
    line-height: 1.2;
}

.deck-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.deck-action-btn {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.deck-action-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}
.deck-action-btn.download:hover {
    color: var(--accent-green);
}
.deck-action-btn.delete:hover {
    color: var(--accent-red);
}
.deck-action-btn.importing {
    animation: spin 1s linear infinite;
    pointer-events: none;
}

.deck-children {
    margin-right: 10px;
    padding-right: 4px;
    border-right: 1px dashed rgba(255, 255, 255, 0.12);
    display: none;
}
.deck-children.expanded {
    display: block;
}

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

/* ─── Sidebar Footer ─────────────────────────────────────────────── */

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-primary);
    flex-shrink: 0;
}
.sidebar-footer .btn {
    width: 100%;
}

/* ─── Import Actions ─────────────────────────────────────────────── */

.import-actions {
    margin-bottom: 12px;
    display: flex;
    justify-content: center;
}

/* ─── Empty State ────────────────────────────────────────────────── */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
}
.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.6;
}
.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 4px;
}
.empty-hint {
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
}

/* ─── Top Bar ────────────────────────────────────────────────────── */

.top-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    height: var(--topbar-height);
    background: rgba(13,17,23,0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
}

.hamburger {
    width: 36px;
    height: 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
    flex-shrink: 0;
}
.hamburger:hover {
    background: var(--bg-hover);
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all var(--transition-fast);
}

/* ─── Timer ──────────────────────────────────────────────────────── */

.timer-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timer-display {
    font-family: var(--font-code);
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--accent-cyan);
    letter-spacing: 1px;
    min-width: 80px;
    text-align: center;
    direction: ltr;
}

.timer-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.timer-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--accent-cyan);
}

/* ─── Screens ────────────────────────────────────────────────────── */

.screen {
    min-height: calc(100dvh - var(--topbar-height));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.hidden {
    display: none !important;
}

/* ─── Welcome Screen ─────────────────────────────────────────────── */

.welcome-screen {
    text-align: center;
}

.welcome-content {
    animation: fadeInUp 0.6s ease;
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

.welcome-content h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.welcome-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 1rem;
}

/* ─── Study Screen ───────────────────────────────────────────────── */

.study-screen {
    justify-content: flex-start;
    padding-top: 20px;
    gap: 16px;
}

/* ─── Card Container ─────────────────────────────────────────────── */

.card-container {
    --card-font-size: 18px;
    width: 100%;
    max-width: 760px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
    box-shadow: var(--shadow-md);
    padding: 24px;
    position: relative;
    animation: cardIn 0.35s ease;
}

.card-container.card-exit {
    animation: cardOut 0.25s ease forwards;
}

/* ─── Card Top Meta: Deck, Badges, Progress & Font Controls (Single Row) ─ */

.card-top-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
}

.meta-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.deck-badge {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 3px 10px;
    border-radius: 12px;
    display: inline-block;
    direction: ltr;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badges-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.study-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: 12px;
    font-size: 0.76rem;
    font-weight: 700;
    animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.study-badge.badge-hard {
    background: rgba(210,153,34,0.18);
    color: var(--accent-yellow);
    border: 1px solid rgba(210,153,34,0.4);
}

.study-badge.badge-good {
    background: rgba(63,185,80,0.18);
    color: var(--accent-green);
    border: 1px solid rgba(63,185,80,0.4);
}

/* ─── Progress Section (In Card Top Meta) ────────────────────────── */

.progress-section {
    display: flex;
    align-items: center;
    gap: 6px;
}

.progress-text {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.prog-pill {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 0.74rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.prog-pill strong {
    color: var(--accent-blue);
    font-family: var(--font-code);
}

.prog-pill.prog-graduated strong {
    color: var(--accent-green);
}

.prog-pill.prog-remaining strong {
    color: var(--accent-yellow);
}

/* ─── Font Size & Top Action Controls ────────────────────────────── */

.card-top-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.top-action-btn.undo-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    height: 28px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.top-action-btn.undo-btn .btn-icon {
    font-size: 0.88rem;
    line-height: 1;
}

.top-action-btn.undo-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

.top-action-btn.undo-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.top-action-btn.undo-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.font-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 700;
    font-family: var(--font-code);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.font-btn:hover {
    background: var(--bg-hover);
    color: var(--accent-blue);
    border-color: var(--accent-blue);
}

.font-btn:active {
    transform: scale(0.92);
}

/* ─── Question (Note 406 Style with dynamic font size) ───────────── */

.question {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: var(--card-font-size, 18px);
    line-height: 1.8;
}

.question * {
    font-size: inherit;
}

/* ─── Toggle Button (Note 406 Style) ────────────────────────────── */

.toggle-button-wrapper {
    text-align: center;
    margin: 20px 0;
}

.toggle-btn {
    background-color: var(--accent-blue);
    color: white;
    border: none;
    padding: 12px 32px;
    font-size: 0.95em;
    font-family: var(--font-main);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    font-weight: 600;
}

.toggle-btn:hover {
    background-color: var(--accent-red);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toggle-btn:active {
    transform: translateY(0);
}

.toggle-btn.active {
    background-color: var(--accent-red);
}

/* ─── Answer Section (Note 406 Style with dynamic font size) ─────── */

.answer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px dashed var(--border-primary);
    animation: fadeIn 0.3s ease-in;
    font-size: var(--card-font-size, 18px);
    line-height: 1.8;
}

.answer-label {
    font-size: 0.75rem !important;
    text-transform: uppercase;
    color: var(--accent-blue);
    margin-bottom: 12px;
    letter-spacing: 1px;
    font-weight: bold;
    display: block;
}

.answer-content {
    font-size: inherit;
    line-height: 1.8;
    margin-bottom: 12px;
}

.answer-content * {
    font-size: inherit;
}

/* ─── Rating Buttons ─────────────────────────────────────────────── */

.rating-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.rating-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: var(--font-main);
    color: var(--text-primary);
}

.rating-btn:active {
    transform: scale(0.93);
}

.rating-icon {
    font-size: 1.3rem;
}

.rating-label {
    font-size: 0.82rem;
    font-weight: 600;
}

.rating-btn kbd {
    font-family: var(--font-code);
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-primary);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-primary);
}

.rating-hard:hover {
    background: rgba(210,153,34,0.12);
    border-color: var(--accent-yellow);
}
.rating-good:hover {
    background: rgba(63,185,80,0.12);
    border-color: var(--accent-green);
}
.rating-easy:hover {
    background: rgba(163,113,247,0.12);
    border-color: var(--accent-purple);
}

/* ─── Terminate & Undo ───────────────────────────────────────────── */

.terminate-row {
    margin-top: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn.undo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-primary);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.btn.undo-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

.btn.undo-btn:active:not(:disabled) {
    transform: scale(0.96);
}

.btn.undo-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* ─── Celebration Screen ─────────────────────────────────────────── */

.celebration-screen {
    position: relative;
    text-align: center;
}

.confetti-canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.celebration-content {
    position: relative;
    z-index: 1;
    animation: celebrationIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-icon {
    font-size: 5rem;
    margin-bottom: 12px;
    animation: celebrationBounce 1s ease infinite;
}

.celebration-content h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-yellow), var(--accent-green), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.celebration-subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 24px;
}

/* ─── Summary Stats ──────────────────────────────────────────────── */

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    max-width: 560px;
    margin: 0 auto 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 16px 12px;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 800;
    font-family: var(--font-code);
    margin-bottom: 4px;
    direction: ltr;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-time .stat-value { color: var(--accent-cyan); }
.stat-cycles .stat-value { color: var(--accent-blue); }
.stat-cards .stat-value { color: var(--accent-green); }
.stat-hards .stat-value { color: var(--accent-yellow); }
.stat-goods .stat-value { color: var(--accent-green); }
.stat-easy .stat-value { color: var(--accent-purple); }

/* ─── Loading Overlay ────────────────────────────────────────────── */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-primary);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ─── Toast ──────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
    pointer-events: auto;
    direction: rtl;
}

.toast-success {
    background: rgba(63,185,80,0.15);
    color: var(--accent-green);
    border: 1px solid rgba(63,185,80,0.3);
}

.toast-error {
    background: rgba(248,81,73,0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248,81,73,0.3);
}

.toast-info {
    background: rgba(88,166,255,0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(88,166,255,0.3);
}

/* ─── Card Inner Content Styling (from 406) ──────────────────────── */

.card-section pre {
    background: var(--bg-primary);
    padding: 14px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    direction: ltr;
    text-align: left;
    border: 1px solid var(--border-primary);
    margin: 10px 0;
}

.card-section code {
    font-family: var(--font-code);
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    color: var(--accent-red);
}

.card-section pre code {
    color: inherit;
    background: transparent;
    padding: 0;
}

.card-section ul, .card-section ol {
    margin: 10px 0;
    padding-right: 24px;
    padding-left: 0;
}

.card-section li {
    margin-bottom: 4px;
}

.card-section blockquote {
    margin: 12px 0;
    padding: 10px 16px;
    border-right: 4px solid var(--accent-blue);
    border-left: none;
    background: rgba(88,166,255,0.06);
    color: var(--text-secondary);
    font-style: italic;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.card-section table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
}

.card-section th,
.card-section td {
    border: 1px solid var(--border-primary);
    padding: 8px 12px;
    text-align: right;
}

.card-section th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.card-section strong, .card-section b {
    color: var(--accent-blue);
}

.card-section a {
    color: var(--accent-blue);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}
.card-section a:hover {
    color: var(--accent-purple);
}

.card-section img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    display: block;
    margin: 10px auto;
}

.card-section br + br {
    display: block;
    content: "";
    margin-top: 8px;
}

/* ─── Animations ─────────────────────────────────────────────────── */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes cardIn {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cardOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-12px) scale(0.98); }
}

@keyframes badgePop {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

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

@keyframes celebrationIn {
    0% { opacity: 0; transform: scale(0.6); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes celebrationBounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-8px) rotate(-5deg); }
    75% { transform: translateY(-4px) rotate(5deg); }
}

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

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

/* ─── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .card-container {
        padding: 16px;
        border-radius: var(--radius-md);
    }

    .card-top-meta {
        gap: 8px;
    }

    .deck-badge {
        max-width: 130px;
    }

    .progress-text {
        font-size: 0.72rem;
        gap: 4px;
    }

    .prog-pill {
        padding: 1px 6px;
        font-size: 0.7rem;
    }

    .rating-buttons {
        gap: 6px;
    }

    .rating-btn {
        padding: 12px 6px;
    }

    .rating-btn kbd {
        display: none;
    }

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

    .top-bar {
        padding: 8px 12px;
    }

    .timer-display {
        font-size: 0.95rem;
    }
}

@media (max-width: 380px) {
    .summary-stats {
        grid-template-columns: 1fr;
    }
}


/* ─── Login Screen (Cloud Auth) ───────────────────────────────────── */

.login-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-screen.hidden {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 20px;
    padding: 36px 28px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(16px);
    text-align: center;
    animation: fadeUp 0.4s ease;
}

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

.login-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, rgba(88, 166, 255, 0.16), rgba(163, 113, 247, 0.16));
    border: 1px solid rgba(88, 166, 255, 0.28);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.login-card h1 {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #fff, #93c5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-bottom: 24px;
}

.login-input-wrap {
    position: relative;
    margin-bottom: 16px;
}

.login-input {
    width: 100%;
    padding: 13px 16px 13px 44px;
    background: rgba(13, 17, 23, 0.85);
    border: 1px solid var(--border-primary);
    border-radius: 12px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
    direction: ltr;
    text-align: center;
    letter-spacing: 2px;
}

.login-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.login-eye-btn {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
}

.login-error {
    background: rgba(248, 81, 73, 0.12);
    border: 1px solid rgba(248, 81, 73, 0.35);
    color: #ff7b72;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* ─── Topbar Extra Buttons ───────────────────────────────────────── */

.topbar-nav-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-dash-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(88, 166, 255, 0.1);
    border: 1px solid rgba(88, 166, 255, 0.25);
    border-radius: var(--radius-md);
    color: var(--accent-blue);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.topbar-dash-btn:hover {
    background: rgba(88, 166, 255, 0.2);
    transform: translateY(-1px);
}

/* ─── Anki Import Progress ───────────────────────────────────────── */

.anki-import-progress {
    padding: 10px 12px;
    margin: 8px 12px;
    background: rgba(88, 166, 255, 0.08);
    border: 1px solid rgba(88, 166, 255, 0.25);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
}

.anki-progress-bar-bg {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 6px;
}

.anki-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
    width: 0%;
    transition: width 0.2s ease;
}

/* ─── Analytics Dashboard Screen ─────────────────────────────────── */

.dashboard-screen {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 16px 60px;
    animation: fadeUp 0.3s ease;
}

.dash-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}

.dash-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.dash-stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.dash-stat-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-blue);
}

.dash-stat-title {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.dash-stat-val {
    font-size: 1.6rem;
    font-weight: 800;
    font-family: var(--font-code);
    color: var(--text-primary);
}

.dash-stat-val.blue { color: var(--accent-blue); }
.dash-stat-val.green { color: var(--accent-green); }
.dash-stat-val.yellow { color: var(--accent-yellow); }
.dash-stat-val.purple { color: var(--accent-purple); }

.dash-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 20px;
}

.dash-panel-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

.ratio-bar-container {
    height: 18px;
    border-radius: 9px;
    background: var(--bg-tertiary);
    overflow: hidden;
    display: flex;
    margin-bottom: 14px;
}

.ratio-seg-hard { background: #d29922; transition: width 0.4s ease; }
.ratio-seg-good { background: #3fb950; transition: width 0.4s ease; }
.ratio-seg-easy { background: #a371f7; transition: width 0.4s ease; }

.ratio-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.85rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.hardest-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hardest-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
}

.hardest-text {
    flex: 1;
    min-width: 0;
}

.hardest-front {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hardest-deck {
    font-size: 0.76rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.hardest-counts {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.deck-progress-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.deck-prog-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.deck-prog-top {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
}

.deck-prog-bar-bg {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.deck-prog-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-blue));
    border-radius: 4px;
    transition: width 0.4s ease;
}
