/* ================================================================
   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;
    background: var(--surface-bg);
    min-height: 100%;
    overscroll-behavior: none;
}

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

html.kawaii-mode {
    background: linear-gradient(135deg, #FFE4E1 0%, #E0FFFF 25%, #F3E5F5 50%, #FFF8DC 75%, #FFE4E1 100%);
    background-attachment: fixed;
}

html.dark-mode {
    background: #0a0a0f;
}

::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);
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.logo:hover { color: var(--brand-500); }
body.sidebar-collapsed .logo { justify-content: center; }
.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;
}
body.sidebar-collapsed #user-menu {
    padding: 6px 0;
    align-items: center;
}
body.sidebar-collapsed #user-email {
    display: none;
}
body.sidebar-collapsed #user-logout-btn,
body.sidebar-collapsed #user-logout-btn.w-full {
    width: auto;
    min-width: 36px;
    min-height: 36px;
    padding: 8px;
    justify-content: center;
}
body.sidebar-collapsed .logout-label {
    display: none;
}

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-container {
    position: fixed;
    top: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    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: translateX(40px) scale(0.96);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 380px;
    min-width: 220px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}
.toast.show {
    opacity: 1;
    transform: translateX(0) scale(1);
}
.toast-exit {
    opacity: 0;
    transform: translateX(40px) scale(0.96);
    pointer-events: none;
}
.toast-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}
.toast-success .toast-icon { background: var(--success-500); }
.toast-error .toast-icon { background: var(--danger-500); }
.toast-info .toast-icon { background: var(--info-500); }
.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); }
.toast-message { flex: 1; line-height: 1.4; }
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0,0,0,0.05);
}
.toast-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--brand-500);
    border-radius: 0 0 0 var(--radius-lg);
}
.toast-success .toast-progress-fill { background: var(--success-500); }
.toast-error .toast-progress-fill { background: var(--danger-500); }
.toast-info .toast-progress-fill { background: var(--info-500); }

@media (max-width: 480px) {
    #toast-container {
        top: auto;
        bottom: 16px;
        left: 16px;
        right: 16px;
        align-items: stretch;
    }
    .toast {
        max-width: none;
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .toast {
        transition: none;
        transform: none;
    }
    .toast-progress-fill { transition: width 0.1s linear; }
}

/* ----------------------------------------------------------------
   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; }
.study-control-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Fullscreen study mode */
#tab-study:fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg);
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
}
#tab-study:fullscreen #study-launcher,
#tab-study:fullscreen #results-area {
    display: none !important;
}
#tab-study:fullscreen #study-control-bar {
    position: relative;
    top: auto;
    flex-shrink: 0;
    margin-bottom: 12px;
}
#tab-study:fullscreen #study-area {
    flex: 1;
    min-height: 0;
    border-radius: var(--radius-xl);
    overflow: hidden;
}
#tab-study:fullscreen #study-area .iframe-wrap {
    height: 100%;
}
#tab-study:fullscreen #study-area .viewer-frame {
    height: 100%;
}

/* ----------------------------------------------------------------
   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; margin-bottom: 16px; }
.password-wrap .auth-input { padding-right: 36px; }
.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; }

.icon-only:focus-visible,
nav button:focus-visible,
.sidebar-footer button:focus-visible,
.sidebar-collapse-btn:focus-visible,
.theme-toggle:focus-visible {
    outline: 2px solid var(--brand-500);
    outline-offset: 2px;
    border-radius: var(--radius-md);
}

@media (prefers-reduced-motion: reduce) {
    .tab { animation: 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); }
.admin-rate-limits {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px;
    margin-top: 10px;
}
.limit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    background: var(--surface-sunken);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}
.limit-row span {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}
.admin-service-tier-form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.admin-service-tier-form .admin-input {
    width: auto;
    min-width: 200px;
    flex: 1;
}
.settings-admin-save {
    margin-top: 12px;
}
.admin-table td:last-child {
    white-space: nowrap;
    width: 1%;
}

/* Admin model editor */
.admin-models-editor {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 12px;
}
.admin-model-group {
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px;
}
.admin-model-group h5 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 10px;
    text-transform: capitalize;
}
.admin-model-field {
    margin-bottom: 10px;
}
.admin-model-field:last-child { margin-bottom: 0; }
.admin-model-field label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: capitalize;
}
.admin-model-field input[type="text"] {
    width: 100%;
    font-size: 13px;
    padding: 6px 10px;
}
.admin-model-field .model-default {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 3px;
}
.admin-reasoning-field {
    margin-top: -6px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-subtle);
}
.admin-reasoning-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    cursor: pointer;
}
.admin-reasoning-label input[type="checkbox"] {
    margin: 0;
}
.admin-reasoning-select {
    width: 100%;
    margin-top: 6px;
    font-size: 13px;
    padding: 5px 8px;
}
.admin-reasoning-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 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-chevron .icon {
    width: 14px;
    height: 14px;
}

.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(180%);
    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 — JS-driven so it floats above every UI layer */
[data-tooltip] {
    position: relative;
}
#js-tooltip {
    position: fixed;
    z-index: 10000;
    padding: 6px 10px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.96);
    transition: opacity 0.12s ease, transform 0.12s ease;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}
#js-tooltip.show {
    opacity: 1;
    transform: scale(1);
}
/* Disable legacy CSS pseudo-tooltips */
[data-tooltip]::after { display: none !important; }
@media (max-width: 768px) {
    #js-tooltip { display: none !important; }
}

/* ================================================================
   20. UI Polish Utilities
   ================================================================ */

