/* ================================================================
   PROJECTCARDS DESIGN SYSTEM v2.0
   ================================================================ */

/* ----------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   ---------------------------------------------------------------- */
:root {
    /* Primary Brand */
    --brand-50: #eef5ff;
    --brand-100: #d9e8ff;
    --brand-200: #bcd6ff;
    --brand-300: #8ebeff;
    --brand-400: #599cff;
    --brand-500: #3b82f6;
    --brand-600: #2563eb;
    --brand-700: #1d4ed8;
    --brand-800: #1e40af;
    --brand-900: #1e3a8a;

    /* Neutral Scale (Warm Grays) */
    --gray-0: #ffffff;
    --gray-50: #fafaf9;
    --gray-100: #f5f5f4;
    --gray-200: #e7e5e4;
    --gray-300: #d6d3d1;
    --gray-400: #a8a29e;
    --gray-500: #78716c;
    --gray-600: #57534e;
    --gray-700: #44403c;
    --gray-800: #292524;
    --gray-900: #1c1917;
    --gray-950: #0c0a09;

    /* Semantic Colors */
    --success-50: #f0fdf4;
    --success-500: #22c55e;
    --success-600: #16a34a;
    --warning-50: #fffbeb;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --danger-50: #fef2f2;
    --danger-500: #ef4444;
    --danger-600: #dc2626;
    --info-50: #eff6ff;
    --info-500: #3b82f6;

    /* Surfaces (Light) */
    --surface-bg: var(--gray-50);
    --surface-elevated: var(--gray-0);
    --surface-sunken: var(--gray-100);
    --surface-hover: var(--gray-100);
    --surface-active: var(--brand-50);

    /* Text (Light) */
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-tertiary: var(--gray-500);
    --text-muted: var(--gray-400);
    --text-on-brand: #ffffff;
    --text-on-dark: #f5f5f4;

    /* Borders (Light) */
    --border-subtle: var(--gray-200);
    --border-default: var(--gray-300);
    --border-focus: var(--brand-500);

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 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.06), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.03);
    --shadow-glow: 0 0 0 3px rgba(59,130,246,0.15);

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'SF Mono', Monaco, Inconsolata, 'Fira Code', monospace;

    /* Sidebar */
    --sidebar-width: 240px;

    /* Transitions */
    --transition-fast: 120ms ease;
    --transition-base: 180ms ease;
    --transition-slow: 250ms ease;
}

/* ----------------------------------------------------------------
   Dark Mode Overrides
   ---------------------------------------------------------------- */
body.dark-mode {
    --surface-bg: #0a0a0f;
    --surface-elevated: #121214;
    --surface-sunken: #0c0c0e;
    --surface-hover: #1a1a1e;
    --surface-active: rgba(59,130,246,0.12);

    --text-primary: #f5f5f4;
    --text-secondary: #a8a29e;
    --text-tertiary: #78716c;
    --text-muted: #57534e;
    --text-on-brand: #f5f5f4;

    --border-subtle: rgba(255,255,255,0.06);
    --border-default: rgba(255,255,255,0.1);
    --border-focus: var(--brand-400);

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
    --shadow-xl: 0 20px 25px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 0 3px rgba(96,165,250,0.2);
}

/* ----------------------------------------------------------------
   2. Base & Reset
   ---------------------------------------------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--surface-bg);
    color: var(--text-primary);
    line-height: 1.55;
    font-size: 14px;
    overflow-x: hidden;
}

::selection {
    background: var(--brand-200);
    color: var(--brand-900);
}
body.dark-mode ::selection {
    background: var(--brand-800);
    color: var(--brand-100);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
body.dark-mode ::-webkit-scrollbar-thumb { background: #2a2a2e; }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: #3a3a3e; }

/* ----------------------------------------------------------------
   3. Layout (Sidebar + Main)
   ---------------------------------------------------------------- */
header {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface-elevated);
    border-right: 1px solid var(--border-subtle);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: width 0.45s cubic-bezier(0.32, 0.72, 0, 1);
}
.header-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px 14px;
}
.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
    padding: 0 6px;
    cursor: pointer;
    transition: color var(--transition-fast);
}
.logo:hover { color: var(--brand-500); }
.logo img {
    width: 28px;
    height: 28px;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
nav button {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    min-height: 44px;
    padding: 9px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-md);
    text-align: left;
    transition: all var(--transition-fast);
    position: relative;
}
nav button img { width: 18px; height: 18px; opacity: 0.7; transition: opacity var(--transition-fast); }
nav button:hover { background: var(--surface-hover); color: var(--text-primary); }
nav button:hover img { opacity: 1; }
nav button.active {
    background: var(--surface-active);
    color: var(--brand-600);
    font-weight: 600;
}
body.dark-mode nav button.active { color: var(--brand-400); }
nav button.active::before {
    content: '';
    position: absolute;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--brand-500);
    border-radius: 0 3px 3px 0;
}
nav button.active img { opacity: 1; filter: none; }

/* Label transition for smooth collapse */
.nav-label {
    display: inline-block;
    max-width: 200px;
    opacity: 1;
    transform: scale(1);
    transition: opacity 0.18s ease, max-width 0.35s ease, transform 0.25s ease, margin 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    vertical-align: middle;
}

/* Collapsed sidebar */
body.sidebar-collapsed header { width: 64px; }
body.sidebar-collapsed main { margin-left: 64px; }
body.sidebar-collapsed .header-inner { padding: 20px 10px; align-items: center; }
body.sidebar-collapsed .logo { gap: 0; padding: 0; margin-bottom: 16px; }
body.sidebar-collapsed .logo img { width: 32px; height: 32px; }
body.sidebar-collapsed .nav-label { opacity: 0; max-width: 0; transform: scale(0.85); pointer-events: none; }
body.sidebar-collapsed nav button { justify-content: center; padding: 10px; gap: 0; }
body.sidebar-collapsed nav button img { width: 20px; height: 20px; }
body.sidebar-collapsed nav button::before { left: -10px; }
body.sidebar-collapsed .sidebar-footer { align-items: center; }
body.sidebar-collapsed .sidebar-footer button { justify-content: center; padding: 10px; gap: 0; }
body.sidebar-collapsed .sidebar-footer button img { width: 18px; height: 18px; }
body.sidebar-collapsed .theme-toggle { justify-content: center; padding: 10px; gap: 0; }
body.sidebar-collapsed .theme-toggle img { width: 18px; height: 18px; }
body.sidebar-collapsed .sidebar-collapse-btn { justify-content: center; padding: 10px; gap: 0; }
body.sidebar-collapsed nav button[data-tooltip]::after,
body.sidebar-collapsed .sidebar-footer button[data-tooltip]::after {
    bottom: auto;
    top: 50%;
    left: calc(100% + 8px);
    transform: translateY(-50%) scale(0.95);
}
body.sidebar-collapsed nav button[data-tooltip]:hover::after,
body.sidebar-collapsed nav button[data-tooltip]:focus-visible::after,
body.sidebar-collapsed .sidebar-footer button[data-tooltip]:hover::after,
body.sidebar-collapsed .sidebar-footer button[data-tooltip]:focus-visible::after {
    transform: translateY(-50%) scale(1);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-footer button {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-md);
    text-align: left;
    transition: all var(--transition-fast);
}
.sidebar-footer button:hover { background: var(--surface-hover); color: var(--text-primary); }
.sidebar-footer button img { width: 16px; height: 16px; opacity: 0.6; }

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-md);
    text-align: left;
    transition: all var(--transition-fast);
    margin-top: 4px;
}
.sidebar-collapse-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.sidebar-collapse-btn .expand-icon { display: none; }
body.sidebar-collapsed .sidebar-collapse-btn .collapse-icon { display: none; }
body.sidebar-collapsed .sidebar-collapse-btn .expand-icon { display: inline-block; }

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-tertiary);
    cursor: pointer;
    border-radius: var(--radius-md);
    text-align: left;
    transition: all var(--transition-fast);
}
.theme-toggle:hover { background: var(--surface-hover); color: var(--text-primary); }
.theme-toggle img { width: 16px; height: 16px; opacity: 0.6; }