/* Auth */
.auth-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.auth-options label {
    font-size: 12px;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.auth-options input[type="checkbox"] { margin: 0; }
.auth-error {
    color: var(--danger-500);
    font-size: 13px;
    margin: 12px 0 0;
    text-align: center;
    display: none;
}
.auth-error.show { display: block; }
.auth-verify-input {
    text-align: center;
    letter-spacing: 8px;
    font-size: 20px;
}
.auth-form-link {
    font-weight: 500;
}

/* Modal variants */
.modal-analysis { z-index: 2500; }
.modal-analysis .preview-box,
.modal-analysis .modal-box {
    max-width: 600px;
    height: auto;
    max-height: 85vh;
}
.modal-analysis .preview-body {
    display: block;
    padding: 20px;
    overflow-y: auto;
    align-items: flex-start;
    justify-content: flex-start;
}
.modal-analysis .analysis-content { width: 100%; }
.modal-analysis .analysis-loading { color: var(--text-tertiary); }
.modal-analysis .preview-footer,
.modal-prereq .preview-footer,
.modal-footer-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.modal-prereq { z-index: 2600; }
.modal-prereq .preview-box {
    max-width: 500px;
    height: auto;
    max-height: 80vh;
}
.modal-prereq .preview-body {
    display: block;
    padding: 20px;
    overflow-y: auto;
}
.modal-prereq .prereq-help {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
}
.modal-main { z-index: 3000; }
.modal-edit .edit-box {
    max-width: 900px;
    height: 85vh;
}
.modal-edit .edit-body {
    padding: 0;
    overflow: hidden;
}
.modal-edit .edit-iframe {
    width: 100%;
    height: 70vh;
    min-height: 600px;
    border: none;
    display: block;
}

/* Charts */
.chart-wrap {
    position: relative;
    height: 240px;
}

/* Settings */
.setting-desc {
    font-size: 12px;
    color: var(--text-tertiary);
    margin: 4px 0 0;
}
.setting-control {
    display: flex;
    align-items: center;
    gap: 8px;
}
.setting-control input[type="range"] { width: 140px; }
.setting-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--brand-600);
    min-width: 42px;
}
.setting-row-divider {
    margin-top: 12px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 12px;
}
.settings-account-box {
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--surface-sunken);
    border-radius: 6px;
}
.settings-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.settings-admin h4 {
    font-size: 13px;
    margin: 12px 0 8px;
    color: var(--text-primary);
}
.settings-admin .admin-table-wrap { overflow-x: auto; }
.settings-admin .admin-save-status {
    font-size: 12px;
    color: var(--success-600);
    margin-top: 8px;
    display: none;
}
.settings-admin .admin-save-status.show { display: block; }
.settings-media-list { font-size: 13px; }
.settings-toggle {
    width: 28px;
    height: 28px;
    cursor: pointer;
}
.storage-info {
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.rate-limits-list { margin-top: 12px; }
.validate-result { margin-top: 8px; font-size: 12px; }
.validate-message-list {
    margin: 4px 0 0;
    padding-left: 16px;
}
.settings-refresh { margin-top: 8px; }

/* Docs */
.docs-hr {
    margin: 32px 0;
    border: none;
    border-top: 1px solid var(--border-subtle);
}
.docs-table {
    font-size: 12px;
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
}
.docs-table th,
.docs-table td {
    padding: 6px 8px;
    border: 1px solid var(--border-subtle);
    text-align: left;
}
.docs-table th { background: var(--surface-sunken); }
.docs-icon-search {
    margin: 12px 0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.docs-icon-search input {
    width: 100%;
    max-width: 400px;
    padding: 8px 12px;
    border: 1px solid var(--border-default);
    border-radius: 6px;
    font-size: 14px;
    background: var(--surface-elevated);
    color: var(--text-primary);
}
.docs-icon-search label {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}
.docs-icon-count {
    margin-left: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}
.docs-icon-browser {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface-sunken);
}
.icon-browser-empty {
    grid-column: 1 / -1;
    color: var(--text-secondary);
}
.icon-browser-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
}
.icon-browser-img {
    object-fit: contain;
    flex-shrink: 0;
}
.icon-browser-img-50 { width: 20px; height: 20px; }
.icon-browser-img-100 { width: 32px; height: 32px; }
.icon-browser-code {
    font-size: 11px;
    word-break: break-all;
    color: var(--text-secondary);
}

/* Library */
.library-empty-icon {
    width: 64px;
    height: 64px;
    opacity: 0.6;
}

/* Study */
.study-counter {
    font-size: 13px;
    color: var(--text-tertiary);
    min-width: 60px;
    text-align: right;
}
.study-launcher-due {
    display: none;
}
.deck-select-btn {
    min-width: 180px;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#deck-dropdown { display: none; }
.deck-dropdown-action { font-size: 12px; padding: 4px 8px; }
.btn-study-start { padding: 10px 24px; font-size: 15px; font-weight: 600; }
.study-stat-dot-new { background: var(--info-500); }
.study-stat-dot-learning { background: var(--warning-500); }
.study-stat-dot-review { background: var(--success-500); }

/* Create page */
.create-controls-row { padding: 16px 16px 0; }
.sidebar-upload-btn { font-size: 11px; padding: 3px 6px; }
.sidebar-import-row { margin-top: 8px; }
.sidebar-import-actions { display: flex; gap: 4px; }
.sidebar-import-actions .btn { font-size: 11px; padding: 3px 6px; }
.template-skeleton-row { padding: 8px 10px; }
.template-sidebar-footer { display: none; }
.template-sidebar-footer.show { display: flex; }
.template-footer-actions { display: flex; gap: 6px; }
.template-footer-actions .btn { font-size: 11px; padding: 3px 6px; }
.template-footer-selection { display: flex; align-items: center; gap: 8px; }
.template-footer-selection .btn { font-size: 12px; padding: 4px 8px; }
#single-builder-view, #bulk-creator-view { display: none; }
#bulk-progress, #bulk-results { display: none; }
#bulk-progress.show, #bulk-results.show { display: block; }
.bulk-generate-btn { font-size: 15px; padding: 10px 22px; }
.results-action-btn { font-size: 12px; padding: 4px 10px; }

/* Mobile sidebar backdrop */
.mobile-sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}
@media (max-width: 700px) {
    body.sidebar-open .mobile-sidebar-backdrop {
        display: block;
    }
    body.sidebar-open { overflow: hidden; }
}

/* ================================================================
   21. Inline-Style Replacement Utilities
   ================================================================ */