#user-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    margin-bottom: 4px;
}
#user-email {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}

main {
    margin-left: var(--sidebar-width);
    max-width: none;
    padding: 28px 36px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.45s cubic-bezier(0.32, 0.72, 0, 1);
}
main.create-active {
    padding: 0;
}

.page-header {
    margin-bottom: 24px;
}
.page-header h1, .page-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header h1 img, .page-header h2 img { width: 24px; height: 24px; }
.page-header p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 6px 0 0;
}

.tab { display: none; animation: fadeIn 0.2s ease; }
.tab.active { display: block; flex: 1; }
#tab-library.active, #tab-study.active { display: flex; flex-direction: column; }
#study-area { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#study-area .iframe-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
#study-area .viewer-frame {
    flex: 1;
    min-height: 0;
    height: 100%;
    max-height: none;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ----------------------------------------------------------------
   4. Typography
   ---------------------------------------------------------------- */
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.25; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.3; }
h3 { font-size: 16px; font-weight: 600; line-height: 1.35; }
h4 { font-size: 14px; font-weight: 600; line-height: 1.4; }
p { color: var(--text-secondary); }

/* ----------------------------------------------------------------
   5. Components
   ---------------------------------------------------------------- */

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-elevated);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-xs);
    white-space: nowrap;
}
.btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-default);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 11px 24px; font-size: 15px; border-radius: var(--radius-lg); font-weight: 600; }

.btn-primary {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: var(--text-on-brand);
    box-shadow: 0 1px 2px rgba(37,99,235,0.2);
}
.btn-primary:hover {
    background: var(--brand-700);
    border-color: var(--brand-700);
    box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}
.btn-danger {
    background: var(--danger-50);
    border-color: var(--danger-200);
    color: var(--danger-600);
}
body.dark-mode .btn-danger { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.2); }
.btn-danger:hover {
    background: var(--danger-100);
    border-color: var(--danger-300);
    box-shadow: 0 2px 8px rgba(220,38,38,0.15);
}
.btn-ghost {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-subtle); }

.icon-btn { gap: 6px; }
.icon-btn img { width: 16px; height: 16px; }
.icon-only {
    padding: 14px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
    min-width: 44px;
    min-height: 44px;
}
.icon-only:hover { background: var(--surface-hover); color: var(--text-primary); }
.icon-only img { width: 16px; height: 16px; }

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
    padding: 9px 13px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface-elevated);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
    width: 100%;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}
textarea { resize: vertical; min-height: 80px; }
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
body.dark-mode select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); }

/* Cards */
.card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: transform var(--transition-base), box-shadow var(--transition-base), border-color var(--transition-base);
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}
.card-flat {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    color: var(--text-secondary);
}
.badge-new { background: var(--info-50); color: var(--info-500); }
.badge-learning { background: var(--warning-50); color: var(--warning-600); }
.badge-review { background: var(--success-50); color: var(--success-600); }
.badge-due { background: var(--brand-50); color: var(--brand-600); }
body.dark-mode .badge-due { background: rgba(59,130,246,0.15); color: var(--brand-400); }
.badge-relearning { background: var(--danger-50); color: var(--danger-600); }

/* Progress Bars */
.progress-track {
    height: 8px;
    background: var(--surface-sunken);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--brand-500);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-fill.green { background: var(--success-500); }
.progress-fill.yellow { background: var(--warning-500); }
.progress-fill.red { background: var(--danger-500); }

/* Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 80px 24px;
    color: var(--text-secondary);
}
.empty-state-icon {
    width: 88px;
    height: 88px;
    margin-bottom: 24px;
    opacity: 0.5;
    filter: grayscale(0.2);
}
.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}
.empty-state p {
    font-size: 14px;
    color: var(--text-tertiary);
    max-width: 320px;
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Toasts */
.toast {
    position: fixed;
    bottom: 28px;
    right: 28px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-subtle);
    opacity: 0;
    transform: translateY(16px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}
.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.toast-success { border-left: 3px solid var(--success-500); }
.toast-error { border-left: 3px solid var(--danger-500); }
.toast-info { border-left: 3px solid var(--info-500); }

/* ----------------------------------------------------------------
   6. Page: Library (Decks)
   ---------------------------------------------------------------- */
.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
    overflow: visible;
}
.deck-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    position: relative;
    overflow: visible;
}
.deck-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
    opacity: 0.8;
    transition: height var(--transition-base);
}
.deck-card:hover::before { height: 5px; }
.deck-card h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.deck-card p {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}
.deck-card .deck-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
}
.deck-card .actions {
    margin-top: 14px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transform: translateY(4px);
    transition: all var(--transition-fast);
    overflow: visible;
}
.deck-card:hover .actions { opacity: 1; transform: translateY(0); }
.sub-deck-list {
    margin: 8px 0 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sub-deck-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: var(--radius-md);
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--surface-base);
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.sub-deck-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.sub-deck-item .icon { width: 14px; height: 14px; opacity: 0.7; }
.sub-deck-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--surface-elevated);
    padding: 1px 6px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
}

.new-deck-form {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
    max-width: 640px;
}
.new-deck-form input { flex: 1; }
.new-deck-form select { width: auto; min-width: 140px; }

.deck-tree {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.deck-tree:has(.deck-grid) {
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
    padding: 0;
}
.deck-tree-item {
    display: flex;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.deck-tree-item:last-child { border-bottom: none; }
.deck-tree-item:hover { background: var(--surface-hover); }
.deck-tree-item .indent { display: inline-block; width: 20px; flex-shrink: 0; }
.deck-tree-item .toggle {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: var(--text-muted);
    flex-shrink: 0; cursor: pointer;
    margin-right: 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}
.deck-tree-item .toggle:hover { background: var(--surface-sunken); color: var(--text-primary); }
.deck-tree-item .deck-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.deck-tree-item .deck-count {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-right: 14px;
}
.deck-tree-item .deck-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.deck-tree-item:hover .deck-actions { opacity: 1; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--brand-600);
    cursor: pointer;
    margin-bottom: 16px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}
.back-link:hover { background: var(--surface-hover); text-decoration: none; }
body.dark-mode .back-link { color: var(--brand-400); }

/* ----------------------------------------------------------------
   7. Page: Create (Build)
   ---------------------------------------------------------------- */
.build-layout {
    display: flex;
    gap: 0;
    height: calc(100vh);
    min-height: 500px;
}
.template-sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--surface-elevated);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    gap: 8px;
}
.sidebar-header-actions { display: flex; gap: 4px; }
.sidebar-header-actions.hidden { display: none; }
#bulk-mode-toggle { width: 28px; height: 28px; object-fit: contain; cursor: pointer; }
.sidebar-bulk-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-sunken);
}
.sidebar-bulk-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.template-list-item .t-toggle.hidden { display: none; }
.template-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.template-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--surface-sunken);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    user-select: none;
    margin-bottom: 3px;
}
.template-list-item:hover { background: var(--surface-hover); color: var(--text-primary); border-color: var(--border-subtle); }
.template-list-item.active {
    background: var(--surface-active);
    color: var(--brand-600);
    font-weight: 600;
}
body.dark-mode .template-list-item.active { color: var(--brand-400); }
.template-list-item .t-toggle { cursor: pointer; flex-shrink: 0; width: 28px; height: 28px; object-fit: contain; }
.template-list-item .t-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-list-item .t-create {
    font-size: 11px;
    color: var(--brand-600);
    opacity: 0;
    transition: opacity var(--transition-fast);
    cursor: pointer;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    background: var(--brand-50);
    border: 1px solid var(--brand-200);
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
body.dark-mode .template-list-item .t-create {
    background: var(--brand-900);
    border-color: var(--brand-700);
    color: var(--brand-300);
}
.template-list-item:hover .t-create { opacity: 1; }
.template-list-item .t-create:hover {
    background: var(--brand-100);
}
body.dark-mode .template-list-item .t-create:hover {
    background: var(--brand-800);
}
.template-list-item .t-delete {
    font-size: 11px;
    color: var(--danger-500);
    opacity: 0;
    transition: opacity var(--transition-fast);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}
.template-list-item:hover .t-delete { opacity: 1; }
.template-list-item .t-delete:hover { background: var(--danger-50); }
.sidebar-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-top: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--text-tertiary);
    background: var(--surface-elevated);
}
.build-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-bg);
}
.build-content > .empty-state { flex: 1; }

#single-builder-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}
#single-builder-view .builder-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}
#single-builder-view .builder-header span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}
#builder-iframe {
    flex: 1;
    min-height: 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
}
#bulk-creator-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}

/* Bulk Creator v2 */
.bulk-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 20px;
}
.bulk-header { flex-shrink: 0; }
.bulk-header h3 { font-size: 18px; font-weight: 700; color: var(--text-primary); margin: 0 0 10px; letter-spacing: -0.01em; }
.bulk-template-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bulk-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--brand-50);
    border: 1px solid var(--brand-200);
    color: var(--brand-700);
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
}
body.dark-mode .bulk-chip {
    background: var(--brand-900);
    border-color: var(--brand-700);
    color: var(--brand-300);
}
.bulk-chip .chip-icon { width: 14px; height: 14px; opacity: 0.7; }

/* Prompt Card */
.bulk-prompt-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}
.bulk-prompt-card > label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.bulk-prompt-card textarea {
    width: 100%;
    min-height: 110px;
    padding: 14px 16px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 14px;
    resize: vertical;
    box-sizing: border-box;
    background: var(--surface-sunken);
    color: var(--text-primary);
    line-height: 1.5;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.bulk-prompt-card textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}
body.dark-mode .bulk-prompt-card textarea:focus {
    box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.bulk-examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.bulk-examples > span {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 4px;
}
.bulk-example-chip {
    padding: 4px 10px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--surface-sunken);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.bulk-example-chip:hover {
    background: var(--brand-50);
    border-color: var(--brand-300);
    color: var(--brand-700);
}
body.dark-mode .bulk-example-chip:hover {
    background: var(--brand-900);
    border-color: var(--brand-700);
    color: var(--brand-300);
}

/* Upload Zones */
.bulk-upload-zones {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
@media (max-width: 700px) {
    .bulk-upload-zones { grid-template-columns: 1fr; }
}
.bulk-upload-zone {
    border: 2px dashed var(--border-default);
    border-radius: var(--radius-lg);
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--surface-elevated);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 100px;
    justify-content: center;
}
.bulk-upload-zone:hover {
    border-color: var(--brand-400);
    background: var(--brand-50);
}
body.dark-mode .bulk-upload-zone:hover {
    background: rgba(59,130,246,0.08);
}
.bulk-upload-zone img { opacity: 0.5; }
.bulk-upload-zone span {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.bulk-upload-zone small {
    font-size: 11px;
    color: var(--text-muted);
}
.bulk-upload-zone .image-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 5px;
    margin-top: 8px;
    width: 100%;
}
.bulk-upload-zone .image-preview-grid img {
    width: 100%;
    height: 48px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}
.bulk-upload-zone .file-list {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    width: 100%;
    text-align: left;
}
.bulk-upload-zone .audio-preview {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 6px;
    width: 100%;
    text-align: left;
}

/* Settings Bar */
.bulk-settings-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
}
.bulk-pill-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.bulk-pill-group > label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.bulk-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bulk-pill {
    padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    background: var(--surface-elevated);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: 500;
}
.bulk-pill:hover {
    border-color: var(--border-default);
    color: var(--text-primary);
}
.bulk-pill.active {
    background: var(--brand-500);
    border-color: var(--brand-500);
    color: #fff;
    font-weight: 600;
}

/* Advanced collapsible sections */
.bulk-advanced {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
    flex-shrink: 0;
}
.bulk-advanced summary {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    list-style: none;
}
.bulk-advanced summary::-webkit-details-marker { display: none; }
.bulk-advanced summary::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid var(--text-muted);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform 0.15s ease;
    margin-right: 2px;
}
.bulk-advanced[open] summary::before {
    transform: rotate(90deg);
}
.bulk-advanced > div {
    padding: 0 14px 14px;
}