/* Text utilities */
.text-tertiary { color: var(--text-tertiary); }
.text-danger { color: var(--danger-500); }
.text-warning { color: var(--warning-500); }
.text-small { font-size: 12px; }
.text-pre-wrap { white-space: pre-wrap; }
.analysis-verdict { font-weight: 600; margin-bottom: 8px; }
.analysis-report {
    white-space: pre-wrap;
    line-height: 1.5;
    margin-bottom: 16px;
}
.analysis-files-title {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}
.analysis-files-list {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-left: 16px;
}

/* Layout utilities */
.w-full { width: 100%; }
.flex-row-center {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Modal content */
.modal-select {
    margin-bottom: 10px;
    width: 100%;
}
.modal-body-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
}
.modal-body-text.spaced {
    margin: 0 0 10px;
}
.modal-section { margin-bottom: 16px; }
.modal-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.modal-shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-subtle);
}
.modal-shortcut-desc {
    color: var(--text-secondary);
    font-size: 13px;
}
.modal-kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    padding: 3px 8px;
    background: var(--surface-sunken);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    min-width: 28px;
    text-align: center;
}

/* Empty states */
.empty-state-padded { padding: 32px 0; }
.empty-state-compact { padding: 16px; }
.pane-empty-padded { padding: 40px 20px; }

/* Stats / media browser */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}
.media-card {
    background: var(--surface-raised);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 8px;
}
.media-thumb {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}
.media-thumb-icon {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-sunken);
    border-radius: 4px;
    font-size: 24px;
}
.media-filename {
    font-size: 11px;
    margin: 6px 0 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.media-size {
    font-size: 10px;
    color: var(--text-tertiary);
    margin: 2px 0 0;
}
.media-delete-btn {
    margin-top: 6px;
    width: 100%;
    font-size: 11px;
    padding: 2px 4px;
}
.media-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    padding: 8px 10px;
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}
.media-toolbar label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.media-toolbar .btn {
    min-height: 32px;
    padding: 5px 12px;
    font-size: 12px;
}
.media-card {
    position: relative;
}
.media-select {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
}
.media-card.selected .media-thumb,
.media-card.selected .media-thumb-icon {
    outline: 2px solid var(--brand-500);
    outline-offset: -2px;
}
.limit-text-muted { color: var(--text-tertiary); }

/* Card / deck toolbars */
.card-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.card-toolbar > input[type="text"],
.card-toolbar > select {
    width: auto;
    min-width: 0;
}
.card-toolbar-input {
    flex: 1;
    min-width: 180px;
}
.card-toolbar-select {
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    background: var(--surface-elevated);
    color: var(--text-primary);
    cursor: pointer;
    width: auto;
}
.card-toolbar-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Prerequisite lists */
.prereq-list { margin: 0; }
.prereq-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}
.prereq-empty {
    color: var(--text-tertiary);
    font-size: 13px;
}

/* Buttons */
.btn-xs {
    font-size: 11px;
    padding: 2px 8px;
}

/* File list items */
.file-list-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-list-remove {
    color: var(--danger-500);
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
}

/* Bulk image previews */
.bulk-image-preview {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
}
.bulk-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.bulk-image-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 10px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    cursor: pointer;
}
.bulk-image-remove .icon { filter: invert(1); }

/* Study countdown */
.study-countdown {
    background: var(--surface-sunken);
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 20px;
    display: inline-block;
}
.study-countdown-label {
    font-size: 13px;
    color: var(--text-tertiary);
    margin: 0 0 4px;
}
.study-countdown-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--brand-600);
    margin: 0;
}

/* Admin */
.admin-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Pointer / cursors */
.cursor-pointer { cursor: pointer; }
.card-id {
    color: var(--text-primary);
    font-size: 12px;
}
.pagination-wrap { margin-top: 16px; }

/* ================================================================
   KAWAII / SHIBUYA-KEI FULL REPLACEMENT THEME
   ================================================================ */

body.kawaii-mode {
    /* Pastel palette */
    --kawaii-pink: #FF8FA3;
    --kawaii-mint: #7FD8BE;
    --kawaii-lavender: #C8B6FF;
    --kawaii-lemon: #FFE66D;
    --kawaii-sky: #89CFF0;
    --kawaii-peach: #FFCDB2;
    --kawaii-cream: #FFF0F3;
    --kawaii-text: #2D2D2D;
    --kawaii-text-soft: #5A5A5A;
    --kawaii-text-muted: #888888;
    --kawaii-card-bg: rgba(255, 255, 255, 0.82);
    --kawaii-border: #2D2D2D;

    /* Override semantic tokens */
    --brand-50: #FFF0F3;
    --brand-100: #FFD6DE;
    --brand-200: #FFB6C4;
    --brand-300: #FF9AAF;
    --brand-400: #FF8FA3;
    --brand-500: #FF8FA3;
    --brand-600: #E66B82;
    --brand-700: #CC5269;
    --brand-800: #A63D51;
    --brand-900: #7D2D3C;

    --success-50: #E8FAF4;
    --success-500: #4BD4A7;
    --success-600: #36B38B;
    --warning-50: #FFF9E6;
    --warning-500: #F5C542;
    --warning-600: #D4A72E;
    --danger-50: #FFEBEE;
    --danger-500: #FF6B6B;
    --danger-600: #E74C3C;
    --info-50: #EAF7FC;
    --info-500: #5BC8F0;

    --surface-bg: transparent;
    --surface-elevated: rgba(255, 255, 255, 0.82);
    --surface-sunken: rgba(255, 255, 255, 0.55);
    --surface-hover: rgba(255, 240, 243, 0.7);
    --surface-active: rgba(255, 143, 163, 0.18);

    --text-primary: var(--kawaii-text);
    --text-secondary: var(--kawaii-text-soft);
    --text-tertiary: var(--kawaii-text-muted);
    --text-muted: #999999;
    --text-on-brand: #ffffff;
    --text-on-dark: #ffffff;

    --border-subtle: rgba(45, 45, 45, 0.14);
    --border-default: rgba(45, 45, 45, 0.22);
    --border-focus: var(--kawaii-lavender);

    --shadow-xs: 2px 2px 0px rgba(0,0,0,0.06);
    --shadow-sm: 4px 4px 0px rgba(0,0,0,0.08);
    --shadow-md: 6px 6px 0px rgba(0,0,0,0.08);
    --shadow-lg: 8px 8px 0px rgba(0,0,0,0.08);
    --shadow-xl: 10px 10px 0px rgba(0,0,0,0.08);
    --shadow-glow: 0 0 0 3px rgba(200, 182, 255, 0.35);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --radius-full: 999px;

    --font-sans: 'Zen Maru Gothic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'DotGothic16', 'SF Mono', Monaco, monospace;

    font-family: var(--font-sans);
    font-weight: 500;
}