/* Actions */
.bulk-actions { flex-shrink: 0; }

/* Progress */
.bulk-progress { flex-shrink: 0; }
.bulk-stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.bulk-step {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    transition: all var(--transition-fast);
}
.bulk-step.active {
    background: var(--brand-50);
    border-color: var(--brand-300);
    color: var(--brand-700);
}
body.dark-mode .bulk-step.active {
    background: var(--brand-900);
    border-color: var(--brand-700);
    color: var(--brand-300);
}
.bulk-step .step-icon { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; }
.bulk-step .step-icon img { width: 14px; height: 14px; }
.progress-message {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-top: 8px;
    text-align: center;
}
.progress-bar-wrap {
    height: 6px;
    background: var(--surface-sunken);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
    transition: width 0.4s ease;
}

/* Results */
.bulk-results {
    flex-shrink: 0;
    border-top: 1px solid var(--border-subtle);
    padding-top: 16px;
}
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.results-header span { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.results-actions { display: flex; gap: 8px; }
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
    max-height: 420px;
    overflow-y: auto;
}
.result-card-v2 {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all var(--transition-fast);
    position: relative;
}
.result-card-v2:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-sm);
}
.result-card-v2 .rc-check {
    position: absolute;
    top: 10px;
    right: 10px;
}
.result-card-v2 .rc-check input {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-600);
    cursor: pointer;
}
.result-card-v2 .rc-template {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
body.dark-mode .result-card-v2 .rc-template { color: var(--brand-400); }
.result-card-v2 .rc-preview {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.result-card-v2 .rc-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
}
.results-save-bar { display: flex; gap: 10px; justify-content: flex-end; }

/* ----------------------------------------------------------------
   8. Page: Study
   ---------------------------------------------------------------- */
.study-launcher {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: 24px 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.study-launcher-header { margin-bottom: 20px; }
.study-launcher-title { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.study-launcher-subtitle { font-size: 14px; color: var(--text-tertiary); margin-top: 4px; }
.study-launcher-due {
    font-size: 15px;
    font-weight: 700;
    color: var(--brand-600);
    margin-top: 10px;
    min-height: 22px;
}
body.dark-mode .study-launcher-due { color: var(--brand-400); }
.study-launcher-due.empty { color: var(--text-tertiary); font-weight: 500; }
.study-launcher-body { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.study-launcher-stats {
    display: flex;
    gap: 20px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border-subtle);
}
.study-stat { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); }
.study-stat-dot { width: 10px; height: 10px; border-radius: 50%; }

.study-control-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 12px 18px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}
.study-control-bar .deck-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.study-control-bar .progress { font-size: 14px; color: var(--text-tertiary); margin-left: auto; }

/* ----------------------------------------------------------------
   9. Page: Stats
   ---------------------------------------------------------------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--brand-500), var(--brand-400));
    opacity: 0.6;
}
.stat-value {
    font-size: 36px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    letter-spacing: -1px;
}
.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.stat-bar-wrap {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}
.stat-bar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}
.stat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 14px;
}
.stat-row:last-child { margin-bottom: 0; }
.stat-row-name { width: 90px; color: var(--text-secondary); flex-shrink: 0; font-weight: 500; }
.stat-row-bar { flex: 1; height: 10px; background: var(--surface-sunken); border-radius: var(--radius-full); overflow: hidden; }
.stat-row-fill { height: 100%; border-radius: var(--radius-full); transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.stat-row-count { width: 48px; text-align: right; color: var(--text-tertiary); flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------
   10. Page: Settings
   ---------------------------------------------------------------- */
.settings-wrap { max-width: 720px; }
.settings-section {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    padding: 22px;
}
.settings-section h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-section h3 img { width: 18px; height: 18px; }
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    border-top: 1px solid var(--border-subtle);
}
.setting-row:first-of-type { border-top: none; }
.setting-row span { font-size: 14px; color: var(--text-primary); font-weight: 500; }
.setting-row .setting-desc {
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
    margin-top: 2px;
}
.setting-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--brand-600);
}
.setting-row input[type="range"] {
    flex: 1;
    max-width: 200px;
    accent-color: var(--brand-600);
}

.storage-bar-wrap { margin-top: 10px; }
.storage-bar { height: 10px; background: var(--surface-sunken); border-radius: var(--radius-full); overflow: hidden; }
.storage-bar-fill { height: 100%; border-radius: var(--radius-full); background: var(--brand-500); }
.storage-bar-fill.green { background: var(--success-500); }
.storage-bar-fill.yellow { background: var(--warning-500); }
.storage-bar-fill.red { background: var(--danger-500); }

.limit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.limit-card {
    background: var(--surface-sunken);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border: 1px solid var(--border-subtle);
}
.limit-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.limit-card-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.limit-card-value { font-size: 13px; font-weight: 700; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.limit-card .limit-bar { width: 100%; height: 6px; }
.limit-bar { height: 6px; background: var(--surface-sunken); border-radius: var(--radius-full); overflow: hidden; }
.limit-bar-fill { height: 100%; border-radius: var(--radius-full); background: var(--brand-500); }
.limit-bar-fill.yellow { background: var(--warning-500); }
.limit-bar-fill.red { background: var(--danger-500); }

/* ----------------------------------------------------------------
   11. Tables & Lists
   ---------------------------------------------------------------- */
.card-table {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    box-shadow: var(--shadow-xs);
}
.card-table-header, .card-table-row {
    display: grid;
    grid-template-columns: 28px 44px minmax(0, 1fr) 78px 56px 40px 50px 50px 56px 68px 44px 110px;
    gap: 8px;
    padding: 11px 14px;
    align-items: center;
}
.card-table-row.inactive { opacity: 0.45; }
.card-table-row .num-col {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.card-table-header {
    background: var(--surface-sunken);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border-subtle);
}
.card-table-row {
    font-size: 13px;
    border-top: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}
.card-table-row:first-child { border-top: none; }
.card-table-row:hover { background: var(--surface-hover); }
.card-table-row .front {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    color: var(--text-primary);
    min-width: 0;
    line-height: 1.45;
    font-weight: 500;
}
.card-table-row .template-tag { font-size: 12px; color: var(--text-tertiary); }
.delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.delete-btn:hover { color: var(--danger-500); background: var(--danger-50); }

.card-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.card-actions button {
    background: none;
    border: none;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 5px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}
.card-actions button:hover { color: var(--text-primary); background: var(--surface-hover); }
.card-actions .act-delete:hover { color: var(--danger-500); background: var(--danger-50); }

.bulk-bar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 14px;
    font-size: 13px;
}
.bulk-bar.active { display: flex; }
.bulk-bar span { color: var(--text-primary); font-weight: 600; }

.sort-bar { margin-bottom: 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sort-bar label { font-size: 12px; color: var(--text-tertiary); margin-right: 4px; font-weight: 500; }

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-bar input[type="text"] { flex: 1; min-width: 180px; }
.filter-bar select { font-size: 13px; padding: 7px 10px; width: auto; }
.filter-bar label { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; cursor: pointer; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; }
.pagination button { padding: 6px 14px; font-size: 13px; }
.pagination span { font-size: 13px; color: var(--text-secondary); }

/* ----------------------------------------------------------------
   12. Modals & Overlays
   ---------------------------------------------------------------- */
.preview-overlay, .edit-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    backdrop-filter: blur(0px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, background 0.2s ease, backdrop-filter 0.2s ease;
}
.preview-overlay.active, .edit-overlay.active {
    opacity: 1;
    pointer-events: auto;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.preview-box, .modal-box {
    transform: scale(0.94) translateY(12px);
    opacity: 0;
    transition: transform 0.25s var(--ease-spring), opacity 0.2s ease;
}
.preview-overlay.active .preview-box,
.preview-overlay.active .modal-box,
.edit-overlay.active .preview-box,
.edit-overlay.active .modal-box {
    transform: scale(1) translateY(0);
    opacity: 1;
}
.preview-box {
    background: var(--surface-elevated);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 760px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-subtle);
}
.preview-header, .edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--surface-sunken);
}
.preview-title, .edit-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.preview-close, .edit-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}
.preview-close:hover, .edit-close:hover { color: var(--danger-500); background: var(--danger-50); }
.preview-body, .edit-body {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: var(--surface-bg);
}
.preview-body iframe, .edit-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-md);
    background: var(--surface-elevated);
}
.preview-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-fast);
}
.preview-nav:hover { background: var(--surface-hover); color: var(--text-primary); transform: translateY(-50%) scale(1.05); }
.preview-nav.prev { left: 10px; }
.preview-nav.next { right: 10px; }
.preview-nav:disabled { opacity: 0.3; cursor: not-allowed; transform: translateY(-50%) scale(1); }
.preview-footer, .edit-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border-subtle);
    background: var(--surface-sunken);
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
}

.edit-box {
    background: var(--surface-elevated);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-subtle);
}
.edit-field { margin-bottom: 18px; }
.edit-field label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}
.edit-field input[type="text"],
.edit-field textarea,
.edit-field select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface-elevated);
    color: var(--text-primary);
}
.edit-field textarea { resize: vertical; min-height: 70px; }
.edit-field input:focus,
.edit-field textarea:focus,
.edit-field select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}
.edit-field .hint {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 6px;
}
.edit-group {
    background: var(--surface-sunken);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 18px;
}
.edit-group-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.edit-check {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-primary);
}
.edit-check input { cursor: pointer; width: 16px; height: 16px; accent-color: var(--brand-600); }
.edit-check:last-child { margin-bottom: 0; }

.modal-box {
    background: var(--surface-elevated);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-subtle);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border-subtle); background: var(--surface-sunken); }
.modal-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; padding: 4px; border-radius: var(--radius-sm); transition: all var(--transition-fast); }
.modal-close:hover { color: var(--danger-500); background: var(--danger-50); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border-subtle); background: var(--surface-sunken); }
.modal-input { width: 100%; padding: 10px 14px; border: 1px solid var(--border-default); border-radius: var(--radius-md); font-size: 14px; color: var(--text-primary); background: var(--surface-elevated); box-sizing: border-box; transition: border-color var(--transition-fast), box-shadow var(--transition-fast); }
.modal-input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-glow); }
.modal-confirm-text { font-size: 13px; color: var(--text-secondary); margin-top: 10px; }
.modal-confirm-input { margin-top: 8px; }
.deck-picker-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.deck-picker-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    border: 1px solid transparent;
    font-weight: 500;
    transition: all var(--transition-fast);
}
.deck-picker-row:hover { background: var(--surface-hover); border-color: var(--border-subtle); }
.deck-picker-row input[type="radio"] { cursor: pointer; }

/* Dropdown menus */
.deck-menu, .card-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 170px;
    z-index: 100;
    padding: 6px 0;
    display: none;
}
.deck-menu.portaled, .card-menu.portaled {
    position: fixed;
    z-index: 9999;
}
.deck-menu.active, .card-menu.active { display: block; animation: menuIn 0.15s ease; }
@keyframes menuIn {
    from { opacity: 0; transform: scale(0.96) translateY(-4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
.deck-menu button, .card-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 9px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}
.deck-menu button:hover, .card-menu button:hover { background: var(--surface-hover); }
.deck-menu button.danger, .card-menu button.danger { color: var(--danger-500); }
.deck-menu button.danger:hover, .card-menu button.danger:hover { background: var(--danger-50); }
.deck-menu-wrap { position: relative; overflow: visible; }
.card-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.card-menu-btn:hover { color: var(--text-primary); background: var(--surface-hover); }

.deck-select-wrap { position: relative; }
.deck-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    padding: 8px 0;
}
.deck-dropdown-actions {
    display: flex;
    gap: 8px;
    padding: 0 14px 10px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 6px;
}
.deck-dropdown label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    font-weight: 500;
    transition: background var(--transition-fast);
}
.deck-dropdown .deck-nested {
    padding-left: 28px;
}
.deck-dropdown label:hover { background: var(--surface-hover); }
.deck-dropdown input[type="checkbox"] { cursor: pointer; accent-color: var(--brand-600); }

/* ----------------------------------------------------------------
   13. Auth Screen
   ---------------------------------------------------------------- */