/* Global pastel gradient background */
body.kawaii-mode {
    background: linear-gradient(135deg, #FFE4E1 0%, #E0FFFF 25%, #F3E5F5 50%, #FFF8DC 75%, #FFE4E1 100%);
    background-attachment: fixed;
    color: var(--kawaii-text);
}

/* Grid floor overlay */
body.kawaii-mode .kawaii-grid-floor {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.5) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.5) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
}

/* Scanline overlay */
body.kawaii-mode .kawaii-scanlines {
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 3px,
        rgba(0,0,0,0.02) 3px,
        rgba(0,0,0,0.02) 6px
    );
    pointer-events: none;
    z-index: 9999;
}

/* Floating decorative shapes */
@keyframes kawaii-float {
    0%, 100% { transform: translateY(0px) rotate(0deg); }
    33% { transform: translateY(-20px) rotate(5deg); }
    66% { transform: translateY(10px) rotate(-3deg); }
}
@keyframes kawaii-drift {
    0% { transform: translateX(0) translateY(0); }
    50% { transform: translateX(30px) translateY(-20px); }
    100% { transform: translateX(0) translateY(0); }
}

body.kawaii-mode .kawaii-deco {
    position: fixed;
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
}
body.kawaii-mode .kawaii-deco-1 {
    width: 120px; height: 120px;
    background: var(--kawaii-pink);
    border-radius: 50%;
    top: 10%; left: -40px;
    animation: kawaii-float 18s infinite ease-in-out;
}
body.kawaii-mode .kawaii-deco-2 {
    width: 80px; height: 80px;
    background: var(--kawaii-mint);
    border-radius: 20px;
    top: 40%; right: -20px;
    animation: kawaii-drift 22s infinite ease-in-out;
}
body.kawaii-mode .kawaii-deco-3 {
    width: 60px; height: 60px;
    background: var(--kawaii-lemon);
    border-radius: 50%;
    bottom: 20%; left: 10%;
    animation: kawaii-float 15s infinite ease-in-out reverse;
}
body.kawaii-mode .kawaii-deco-4 {
    width: 100px; height: 100px;
    border: 4px solid var(--kawaii-lavender);
    border-radius: 50%;
    top: 60%; right: 5%;
    animation: kawaii-drift 25s infinite ease-in-out;
}

body.kawaii-mode header {
    border-right: 3px solid var(--kawaii-border);
    background: var(--kawaii-cream);
}
body.kawaii-mode main {
    padding-top: 28px;
}

/* Typography */
body.kawaii-mode h1,
body.kawaii-mode h2,
body.kawaii-mode h3,
body.kawaii-mode .page-header h2,
body.kawaii-mode .study-launcher-title,
body.kawaii-mode .deck-pane-title,
body.kawaii-mode .auth-logo,
body.kawaii-mode .logo,
body.kawaii-mode .modal-title,
body.kawaii-mode .stat-value,
body.kawaii-mode .bulk-header h3 {
    font-family: 'DotGothic16', monospace;
    font-weight: 400;
    letter-spacing: 1px;
}
body.kawaii-mode .logo {
    color: var(--kawaii-pink);
    text-shadow: 3px 3px 0px var(--kawaii-lavender);
    font-size: 22px;
}

/* Sidebar nav */
body.kawaii-mode nav button {
    border: 2.5px solid transparent;
    border-radius: 16px;
    background: rgba(255,255,255,0.6);
    margin-bottom: 4px;
    font-family: 'DotGothic16', monospace;
    font-size: 13px;
    color: var(--kawaii-text);
    transition: all 0.15s ease;
}
body.kawaii-mode nav button:hover {
    background: rgba(255,255,255,0.9);
    border-color: var(--kawaii-border);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.06);
}
body.kawaii-mode nav button.active {
    background: var(--kawaii-pink);
    color: #ffffff;
    border-color: var(--kawaii-border);
    transform: translate(-2px, -2px);
    box-shadow: 4px 4px 0px rgba(255, 143, 163, 0.4);
}
body.kawaii-mode nav button.active::before { display: none; }
body.kawaii-mode nav button img { opacity: 0.85; filter: none; }
body.kawaii-mode nav button.active img { opacity: 1; }

body.kawaii-mode .sidebar-footer button {
    border: 2.5px solid transparent;
    border-radius: 14px;
    font-family: 'DotGothic16', monospace;
    font-size: 12px;
    background: rgba(255,255,255,0.5);
}
body.kawaii-mode .sidebar-footer button:hover {
    background: rgba(255,255,255,0.9);
    border-color: var(--kawaii-border);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.06);
}