#auth-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--surface-bg);
    display: none;
    align-items: center;
    justify-content: center;
}
.auth-box {
    background: var(--surface-elevated);
    padding: 44px 40px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-subtle);
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow-xl);
}
.auth-logo {
    font-size: 22px;
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.auth-logo img { width: 32px; height: 32px; }
.auth-subtitle { font-size: 14px; color: var(--text-tertiary); text-align: center; margin-bottom: 32px; }
.auth-input {
    width: 100%;
    padding: 11px 14px;
    margin-bottom: 14px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    box-sizing: border-box;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.auth-input:focus { border-color: var(--brand-500); box-shadow: var(--shadow-glow); }
.auth-btn {
    width: 100%;
    padding: 12px;
    background: var(--brand-600);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 1px 3px rgba(37,99,235,0.2);
}
.auth-btn:hover { background: var(--brand-700); box-shadow: 0 4px 12px rgba(37,99,235,0.25); transform: translateY(-1px); }
.auth-btn:active { transform: translateY(0) scale(0.98); }
.auth-link { color: var(--brand-600); text-decoration: none; font-size: 13px; font-weight: 500; }
.auth-link:hover { text-decoration: underline; }
body.dark-mode .auth-link { color: var(--brand-400); }

/* Password toggle */
.password-wrap { position: relative; }
.password-toggle { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 13px; color: var(--text-muted); padding: 0; font-weight: 500; transition: color var(--transition-fast); }
.password-toggle:hover { color: var(--text-primary); }

/* ----------------------------------------------------------------
   14. Docs
   ---------------------------------------------------------------- */
.docs {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-xs);
}
.docs h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 28px 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-subtle);
}
.docs h2:first-child { margin-top: 0; }
.docs h3 { font-size: 15px; font-weight: 700; color: var(--text-primary); margin: 18px 0 10px; }
.docs p { font-size: 14px; color: var(--text-secondary); margin-bottom: 12px; line-height: 1.65; }
.docs ul { font-size: 14px; color: var(--text-secondary); margin: 10px 0 14px 24px; line-height: 1.65; }
.docs li { margin-bottom: 6px; }
.docs code {
    background: var(--surface-sunken);
    padding: 3px 7px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--danger-500);
    border: 1px solid var(--border-subtle);
}
.docs pre {
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    overflow-x: auto;
    margin: 12px 0 18px;
}
.docs pre code { background: none; padding: 0; color: var(--text-primary); font-size: 13px; border: none; }
.docs .note {
    background: var(--info-50);
    border-left: 3px solid var(--info-500);
    padding: 12px 16px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-size: 13px;
    color: var(--brand-700);
    margin: 12px 0;
}
.docs .warning {
    background: var(--warning-50);
    border-left: 3px solid var(--warning-500);
    padding: 12px 16px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-size: 13px;
    color: var(--warning-600);
    margin: 12px 0;
}

/* ----------------------------------------------------------------
   15. Tour / Onboarding
   ---------------------------------------------------------------- */
.tour-overlay { position: fixed; inset: 0; z-index: 5000; background: rgba(0,0,0,0.35); display: none; }
.tour-overlay.active { display: block; }
.tour-tooltip {
    position: absolute;
    background: var(--surface-elevated);
    border-radius: var(--radius-lg);
    padding: 18px;
    max-width: 300px;
    box-shadow: var(--shadow-xl);
    z-index: 5001;
    border: 1px solid var(--border-subtle);
}
.tour-tooltip::after { content: ''; position: absolute; width: 0; height: 0; }
.tour-tooltip.arrow-bottom::after { top: 100%; left: 24px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid var(--surface-elevated); }
.tour-tooltip.arrow-top::after { bottom: 100%; left: 24px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid var(--surface-elevated); }
.tour-title { font-size: 15px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.tour-body { font-size: 14px; color: var(--text-secondary); margin-bottom: 14px; line-height: 1.55; }
.tour-actions { display: flex; justify-content: space-between; align-items: center; }
.tour-actions button { font-size: 13px; padding: 7px 14px; }

/* ----------------------------------------------------------------
   16. Skeleton Loaders
   ---------------------------------------------------------------- */
.skeleton {
    background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--surface-hover) 50%, var(--surface-sunken) 75%);
    background-size: 200% 100%;
    border-radius: var(--radius-sm);
    animation: skeleton-shimmer 1.6s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-text { height: 14px; margin-bottom: 10px; width: 100%; }
.skeleton-text.short { width: 60%; }
.skeleton-circle { width: 40px; height: 40px; border-radius: 50%; }
@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; background: var(--surface-sunken); opacity: 0.7; }
}

/* ----------------------------------------------------------------
   17. Icons & Utilities
   ---------------------------------------------------------------- */
.icon { width: 16px; height: 16px; vertical-align: middle; display: inline-block; object-fit: contain; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 32px; height: 32px; }
.empty-icon { margin-bottom: 16px; opacity: 0.4; filter: grayscale(0.2); }

.chevron-down {
    display: inline-block;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    margin-left: 6px;
    vertical-align: middle;
    opacity: 0.5;
}
.back-arrow {
    display: inline-block;
    width: 6px; height: 6px;
    border-left: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    margin-right: 6px;
    vertical-align: middle;
    opacity: 0.5;
}
.tree-toggle {
    display: inline-block;
    width: 0; height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid currentColor;
    margin-right: 6px;
    vertical-align: middle;
    opacity: 0.5;
    transition: transform 0.15s ease;
}
.tree-toggle.expanded { transform: rotate(90deg); }

/* Status colors */
.status-new { color: var(--info-500); }
.status-learning { color: var(--warning-500); }
.status-review { color: var(--success-500); }
.status-relearning { color: var(--danger-500); }
.due-now { color: var(--danger-500); font-weight: 600; }
.due-soon { color: var(--warning-500); }
.due-later { color: var(--text-tertiary); }

/* Rating colors */
.rating-again { color: var(--danger-500); }
.rating-hard { color: var(--warning-500); }
.rating-good { color: var(--success-500); }
.rating-easy { color: var(--info-500); }

/* Focus accessibility */
*:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
*:focus:not(:focus-visible) { outline: none; }

/* Viewer / Builder frames */
.viewer-frame, .builder-frame {
    width: 100%;
    height: auto;
    min-height: 320px;
    max-height: 85vh;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
}
.iframe-wrap { position: relative; }
.viewer-overlay {
    position: absolute;
    inset: 0;
    background: var(--surface-bg);
    opacity: 1;
    transition: opacity 0.25s ease;
    pointer-events: none;
    border-radius: var(--radius-lg);
    z-index: 5;
}

/* Counter */
.counter { font-size: 13px; color: var(--text-secondary); margin-left: auto; }

/* Results */
.results {
    margin-top: 16px;
    padding: 14px 18px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    font-size: 13px;
    box-shadow: var(--shadow-xs);
}
.results h3 { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; }
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.result-row:last-child { border-bottom: none; }

/* Admin */
.admin-table { width: 100%; font-size: 13px; border-collapse: collapse; margin-top: 10px; }
.admin-table th, .admin-table td { padding: 10px; text-align: left; border-bottom: 1px solid var(--border-subtle); }
.admin-table th { background: var(--surface-sunken); font-weight: 700; color: var(--text-tertiary); text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; }
.admin-input { width: 80px; padding: 5px 8px; border: 1px solid var(--border-default); border-radius: var(--radius-sm); font-size: 12px; background: var(--surface-elevated); color: var(--text-primary); }
.admin-input:focus { outline: none; border-color: var(--border-focus); box-shadow: var(--shadow-glow); }

/* Stat badges */
.stat-badge {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
    color: var(--text-secondary);
    font-weight: 600;
}
.stat-badge.active-new { background: var(--info-50); color: var(--info-500); }
.stat-badge.active-learning { background: var(--warning-50); color: var(--warning-600); }
.stat-badge.active-review { background: var(--success-50); color: var(--success-600); }

/* ----------------------------------------------------------------
   Library Split-Pane Deck Browser
   ---------------------------------------------------------------- */

/* Layout */
.library-split {
    display: flex;
    flex: 1;
    min-height: 0;
    margin: -28px -36px;
}
.library-sidebar {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-subtle);
    background: var(--surface-elevated);
    display: flex;
    flex-direction: column;
}
.library-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 28px 36px;
}

/* Sidebar Header */
.library-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-subtle);
}
.library-sidebar-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.library-sidebar-search {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
}
.library-sidebar-search input {
    width: 100%;
    padding: 7px 11px;
    font-size: 13px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
    color: var(--text-primary);
}
.library-sidebar-search input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-glow);
}
.library-sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border-subtle);
}

/* Deck Navigator Tree */
.deck-nav-tree {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
    user-select: none;
}
.deck-nav-tree::-webkit-scrollbar { width: 5px; }
.deck-nav-tree::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 3px; }

.tree-row {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    margin: 0 6px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    position: relative;
}
.tree-row:hover {
    background: var(--surface-hover);
}
.tree-row.selected {
    background: var(--surface-active);
    box-shadow: inset 3px 0 0 0 var(--brand-500);
}
.tree-row.dragging {
    opacity: 0.4;
}
.tree-row.drop-target {
    box-shadow: inset 0 -2px 0 0 var(--brand-500);
}
.tree-row.drop-child {
    background: var(--brand-50);
    box-shadow: inset 0 0 0 1px var(--brand-200);
}
body.dark-mode .tree-row.drop-child {
    background: rgba(59,130,246,0.12);
    box-shadow: inset 0 0 0 1px rgba(96,165,250,0.25);
}
.deck-nav-tree.drop-root {
    background: var(--brand-50);
    box-shadow: inset 0 0 0 2px var(--brand-300);
}
body.dark-mode .deck-nav-tree.drop-root {
    background: rgba(59,130,246,0.08);
    box-shadow: inset 0 0 0 2px rgba(96,165,250,0.35);
}
.deck-drop-root-zone {
    display: none;
    margin: 8px 6px;
    padding: 10px 12px;
    border: 2px dashed var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    font-size: 12px;
    text-align: center;
    transition: all 0.15s ease;
}
.deck-nav-tree:has(.dragging) .deck-drop-root-zone {
    display: block;
}
.deck-drop-root-zone.active {
    border-color: var(--brand-400);
    background: var(--brand-50);
    color: var(--brand-600);
}
body.dark-mode .deck-drop-root-zone.active {
    background: rgba(59,130,246,0.12);
    border-color: rgba(96,165,250,0.5);
    color: var(--brand-400);
}

.tree-indent {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    height: 28px;
}
.tree-indent-line {
    width: 16px;
    height: 100%;
    border-left: 1px solid var(--border-subtle);
    margin-left: 10px;
}

.tree-chevron {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 2px;
    border-radius: var(--radius-sm);
    transition: transform 180ms ease, background var(--transition-fast);
    color: var(--text-muted);
}
.tree-chevron:hover {
    background: var(--surface-sunken);
    color: var(--text-primary);
}
.tree-chevron.expanded {
    transform: rotate(90deg);
}
.tree-chevron.placeholder {
    visibility: hidden;
    pointer-events: none;
}

.tree-grip {
    width: 14px;
    height: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    flex-shrink: 0;
    margin-right: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
    cursor: grab;
}
.tree-grip::before,
.tree-grip::after {
    content: '';
    display: block;
    width: 10px;
    height: 1px;
    background: var(--text-muted);
    border-radius: 1px;
}
.tree-row:hover .tree-grip {
    opacity: 1;
}
.tree-row.dragging .tree-grip {
    cursor: grabbing;
}

.tree-label {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 2px 0;
}

.tree-stats {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 6px;
}
.tree-stat {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
}
.tree-stat.new { color: var(--info-500); }
.tree-stat.learning { color: var(--warning-500); }
.tree-stat.review { color: var(--success-500); }
.tree-stat.due { color: var(--danger-500); }

.tree-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.tree-row:hover .tree-actions {
    opacity: 1;
}

/* Tree children container with smooth expand */
.tree-children {
    overflow: hidden;
    transition: max-height 200ms cubic-bezier(0.4, 0, 0.2, 1), opacity 180ms ease;
    max-height: 2000px;
    opacity: 1;
}
.tree-children.collapsed {
    max-height: 0;
    opacity: 0;
}

/* Inline new deck form */
.tree-new-deck {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 0 6px;
}
.tree-new-deck input {
    flex: 1;
    padding: 5px 9px;
    font-size: 13px;
    border: 1px solid var(--border-focus);
    border-radius: var(--radius-sm);
    background: var(--surface-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-glow);
}

/* Content Pane Header */
.deck-pane-header {
    margin-bottom: 24px;
}
.deck-pane-breadcrumb {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.deck-pane-breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}
.deck-pane-breadcrumb a:hover {
    color: var(--brand-500);
}
.deck-pane-breadcrumb .sep {
    color: var(--border-default);
}
.deck-pane-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.4px;
    margin-bottom: 14px;
}
.deck-pane-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Stats Row */
.deck-stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}
.deck-stat-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    text-align: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.deck-stat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.deck-stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.5px;
}
.deck-stat-card .stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 4px;
}
.deck-stat-card.new .stat-value { color: var(--info-500); }
.deck-stat-card.new .stat-label { color: var(--info-500); }
.deck-stat-card.learning .stat-value { color: var(--warning-500); }
.deck-stat-card.learning .stat-label { color: var(--warning-500); }
.deck-stat-card.review .stat-value { color: var(--success-500); }
.deck-stat-card.review .stat-label { color: var(--success-500); }
.deck-stat-card.due .stat-value { color: var(--danger-500); }
.deck-stat-card.due .stat-label { color: var(--danger-500); }

/* Sub-deck mini cards */
.subdeck-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-bottom: 20px;
}
.subdeck-row::-webkit-scrollbar { height: 4px; }
.subdeck-row::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 2px; }
.subdeck-mini {
    flex-shrink: 0;
    min-width: 160px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.subdeck-mini:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}