/* Buttons */
body.kawaii-mode .btn,
body.kawaii-mode .auth-btn,
body.kawaii-mode .timer-btn {
    border: 2.5px solid var(--kawaii-border);
    border-radius: 14px;
    background: #ffffff;
    color: var(--kawaii-text);
    font-family: 'DotGothic16', monospace;
    font-weight: 400;
    box-shadow: 4px 4px 0px rgba(0,0,0,0.08);
    transition: all 0.1s ease;
}
body.kawaii-mode .btn:hover,
body.kawaii-mode .auth-btn:hover {
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0px rgba(0,0,0,0.1);
}
body.kawaii-mode .btn:active,
body.kawaii-mode .auth-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0px rgba(0,0,0,0.08);
}
body.kawaii-mode .btn-primary,
body.kawaii-mode .auth-btn {
    background: var(--kawaii-mint);
    color: #ffffff;
    border-color: var(--kawaii-border);
    box-shadow: 4px 4px 0px rgba(127, 216, 190, 0.4);
}
body.kawaii-mode .btn-primary:hover,
body.kawaii-mode .auth-btn:hover {
    background: #6FCCB2;
    box-shadow: 5px 5px 0px rgba(127, 216, 190, 0.5);
}
body.kawaii-mode .btn-danger {
    background: var(--kawaii-pink);
    color: #ffffff;
    border-color: var(--kawaii-border);
}
body.kawaii-mode .btn-ghost {
    background: rgba(255,255,255,0.5);
    border-color: var(--border-subtle);
    box-shadow: 2px 2px 0px rgba(0,0,0,0.05);
}
body.kawaii-mode .icon-only {
    border: 2.5px solid transparent;
    border-radius: 12px;
}
body.kawaii-mode .icon-only:hover {
    background: rgba(255,255,255,0.9);
    border-color: var(--kawaii-border);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.06);
}

/* Inputs */
body.kawaii-mode input[type="text"],
body.kawaii-mode input[type="email"],
body.kawaii-mode input[type="password"],
body.kawaii-mode input[type="number"],
body.kawaii-mode textarea,
body.kawaii-mode select,
body.kawaii-mode .auth-input,
body.kawaii-mode .library-sidebar-search input,
body.kawaii-mode .modal-input,
body.kawaii-mode .admin-input,
body.kawaii-mode .admin-rate-limits .admin-input,
body.kawaii-mode .admin-service-tier-form .admin-input {
    border: 2.5px solid var(--kawaii-border);
    border-radius: 12px;
    background: rgba(255,255,255,0.9);
    color: var(--kawaii-text);
    font-family: var(--font-sans);
    font-weight: 500;
    box-shadow: 2px 2px 0px rgba(0,0,0,0.04);
}
body.kawaii-mode input:focus,
body.kawaii-mode textarea:focus,
body.kawaii-mode select:focus {
    border-color: var(--kawaii-lavender);
    box-shadow: 0 0 0 3px rgba(200, 182, 255, 0.35), 2px 2px 0px rgba(0,0,0,0.04);
}
body.kawaii-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='%232D2D2D' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}
body.kawaii-mode .card-toolbar > input[type="text"],
body.kawaii-mode .card-toolbar > select,
body.kawaii-mode .card-toolbar-input,
body.kawaii-mode .card-toolbar-select {
    width: auto;
    min-width: 0;
}
body.kawaii-mode .card-toolbar-input {
    flex: 1;
    min-width: 180px;
}
body.kawaii-mode .admin-input,
body.kawaii-mode .admin-rate-limits input[type="number"],
body.kawaii-mode .admin-service-tier-form select {
    width: auto;
    min-width: 80px;
}
body.kawaii-mode .admin-service-tier-form select {
    min-width: 240px;
}
body.kawaii-mode .admin-model-group {
    background: var(--kawaii-card-bg);
    border: 2.5px solid var(--kawaii-border);
    border-radius: 16px;
    box-shadow: 4px 4px 0px rgba(0,0,0,0.06);
}
body.kawaii-mode .admin-model-group h5 {
    color: var(--kawaii-pink);
    font-family: 'DotGothic16', monospace;
}

/* Custom checkboxes */
body.kawaii-mode input[type="checkbox"] {
    appearance: none;
    width: 22px;
    height: 22px;
    border: 2.5px solid var(--kawaii-border);
    border-radius: 8px;
    background: #ffffff;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}
body.kawaii-mode input[type="checkbox"]:checked {
    background: var(--kawaii-lavender);
    border-color: var(--kawaii-border);
    transform: rotate(-4deg);
}
body.kawaii-mode input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 45%; left: 50%;
    transform: translate(-50%, -50%);
    color: #ffffff;
    font-weight: 900;
    font-size: 13px;
    font-family: 'DotGothic16', monospace;
}

/* Cards */
body.kawaii-mode .card,
body.kawaii-mode .card-flat,
body.kawaii-mode .deck-card,
body.kawaii-mode .stat-card,
body.kawaii-mode .study-launcher,
body.kawaii-mode .settings-section,
body.kawaii-mode .bulk-prompt-card,
body.kawaii-mode .template-list-item,
body.kawaii-mode .result-card-v2,
body.kawaii-mode .subdeck-mini,
body.kawaii-mode .card-preview-item,
body.kawaii-mode .deck-stat-card,
body.kawaii-mode .limit-card,
body.kawaii-mode .study-control-bar,
body.kawaii-mode .results,
body.kawaii-mode .docs,
body.kawaii-mode .tour-tooltip,
body.kawaii-mode .modal-box,
body.kawaii-mode .preview-box,
body.kawaii-mode .edit-box,
body.kawaii-mode .auth-box,
body.kawaii-mode .library-sidebar,
body.kawaii-mode .template-sidebar,
body.kawaii-mode .bulk-advanced,
body.kawaii-mode .card-table,
body.kawaii-mode .deck-tree,
body.kawaii-mode .floating-bulk-bar,
body.kawaii-mode .toast {
    background: var(--kawaii-card-bg);
    border: 3px solid var(--kawaii-border);
    border-radius: 22px;
    box-shadow: 6px 6px 0px rgba(0,0,0,0.06);
    backdrop-filter: blur(12px);
}
body.kawaii-mode .card:hover,
body.kawaii-mode .deck-card:hover,
body.kawaii-mode .stat-card:hover,
body.kawaii-mode .template-list-item:hover,
body.kawaii-mode .result-card-v2:hover,
body.kawaii-mode .subdeck-mini:hover,
body.kawaii-mode .card-preview-item:hover,
body.kawaii-mode .deck-stat-card:hover {
    transform: translate(-2px, -2px);
    box-shadow: 8px 8px 0px rgba(0,0,0,0.08);
}

/* Deck card color-coded top stripes */
body.kawaii-mode .deck-card::before {
    height: 5px;
    border-radius: 22px 22px 0 0;
    background: linear-gradient(90deg, var(--kawaii-pink), var(--kawaii-lavender));
    opacity: 1;
}

/* Badges */
body.kawaii-mode .badge {
    border: 2px solid var(--kawaii-border);
    font-family: 'DotGothic16', monospace;
    font-size: 11px;
    padding: 3px 10px;
}
body.kawaii-mode .badge-new { background: var(--kawaii-sky); color: #ffffff; }
body.kawaii-mode .badge-learning { background: var(--kawaii-lemon); color: var(--kawaii-text); }
body.kawaii-mode .badge-review { background: var(--kawaii-mint); color: #ffffff; }
body.kawaii-mode .badge-due { background: var(--kawaii-lavender); color: #ffffff; }
body.kawaii-mode .badge-relearning { background: var(--kawaii-pink); color: #ffffff; }

/* Progress bars */
body.kawaii-mode .progress-track,
body.kawaii-mode .progress-bar-wrap,
body.kawaii-mode .storage-bar,
body.kawaii-mode .limit-bar,
body.kawaii-mode .stat-row-bar {
    background: rgba(0,0,0,0.06);
    border: 2px solid var(--kawaii-border);
    border-radius: 999px;
    height: 10px;
}
body.kawaii-mode .progress-fill,
body.kawaii-mode .progress-bar-fill,
body.kawaii-mode .storage-bar-fill,
body.kawaii-mode .limit-bar-fill,
body.kawaii-mode .stat-row-fill {
    background: linear-gradient(90deg, var(--kawaii-mint), var(--kawaii-sky));
    border-radius: 999px;
}
body.kawaii-mode .progress-fill.green,
body.kawaii-mode .storage-bar-fill.green,
body.kawaii-mode .limit-bar-fill.green { background: linear-gradient(90deg, var(--kawaii-mint), #4BD4A7); }
body.kawaii-mode .progress-fill.yellow,
body.kawaii-mode .storage-bar-fill.yellow,
body.kawaii-mode .limit-bar-fill.yellow { background: linear-gradient(90deg, var(--kawaii-lemon), #F5C542); }
body.kawaii-mode .progress-fill.red,
body.kawaii-mode .storage-bar-fill.red,
body.kawaii-mode .limit-bar-fill.red { background: linear-gradient(90deg, var(--kawaii-pink), #FF6B6B); }

/* Auth screen */
body.kawaii-mode #auth-screen {
    background: linear-gradient(135deg, #FFE4E1 0%, #E0FFFF 25%, #F3E5F5 50%, #FFF8DC 75%, #FFE4E1 100%);
}
body.kawaii-mode .auth-box {
    border: 3px solid var(--kawaii-border);
    border-radius: 28px;
    box-shadow: 10px 10px 0px rgba(0,0,0,0.08);
    background: var(--kawaii-card-bg);
}
body.kawaii-mode .auth-logo {
    font-family: 'DotGothic16', monospace;
    color: var(--kawaii-pink);
    text-shadow: 3px 3px 0px var(--kawaii-lavender);
    font-size: 26px;
}
body.kawaii-mode .auth-link {
    color: var(--kawaii-pink);
    font-weight: 700;
}

/* Study launcher */
body.kawaii-mode .study-launcher-title {
    color: var(--kawaii-pink);
    text-shadow: 2px 2px 0px rgba(200, 182, 255, 0.4);
    font-size: 22px;
}
body.kawaii-mode .study-stat-dot {
    border: 2px solid var(--kawaii-border);
}

/* Page headers */
body.kawaii-mode .page-header h2 {
    color: var(--kawaii-pink);
    text-shadow: 2px 2px 0px rgba(200, 182, 255, 0.4);
}

/* Library */
body.kawaii-mode .library-sidebar {
    border-right: 3px solid var(--kawaii-border);
    background: var(--kawaii-cream);
    border-radius: 0;
}
body.kawaii-mode .tree-row.selected {
    background: var(--kawaii-pink);
    color: #ffffff;
    box-shadow: 3px 3px 0px rgba(0,0,0,0.08);
    border-radius: 14px;
}
body.kawaii-mode .tree-row.selected .tree-label,
body.kawaii-mode .tree-row.selected .tree-stat {
    color: #ffffff;
}
body.kawaii-mode .tree-row.selected .tree-stat {
    background: rgba(255,255,255,0.25);
}
body.kawaii-mode .deck-pane-title {
    color: var(--kawaii-pink);
    text-shadow: 2px 2px 0px rgba(200, 182, 255, 0.4);
}

/* Create page */
body.kawaii-mode .template-sidebar {
    border-right: 3px solid var(--kawaii-border);
    border-radius: 0;
    background: var(--kawaii-cream);
}
body.kawaii-mode .template-list-item {
    border: 2.5px solid transparent;
}
body.kawaii-mode .template-list-item.active {
    background: var(--kawaii-pink);
    color: #ffffff;
    border-color: var(--kawaii-border);
    box-shadow: 4px 4px 0px rgba(255, 143, 163, 0.4);
}
body.kawaii-mode .template-list-item .t-create {
    background: var(--kawaii-lemon);
    color: var(--kawaii-text);
    border-color: var(--kawaii-border);
    font-family: 'DotGothic16', monospace;
    font-size: 10px;
}
body.kawaii-mode .bulk-chip {
    background: var(--kawaii-lemon);
    color: var(--kawaii-text);
    border: 2px solid var(--kawaii-border);
    font-family: 'DotGothic16', monospace;
}
body.kawaii-mode .bulk-pill.active {
    background: var(--kawaii-pink);
    border-color: var(--kawaii-border);
    box-shadow: 3px 3px 0px rgba(255, 143, 163, 0.35);
}
body.kawaii-mode .bulk-upload-zone {
    border: 2.5px dashed var(--kawaii-border);
    border-radius: 18px;
    background: rgba(255,255,255,0.6);
}
body.kawaii-mode .bulk-upload-zone:hover {
    background: var(--kawaii-cream);
    border-color: var(--kawaii-pink);
}
body.kawaii-mode .bulk-step.active {
    background: var(--kawaii-mint);
    color: #ffffff;
    border-color: var(--kawaii-border);
}

/* Stats */
body.kawaii-mode .stat-card::after {
    height: 5px;
    background: linear-gradient(90deg, var(--kawaii-pink), var(--kawaii-lavender), var(--kawaii-sky));
}
body.kawaii-mode .stat-value {
    color: var(--kawaii-pink);
}

/* Settings */
body.kawaii-mode .settings-section h3 {
    color: var(--kawaii-pink);
    font-family: 'DotGothic16', monospace;
}
body.kawaii-mode .setting-row span {
    font-weight: 700;
}

/* Tables */
body.kawaii-mode .card-table-header {
    background: var(--kawaii-cream);
    font-family: 'DotGothic16', monospace;
    font-size: 10px;
    letter-spacing: 1px;
}
body.kawaii-mode .card-table-row:hover {
    background: var(--kawaii-cream);
}

/* Modals / overlays */
body.kawaii-mode .preview-overlay.active,
body.kawaii-mode .edit-overlay.active {
    background: rgba(255, 240, 243, 0.65);
    backdrop-filter: blur(6px);
}
body.kawaii-mode .preview-header,
body.kawaii-mode .edit-header,
body.kawaii-mode .modal-header,
body.kawaii-mode .modal-footer,
body.kawaii-mode .preview-footer {
    background: var(--kawaii-cream);
    border-color: var(--kawaii-border);
}
body.kawaii-mode .preview-close:hover,
body.kawaii-mode .edit-close:hover,
body.kawaii-mode .modal-close:hover {
    background: var(--kawaii-pink);
    color: #ffffff;
}

/* Dropdown menus */
body.kawaii-mode .deck-menu,
body.kawaii-mode .card-menu,
body.kawaii-mode .deck-dropdown {
    background: var(--kawaii-card-bg);
    border: 3px solid var(--kawaii-border);
    border-radius: 16px;
    box-shadow: 6px 6px 0px rgba(0,0,0,0.08);
}
body.kawaii-mode .deck-menu button:hover,
body.kawaii-mode .card-menu button:hover,
body.kawaii-mode .deck-dropdown label:hover {
    background: var(--kawaii-cream);
}
body.kawaii-mode .deck-menu button.danger:hover,
body.kawaii-mode .card-menu button.danger:hover {
    background: var(--kawaii-pink);
    color: #ffffff;
}

/* Toasts */
body.kawaii-mode .toast {
    border: 3px solid var(--kawaii-border);
    border-radius: 18px;
    font-family: 'DotGothic16', monospace;
}
body.kawaii-mode .toast-success { border-left: 3px solid var(--kawaii-mint); }
body.kawaii-mode .toast-error { border-left: 3px solid var(--kawaii-pink); }
body.kawaii-mode .toast-info { border-left: 3px solid var(--kawaii-sky); }

/* Empty states */
body.kawaii-mode .empty-state h3 {
    color: var(--kawaii-pink);
    font-family: 'DotGothic16', monospace;
}
body.kawaii-mode .empty-state-icon {
    filter: drop-shadow(3px 3px 0px rgba(0,0,0,0.08));
}
body.kawaii-mode #build-empty-state {
    background: var(--kawaii-card-bg);
    border: 3px solid var(--kawaii-border);
    border-radius: 28px;
    box-shadow: 8px 8px 0px rgba(0,0,0,0.06);
    backdrop-filter: blur(12px);
    margin: 20px;
    padding: 60px 24px;
}

/* App loader */
body.kawaii-mode .app-loader {
    background: linear-gradient(135deg, #FFE4E1 0%, #E0FFFF 25%, #F3E5F5 50%, #FFF8DC 75%, #FFE4E1 100%);
}
body.kawaii-mode .app-loader-content {
    background: var(--kawaii-card-bg);
    border: 3px solid var(--kawaii-border);
    border-radius: 28px;
    box-shadow: 8px 8px 0px rgba(0,0,0,0.08);
    padding: 36px 44px;
}
body.kawaii-mode .app-loader-text {
    font-family: 'DotGothic16', monospace;
    color: var(--kawaii-pink);
    text-shadow: 2px 2px 0px var(--kawaii-lavender);
}
body.kawaii-mode .app-loader-bar {
    background: rgba(0,0,0,0.06);
    border: 2px solid var(--kawaii-border);
    border-radius: 999px;
    overflow: hidden;
}
body.kawaii-mode .app-loader-progress {
    background: linear-gradient(90deg, var(--kawaii-mint), var(--kawaii-sky));
}

/* Status / rating colors */
body.kawaii-mode .status-new { color: var(--kawaii-sky); }
body.kawaii-mode .status-learning { color: var(--kawaii-lemon); text-shadow: 1px 1px 0px rgba(0,0,0,0.1); }
body.kawaii-mode .status-review { color: var(--kawaii-mint); }
body.kawaii-mode .status-relearning { color: var(--kawaii-pink); }
body.kawaii-mode .rating-again { color: var(--kawaii-pink); }
body.kawaii-mode .rating-hard { color: var(--kawaii-lemon); text-shadow: 1px 1px 0px rgba(0,0,0,0.1); }
body.kawaii-mode .rating-good { color: var(--kawaii-mint); }
body.kawaii-mode .rating-easy { color: var(--kawaii-sky); }

/* Focus rings */
body.kawaii-mode *:focus-visible {
    outline: 3px solid var(--kawaii-lavender);
    outline-offset: 2px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    body.kawaii-mode main {
        margin-top: 26px;
        padding-top: 16px;
    }
    body.kawaii-mode header {
        top: 26px;
    }
    body.kawaii-mode .kawaii-deco {
        display: none;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    body.kawaii-mode .kawaii-deco {
        animation: none;
    }
}


/* ================================================================
   Global Search Tab
   ================================================================ */

.search-tab-body {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 220px;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}

.search-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.search-toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand-500);
    cursor: pointer;
}

.search-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 0;
    color: var(--text-secondary);
}

.search-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.global-search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.global-search-card {
    background: var(--surface-elevated);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.global-search-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--brand-300);
}

.global-search-card.inactive {
    opacity: 0.55;
}

.gsc-deck {
    font-size: 12px;
    font-weight: 700;
    color: var(--brand-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gsc-front {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gsc-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: auto;
    font-size: 12px;
}

.gsc-template {
    background: var(--surface-2);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
}

.gsc-status {
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.gsc-status.new { background: var(--info-50); color: var(--info-500); }
.gsc-status.learning { background: var(--warning-50); color: var(--warning-600); }
.gsc-status.review { background: var(--success-50); color: var(--success-600); }
.gsc-status.relearning { background: var(--danger-50); color: var(--danger-600); }

.gsc-due {
    color: var(--text-tertiary);
}

body.dark-mode .gsc-deck { color: var(--brand-400); }
body.dark-mode .gsc-template { background: rgba(255,255,255,0.08); }
body.dark-mode .gsc-status.new { background: rgba(59,130,246,0.15); }
body.dark-mode .gsc-status.learning { background: rgba(245,158,11,0.15); }
body.dark-mode .gsc-status.review { background: rgba(34,197,94,0.15); }
body.dark-mode .gsc-status.relearning { background: rgba(239,68,68,0.15); }

body.kawaii-mode .search-input {
    border-width: 2.5px;
    border-color: var(--text);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.06);
}

body.kawaii-mode .search-input:focus {
    border-color: var(--lavender);
    box-shadow: 4px 4px 0px rgba(200,182,255,0.25);
}

body.kawaii-mode .global-search-card {
    border-width: 3px;
    border-color: var(--text);
    box-shadow: 6px 6px 0px rgba(0,0,0,0.06);
}

body.kawaii-mode .global-search-card:hover {
    transform: translate(-2px, -2px);
    box-shadow: 8px 8px 0px rgba(0,0,0,0.1);
    border-color: var(--lavender);
}

@media (max-width: 640px) {
    .search-input-wrap {
        flex-direction: column;
        align-items: stretch;
    }
    .search-input-wrap .btn {
        width: 100%;
        justify-content: center;
    }
    .global-search-grid {
        grid-template-columns: 1fr;
    }
}


/* ================================================================
   Preview Sidebar — Related Cards
   ================================================================ */

.preview-with-sidebar {
    flex-direction: row;
    max-width: 1100px;
}

.preview-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
}

.preview-sidebar {
    width: 280px;
    border-left: 1px solid var(--border-subtle);
    background: var(--surface-sunken);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.preview-sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-sidebar-header .icon {
    width: 18px;
    height: 18px;
    opacity: 0.7;
}

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

.preview-sidebar-empty {
    font-size: 13px;
    color: var(--text-tertiary);
    text-align: center;
    padding: 24px 8px;
    margin: 0;
}

.preview-sidebar-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

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

.preview-related-card {
    background: var(--surface-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.preview-related-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
    border-color: var(--brand-300);
}

.preview-related-card.inactive {
    opacity: 0.55;
}

.prc-deck {
    font-size: 11px;
    font-weight: 700;
    color: var(--brand-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.prc-front {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

body.dark-mode .preview-sidebar { background: rgba(0,0,0,0.2); }
body.dark-mode .prc-deck { color: var(--brand-400); }

body.kawaii-mode .preview-with-sidebar {
    border-width: 3px;
    border-color: var(--text);
    box-shadow: 10px 10px 0px rgba(0,0,0,0.1);
}

body.kawaii-mode .preview-sidebar {
    border-left-width: 3px;
    border-color: var(--text);
    background: var(--cream);
}

body.kawaii-mode .preview-related-card {
    border-width: 2.5px;
    border-color: var(--text);
    box-shadow: 3px 3px 0px rgba(0,0,0,0.06);
}

body.kawaii-mode .preview-related-card:hover {
    transform: translate(-1px, -1px);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.1);
    border-color: var(--lavender);
}

@media (max-width: 860px) {
    .preview-with-sidebar {
        flex-direction: column;
        width: 95%;
        height: 92vh;
        max-width: 600px;
    }
    .preview-sidebar {
        width: 100%;
        height: 180px;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
    }
    body.kawaii-mode .preview-sidebar {
        border-top-width: 3px;
        border-left: none;
    }
}


/* ================================================================
   Study Focus Input
   ================================================================ */

.study-focus-input {
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--surface-elevated);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    min-width: 180px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.study-focus-input:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}

.study-focus-input::placeholder {
    color: var(--text-tertiary);
}

body.kawaii-mode .study-focus-input {
    border-width: 2.5px;
    border-color: var(--text);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.06);
}

body.kawaii-mode .study-focus-input:focus {
    border-color: var(--mint);
    box-shadow: 4px 4px 0px rgba(127,216,190,0.25);
}

@media (max-width: 640px) {
    .study-launcher-body {
        flex-direction: column;
        align-items: stretch;
    }
    .study-focus-input {
        width: 100%;
    }
    .btn-study-start {
        width: 100%;
        justify-content: center;
    }
}


/* ================================================================
   Cost-Based Usage & Budget UI
   ================================================================ */

.monthly-budget-info {
    margin-bottom: 16px;
}

.budget-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
}

.budget-label {
    font-weight: 600;
    color: var(--text-primary);
}

.budget-value {
    font-weight: 700;
    color: var(--text-primary);
}

.budget-muted {
    font-weight: 400;
    color: var(--text-tertiary);
}

.budget-remaining {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 8px 0 0;
}

.usage-breakdown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.usage-breakdown-table th,
.usage-breakdown-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.usage-breakdown-table th {
    color: var(--text-secondary);
    font-weight: 600;
}

.usage-breakdown-table td:last-child {
    text-align: right;
    font-family: monospace;
}

.admin-user-budgets {
    margin-bottom: 16px;
}

.admin-user-budgets .admin-table td:last-child {
    white-space: nowrap;
}

body.kawaii-mode .budget-value {
    color: var(--pink);
}

body.kawaii-mode .usage-breakdown-table th {
    color: var(--text);
}