.subdeck-mini .sd-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.subdeck-mini .sd-count {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Card Preview Grid */
.card-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}
.card-preview-item {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: transform 150ms ease, box-shadow 150ms ease;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 120px;
}
.card-preview-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-default);
}
.card-preview-item.inactive {
    opacity: 0.5;
}
.card-preview-item .cp-select {
    position: absolute;
    top: 10px;
    right: 10px;
}
.card-preview-item .cp-front {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    padding-right: 20px;
}
.card-preview-item .cp-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    flex-wrap: wrap;
}
.card-preview-item .cp-template {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    background: var(--surface-sunken);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
}
.card-preview-item .cp-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-full);
}
.card-preview-item .cp-status.new { background: var(--info-50); color: var(--info-500); }
.card-preview-item .cp-status.learning { background: var(--warning-50); color: var(--warning-600); }
.card-preview-item .cp-status.review { background: var(--success-50); color: var(--success-600); }
.card-preview-item .cp-status.relearning { background: var(--danger-50); color: var(--danger-600); }
body.dark-mode .card-preview-item .cp-status.new { background: rgba(59,130,246,0.15); }
body.dark-mode .card-preview-item .cp-status.learning { background: rgba(245,158,11,0.15); }
body.dark-mode .card-preview-item .cp-status.review { background: rgba(34,197,94,0.15); }
body.dark-mode .card-preview-item .cp-status.relearning { background: rgba(239,68,68,0.15); }
.card-preview-item .cp-due {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

/* Floating Bulk Bar */
.floating-bulk-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(120%);
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 500;
    transition: transform 250ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.floating-bulk-bar.active {
    transform: translateX(-50%) translateY(0);
}
.floating-bulk-bar .bulk-count {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}
.floating-bulk-bar .bulk-divider {
    width: 1px;
    height: 20px;
    background: var(--border-subtle);
}

/* View Toggle */
.view-toggle {
    display: flex;
    align-items: center;
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 2px;
}
.view-toggle button {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.view-toggle button.active {
    background: var(--surface-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

/* Deck picker tree (shared component) */
.picker-tree {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-elevated);
    padding: 4px 0;
}
.picker-tree-row {
    display: flex;
    align-items: center;
    padding: 7px 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 13px;
}
.picker-tree-row:hover {
    background: var(--surface-hover);
}
.picker-tree-row.selected {
    background: var(--surface-active);
}
.picker-tree-row input[type="checkbox"],
.picker-tree-row input[type="radio"] {
    margin-right: 8px;
    flex-shrink: 0;
}

/* Empty state inside pane */
.pane-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.pane-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 16px 0 6px;
}
.pane-empty p {
    font-size: 14px;
    color: var(--text-tertiary);
    margin-bottom: 20px;
    max-width: 320px;
}

/* Context menu for tree rows */
.tree-context-menu {
    position: fixed;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    padding: 6px;
    min-width: 180px;
    animation: menuIn 0.15s ease;
}
.tree-context-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    font-size: 13px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.tree-context-menu button:hover {
    background: var(--surface-hover);
}
.tree-context-menu button.danger {
    color: var(--danger-500);
}
.tree-context-menu button.danger:hover {
    background: var(--danger-50);
}
body.dark-mode .tree-context-menu button.danger:hover {
    background: rgba(239,68,68,0.12);
}

/* Responsive for library */
@media (max-width: 768px) {
    .library-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .library-sidebar.open {
        transform: translateX(0);
    }
    .library-content {
        padding: 20px 16px;
    }
    .deck-stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .card-preview-grid {
        grid-template-columns: 1fr;
    }
}

/* ----------------------------------------------------------------
   18. Responsive
   ---------------------------------------------------------------- */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 110;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
}
.mobile-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    position: relative;
    transition: all 0.2s ease;
}
.mobile-toggle span::before,
.mobile-toggle span::after {
    content: '';
    position: absolute;
    left: 0;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all 0.2s ease;
}
.mobile-toggle span::before { top: -6px; }
.mobile-toggle span::after { top: 6px; }

@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .mobile-toggle { display: flex; }
    header { transform: translateX(-100%); transition: transform 0.25s ease; }
    header.open { transform: translateX(0); }
    main { margin-left: 0; padding: 20px 16px; }
    .deck-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .card-table-header, .card-table-row {
        grid-template-columns: 28px 44px minmax(0, 1fr) 78px 56px 40px;
    }
    .card-table-header .hide-sm, .card-table-row .hide-sm { display: none; }
}

/* App loader */
.app-loader {
    position: fixed;
    inset: 0;
    background: var(--surface-bg, #fafafa);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}
.app-loader.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.app-loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.app-loader-icon {
    width: 48px;
    height: 48px;
    animation: loader-pulse 1.5s ease-in-out infinite;
}
@keyframes loader-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}
.app-loader-text {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary, #1a1a1a);
    letter-spacing: -0.3px;
}
.app-loader-bar {
    width: 160px;
    height: 4px;
    background: var(--surface-sunken, #e5e5e5);
    border-radius: 2px;
    overflow: hidden;
}
.app-loader-progress {
    width: 40%;
    height: 100%;
    background: var(--brand-500, #6366f1);
    border-radius: 2px;
    animation: loader-slide 1.2s ease-in-out infinite;
}
@keyframes loader-slide {
    0% { transform: translateX(-150%); }
    100% { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
    .app-loader-icon, .app-loader-progress { animation: none; }
}
body.dark-mode .app-loader { background: var(--surface-bg, #0a0a0f); }

/* Confetti */
.confetti-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* Tooltip system */
[data-tooltip] {
    position: relative;
}
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    padding: 6px 10px;
    background: var(--surface-bg-tertiary, #1f1f23);
    color: var(--text-primary, #fafafa);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: var(--radius-sm, 6px);
    box-shadow: var(--shadow-sm, 0 2px 8px rgba(0,0,0,0.25));
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 1000;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}
[data-tooltip][data-tooltip-pos="bottom"]::after {
    bottom: auto;
    top: calc(100% + 6px);
}
[data-tooltip][data-tooltip-pos="left"]::after {
    bottom: auto;
    top: 50%;
    left: auto;
    right: calc(100% + 6px);
    transform: translateY(-50%) scale(0.95);
}
[data-tooltip][data-tooltip-pos="left"]:hover::after,
[data-tooltip][data-tooltip-pos="left"]:focus-visible::after {
    transform: translateY(-50%) scale(1);
}
[data-tooltip][data-tooltip-pos="right"]::after {
    bottom: auto;
    top: 50%;
    left: calc(100% + 6px);
    transform: translateY(-50%) scale(0.95);
}
[data-tooltip][data-tooltip-pos="right"]:hover::after,
[data-tooltip][data-tooltip-pos="right"]:focus-visible::after {
    transform: translateY(-50%) scale(1);
}
@media (max-width: 768px) {
    [data-tooltip]::after { display: none; }
}
