/* ==========================================================================
   AQG — Question Bank Builder
   Premium Dark-Mode Design System
   ========================================================================== */

/* --------------------------------------------------------------------------
   Google Fonts Import
   Inter: UI text (Latin)
   Noto Sans TC: Chinese characters (Traditional Chinese)
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400..600&family=Inter:wght@400;500;600;700&family=Noto+Sans+TC:wght@400;500;700&family=Noto+Serif+TC:wght@500;600;700&display=swap');

/* ==========================================================================
   1. CSS Custom Properties (Design Tokens)
   ========================================================================== */
:root {
  /* --- Color Palette: Backgrounds --- */
  --bg-primary: #F5F0E8;            /* Cream white / Paper color */
  --bg-secondary: #ffffff;          /* Card background */
  --bg-tertiary: #ffffff;           /* Card background */
  --bg-input: #ffffff;              /* Input field background */

  /* --- Color Palette: Glass Effect --- */
  --glass-bg: rgba(255, 255, 255, 0.9);
  --glass-border: #000000;
  --glass-blur: 0px;
  --glass-bg-hover: #FDE047;

  /* --- Color Palette: Accents --- */
  --accent-primary: #000000;        /* Pure black */
  --accent-primary-hover: #333333;  
  --accent-primary-muted: rgba(253, 224, 71, 0.2); /* Highlighter yellow tint */
  --accent-secondary: #000000;
  --accent-secondary-hover: #333333;

  /* --- Color Palette: Semantic --- */
  --color-success: #10B981;         
  --color-success-muted: rgba(16, 185, 129, 0.15);
  --color-warning: #F59E0B;         
  --color-warning-muted: rgba(245, 158, 11, 0.15);
  --color-danger: #EF4444;          
  --color-danger-muted: rgba(239, 68, 68, 0.15);

  /* --- Color Palette: Text --- */
  --text-primary: #000000;
  --text-secondary: #3f3f46;        
  --text-muted: #71717a;
  --text-inverse: #ffffff;

  /* --- Typography --- */
  --font-family: 'Inter', 'Plus Jakarta Sans', 'Noto Sans TC', sans-serif;
  --font-family-title: 'Archivo Black', sans-serif;
  --font-family-mono: 'Space Mono', monospace;
  --font-size-xs: 0.6875rem;    /* 11px */
  --font-size-sm: 0.75rem;      /* 12px */
  --font-size-base: 0.875rem;   /* 14px */
  --font-size-md: 1rem;         /* 16px */
  --font-size-lg: 1.125rem;     /* 18px */
  --font-size-xl: 1.5rem;       /* 24px */
  --font-size-2xl: 2rem;        /* 32px */
  --line-height: 1.6;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* --- Spacing Scale --- */
  --space-1: 0.25rem;   /* 4px */
  --space-2: 0.5rem;    /* 8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */

  /* --- Border Radius --- */
  --radius-sm: 4px;     
  --radius-md: 8px;     
  --radius-lg: 12px;    
  --radius-xl: 16px;    
  --radius-full: 9999px;

  /* --- Shadows (Brutalist Offset Shadows) --- */
  --shadow-sm: 2px 2px 0px #000000;
  --shadow-md: 4px 4px 0px #000000;
  --shadow-lg: 5px 5px 0px #000000;
  --shadow-glow-blue: 0 0 0px transparent;
  --shadow-glow-purple: 0 0 0px transparent;

  /* --- Layout Dimensions --- */
  --header-height: 56px;
  --steps-bar-height: 0px;
  --sidebar-width: 270px;
  --paper-tray-width: 270px;
  --subject-card-size: 200px;
  --question-thumb-height: 120px;

  /* --- Transitions (Elastic / Non-linear Easing) --- */
  --transition-fast: 0.1s ease;
  --transition-base: 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-slow: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  --transition-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* --- Z-Index Scale --- */
  --z-base: 1;
  --z-header: 100;
  --z-sidebar: 90;
  --z-paper-tray: 80;
  --z-modal-overlay: 200;
  --z-modal: 210;
  --z-toast: 300;

  /* audit-added tokens */
  --accent-highlight: #FDE047;
  --accent-highlight-hover: #FACC15;
  --accent-highlight-soft: #FFF3A3;
  --btn-fill: #FDE047; --btn-fill-text: #1a1a1a; --btn-fill-hover: #FACC15;   /* Classic：實色光黃掣（brutalist；黑字）——用戶明確要黃、唔要黑 */
  --accent-info: #0A84FF;
  --accent-info-ring: rgba(10, 132, 255, 0.15);
  --accent-link: #007AFF;
  --accent-purple: #BF5AF2;
  --accent-code-badge: #E91E63;
  --badge-purple-bg: rgba(139, 92, 246, 0.15);
  --badge-purple-color: #a78bfa;
  --text-ink-strong: #1c1c1e;
  --text-ink-body: #1a1a1c;
  --text-strong: #111111;
  --paper-text: #1a1a1a;
  --paper-text-secondary: #555;
  --paper-text-muted: #666;
  --paper-border: #333;
  --text-ios-grey: #555559;
  --text-ios-grey-2: #636366;
  --text-grey: #5f636d;
  --text-grey-strong: #686b75;
  --step-tab-text: #4b5563;
  --separator: #e5e5ea;
  --separator-strong: #d1d1d6;
  --border-control: #c7c7cc;
  --border-grey-mid: #8e8e93;
  --border-row: #d8dbe2;
  --border-ink-soft: #1f1f1f;
  --border-hairline-08: rgba(0, 0, 0, 0.08);
  --border-hairline-06: rgba(0, 0, 0, 0.06);
  --surface-grey: #f5f5f7;
  --surface-hover: #f2f2f7;
  --surface-muted: #f3f4f6;
  --surface-label: #eaeaea;
  --surface-off-white: #fafafa;
  --surface-pressed: #e5e5ea;
  --track-grey: #e5e7eb;
  --header-cream: #FAF8F5;
  --surface-warm-1: #fbfaf7;
  --surface-warm-2: #fffdf7;
  --surface-warm-3: #fffdf0;
  --overlay-cream: rgba(245, 240, 232, 0.75);
  --glass-bg-header: rgba(10, 14, 26, 0.85);
  --shadow-xs: 1px 1px 0px #000000;
  --shadow-badge: 1.5px 1.5px 0px #000000;
  --shadow-card: 3px 3px 0px #000000;
  --shadow-dash: 2px 3px 0px #000000;
  --shadow-xl: 8px 8px 0px #000000;
}

/* ==========================================================================
   Theme: E · 融合靛藍 (premium) — override layer over Classic (:root).
   Applied via <html data-theme="e">. Classic (brutalist) stays in :root, untouched.
   Only theme-varying tokens are overridden; spacing / radius / sizes / z / transitions
   are theme-invariant and inherited from :root.
   ========================================================================== */
[data-theme="e"], [data-theme="v3"] {
  /* Backgrounds — warm paper */
  --bg-primary: #F6F4EF;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #FFFFFF;
  --bg-input: #FFFFFF;

  /* Glass — soft & blurred */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: #B5A88E;
  --glass-blur: 8px;
  --glass-bg-hover: #ECECF8;        /* indigo tint, replaces highlighter yellow */

  /* Accents — indigo primary, gold secondary */
  --accent-primary: #3C3A94;
  --accent-primary-hover: #2E2C78;
  --accent-primary-muted: rgba(60, 58, 148, 0.10);
  --accent-secondary: #8A5F22;
  --accent-secondary-hover: #6E4C1B;

  /* Text — warm ink */
  --text-primary: #23201B;
  --text-secondary: #57514A;
  --text-muted: #857C6E;
  --text-inverse: #FFFFFF;

  /* Typography — serif display headings */
  --font-family-title: 'Fraunces', Georgia, 'Noto Serif TC', serif;

  /* Shadows — soft & warm (replaces brutalist hard offsets) */
  --shadow-sm: 0 1px 2px rgba(45, 38, 28, 0.08);
  --shadow-md: 0 1px 2px rgba(45, 38, 28, 0.05), 0 8px 20px -8px rgba(45, 38, 28, 0.18);
  --shadow-lg: 0 2px 6px rgba(45, 38, 28, 0.06), 0 16px 32px -12px rgba(45, 38, 28, 0.24);
  /* audit-added tokens */
  --accent-highlight: #EBD9A3;
  --accent-highlight-hover: #DFC98E;
  --accent-highlight-soft: #F0E4B8;
  --btn-fill: #8A5F22; --btn-fill-text: #FFFFFF; --btn-fill-hover: #6E4C1B;   /* V1：實色深金掣（同 student/teacher 一致） */
  --accent-info: #3C3A94;
  --accent-info-ring: rgba(60, 58, 148, 0.15);
  --accent-link: #3C3A94;
  --accent-purple: #8A5F22;
  --accent-code-badge: #8A5F22;
  --badge-purple-bg: rgba(60, 58, 148, 0.12);
  --badge-purple-color: #3C3A94;
  --text-ink-strong: #23201B;
  --text-ink-body: #2A2620;
  --text-strong: #23201B;
  --paper-text: #23201B;
  --paper-text-secondary: #6E665C;
  --paper-text-muted: #857C6E;
  --paper-border: #C9BCA8;
  --text-ios-grey: #57514A;
  --text-ios-grey-2: #857C6E;
  --text-grey: #7C736A;
  --text-grey-strong: #857C6E;
  --step-tab-text: #57514A;
  --separator: #EAE5DD;
  --separator-strong: #DAD3C8;
  --border-control: #D8D2C8;
  --border-grey-mid: #B7AF9F;
  --border-row: #E4DED4;
  --border-ink-soft: #E0DAD0;
  --border-hairline-08: rgba(35, 32, 27, 0.08);
  --border-hairline-06: rgba(35, 32, 27, 0.06);
  --surface-grey: #EFEBE3;
  --surface-hover: #E9E4DB;
  --surface-muted: #EEE9E0;
  --surface-label: #E4DFD6;
  --surface-off-white: #FBFAF6;
  --surface-pressed: #E4DDD2;
  --track-grey: #E4DED4;
  --header-cream: #F1EDE6;
  --surface-warm-1: #EFEBE3;
  --surface-warm-2: #F2EEE6;
  --surface-warm-3: #F0EBDF;
  --overlay-cream: rgba(246, 244, 239, 0.75);
  --glass-bg-header: rgba(246, 244, 239, 0.72);
  --shadow-xs: 0 1px 3px rgba(35, 32, 27, 0.10);
  --shadow-badge: 0 1px 2px rgba(35, 32, 27, 0.08);
  --shadow-card: 0 2px 8px rgba(35, 32, 27, 0.10);
  --shadow-dash: 0 2px 6px rgba(35, 32, 27, 0.10);
  --shadow-xl: 0 12px 32px rgba(35, 32, 27, 0.14);
}

/* ==========================================================================
   Version 3 · Bold Blue — 承 [data-theme="e"] 個暖底，只把暖金 accent 換成靛藍、
   紙色調涼少少，令主色由「暖 + 靛藍輕 accent」變「濃靛藍」。primary #3C3A94 沿用。
   ========================================================================== */
[data-theme="v3"] {
  --bg-primary: #F3F3F8;
  --glass-bg-hover: #E7E6F6;
  --accent-secondary: #514FB0;
  --accent-secondary-hover: #3C3A94;
  --accent-highlight: #C9C7EC;
  --accent-highlight-hover: #B4B1E4;
  --accent-highlight-soft: #E7E6F6;
  --btn-fill: #3C3A94; --btn-fill-text: #FFFFFF; --btn-fill-hover: #2E2C78;   /* V3：實色深靛藍掣（同 student/teacher 一致） */
  --accent-purple: #514FB0;
  --accent-code-badge: #3C3A94;
  --paper-border: #C3C0E0;
  --header-cream: #EEEEF5;
  --overlay-cream: rgba(243, 243, 248, 0.75);
  --glass-bg-header: rgba(243, 243, 248, 0.72);
}


/* ==========================================================================
   2. CSS Reset & Base Styles
   ========================================================================== */

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

/* --- Base document --- */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- Links --- */
a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--transition-base);
}

a:hover {
  color: var(--accent-primary-hover);
}

/* --- Images --- */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* --- Lists --- */
ul, ol {
  list-style: none;
}

/* --- Focus visible --- */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}


/* ==========================================================================
   3. Custom Scrollbar
   ========================================================================== */

/* Webkit scrollbar (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}


/* ==========================================================================
   4. Keyframe Animations
   ========================================================================== */

/* Fade in from transparent */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Slide up into view with fade */
@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Slide in from right (paper tray, modals) */
@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

/* Slide up from bottom (bottom sheets on mobile) */
@keyframes slideUpSheet {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* Subtle pulse for loading indicators */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.05); opacity: 0.7; }
}

/* Continuous spin for spinners */
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* Scale in for modals */
@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}


/* ==========================================================================
   5. App Header
   ========================================================================== */

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--glass-bg-header);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  padding: 0 var(--space-6);
  z-index: var(--z-header);
  gap: 0 !important;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.header-center {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1.2;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
  flex: 1.5;
  min-width: 0;
}

/* Logo / app title area */
.app-header__logo {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  white-space: nowrap;
}

.app-header__logo-icon {
  font-size: var(--font-size-xl);
}

/* Breadcrumb navigation */
.app-header__breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  flex: 0 1 auto !important;
  min-width: 0;
}

.app-header__breadcrumb-separator {
  color: var(--text-muted);
  opacity: 0.5;
}

.app-header__breadcrumb-current {
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Header action buttons group */
.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Back button */
.app-header__back {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
}

.app-header__back:hover {
  color: var(--text-primary);
  background: var(--glass-bg);
}


/* ==========================================================================
   6. Home Screen — Subject Cards Grid
   ========================================================================== */

.home-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  animation: fadeIn 0.6s ease;
}

.home-screen__title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-2);
  text-align: center;
}

.home-screen__subtitle {
  color: var(--text-secondary);
  font-size: var(--font-size-md);
  margin-bottom: var(--space-10);
  text-align: center;
}

/* Subject cards grid container */
.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--subject-card-size), 1fr));
  gap: var(--space-6);
  max-width: 900px;
  width: 100%;
}

/* --- Individual Subject Card --- */
.subject-card {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  cursor: pointer;
  transition: all var(--transition-slow);
  animation: slideUp 0.5s ease both;
  text-align: center;
  padding: var(--space-4);
}

/* Staggered animation delays for cards */
.subject-card:nth-child(1) { animation-delay: 0ms; }
.subject-card:nth-child(2) { animation-delay: 60ms; }
.subject-card:nth-child(3) { animation-delay: 120ms; }
.subject-card:nth-child(4) { animation-delay: 180ms; }
.subject-card:nth-child(5) { animation-delay: 240ms; }
.subject-card:nth-child(6) { animation-delay: 300ms; }
.subject-card:nth-child(7) { animation-delay: 360ms; }
.subject-card:nth-child(8) { animation-delay: 420ms; }

/* Hover: lift card with a soft glow */
.subject-card:hover {
  transform: translateY(-6px);
  border-color: rgba(255, 255, 255, 0.12);
  background: var(--glass-bg-hover);
  box-shadow: var(--shadow-lg), var(--shadow-glow-blue);
}

/* Card icon */
.subject-card__icon {
  font-size: 2.5rem;
  line-height: 1;
}

/* Subject name */
.subject-card__name {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

/* Question count shown on card */
.subject-card__count {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* --- "Add New Subject" Card Variant --- */
.subject-card--add {
  border-style: dashed;
  border-width: 2px;
  border-color: rgba(255, 255, 255, 0.1);
  background: transparent;
  color: var(--text-muted);
}

.subject-card--add:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-primary-muted);
  box-shadow: var(--shadow-glow-blue);
}

.subject-card--add .subject-card__icon {
  font-size: 2rem;
  opacity: 0.6;
}


/* ==========================================================================
   7. App Layout — Three-Column Structure
   ========================================================================== */

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: var(--header-height);
}

/* --- Sidebar (Left Column) --- */
.sidebar {
  position: fixed;
  top: calc(var(--header-height) + var(--steps-bar-height));
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--glass-border);
  overflow-y: auto;
  z-index: var(--z-sidebar);
  transition: transform var(--transition-slow);
}

/* --- Main Content (Center Column) --- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  margin-right: var(--paper-tray-width);
  padding: var(--space-6);
  min-height: calc(100vh - var(--header-height) - var(--steps-bar-height));
  transition: margin var(--transition-slow);
}

/* Toolbar above the question grid */
.main-content__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}

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

.main-content__toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.main-content__count {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Question grid layout (re-styled to vertical column list) */
.question-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  width: 100%;
}

/* --- Paper Tray (Right Column) --- */
.paper-tray {
  position: fixed;
  top: calc(var(--header-height) + var(--steps-bar-height));
  right: 0;
  bottom: 0;
  width: var(--paper-tray-width);
  background: var(--bg-secondary);
  border-left: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-paper-tray);
  animation: slideInRight 0.4s ease;
  transition: transform var(--transition-slow);
}

/* Collapsed state — hidden off-screen */
.paper-tray--collapsed {
  transform: translateX(100%);
}

/* Paper tray header bar */
.paper-tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.paper-tray-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
}

/* Scrollable list of paper items */
.paper-items {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
}

/* Individual draggable item in the paper tray */
.paper-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
  cursor: grab;
  transition: all var(--transition-base);
}

.paper-item:hover {
  background: var(--glass-bg-hover);
  border-color: rgba(255, 255, 255, 0.1);
}

/* Drag handle indicator */
.paper-item__drag {
  color: var(--text-muted);
  cursor: grab;
  font-size: var(--font-size-md);
  flex-shrink: 0;
}

/* Small thumbnail in paper item */
.paper-item__thumb {
  width: 48px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

/* Item metadata */
.paper-item__info {
  flex: 1;
  min-width: 0;
}

.paper-item__code {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paper-item__score {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* Remove button on paper item */
.paper-item__remove {
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
  flex-shrink: 0;
  font-size: var(--font-size-md);
}

.paper-item__remove:hover {
  color: var(--color-danger);
  background: var(--color-danger-muted);
}

/* Paper summary bar (totals) */
.paper-summary {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  font-size: var(--font-size-sm);
}

.paper-summary__label {
  color: var(--text-secondary);
}

.paper-summary__value {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

/* Export/preview buttons row */
.paper-actions {
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
}

.paper-actions .btn {
  flex: 1;
}


/* ==========================================================================
   8. Filter Panel (Sidebar Content)
   ========================================================================== */

.filter-panel {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Each filter group: label + control */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

details.filter-group {
  border: 2px solid var(--glass-border) !important;
  background-color: var(--bg-secondary) !important;
  border-radius: 6px !important;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm) !important;
  display: block;
}

summary.filter-label {
  padding: 10px 14px 10px 24px;
  font-weight: 800;
  font-size: 13px;
  color: var(--text-primary) !important;
  background-color: var(--bg-primary) !important;
  border-bottom: 2px solid var(--glass-border) !important;
  cursor: pointer;
  user-select: none;
  display: list-item;
}

details.filter-group:not([open]) summary.filter-label {
  border-bottom: none !important;
}

.filter-group__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Styled Dark Select Dropdown --- */
.filter-select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  padding-right: var(--space-8);
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all var(--transition-base);
  /* Custom dropdown arrow */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8.5L1 3.5h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
}

.filter-select:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.filter-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

/* --- Search Box --- */
.search-box {
  position: relative;
}

.search-box__icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  pointer-events: none;
}

.search-box__input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  padding-left: var(--space-8);
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  transition: all var(--transition-base);
}

.search-box__input::placeholder {
  color: var(--text-muted);
}

.search-box__input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

/* --- Tag Chips Container --- */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Individual toggleable tag chip */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  transition: all var(--transition-base);
  user-select: none;
}

.tag-chip:hover {
  background: var(--glass-bg-hover);
  border-color: rgba(255, 255, 255, 0.12);
}

/* Active / selected state */
.tag-chip--active {
  background: var(--accent-primary-muted);
  border-color: var(--accent-primary);
  color: var(--accent-primary-hover);
}

/* Color-coded tag variants */
.tag-chip--blue    { --chip-color: var(--accent-primary); }
.tag-chip--purple  { --chip-color: var(--accent-secondary); }
.tag-chip--green   { --chip-color: var(--color-success); }
.tag-chip--yellow  { --chip-color: var(--color-warning); }
.tag-chip--red     { --chip-color: var(--color-danger); }

.tag-chip--blue.tag-chip--active,
.tag-chip--purple.tag-chip--active,
.tag-chip--green.tag-chip--active,
.tag-chip--yellow.tag-chip--active,
.tag-chip--red.tag-chip--active {
  background: color-mix(in srgb, var(--chip-color) 15%, transparent);
  border-color: var(--chip-color);
  color: var(--chip-color);
}


/* ==========================================================================
   9. Question Cards
   ========================================================================== */

.question-card {
  position: relative;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-base);
  animation: slideUp 0.4s ease both;
}

/* Staggered card entrance — applied via JS or nth-child */
.question-card:nth-child(1)  { animation-delay: 0ms; }
.question-card:nth-child(2)  { animation-delay: 30ms; }
.question-card:nth-child(3)  { animation-delay: 60ms; }
.question-card:nth-child(4)  { animation-delay: 90ms; }
.question-card:nth-child(5)  { animation-delay: 120ms; }
.question-card:nth-child(6)  { animation-delay: 150ms; }
.question-card:nth-child(7)  { animation-delay: 180ms; }
.question-card:nth-child(8)  { animation-delay: 210ms; }
.question-card:nth-child(9)  { animation-delay: 240ms; }
.question-card:nth-child(10) { animation-delay: 270ms; }
.question-card:nth-child(11) { animation-delay: 300ms; }
.question-card:nth-child(12) { animation-delay: 330ms; }

/* Hover: border highlight */
.question-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-md);
}

/* Selected state — blue border + tinted background */
.question-card--selected {
  border-color: var(--accent-primary);
  background: var(--accent-primary-muted);
}

.question-card--selected:hover {
  border-color: var(--accent-primary-hover);
}

/* Thumbnail image area */
.question-card__thumb {
  width: 100%;
  height: var(--question-thumb-height);
  object-fit: cover;
  background: var(--bg-tertiary);
  display: block;
}

/* Card body content */
.question-card__body {
  padding: var(--space-3);
}

/* Top row: code + score */
.question-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.question-card__code {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tag chips row within card */
.question-card__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* Selection checkbox overlay */
.question-card__checkbox {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  cursor: pointer;
  color: transparent;
  font-size: var(--font-size-sm);
}

.question-card__checkbox:hover {
  border-color: var(--accent-primary);
}

/* Checked state */
.question-card--selected .question-card__checkbox {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: var(--text-inverse);
}


/* ==========================================================================
   10. Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1.4;
  cursor: pointer;
  transition: all var(--transition-base);
  white-space: nowrap;
  user-select: none;
}

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

/* Primary — filled blue */
.btn--primary {
  background: var(--accent-primary);
  color: var(--text-inverse);
  border-color: var(--accent-primary);
}

.btn--primary:hover {
  background: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
  box-shadow: var(--shadow-glow-blue);
}

/* Secondary — outlined */
.btn--secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--glass-border);
}

.btn--secondary:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Danger — red */
.btn--danger {
  background: var(--color-danger);
  color: var(--text-inverse);
  border-color: var(--color-danger);
}

.btn--danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

/* Ghost — no border, minimal */
.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: var(--space-2);
}

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

/* Small variant */
.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--font-size-xs);
}

/* Icon-only button */
.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}


/* ==========================================================================
   11. Badges
   ========================================================================== */

/* Score / count badge */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* Score badge with blue accent */
.badge--score {
  background: var(--accent-primary-muted);
  color: var(--accent-primary-hover);
}

/* Tag badge — color coding via CSS custom prop */
.badge--tag {
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  background: var(--badge-bg, var(--bg-tertiary));
  color: var(--badge-color, var(--text-secondary));
}

/* Predefined tag badge color variants */
.badge--blue {
  --badge-bg: var(--accent-primary-muted);
  --badge-color: var(--accent-primary-hover);
}

.badge--purple {
  --badge-bg: var(--badge-purple-bg);
  --badge-color: var(--badge-purple-color);
}

.badge--green {
  --badge-bg: var(--color-success-muted);
  --badge-color: var(--color-success);
}

.badge--yellow {
  --badge-bg: var(--color-warning-muted);
  --badge-color: var(--color-warning);
}

.badge--red {
  --badge-bg: var(--color-danger-muted);
  --badge-color: var(--color-danger);
}


/* ==========================================================================
   12. Toggle Switch
   ========================================================================== */

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.toggle__track {
  width: 40px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  position: relative;
  transition: all var(--transition-base);
}

.toggle__thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: all var(--transition-base);
}

/* Active state */
.toggle--active .toggle__track {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.toggle--active .toggle__thumb {
  left: 20px;
  background: var(--text-inverse);
}

.toggle__label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}


/* ==========================================================================
   13. Modals
   ========================================================================== */

/* Full-screen overlay backdrop */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  animation: fadeIn 0.2s ease;
}

/* Base modal container */
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  width: 500px;
  max-width: 100%;
  z-index: var(--z-modal);
  animation: scaleIn 0.25s ease;
  overflow: hidden;
}

/* Medium modal — for editors */
.modal--medium {
  width: 600px;
}

/* Large modal — for previews, full-screen content */
.modal--large {
  width: 90vw;
  height: 90vh;
}

/* Modal header */
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.modal-header__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.modal-header__close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--font-size-xl);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
  line-height: 1;
}

.modal-header__close:hover {
  color: var(--text-primary);
  background: var(--glass-bg-hover);
}

/* Modal body — scrollable */
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6);
}

/* Modal footer — action buttons */
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--glass-border);
  flex-shrink: 0;
}


/* ==========================================================================
   14. Question Detail (inside modal)
   ========================================================================== */

.question-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Large image display */
.question-detail__image {
  width: 100%;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
}

/* Metadata row */
.question-detail__meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
}

.question-detail__meta-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.question-detail__meta-label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.question-detail__meta-value {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
}

/* Tags row */
.question-detail__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Solution toggle section */
.question-detail__solution {
  border-top: 1px solid var(--glass-border);
  padding-top: var(--space-5);
}

.question-detail__solution-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  font-weight: var(--font-weight-medium);
  color: var(--accent-primary);
  margin-bottom: var(--space-3);
}

.question-detail__solution-content {
  padding: var(--space-4);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
}


/* ==========================================================================
   15. Question Editor (inside modal)
   ========================================================================== */

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

/* Form field group */
.question-editor__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.question-editor__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

/* Text input and textarea */
.question-editor__input,
.question-editor__textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  transition: all var(--transition-base);
}

.question-editor__textarea {
  min-height: 100px;
  resize: vertical;
}

.question-editor__input:focus,
.question-editor__textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

/* --- Image Upload Zone --- */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
  color: var(--text-muted);
  min-height: 160px;
}

.upload-zone:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-muted);
  color: var(--accent-primary-hover);
}

/* Active drag state */
.upload-zone--active {
  border-color: var(--accent-primary);
  background: var(--accent-primary-muted);
}

.upload-zone__icon {
  font-size: var(--font-size-2xl);
}

.upload-zone__text {
  font-size: var(--font-size-sm);
}

.upload-zone__hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

/* Preview of uploaded image */
.upload-zone__preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
}

/* Tag selector within editor */
.question-editor__tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}


/* ==========================================================================
   16. Paper Preview (A4 Simulation)
   ========================================================================== */

.paper-preview {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-8);
  background: var(--bg-primary);
  min-height: 100%;
  overflow-y: auto;
}

/* A4 paper sheet */
.paper-preview__sheet {
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  background: var(--bg-secondary);
  color: var(--paper-text);
  padding: 20mm 25mm;
  box-shadow: 0 4px 40px rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  font-family: "Georgia", "Times New Roman", "Noto Serif TC", "PMingLiU", serif;
  font-size: 12pt;
  line-height: 1.8;
}

/* Paper header: school name, subject, date */
.paper-preview__header {
  text-align: center;
  margin-bottom: 8mm;
  padding-bottom: 4mm;
  border-bottom: 2px solid var(--paper-border);
}

.paper-preview__school {
  font-size: 18pt;
  font-weight: var(--font-weight-bold);
  margin-bottom: 2mm;
}

.paper-preview__subject {
  font-size: 14pt;
  font-weight: var(--font-weight-semibold);
  margin-bottom: 1mm;
}

.paper-preview__info {
  font-size: 10pt;
  color: var(--paper-text-secondary);
  display: flex;
  justify-content: space-between;
  margin-top: 3mm;
}

/* Individual numbered question */
.paper-preview__question {
  margin-bottom: 6mm;
  page-break-inside: avoid;
}

.paper-preview__question-number {
  font-weight: var(--font-weight-bold);
  margin-right: 2mm;
}

.paper-preview__question-marks {
  float: right;
  font-size: 10pt;
  color: var(--paper-text-muted);
}

.paper-preview__question-image {
  max-width: 100%;
  margin: 3mm 0;
}


/* ==========================================================================
   17. Word Import (inside modal)
   ========================================================================== */

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

/* Large drop zone */
.word-import__dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-12);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
  color: var(--text-muted);
}

.word-import__dropzone:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-muted);
}

.word-import__dropzone-icon {
  font-size: 3rem;
}

.word-import__dropzone-text {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.word-import__dropzone-hint {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Content preview area */
.word-import__preview {
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  max-height: 400px;
  overflow-y: auto;
}

/* Split tools */
.word-import__tools {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}


/* ==========================================================================
   18. Dropdown (Custom Styled)
   ========================================================================== */

.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: all var(--transition-base);
}

.dropdown__trigger:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  min-width: 180px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: 50;
  animation: slideUp 0.15s ease;
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.dropdown__item:hover {
  background: var(--glass-bg-hover);
  color: var(--text-primary);
}

.dropdown__item--active {
  background: var(--accent-primary-muted);
  color: var(--accent-primary-hover);
}


/* ==========================================================================
   19. Empty State & Loading
   ========================================================================== */

/* Centered message when no results / empty list */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
  gap: var(--space-4);
  animation: fadeIn 0.4s ease;
}

.empty-state__icon {
  font-size: 3rem;
  opacity: 0.4;
}

.empty-state__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.empty-state__text {
  font-size: var(--font-size-sm);
  max-width: 360px;
}

/* --- Loading Spinner --- */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
}

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

/* Smaller inline spinner */
.loading__spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

/* Pulse animation for skeleton loading */
.loading--pulse {
  animation: pulse 1.5s ease-in-out infinite;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}


/* ==========================================================================
   20. Toast Notifications
   ========================================================================== */

/* Container — fixed bottom-right */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideUp 0.3s ease;
  max-width: 380px;
}

.toast__icon {
  flex-shrink: 0;
  font-size: var(--font-size-md);
}

.toast__message {
  flex: 1;
}

.toast__close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1);
  font-size: var(--font-size-md);
  transition: color var(--transition-fast);
}

.toast__close:hover {
  color: var(--text-primary);
}

/* Toast color variants — left-side accent bar */
.toast--success { border-left: 3px solid var(--color-success); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--danger  { border-left: 3px solid var(--color-danger); }
.toast--info    { border-left: 3px solid var(--accent-primary); }


/* ==========================================================================
   21. Utility Classes
   ========================================================================== */

/* Text helpers */
.text-muted    { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary  { color: var(--text-primary); }
.text-accent   { color: var(--accent-primary); }
.text-center   { text-align: center; }
.text-sm       { font-size: var(--font-size-sm); }
.text-xs       { font-size: var(--font-size-xs); }

/* Flex helpers */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2       { gap: var(--space-2); }
.gap-3       { gap: var(--space-3); }
.gap-4       { gap: var(--space-4); }

/* Spacing */
.mt-4  { margin-top: var(--space-4); }
.mb-4  { margin-bottom: var(--space-4); }

/* Truncation */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Visually hidden (accessible) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ==========================================================================
   22. Print Styles
   Hide all chrome; show only paper preview content on white background.
   ========================================================================== */

@media print {
  /* Hide application UI elements */
  .app-header,
  .sidebar,
  .paper-tray,
  .modal-overlay,
  .modal-header__close,
  .modal-footer,
  .toast-container,
  .btn,
  .filter-panel,
  .main-content__toolbar {
    display: none !important;
  }

  /* Reset page to white */
  html, body {
    background: #fff !important;
    color: var(--text-primary) !important;
    font-size: 12pt;
  }

  /* Remove fixed positioning */
  .app-layout {
    display: block;
  }

  .main-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Paper preview sheet adjustments */
  #modal-paper-preview {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: auto !important;
    background: none !important;
  }
  #modal-paper-preview .modal {
    background: none !important;
    box-shadow: none !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  #modal-paper-preview .modal-header {
    display: none !important;
  }
  #modal-paper-preview .modal-body {
    padding: 0 !important;
    overflow: visible !important;
  }

  .paper-preview {
    padding: 0;
    background: none;
  }

  .paper-preview__sheet {
    box-shadow: none;
    width: 100%;
    padding: 15mm 20mm;
    min-height: auto;
  }

  /* Ensure images print */
  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  /* Page break control */
  .paper-preview__question {
    page-break-inside: avoid;
  }

  /* Remove animations and transitions */
  * {
    animation: none !important;
    transition: none !important;
  }
}


/* ==========================================================================
   23. Responsive — Tablet (below 1200px)
   Collapse paper tray to a bottom sheet overlay.
   ========================================================================== */

@media (max-width: 1200px) {
  /* Remove right margin, paper tray becomes overlay */
  .main-content {
    margin-right: 0;
  }

  /* Paper tray transforms into a bottom sheet */
  .paper-tray {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--glass-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: slideUpSheet 0.4s ease;
    z-index: var(--z-paper-tray);
  }

  /* Collapsed = hidden below screen */
  .paper-tray--collapsed {
    transform: translateY(100%);
  }

  /* Add a drag handle at the top of the bottom sheet */
  .paper-tray-header::before {
    content: '';
    position: absolute;
    top: var(--space-2);
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.2);
  }

  .paper-tray-header {
    position: relative;
    padding-top: var(--space-6);
  }
}


/* ==========================================================================
   24. Responsive — Mobile (below 768px)
   Sidebar becomes hamburger overlay. Simplify grid.
   ========================================================================== */

@media (max-width: 768px) {
  /* Sidebar becomes off-screen overlay */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    z-index: calc(var(--z-header) + 10);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-lg);
    padding-top: var(--header-height);
  }

  /* Visible state — toggled via JS */
  .sidebar--open {
    transform: translateX(0);
  }

  /* Main content takes full width */
  .main-content {
    margin-left: 0;
    margin-right: 0;
    padding: var(--space-4);
  }

  /* Simplify question grid to 2 columns */
  .question-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
  }

  /* Reduce subject card sizes */
  .subjects-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-4);
  }

  /* Header adjustments */
  .app-header {
    padding: 0 var(--space-4);
  }

  .app-header__breadcrumb {
    display: none;
  }

  /* Modals go full-width on mobile */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: 95vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }

  .modal--large {
    width: 100%;
    height: 95vh;
  }

  /* Paper preview adjustments for small screens */
  .paper-preview__sheet {
    padding: 10mm 12mm;
    font-size: 10pt;
  }

  /* Toast adjustments */
  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    bottom: var(--space-4);
  }

  .toast {
    max-width: 100%;
  }
}

/* --- Very small screens (below 480px) --- */
@media (max-width: 480px) {
  .question-grid {
    grid-template-columns: 1fr;
  }

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

  .home-screen__title {
    font-size: var(--font-size-xl);
  }
}


/* ==========================================================================
   25. Sidebar Overlay Backdrop (Mobile)
   Shown behind the sidebar when it's open on mobile.
   ========================================================================== */

.sidebar-backdrop {
  display: none;
}

@media (max-width: 768px) {
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-header) + 5);
  }

  .sidebar-backdrop--visible {
    display: block;
    animation: fadeIn 0.2s ease;
  }
}


/* ==========================================================================
   26. Hamburger Menu Button (Mobile only)
   ========================================================================== */

.hamburger {
  display: none;
  background: none;
  border: 2px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  cursor: pointer;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 768px) {
  .hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Form Layout and Element Styles (Aliases for Editor/Modals) */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  width: 100%;
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  display: block;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  transition: all var(--transition-base);
  box-sizing: border-box;
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

.form-row {
  display: flex;
  gap: var(--space-3);
  width: 100%;
}

.form-row--3 > * {
  flex: 1;
  min-width: 0;
}

/* Loading Screen Styles */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-primary);
  z-index: var(--z-modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 400px;
  width: 90%;
  padding: var(--space-8);
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: fadeIn 0.4s ease;
  box-sizing: border-box;
}

.loading-icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  line-height: 1;
  animation: pulse 2s infinite ease-in-out;
}

.loading-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-2);
  color: var(--text-primary);
}

.loading-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-6);
}

.loading-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: var(--space-4);
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.loading-status {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
}

/* Utility class to hide elements */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Design Blueprint Overrides
   ========================================================================== */

/* --- macOS Window Controls & Branding --- */
.window-controls {
  display: flex;
  gap: 8px;
  margin-right: 16px;
  align-items: center;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot--red { background-color: #FF5F56; }
.dot--yellow { background-color: #FFBD2E; }
.dot--green { background-color: #27C93F; }

/* Removed old dark mode overrides to support Cosmic Brutalist Fusion light mode */

/* ==========================================================================
   22. Steps Tab Bar
   ========================================================================== */
.steps-tab-bar {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  align-items: center;
  height: 100%;
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-bottom: none !important;
  padding: 0 !important;
  position: static !important;
  box-shadow: none !important;
  z-index: auto !important;
}

/* --- Step panels container (under the horizontal steps bar) --- */
.app-body {
  display: flex;
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  margin-top: var(--steps-bar-height);
  min-height: calc(100vh - var(--header-height) - var(--steps-bar-height));
}

/* --- Premium Horizontal Question Card --- */
.question-card-horizontal {
  display: flex;
  background-color: var(--bg-secondary);
  color: var(--text-ink-strong);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hairline-08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transition: transform var(--transition-base), box-shadow var(--transition-base);
  width: 100%;
  box-sizing: border-box;
}

.question-card-horizontal:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.question-card-horizontal--selected {
  border-color: var(--accent-info);
  box-shadow: 0 0 0 2px var(--accent-info-ring), var(--shadow-lg);
}

/* Left panel for checkboxes and action icons */
.question-card-horizontal__left-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--space-4);
  border-right: 1px solid var(--separator);
  background-color: var(--surface-grey);
  gap: var(--space-4);
  width: 70px;
  min-width: 70px;
  box-sizing: border-box;
}

/* Custom Checkbox */
.question-card-horizontal__checkbox-label {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.question-card-horizontal__checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-control);
  background: var(--bg-secondary);
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.question-card-horizontal__checkbox:checked {
  background: var(--accent-info);
  border-color: var(--accent-info);
}

.question-card-horizontal__checkbox:checked::after {
  content: "";
  width: 10px;
  height: 5px;
  border-left: 2px solid var(--text-inverse);
  border-bottom: 2px solid var(--text-inverse);
  transform: rotate(-45deg);
  position: absolute;
  top: 5px;
}

/* Middle body: Question content area */
.question-card-horizontal__body {
  flex: 1;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background-color: var(--bg-secondary);
  overflow: hidden;
  box-sizing: border-box;
}

/* Local Language Selector */
.question-card-horizontal__lang-toggle {
  display: flex;
  gap: 2px;
  background-color: var(--separator);
  padding: 2px;
  border-radius: var(--radius-sm);
  align-self: flex-start;
  user-select: none;
}

.question-card-horizontal__lang-btn {
  background: transparent;
  border: none;
  padding: 4px 12px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--text-ios-grey);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.question-card-horizontal__lang-btn.active {
  background-color: var(--bg-secondary);
  color: var(--text-ink-strong);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.question-card-horizontal__content-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 160px;
  width: 100%;
}

.question-card-horizontal__img {
  max-width: 100%;
  max-height: 250px;
  object-fit: contain;
}

.question-card-horizontal__text-fallback {
  font-family: "Georgia", "Times New Roman", "Noto Serif TC", "PMingLiU", serif;
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-ink-body);
  white-space: pre-wrap;
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-secondary);
  border: none;
  box-shadow: none;
  tab-size: 4;
  -moz-tab-size: 4;
  box-sizing: border-box;
}

/* Detail modal text paper classes */
.detail-text-paper {
  font-family: "Georgia", "Times New Roman", "Noto Serif TC", "PMingLiU", serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  padding: 20px 24px;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: none;
  margin-bottom: 16px;
  tab-size: 4;
  -moz-tab-size: 4;
  width: 100%;
  box-sizing: border-box;
}

.detail-text-paper--solution {
  font-size: 15px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid var(--accent-primary);
  border-color: var(--glass-border) var(--glass-border) var(--glass-border) var(--accent-primary);
  margin-top: 8px;
}

/* Detail modal image container */
.detail-image-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--bg-secondary);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
  min-height: 120px;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-4);
}

.detail-image {
  max-width: 100%;
  max-height: 350px;
  object-fit: contain;
  display: block;
}

/* Detail modal solution content paper container */
.detail-solution-content {
  background-color: var(--bg-secondary);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--separator);
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.detail-solution-content .detail-image {
  background-color: var(--bg-secondary);
}

.detail-solution-content .detail-text-paper--solution {
  background: transparent;
  color: var(--text-ink-body);
  border: none;
  border-left: 3px solid var(--accent-primary);
  padding: 8px 12px;
  margin-top: 0;
  margin-bottom: 0;
  width: 100%;
}

/* Right panel: Metadata detail table */
.question-card-horizontal__right-meta {
  width: 320px;
  min-width: 320px;
  padding: var(--space-4);
  background-color: var(--surface-grey);
  border-left: 1px solid var(--separator);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-sizing: border-box;
}

.question-card-horizontal__meta-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.question-card-horizontal__code-badge {
  background-color: var(--accent-code-badge);
  color: var(--text-inverse);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.question-card-horizontal__meta-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 4px;
}

.question-card-horizontal__meta-table td {
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--separator);
  vertical-align: middle;
}

.question-card-horizontal__meta-table td.label {
  font-weight: 600;
  color: var(--text-ios-grey-2);
  background-color: var(--surface-label);
  width: 75px;
  text-align: right;
}

.question-card-horizontal__meta-table td.value {
  color: var(--text-ink-strong);
  background-color: var(--bg-secondary);
}

.question-card-horizontal__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: auto;
  width: 100%;
}

.question-card-horizontal__btn-toggle {
  flex: 1;
}

/* Inline Solution Panel */
.question-card-horizontal__solution-wrapper {
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  align-self: flex-start;
  width: 100%;
}

.question-card-horizontal__btn-toggle-sol {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background-color: transparent;
  border: 1px solid var(--separator);
  color: var(--accent-info);
  padding: 6px 12px;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  align-self: flex-start;
  user-select: none;
}

.question-card-horizontal__btn-toggle-sol:hover {
  background-color: var(--surface-hover);
  border-color: var(--separator-strong);
}

.question-card-horizontal__sol-box {
  margin-top: var(--space-3);
  padding: var(--space-4);
  background-color: var(--surface-grey);
  border-radius: var(--radius-md);
  border: 1px dashed var(--separator);
  width: 100%;
  box-sizing: border-box;
  animation: fadeIn 0.2s ease-out;
}

.question-card-horizontal__sol-box.hidden {
  display: none;
}

.question-card-horizontal__sol-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  color: var(--accent-info);
  margin-bottom: var(--space-2);
  display: block;
}

.question-card-horizontal__sol-box-content {
  width: 100%;
}

.question-card-horizontal__sol-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question-card-horizontal__sol-img {
  max-width: 100%;
  max-height: 250px;
  object-fit: contain;
  display: block;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  padding: 4px;
}

.question-card-horizontal__sol-text {
  font-family: "Georgia", "Times New Roman", "Noto Serif TC", "PMingLiU", serif;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-ink-body);
  white-space: pre-wrap;
  padding: 12px 16px;
  background-color: var(--surface-off-white);
  border-left: 3px solid var(--border-grey-mid);
  border-color: var(--separator) var(--separator) var(--separator) var(--border-grey-mid);
  border-radius: 4px;
  margin-top: 8px;
  tab-size: 4;
  -moz-tab-size: 4;
  box-sizing: border-box;
  width: 100%;
}

/* --- Premium Pagination Controls --- */
.pagination-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background-color: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-hairline-06);
  box-shadow: var(--shadow-sm);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.pagination-header__left {
  display: flex;
  gap: var(--space-2);
}

.pagination-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pagination-header__center {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pagination-size-label {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.pagination-size-select {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  background-color: var(--bg-secondary);
  font-size: var(--font-size-sm);
  color: var(--text-ink-strong);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.pagination-size-select:focus {
  border-color: var(--accent-info);
}

.pagination-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
  margin-bottom: var(--space-6);
}

.pagination-pages {
  display: flex;
  gap: 4px;
}

.pagination-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--separator);
  background-color: var(--bg-secondary);
  color: var(--text-ink-strong);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination-page-btn:hover {
  background-color: var(--surface-hover);
  border-color: var(--separator-strong);
}

.pagination-page-btn.active {
  background-color: var(--accent-info);
  border-color: var(--accent-info);
  color: var(--text-inverse);
}

.pagination-page-btn.disabled {
  background-color: transparent;
  border-color: transparent;
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.pagination-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  cursor: pointer;
}

.pagination-nav-btn.disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* Custom outline button modifications */
.btn--outline {
  background-color: var(--bg-secondary);
  border: 1px solid var(--separator);
  color: var(--text-ink-strong);
  font-size: var(--font-size-xs);
  padding: 6px 12px;
  font-weight: var(--font-weight-medium);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.btn--outline:hover {
  background-color: var(--surface-hover);
  border-color: var(--separator-strong);
}
.btn--danger-outline {
  color: var(--color-danger);
  border-color: rgba(255, 69, 58, 0.2);
}
.btn--danger-outline:hover {
  background-color: rgba(255, 69, 58, 0.05);
  border-color: var(--color-danger);
}

.step-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.step-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.step-tab.active {
  color: var(--accent-info);
  background: rgba(10, 132, 255, 0.08);
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  transition: all var(--transition-base);
}

.step-tab.active .step-num {
  background: var(--accent-info);
  color: var(--text-inverse);
}

/* ==========================================================================
   23. Left Sidebar Checkbox Tree
   ========================================================================== */
.sidebar-tree {
  max-height: 350px;
  overflow-y: auto;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.tree-node {
  margin-bottom: var(--space-1);
}

.tree-node-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
}

.tree-node-summary:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

/* Hide default detail summary marker */
.tree-node-summary::-webkit-details-marker {
  display: none;
}

.tree-arrow {
  color: var(--text-muted);
  font-size: 11px;
  width: 12px;
  display: inline-block;
  transition: transform 0.2s ease;
}

details.tree-node[open] > summary > .tree-arrow {
  transform: rotate(90deg);
}

.tree-node-children {
  margin-left: 20px;
  padding-left: 8px;
  border-left: 1px dashed rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: 4px;
}

.tree-topic-node {
  min-width: 0;
}

.tree-topic-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  cursor: pointer;
  list-style: none;
}

.tree-topic-summary::-webkit-details-marker {
  display: none;
}

.tree-topic-summary::before {
  content: "\25B6";
  flex: 0 0 10px;
  color: var(--text-muted);
  font-size: 9px;
  transition: transform 0.2s ease;
}

.tree-topic-node[open] > .tree-topic-summary::before {
  transform: rotate(90deg);
}

.tree-skill-children {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 3px 0 6px 16px;
  padding-left: 10px;
  border-left: 1px solid var(--glass-border);
}

.tree-skill-label {
  line-height: 1.35;
}

/* Custom mac-style Checkbox in Tree */
.tree-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}

.tree-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--bg-tertiary);
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.autogen-distribution-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.autogen-distribution-heading {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.autogen-segmented {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 240px;
  padding: 3px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.autogen-segment {
  min-height: 32px;
  padding: 5px 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
}

.autogen-segment.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.autogen-selection-summary {
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
}

.random-panel-body.autogen-global-quantities {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 16px;
}

.autogen-global-quantities .random-type-row {
  align-items: stretch;
  min-width: 0;
  padding: 0;
  border-bottom: 0;
}

.autogen-global-quantities .random-type-name {
  min-height: 36px;
  line-height: 1.35;
}

.autogen-global-quantities .random-type-control,
.autogen-global-quantities .random-type-input {
  width: 100%;
}

@media (max-width: 900px) {
  .random-panel-body.autogen-global-quantities {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .random-panel-body.autogen-global-quantities {
    grid-template-columns: minmax(0, 1fr);
  }

  .autogen-global-quantities .random-type-name {
    min-height: 0;
  }
}

.autogen-balanced-preview,
.autogen-allocation-feedback {
  min-height: 20px;
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.autogen-balanced-preview:empty,
.autogen-allocation-feedback:empty {
  display: none;
}

.autogen-cross-topic-reserve {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 2.2fr);
  align-items: end;
  gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--separator);
  border-bottom: 1px solid var(--separator);
}

.autogen-cross-topic-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.autogen-cross-topic-status {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.autogen-cross-topic-controls {
  display: grid;
  grid-template-columns: minmax(150px, auto) 88px minmax(180px, 1fr);
  align-items: end;
  gap: 12px;
}

.autogen-cross-topic-toggle,
.autogen-cross-topic-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.autogen-cross-topic-field {
  align-items: stretch;
  flex-direction: column;
  gap: 5px;
}

.autogen-cross-topic-field input,
.autogen-cross-topic-field select {
  width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid var(--border-control);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.autogen-cross-topic-reserve :disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.autogen-custom-allocation {
  margin-top: 4px;
}

.autogen-allocation-table-wrap {
  max-width: 100%;
  overflow-x: auto;
}

.autogen-allocation-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.autogen-allocation-table th,
.autogen-allocation-table td {
  padding: 8px;
  border-bottom: 1px solid var(--separator);
  text-align: center;
  vertical-align: middle;
}

.autogen-allocation-table th:first-child,
.autogen-allocation-table td:first-child {
  width: 34%;
  text-align: left;
}

.autogen-allocation-table input {
  width: 58px;
  min-height: 32px;
  padding: 4px 6px;
  border: 1px solid var(--border-control);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-align: center;
}

.autogen-allocation-table input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.autogen-topic-name {
  display: block;
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.autogen-topic-scope {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 10px;
}

@media (max-width: 560px) {
  .autogen-distribution-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .autogen-segmented {
    width: 100%;
  }

  .autogen-selection-summary {
    text-align: left;
  }

  .autogen-cross-topic-reserve,
  .autogen-cross-topic-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .autogen-allocation-table-wrap {
    overflow: visible;
  }

  .autogen-allocation-table {
    display: block;
    min-width: 0;
  }

  .autogen-allocation-table thead {
    display: none;
  }

  .autogen-allocation-table tbody,
  .autogen-allocation-table tfoot {
    display: block;
  }

  .autogen-allocation-table tbody tr,
  .autogen-allocation-table tfoot tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--separator);
  }

  .autogen-allocation-table th,
  .autogen-allocation-table td {
    width: auto !important;
    padding: 0;
    border: 0;
  }

  .autogen-allocation-table tbody th:first-child,
  .autogen-allocation-table tfoot th:first-child {
    grid-column: 1 / -1;
  }

  .autogen-allocation-table tbody td:not(:last-child)::before,
  .autogen-allocation-table tfoot td:not(:last-child)::before {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
  }

  .autogen-allocation-table tbody td:nth-child(2)::before,
  .autogen-allocation-table tfoot td:nth-child(2)::before { content: "MC"; }
  .autogen-allocation-table tbody td:nth-child(3)::before,
  .autogen-allocation-table tfoot td:nth-child(3)::before { content: "\2605  L1"; }
  .autogen-allocation-table tbody td:nth-child(4)::before,
  .autogen-allocation-table tfoot td:nth-child(4)::before { content: "\2605\2605  L2"; }
  .autogen-allocation-table tbody td:nth-child(5)::before,
  .autogen-allocation-table tfoot td:nth-child(5)::before { content: "\2605\2605\2605  L3"; }

  .autogen-allocation-table input {
    width: 100%;
  }

  .autogen-allocation-table tbody td:last-child {
    display: none;
  }

  .autogen-allocation-table tfoot td:last-child {
    grid-column: 1 / -1;
    padding-top: 2px;
    color: var(--text-primary);
    font-weight: 700;
    text-align: right;
  }

  .autogen-allocation-table tfoot td:last-child::before {
    content: "\5408\8A08  ";
  }
}

.tree-checkbox:checked {
  background: var(--accent-info);
  border-color: var(--accent-info);
}

.tree-checkbox:checked::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 1.5px solid var(--text-inverse);
  border-bottom: 1.5px solid var(--text-inverse);
  transform: rotate(-45deg);
  position: absolute;
  top: 3px;
}

.tree-checkbox:indeterminate {
  background: rgba(10, 132, 255, 0.3);
  border-color: var(--accent-info);
}

.tree-checkbox:indeterminate::after {
  content: "";
  width: 8px;
  height: 2px;
  background: var(--text-inverse);
  position: absolute;
}

/* ==========================================================================
   24. Filter / Random Selection Modes
   ========================================================================== */
.mode-toggle-bar {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: var(--space-4);
  align-self: flex-start;
  width: 320px;
  max-width: 100%;
}

.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  padding: var(--space-2);
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-base);
}

.mode-btn.active {
  background: rgba(10, 132, 255, 0.15);
  color: var(--accent-info);
  border: 1px solid rgba(10, 132, 255, 0.2);
}

.random-selection-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  animation: fadeIn 0.25s ease;
}

.random-panel-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.random-type-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.random-type-name {
  font-size: 14px;
  color: var(--text-secondary);
}

.random-type-control {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.random-type-input {
  width: 60px;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  color: var(--text-primary);
  text-align: center;
}

.random-type-input:focus {
  outline: none;
  border-color: var(--accent-info);
}

.random-type-max {
  font-size: 12px;
  color: var(--text-muted);
}

.random-panel-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

/* ==========================================================================
   25. Organize List (Step 2 Panel)
   ========================================================================== */
.organize-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-8);
}

.organize-item {
  display: flex;
  background-color: var(--bg-secondary);
  color: var(--text-ink-strong);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-hairline-08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transition: transform var(--transition-base), box-shadow var(--transition-base), opacity var(--transition-base);
  width: 100%;
  box-sizing: border-box;
}

.organize-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.organize-item.dragging {
  opacity: 0.4;
  border-color: var(--accent-info);
  transform: scale(0.99);
}

.organize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  cursor: grab;
  color: var(--text-muted);
  font-size: 18px;
  user-select: none;
}

.organize-handle:active {
  cursor: grabbing;
}

.organize-index {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  min-width: 24px;
  text-align: center;
}

.organize-score-input {
  width: 55px;
  padding: 2px 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--separator);
  border-radius: 4px;
  color: var(--text-ink-strong);
  text-align: center;
  font-weight: var(--font-weight-semibold);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.organize-score-input:focus {
  border-color: var(--accent-info);
}

/* ==========================================================================
   26. Analyze Stats Dashboard (Step 3 Panel)
   ========================================================================== */
.stats-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stats-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: var(--space-2);
}

.stat-progress-bar-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.stat-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.stat-progress-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
}

.stat-progress-bar-fill {
  height: 100%;
  background: var(--accent-info);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Sidebar header layout */
.sidebar-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  width: 100%;
}

/* Mode Banner */
.mode-banner {
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.mode-banner-title {
  font-size: 15px;
  font-weight: var(--font-weight-semibold);
  margin: 0 0 2px 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.mode-banner-desc {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.mode-banner.filter-active {
  background: rgba(10, 132, 255, 0.05);
  border: 1px solid rgba(10, 132, 255, 0.12);
  border-left: 4px solid var(--accent-info);
}

.mode-banner.filter-active .mode-banner-title {
  color: var(--accent-info);
}

.mode-banner.random-active {
  background: rgba(191, 90, 242, 0.05);
  border: 1px solid rgba(191, 90, 242, 0.12);
  border-left: 4px solid var(--accent-purple);
}

.mode-banner.random-active .mode-banner-title {
  color: var(--accent-purple);
}

/* --- Paper Preview Online Rich-Text Editor Toolbar --- */
.preview-toolbar {
  display: flex;
  gap: var(--space-2);
  padding: 8px 16px;
  background-color: var(--surface-grey);
  border-bottom: 1px solid var(--separator);
  align-items: center;
  flex-wrap: wrap;
}

.preview-toolbar .btn-sm {
  width: auto;
  height: 32px;
  padding: 0 var(--space-2);
  font-size: var(--font-size-xs);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-ink-strong);
  border: 1px solid var(--separator);
  background-color: var(--bg-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.preview-toolbar .btn-sm:hover {
  background-color: var(--surface-hover);
  border-color: var(--separator-strong);
}

.preview-toolbar .btn-sm:active {
  background-color: var(--surface-pressed);
}

.page-break-divider {
  page-break-after: always;
  height: 0;
  border-top: 2px dashed var(--accent-info);
  margin: 20px 0;
  display: block;
}

@media print {
  .page-break-divider {
    border-top: none !important;
    margin: 0 !important;
  }
  .page-break-divider span {
    display: none !important;
  }
}

/* Color presets styling */
.color-preset-btn {
  transition: transform var(--transition-fast) !important;
}
.color-preset-btn:hover {
  transform: scale(1.25);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.15);
}
.color-preset-btn:active {
  transform: scale(0.9);
}

/* ==========================================================================
   Cosmic Brutalist Fusion Visual Redesign Overrides
   ========================================================================== */

/* Typography & Layout Defaults */
body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  background-image: 
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 24px 24px;
}

h1, h2, h3, .home-title, .hero-brand, .section-title, .step-tab {
  font-family: var(--font-family-title);
  letter-spacing: -0.02em;
}

/* Loading Screen Redesign */
.loading-screen {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.loading-content {
  text-align: center;
  max-width: 400px;
  padding: 40px;
  background: var(--bg-secondary);
  border: 3px solid var(--glass-border);
  box-shadow: var(--shadow-xl);
  border-radius: var(--radius-md);
  position: relative;
}
.loading-icon {
  font-size: 48px;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
}
.loading-title {
  font-family: var(--font-family-title);
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.loading-subtitle {
  font-family: var(--font-family-mono);
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.loading-bar {
  height: 12px;
  background-color: var(--bg-secondary);
  border: 3px solid var(--glass-border);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 12px;
}
.loading-bar-fill {
  height: 100%;
  background-color: var(--accent-highlight);
  border-right: 3px solid var(--glass-border);
  width: 0%;
  transition: width 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.loading-status {
  font-family: var(--font-family-mono);
  font-size: 11px;
  color: var(--text-primary);
}

/* Background Cosmic Aesthetics */
.cosmic-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.cosmic-orbits {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1000px;
  height: 1000px;
  margin-top: -500px;
  margin-left: -500px;
  transform-origin: center center;
  animation: spin 120s linear infinite;
  opacity: 0.85;
  transition: transform 0.1s ease-out;
}
.orbit-node {
  animation: pulse 4s ease-in-out infinite alternate;
}
.node-math { transform-origin: 320px 380px; }
.node-phys { transform-origin: 680px 320px; animation-delay: 1s; }
.node-chem { transform-origin: 500px 820px; animation-delay: 2s; }

.floating-formulas {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}
.formula {
  position: absolute;
  font-family: var(--font-family-mono);
  font-size: 13px;
  color: rgba(0, 0, 0, 0.2);
  pointer-events: none;
  animation: floatFormula 12s ease-in-out infinite;
}
.f1 { top: 12%; left: 8%; animation-delay: 0s; }
.f2 { top: 25%; right: 10%; animation-delay: 2s; }
.f3 { bottom: 15%; left: 15%; animation-delay: 4s; }
.f4 { bottom: 30%; right: 12%; animation-delay: 6s; }
.f5 { top: 5%; left: 45%; animation-delay: 8s; }
.f6 { bottom: 8%; left: 52%; animation-delay: 10s; }

/* Home Screen Layout */
.home-screen {
  position: relative;
  min-height: 100vh;
  padding: 0 40px 40px 40px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background-color: var(--bg-primary) !important;
  overflow-x: hidden;
  z-index: 1;
}

/* Off-screen layout to preserve WebGL context when switching screen views */
.home-screen.hidden {
  display: flex !important;
  opacity: 0 !important;
  pointer-events: none !important;
  position: absolute !important;
  top: -9999px !important;
  left: -9999px !important;
  height: 100vh !important;
  width: 100vw !important;
  overflow: hidden !important;
}

/* Background grid paper overlay */
.cosmic-bg-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
  z-index: -1;
}

/* Top Navigation Bar */
.home-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 90px;
  width: 100%;
  position: relative;
  z-index: 15;
}

.nav-logo {
  font-family: var(--font-family-title), sans-serif;
  font-size: 24px;
  font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -1px;
}

/* ── 品牌文字商標「A∫Maths.hk」(A-integrate-Maths.hk；∫ 積分號做 identity) ──
   重繪成 serif 文字（非嵌 PNG）：可縮放、跨平台一致、跟 site serif 風格。
   固定品牌色（navy A∫M + charcoal aths.hk），三主題淺紙底都讀得清。整支商標用 em，跟容器 font-size 縮放。 */
.wordmark {
  font-family: var(--font-family-title), Georgia, "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  line-height: 1;
}
.wordmark .wm-a { color: #1e2f5e; }          /* navy：A / M */
.wordmark .wm-b { color: #2f3037; }          /* charcoal：aths.hk */
.wordmark .wm-int {                           /* 積分號 ∫：navy、italic、比字母高少少、貼實 A 同 M */
  color: #1e2f5e;
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 500;
  font-size: 1.26em;
  margin: 0 0.01em;
  position: relative;
}
.wordmark .wm-int::after {                     /* reference logo 個積分號頂部有一粒實心圓點——一定要有，要離開頂 curl 有 gap */
  content: "";
  position: absolute;
  top: -0.12em;
  left: 0.30em;
  width: 0.16em;
  height: 0.16em;
  border-radius: 50%;
  background: currentColor;
}
/* Mono 版：深底品牌塊（dashboard／學生 sidebar，白字深底）用——全部 inherit currentColor，保留 ∫ 形但唔用固定 navy */
.wordmark--mono .wm-a,
.wordmark--mono .wm-b,
.wordmark--mono .wm-int { color: inherit; }

.nav-links {
  display: flex;
  gap: 32px;
}

.nav-link {
  font-family: var(--font-family-mono), monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: 0.5px;
  transition: opacity 0.2s ease;
}

.nav-link:hover {
  opacity: 0.7;
}

.nav-buttons {
  display: flex;
  gap: 16px;
  align-items: center;
}

.nav-buttons .nav-links {
  margin-right: 24px;
}

.btn--nav-login {
  font-family: var(--font-family-mono), monospace !important;
  font-weight: 700 !important;
  font-size: 13px !important;
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 3px solid var(--glass-border) !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: 0px !important;
  padding: 8px 20px !important;
  cursor: pointer;
  height: 40px !important;
}

.btn--nav-login.is-signed-in {
  background: var(--accent-highlight) !important;
}

@media (max-width: 560px) {
  .home-screen {
    padding-right: 20px;
    padding-left: 20px;
  }

  .home-navbar {
    height: 72px;
    gap: 12px;
  }

  .nav-logo {
    flex: 0 0 auto;
    font-size: 22px;
  }

  .nav-buttons {
    min-width: 0;
    margin-left: auto;
  }

  .nav-buttons .nav-links {
    display: none;
  }

  .btn--nav-login {
    max-width: 132px;
    height: 36px !important;
    padding: 6px 12px !important;
    overflow: hidden;
    font-size: 11px !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Main Content Area */
.home-hero-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  z-index: 10;
}

/* Centered brand titles */
.hero-titles {
  margin-top: 10px;
  margin-bottom: 20px;
}

.hero-main-title {
  font-family: var(--font-family-title), sans-serif;
  font-size: 68px;
  font-weight: 900;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.1;
  letter-spacing: -1px;
}

.hero-sub-title {
  font-family: var(--font-family-mono), monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 2px;
  margin-top: 8px;
  opacity: 0.8;
}

/* Centered cosmic universe container */
.cosmic-universe {
  width: 1100px;
  height: 520px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -45px;
  margin-bottom: 20px;
}

.cosmic-orb-glow {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.2) 0%, rgba(59, 130, 246, 0.05) 70%, transparent 100%);
  filter: blur(25px);
  z-index: 3;
  pointer-events: none;
}

.cosmic-orb-wrapper {
  position: relative;
  z-index: 4;
  animation: orbFloat 8s ease-in-out infinite;
}

.cosmic-orb {
  width: 340px;
  height: 340px;
  border-radius: 50%;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.18);
  transition: transform 0.1s ease-out;
  overflow: hidden;
}

#fluid-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* SVG Orbitals and Nodes */
.universe-orbits {
  position: absolute;
  width: 800px;
  height: 600px;
  top: 50%;
  left: 50%;
  margin-left: -400px;
  margin-top: -300px;
  z-index: 5;
  pointer-events: none;
  overflow: visible;
}

.orbits-rotator {
  transform-origin: 400px 300px;
  animation: orbitRotate 160s linear infinite;
}


/* Positioned Mathematical Figures and Formulas */
.universe-decorations {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 6;
}

.decor-item {
  position: absolute;
  pointer-events: auto; /* Allow hover and pointer events */
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.3s ease;
  z-index: 6;
}

/* Hover perturbation effect on parent container */
.decor-item:hover {
  transform: scale(1.18) rotate(7deg) translateY(-5px);
  filter: drop-shadow(0px 6px 12px rgba(0,0,0,0.18));
  z-index: 10;
}

/* Center items (.item-dna and .item-integral) need translateX(-50%) preserved on hover */
.item-dna:hover {
  transform: translateX(-50%) scale(1.18) rotate(7deg) translateY(-5px);
}

.item-integral:hover {
  transform: translateX(-50%) scale(1.18) rotate(7deg) translateY(-5px);
}

.decor-item-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: itemFloat 8s ease-in-out infinite;
}

/* Hover perturbation effect: pauses float */
.decor-item:hover .decor-item-inner {
  animation-play-state: paused;
}

.decor-item svg {
  width: 68px;
  height: 68px;
  stroke: #000000;
}

.decor-lbl {
  font-family: var(--font-family-mono), monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--overlay-cream);
  padding: 2px 6px;
  border-radius: 0px;
  white-space: nowrap;
}

/* --- Left Stack (Outer & Inner) --- */
.item-graph {
  left: 1.5%;
  top: 13%;
  transform: rotate(-3deg);
}
.item-graph .decor-item-inner {
  animation-delay: 0s;
}

.item-molecule {
  left: 12.5%;
  top: 40%;
  transform: rotate(2deg);
}
.item-molecule .decor-item-inner {
  animation-delay: 2s;
}

.item-flask {
  left: 1.5%;
  top: 75%;
  transform: rotate(-4deg);
}
.item-flask .decor-item-inner {
  animation-delay: 4s;
}

.item-petri {
  left: 23%;
  top: 22%;
  transform: rotate(1deg);
}
.item-petri .decor-item-inner {
  animation-delay: 1.5s;
}

.item-leaf {
  left: 13.5%;
  top: 58%;
  transform: rotate(-2deg);
}
.item-leaf .decor-item-inner {
  animation-delay: 3.5s;
}


/* --- Right Stack (Outer & Inner) --- */
.item-prism {
  right: 1.5%;
  top: 13%;
  transform: rotate(3deg);
}
.item-prism .decor-item-inner {
  animation-delay: 1s;
}

.item-atom {
  right: 12.5%;
  top: 40%;
  transform: rotate(-1deg);
}
.item-atom .decor-item-inner {
  animation-delay: 3s;
}

.item-magnet {
  right: 1.5%;
  top: 75%;
  transform: rotate(4deg);
}
.item-magnet .decor-item-inner {
  animation-delay: 5s;
}

.item-tube {
  right: 23%;
  top: 22%;
  transform: rotate(-2deg);
}
.item-tube .decor-item-inner {
  animation-delay: 2.5s;
}

.item-water {
  right: 13.5%;
  top: 58%;
  transform: rotate(3deg);
}
.item-water .decor-item-inner {
  animation-delay: 4.5s;
}


/* --- Center Top & Bottom Items --- */
.item-dna {
  left: 63%;
  transform: translateX(-50%) rotate(1deg);
  top: -13%;
}
.item-dna .decor-item-inner {
  animation-delay: 6s;
}

.item-integral {
  left: 43%;
  transform: translateX(-50%) rotate(-2deg);
  bottom: -6%;
}
.item-integral .decor-item-inner {
  animation-delay: 7s;
}


/* --- Floating Formulas Placements --- */
.decor-formula {
  position: absolute;
  font-family: var(--font-family-mono), monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  pointer-events: auto; /* Allow hover and pointer events */
  transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.3s ease;
  z-index: 6;
}

/* Hover perturbation effect for formulas */
.decor-formula:hover {
  transform: scale(1.18) rotate(7deg) translateY(-5px);
  filter: drop-shadow(0px 6px 12px rgba(0,0,0,0.18));
  z-index: 10;
}

.decor-formula-inner {
  animation: formulaFloat 10s ease-in-out infinite;
}

/* Hover perturbation effect: pauses float */
.decor-formula:hover .decor-formula-inner {
  animation-play-state: paused;
}

.df1 { left: 3.5%; top: 4%; transform: rotate(1deg); }
.df1 .decor-formula-inner { animation-delay: 0s; }

.df2 { left: 17.5%; top: 32%; transform: rotate(-2deg); }
.df2 .decor-formula-inner { animation-delay: 2s; }

.df3 { left: 12%; top: 48%; transform: rotate(2deg); }
.df3 .decor-formula-inner { animation-delay: 4s; }

.df4 { left: 4%; top: 85%; transform: rotate(-1.5deg); }
.df4 .decor-formula-inner { animation-delay: 1s; }

.df5 { right: 3.5%; top: 4%; transform: rotate(-2deg); }
.df5 .decor-formula-inner { animation-delay: 5s; }

.df6 { right: 17.5%; top: 32%; transform: rotate(1.5deg); }
.df6 .decor-formula-inner { animation-delay: 3s; }

.df7 { right: 12%; top: 48%; transform: rotate(-1deg); }
.df7 .decor-formula-inner { animation-delay: 6s; }

.df8 { right: 4%; top: 85%; transform: rotate(2.5deg); }
.df8 .decor-formula-inner { animation-delay: 0.5s; }

.df9 { left: 17%; top: 7%; transform: rotate(1deg); }
.df9 .decor-formula-inner { animation-delay: 3.5s; }

.df10 { left: 17.5%; top: 74%; transform: rotate(-2deg); }
.df10 .decor-formula-inner { animation-delay: 1.5s; }

.df11 { right: 17%; top: 7%; transform: rotate(-1deg); }
.df11 .decor-formula-inner { animation-delay: 4.5s; }

.df12 { right: 17.5%; top: 74%; transform: rotate(1.5deg); }
.df12 .decor-formula-inner { animation-delay: 5.5s; }

/* Subjects Slider (Always visible, normal block layout) */
.subjects-slider-container {
  width: 100%;
  padding: 10px 0 20px 0;
  box-sizing: border-box;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  margin-top: 30px;
  -ms-overflow-style: none;  /* IE/Edge */
  scrollbar-width: none;  /* Firefox */
}

.subjects-slider-container::-webkit-scrollbar {
  display: none; /* Chrome/Safari/Webkit */
}



/* Sidebar Recent Paper Items styling */
.recent-paper-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  cursor: pointer;
  box-sizing: border-box;
}

.recent-paper-item:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.recent-paper-item:active {
  transform: translateY(1px);
}

.subjects-slider-track {
  display: flex;
  align-items: stretch;
  gap: 20px;
  padding: 0 40px;
}

/* Subject Card styling */
.subject-card {
  width: 180px;
  height: 220px;
  background: var(--bg-secondary);
  border: 3px solid var(--glass-border) !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: 0px !important;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
}

.subject-card:hover {
  transform: translate(-4px, -4px) !important;
  box-shadow: var(--shadow-xl) !important;
}

.subject-card:active {
  transform: translate(2px, 2px) !important;
  box-shadow: var(--shadow-sm) !important;
}

.subject-card__top {
  padding: 12px;
  font-family: var(--font-family-mono), monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: left;
  text-transform: uppercase;
  border-bottom: 3px solid var(--glass-border);
  transition: background-color 0.15s ease;
}

.subject-card__center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  padding: 10px;
}

/* Text monogram shown when a subject has no line-art SVG icon (no emoji: the
   public-facing UI expresses hierarchy through type, per the formal-UI rule). */
.subject-icon-fallback {
  font-family: var(--font-family-mono), monospace;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.subject-card__bottom {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 3px solid var(--glass-border);
  font-family: var(--font-family-mono), monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  text-transform: uppercase;
  transition: background-color 0.15s ease;
}

/* Yellow Highlighted Top Bar */
.subject-card--yellow-bottom .subject-card__top {
  background-color: var(--accent-highlight) !important;
}

/* Keep fully visible and stylized even if inactive, only handle Coming Soon via click */
.subject-card--inactive {
  opacity: 1;
}



}

/* Retro Windows-like Terminal Console */
.brutal-terminal {
  width: 850px;
  background: #000000;
  border: 3px solid var(--glass-border);
  box-shadow: 6px 6px 0px #000000;
  align-self: center;
  margin-top: 20px;
  margin-bottom: 50px;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.terminal-titlebar {
  background: var(--bg-secondary);
  border-bottom: 3px solid var(--glass-border);
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.terminal-title {
  font-family: var(--font-family-mono), monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.terminal-controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.control-btn {
  font-family: var(--font-family-mono), monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.terminal-body {
  background: #000000;
  padding: 20px;
  font-family: var(--font-family-mono), monospace;
  font-size: 13px;
  color: var(--text-inverse);
  line-height: 1.8;
  min-height: 90px;
  max-height: 180px;
  overflow-y: auto;
}

.terminal-line {
  margin: 4px 0;
}

.terminal-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background-color: var(--bg-secondary);
  animation: blink 1s step-end infinite;
  vertical-align: middle;
  margin-left: 4px;
}

/* Custom Keyframe Animations */
@keyframes orbFloat {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(1.5deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

@keyframes orbitRotate {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

@keyframes itemFloat {
  0% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-6px) rotate(1deg); }
  100% { transform: translateY(0px) rotate(0deg); }
}

/* Buttons System Overrides */
.btn {
  font-family: var(--font-family);
  font-weight: 700;
  border-radius: var(--radius-md) !important;
  border: 3px solid var(--glass-border) !important;
  box-shadow: var(--shadow-card) !important;
  transition: transform var(--transition-base), box-shadow var(--transition-base), background-color var(--transition-base) !important;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
}
.btn:hover:not(:disabled) {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-lg) !important;
}
.btn:active:not(:disabled) {
  transform: translate(1px, 1px);
  box-shadow: var(--shadow-xs) !important;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: var(--shadow-xs) !important;
}

/* Button themes */
.btn--primary {
  background-color: var(--btn-fill) !important;
  color: var(--btn-fill-text) !important;
  border-color: var(--btn-fill) !important;
}
.btn--primary:hover:not(:disabled) {
  background-color: var(--btn-fill-hover) !important;
  border-color: var(--btn-fill-hover) !important;
}
.btn--secondary {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}
.btn--secondary:hover:not(:disabled) {
  background-color: var(--bg-primary) !important;
}
.btn--ghost, .btn--outline {
  background-color: transparent !important;
  color: var(--text-primary) !important;
}
.btn--ghost:hover:not(:disabled), .btn--outline:hover:not(:disabled) {
  background-color: var(--bg-secondary) !important;
}

/* Checkbox & Radio Brutalist Styling */
.tree-checkbox {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--glass-border) !important;
  border-radius: var(--radius-sm);
  background-color: var(--bg-secondary) !important;
  position: relative;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
}
.tree-checkbox:checked {
  background-color: var(--text-primary) !important;
}
.tree-checkbox:checked::after {
  content: "";
  position: absolute;
  top: 45%;
  left: 50%;
  width: 5px;
  height: 9px;
  border: solid #ffffff;
  border-width: 0 2.5px 2.5px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
.tree-checkbox:indeterminate {
  background-color: var(--text-primary) !important;
}
.tree-checkbox:indeterminate::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 2.5px;
  background-color: var(--bg-secondary);
}

/* App Header Overrides */
.app-header {
  background: var(--bg-secondary) !important;
  border-bottom: 3px solid var(--glass-border) !important;
  box-shadow: 0 4px 0px rgba(0,0,0,0.05);
  color: var(--text-primary) !important;
  height: 64px !important;
  display: flex;
  align-items: center;
  padding: 0 var(--space-6) !important;
}
.logo-text {
  font-family: var(--font-family-title);
  font-size: 16px;
  letter-spacing: 0.05em;
  color: var(--text-primary) !important;
  border-right: 2px solid var(--glass-border);
  padding-right: var(--space-4);
  margin-right: var(--space-4);
}
.header-back {
  align-items: center;
  gap: 6px;
  border: 2px solid var(--glass-border) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow-sm) !important;
  color: var(--text-primary) !important;
  font-weight: 800 !important;
  padding: 7px 10px !important;
}
.header-back__label {
  font-size: 12px;
  line-height: 1;
}
.breadcrumb-subject {
  font-weight: 800;
  color: var(--text-primary) !important;
}
.steps-tab-bar {
  background: var(--surface-muted) !important;
  border: 2px solid var(--glass-border) !important;
  border-radius: var(--radius-md) !important;
  padding: 3px !important;
  display: flex;
  gap: 4px;
}
.step-tab {
  border: none !important;
  background: transparent !important;
  color: var(--step-tab-text) !important;
  border-radius: var(--radius-sm) !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  padding: 6px 14px !important;
  transition: all var(--transition-fast) !important;
  cursor: pointer;
}
.step-tab.active {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 2px solid var(--glass-border) !important;
  box-shadow: var(--shadow-sm) !important;
}

/* Layout components brutalist overrides */
.sidebar, .paper-tray {
  background-color: var(--bg-secondary) !important;
  border: 3px solid var(--glass-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-md) !important;
}
.sidebar {
  margin-right: var(--space-4);
}
.paper-tray {
  margin-left: var(--space-4);
  box-sizing: border-box;
  box-shadow: -4px 4px 0px #000000 !important;
}
.main-content {
  background-color: var(--bg-secondary) !important;
  border: 3px solid var(--glass-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-md) !important;
  padding: var(--space-5) !important;
}
.question-card, .organize-item, .stats-card, .recent-paper-item {
  background-color: var(--bg-secondary) !important;
  border: 3px solid var(--glass-border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-card) !important;
  transition: transform var(--transition-base), box-shadow var(--transition-base) !important;
  color: var(--text-primary) !important;
}
.question-card:hover, .organize-item:hover, .recent-paper-item:hover {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-lg) !important;
}

/* Question card styling adjustments */
.question-card-header {
  border-bottom: 2px solid var(--glass-border) !important;
  background-color: var(--header-cream) !important;
  padding: 8px 12px !important;
}
.badge {
  font-family: var(--font-family-mono);
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 2px solid var(--glass-border) !important;
  font-weight: 700;
  border-radius: 0px !important;
  box-shadow: var(--shadow-badge) !important;
}
.badge--score {
  background-color: var(--accent-highlight) !important;
}

/* Modals Override */
.modal {
  background: var(--bg-secondary) !important;
  border: 3px solid var(--glass-border) !important;
  box-shadow: var(--shadow-xl) !important;
  border-radius: var(--radius-lg) !important;
}
.modal-header {
  border-bottom: 3px solid var(--glass-border) !important;
  padding: var(--space-4) var(--space-6) !important;
  background-color: var(--bg-primary) !important;
}
.modal-title {
  color: var(--text-primary) !important;
  font-size: 18px !important;
}
.modal-footer {
  border-top: 3px solid var(--glass-border) !important;
  padding: var(--space-4) var(--space-6) !important;
}

/* Input elements style override */
.form-input, .form-select, .form-textarea, .filter-select, .score-input {
  border: 2px solid var(--glass-border) !important;
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  padding: 8px 12px !important;
  font-family: var(--font-family);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}
.form-input:focus, .form-select:focus, .form-textarea:focus, .filter-select:focus {
  border-color: var(--text-primary) !important;
  box-shadow: 2px 2px 0px var(--accent-highlight) !important;
}

/* ==========================================================================
   AI Compiler Workstation Control Room Terminal Restyling (Step 4)
   ========================================================================== */
#panel-ai-compiler .stats-card {
  background: #15151a !important;
  border: 3px solid var(--glass-border) !important;
  box-shadow: var(--shadow-md) !important;
  border-radius: var(--radius-md) !important;
  padding: var(--space-5) !important;
  color: var(--text-inverse) !important;
}

#panel-ai-compiler .stats-card-title {
  color: var(--accent-highlight) !important;
  font-family: var(--font-family-mono) !important;
  font-size: 14px !important;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 8px;
}

#panel-ai-compiler .stats-card-title::before {
  content: "●";
  color: #EF4444;
  animation: blink 1.5s step-end infinite;
}

/* Specific textareas inside Step 4 */
#ai-compiler-seed-text,
#ai-compiler-code-preview,
#ai-compiler-params-preview {
  background: #09090b !important;
  color: #a7f3d0 !important;
  border: 2px solid #27272a !important;
  font-family: var(--font-family-mono) !important;
  font-size: 12px !important;
  line-height: 1.5 !important;
  border-radius: var(--radius-sm) !important;
  padding: 12px !important;
}
#ai-compiler-seed-text::placeholder {
  color: #52525b;
}
#ai-compiler-seed-text:focus,
#ai-compiler-code-preview:focus,
#ai-compiler-params-preview:focus {
  border-color: #10B981 !important;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.25) !important;
}

/* Compiler terminal logs styling */
#ai-compiler-logs {
  background: #09090b !important;
  color: #34d399 !important;
  border: 2px solid #27272a !important;
  font-family: var(--font-family-mono) !important;
  font-size: 11px !important;
  border-radius: var(--radius-sm) !important;
  padding: 12px !important;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.8) !important;
}

/* Dropdowns in AI Compiler */
#panel-ai-compiler .filter-select,
#panel-ai-compiler .form-input {
  background: #09090b !important;
  border: 2px solid #27272a !important;
  color: var(--text-inverse) !important;
  border-radius: var(--radius-sm) !important;
}
#panel-ai-compiler .filter-select:focus,
#panel-ai-compiler .form-input:focus {
  border-color: var(--accent-highlight) !important;
}

/* Custom dropdown option styling inside AI Compiler */
#panel-ai-compiler option {
  background-color: #09090b !important;
  color: var(--text-inverse) !important;
}

/* Hot-reload re-run button in compiler */
#btn-ai-recompile {
  background-color: #10b981 !important;
  border-color: #10b981 !important;
  color: var(--text-primary) !important;
}
#btn-ai-recompile:hover:not(:disabled) {
  background-color: #059669 !important;
}

/* KaTeX Compiled preview card inside Step 4 */
#ai-compiler-card-preview {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 2px solid var(--glass-border) !important;
  box-shadow: inset 2px 2px 5px rgba(0,0,0,0.05) !important;
  border-radius: var(--radius-sm) !important;
}

/* ==========================================================================
   Animations & Transition Effects
   ========================================================================== */
@keyframes liquid {
  0% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
  25% { border-radius: 50% 50% 30% 70% / 50% 60% 40% 50%; }
  50% { border-radius: 70% 30% 50% 50% / 30% 30% 70% 70%; }
  75% { border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%; }
  100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

@keyframes floatFormula {
  0% { transform: translateY(0px) rotate(0deg); opacity: 0.15; }
  50% { transform: translateY(-15px) rotate(3deg); opacity: 0.3; }
  100% { transform: translateY(0px) rotate(0deg); opacity: 0.15; }
}

@keyframes orbPulse {
  0% { transform: scale(0.95); opacity: 0.4; }
  100% { transform: scale(1.1); opacity: 0.6; }
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1.1); opacity: 1; }
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Non-linear Entrance Animations for Cards and Panels */
.home-screen, .app-layout {
  animation: fadeIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.subject-card {
  opacity: 0;
  animation: cardEntrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.subjects-grid .subject-card:nth-child(1) { animation-delay: 0.05s; }
.subjects-grid .subject-card:nth-child(2) { animation-delay: 0.1s; }
.subjects-grid .subject-card:nth-child(3) { animation-delay: 0.15s; }
.subjects-grid .subject-card:nth-child(4) { animation-delay: 0.2s; }
.subjects-grid .subject-card:nth-child(5) { animation-delay: 0.25s; }
.subjects-grid .subject-card:nth-child(6) { animation-delay: 0.3s; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

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

/* Ensure step panel transitions are smooth */
.app-body {
  transition: opacity 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.app-body.hidden {
  opacity: 0 !important;
  transform: translateY(10px) !important;
  display: none !important;
}

.difficulty-chip { display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; line-height: 1.4; }
.difficulty-chip--easy   { background: #e3f9eb; color: #1fb141; }
.difficulty-chip--medium { background: #fff4d6; color: #b8860b; }
.difficulty-chip--hard   { background: #fde8e8; color: #d93636; }

.diff-filter-btn { padding: 4px 10px; border-radius: 8px; border: 1px solid rgba(0,0,0,0.1);
  background: transparent; cursor: pointer; font-size: 12px; }
.diff-filter-btn.active { background: var(--accent-primary); color: #fff; border-color: transparent; }

.diff-bar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; margin-top: 8px; font-size: 11px; }
.diff-bar__seg { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }
.diff-bar__seg--easy   { background: #1fb141; }
.diff-bar__seg--medium { background: #d6a000; }
.diff-bar__seg--hard   { background: #d93636; }

/* ==========================================================================
   Maths Teacher Dashboard Fusion
   ========================================================================== */
.math-dashboard-panel[hidden] {
  display: none !important;
}

.app-layout--dashboard {
  padding-top: 0 !important;
  background-color: var(--bg-primary);
}

.app-layout--dashboard .app-header,
.app-layout--dashboard .app-body {
  display: none !important;
}

.math-dashboard-panel {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  background-color: var(--bg-primary);
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.055) 1px, transparent 1px);
  background-size: 56px 56px;
  color: var(--text-primary);
}

.math-dashboard-nav {
  min-height: 100vh;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: rgba(255, 255, 255, 0.82);
  border-right: 2px solid var(--glass-border);
}

.math-dashboard-home {
  min-height: 40px;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border-ink-soft);
  border-radius: 8px;
  box-shadow: 1px 2px 0 #000000;
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 900;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

.math-dashboard-home:hover {
  background: var(--accent-highlight-soft);
  transform: translate(-1px, -1px);
  box-shadow: var(--shadow-dash);
}

.math-dashboard-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 20px;
  background: var(--btn-fill);            /* 由淺 highlight → 實色深（同學生 brand 一致：V1 深金/V3 深靛藍/classic 黃） */
  border: 2px solid transparent;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  color: var(--btn-fill-text);
}

.math-dashboard-brand__logo {
  font-family: var(--font-family-title);
  font-size: 34px;
  line-height: 1.05;
}
.math-dashboard-brand .wordmark { font-weight: 700; }   /* 放大加粗，同學生 student-brand（34px/700）一致 */

.math-dashboard-brand__sub {
  font-weight: 900;
  font-size: 14px;
  opacity: .82;
}

.math-dashboard-nav__links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.math-dashboard-nav__item {
  width: 100%;
  min-height: 52px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-grey);
  cursor: pointer;
  text-align: left;
  padding: 0 14px;
  font-family: var(--font-family);
  font-size: 17px;
  font-weight: 900;
  transition: all var(--transition-base);
}

.math-dashboard-nav__item:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  transform: translate(-2px, -2px);
}

.math-dashboard-nav__item.active {
  color: var(--btn-fill-text);
  background: var(--btn-fill);
  border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
  transform: translate(-2px, -2px);
}

.math-dashboard-quota {
  margin-top: auto;
  padding: 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-dash);
}

.math-dashboard-quota__label,
.math-dashboard-stat span,
.math-dashboard-kicker {
  color: var(--text-grey-strong);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.math-dashboard-quota strong {
  display: block;
  margin-top: 8px;
  font-size: 20px;
}

.math-dashboard-quota__bar {
  display: block;
  height: 6px;
  margin-top: 12px;
  background: var(--track-grey);
  border: 1px solid var(--glass-border);
  border-radius: 4px;
  overflow: hidden;
}

.math-dashboard-quota__bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-primary);
}

.math-dashboard-profile-trigger {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1.5rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--surface-warm-1) 100%);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-family);
  text-align: left;
  transition: all var(--transition-base);
}

.math-dashboard-profile-trigger:hover {
  background: var(--bg-secondary);
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

.math-dashboard-profile-trigger__avatar,
.math-dashboard-profile-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  background: var(--accent-highlight);
  border: 1.5px solid var(--border-ink-soft);
  border-radius: 50%;
  box-shadow: var(--shadow-xs);
  font-family: var(--font-family-title);
  font-size: 18px;
  line-height: 1;
}

.math-dashboard-profile-trigger strong {
  display: block;
  font-size: 14px;
  line-height: 1.2;
}

.math-dashboard-profile-trigger small {
  display: block;
  max-width: 176px;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-grey-strong);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.math-dashboard-main {
  min-width: 0;
  padding: var(--space-8) var(--space-10);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.math-dashboard-view {
  max-width: 1200px;
  width: 100%;
}

.math-dashboard-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 26px;
  align-items: start;
  padding: 26px 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(17, 17, 17, 0.10), 3px 3px 0 #000000;
}

.math-dashboard-hero--compact {
  align-items: center;
}

.math-dashboard-kicker {
  margin-bottom: 8px;
  font-size: 11px;
}

.math-dashboard-hero h1 {
  max-width: 680px;
  margin: 0;
  font-family: var(--font-family-title);
  font-size: clamp(30px, 3.8vw, 44px);
  line-height: 1.08;
  letter-spacing: 0;
}

.math-dashboard-hero h1 span {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.math-dashboard-hero p {
  max-width: 620px;
  margin-top: 14px;
  color: var(--text-strong);
  font-size: 16px;
  line-height: 1.65;
  font-weight: 700;
}

.math-dashboard-hero__actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

.math-dashboard-hero__actions--row {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.math-dashboard-search {
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-dash);
  transition: all var(--transition-base);
}

.math-dashboard-search:focus-within {
  background: var(--bg-secondary);
  border-color: var(--text-primary);
  box-shadow: var(--shadow-md);
  transform: translate(-2px, -2px);
}

.math-dashboard-search span {
  font-size: 22px;
  font-weight: 900;
}

.math-dashboard-search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text-primary);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  background: transparent;
}

.math-dashboard-primary {
  min-height: 50px;
  justify-content: center;
  font-size: 16px !important;
}

.math-dashboard-logout {
  min-height: 40px;
  align-self: flex-end;
  padding-inline: 18px !important;
  font-size: 14px !important;
}

.math-dashboard-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 26px;
}

.math-dashboard-step {
  min-height: 82px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 1.5rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--surface-warm-1) 100%);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  text-align: left;
  transition: all var(--transition-base);
}

.math-dashboard-step::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 7px;
  background: var(--btn-fill);
  border-right: 2px solid var(--glass-border);
}

.math-dashboard-step:hover {
  transform: translate(-3px, -3px);
  background: var(--bg-secondary);
  box-shadow: var(--shadow-md);
}

.math-dashboard-step span {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  background: var(--btn-fill);
  color: var(--btn-fill-text);
  border: 2px solid transparent;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 900;
  box-shadow: var(--shadow-xs);
  position: relative;
  z-index: 1;
}

.math-dashboard-step strong {
  font-size: 15px;
  line-height: 1.25;
  position: relative;
  z-index: 1;
}

.math-dashboard-stats,
.math-dashboard-class-grid,
.math-dashboard-grid-flex {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
  margin-top: var(--space-6);
}

.math-dashboard-class-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.math-dashboard-profile-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.55fr) repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-6);
  margin-top: var(--space-6);
}

.math-dashboard-profile-card {
  min-height: 122px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 18px 24px;
  background: linear-gradient(180deg, var(--surface-warm-2) 0%, var(--bg-secondary) 100%);
  border: 1.5px solid var(--border-ink-soft);
  border-radius: 8px;
  box-shadow: 0 12px 22px rgba(17, 17, 17, 0.08), 2px 2px 0 #000000;
  overflow: hidden;
  position: relative;
}

.math-dashboard-profile-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--accent-highlight);
  border-right: 1.5px solid var(--border-ink-soft);
}

.math-dashboard-profile-card > * {
  position: relative;
  z-index: 1;
}

.math-dashboard-profile-card span:not(.math-dashboard-profile-avatar) {
  display: block;
  margin-bottom: 6px;
  color: var(--text-grey-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.math-dashboard-profile-card strong {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-family: var(--font-family);
  font-size: clamp(20px, 1.7vw, 25px);
  font-weight: 900;
  line-height: 1.1;
}

.math-dashboard-profile-card--identity strong {
  word-break: normal;
}

.math-dashboard-profile-card small {
  display: block;
  margin-top: 8px;
  color: var(--text-grey);
  font-size: 14px;
  font-weight: 900;
}

.math-dashboard-stat {
  min-height: 122px;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
  transition: all var(--transition-base);
}

.math-dashboard-stat:hover {
  transform: translate(-2px, -2px);
  box-shadow: var(--shadow-md);
}

.math-dashboard-stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--accent-highlight);
  border-right: 2px solid var(--glass-border);
}

.math-dashboard-stat--yellow {
  background: linear-gradient(180deg, #FFF9CC 0%, #fffdf0 100%);
}

.math-dashboard-stat--green {
  background: linear-gradient(180deg, #E9F8F1 0%, #f7fffb 100%);
}

.math-dashboard-stat--red {
  background: linear-gradient(180deg, #FFECEE 0%, #fffafa 100%);
}

.math-dashboard-stat--green::before {
  background: #BCEBD8;
}

.math-dashboard-stat--red::before {
  background: #FFD1D6;
}

.math-dashboard-stat span {
  display: block;
  margin-bottom: 8px;
  font-size: 11px;
  position: relative;
  z-index: 1;
}

.math-dashboard-stat strong {
  display: block;
  font-family: var(--font-family-title);
  font-size: clamp(28px, 3.2vw, 38px);
  line-height: 1.05;
  position: relative;
  z-index: 1;
}

.math-dashboard-stat small {
  display: block;
  margin-top: 8px;
  color: var(--text-grey);
  font-size: 14px;
  font-weight: 900;
  position: relative;
  z-index: 1;
}

.math-dashboard-recent {
  margin-top: 24px;
  padding: 20px 22px 20px 26px;
  background: rgba(255, 255, 255, 0.97);
  border: 1.5px solid var(--border-ink-soft);
  border-radius: 8px;
  box-shadow: 0 12px 24px rgba(17, 17, 17, 0.08), 2px 2px 0 #000000;
  overflow: hidden;
  position: relative;
}

.math-dashboard-recent::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--accent-highlight-soft);
  border-right: 1.5px solid var(--border-ink-soft);
}

.math-dashboard-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.math-dashboard-section-head h2 {
  margin: 0;
  font-family: var(--font-family-title);
  font-size: 21px;
}

.math-dashboard-link {
  border: 0;
  background: transparent;
  color: var(--accent-link);
  cursor: pointer;
  font-weight: 900;
  font-size: 15px;
}

.math-dashboard-recent-list {
  display: flex;
  flex-direction: column;
}

.math-dashboard-recent-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px 0;
  border-top: 1px solid var(--border-row);
}

.math-dashboard-recent-row:first-child {
  border-top: 0;
}

.math-dashboard-recent-row__main {
  min-width: 0;
}

.math-dashboard-recent-row__main strong {
  display: block;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.math-dashboard-recent-row__main span,
.math-dashboard-empty {
  display: block;
  margin-top: 4px;
  color: var(--text-grey-strong);
  font-size: 14px;
  font-weight: 800;
}

.math-dashboard-recent-row__actions {
  display: flex;
  gap: 8px;
}

.math-dashboard-mini-btn {
  min-height: 34px;
  padding: 0 12px;
  background: var(--bg-secondary);
  border: 2px solid var(--glass-border);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  cursor: pointer;
  font-weight: 900;
}

.math-dashboard-mini-btn:hover {
  background: var(--accent-highlight);
}

.math-dashboard-profile-panel {
  margin-top: 24px;
}

.math-dashboard-profile-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.math-dashboard-profile-action {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 14px 16px 14px 22px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--surface-warm-2) 100%);
  border: 1.5px solid var(--border-ink-soft);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(17, 17, 17, 0.07), 1px 2px 0 #000000;
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-family);
  overflow: hidden;
  position: relative;
  text-align: left;
  text-decoration: none;
}

.math-dashboard-profile-action::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--accent-highlight-soft);
  border-right: 1.5px solid var(--border-ink-soft);
}

.math-dashboard-profile-action:hover {
  background: var(--surface-warm-3);
}

.math-dashboard-profile-action strong {
  font-size: 15px;
  line-height: 1.25;
  position: relative;
  z-index: 1;
}

.math-dashboard-profile-action span {
  color: var(--text-grey-strong);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.45;
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   Classes — inline 教師班別管理（Dim 2 單頁 Teacher Hub Merge；由 teacher.js console 遷入）。
   刻意只用 dashboard token（--accent-*/--text-*/--bg-*/--border-*/--color-*/--space-*/--radius-*/
   --font-*），避開 teacher.html 自有嘅 --gold/--card/--line/--gold-soft 設計系統，故三主題
   （e/classic/v3）跟 dashboard 一齊生效。弱項/成績標籤直接用既有 .badge.badge--tag.badge--* 。
   ========================================================================== */
/* 窄屏（≤760px，.math-dashboard-main 係 flex column + align-items:center）：classes view 有 width:100%
   但預設 min-width:auto，會被寬表格嘅 min-content 蓋過而撐爆 grid track。scoped 落 min-width:0（唔郁 shared
   .math-dashboard-view，故 Overview/Profile 不變），令 width:100% 生效、表改由 .classes-table-wrap 內部 scroll（§3.1 H）。 */
#dashboard-view-classes { min-width: 0; }
.classes-head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.classes-quota {
  margin: 0 0 var(--space-4);
  color: var(--text-grey-strong);
  font-size: 14px;
  font-weight: 800;
}
.classes-code {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent-code-badge) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent-code-badge) 34%, transparent);
  color: var(--accent-code-badge);
  font-family: var(--font-family-mono);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}
.classes-input,
.classes-select {
  min-height: 40px;
  min-width: 0;          /* 覆蓋 flex/grid item 預設 min-width:auto，令 input 可縮，唔會撐爆窄屏 grid track（§3.1 H） */
  max-width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
}
.classes-input:focus,
.classes-select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}
.classes-create-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 var(--space-4);
}
.classes-create-row .classes-input { flex: 1 1 220px; }
/* 派發練習 form + 邀請連結（Phase 2 detail 用） */
.classes-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: flex-end;
}
.classes-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.classes-field > label {
  color: var(--text-grey-strong);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.classes-invite-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}
.classes-invite-row .classes-input { flex: 1 1 320px; }
.classes-msg {
  color: var(--text-grey-strong);
  font-size: 13px;
  font-weight: 700;
}
/* detail 內分區（邀請/派發/已派/進度）：段落間距 + 粗體 subhead */
.classes-detail-block { margin-top: var(--space-5); }
.classes-subhead {
  margin: 0 0 var(--space-2);
  font-family: var(--font-family-title);
  font-size: 16px;
  font-weight: 900;
  color: var(--text-primary);
}
/* 表格（detail 學生進度/已派清單、results 成績；§3.1 H：外層 wrap 提供橫向 scroll，
   窄屏（≤760px panel overflow-x:hidden）唔撐爆 body，表自身可內部橫向 scroll） */
.classes-table-wrap {
  overflow-x: auto;
  margin-top: var(--space-2);
}
.classes-table {
  width: 100%;
  border-collapse: collapse;
}
.classes-table th,
.classes-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-row);
  font-size: 14px;
}
.classes-table th {
  color: var(--text-grey-strong);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.classes-table td {
  color: var(--text-primary);
  font-weight: 700;
}

.paper-tray--attention {
  animation: paperTrayAttention 0.9s ease;
}

.sidebar--attention {
  animation: sidebarAttention 0.9s ease;
}

@keyframes paperTrayAttention {
  0%, 100% { box-shadow: 4px 4px 0 #000000 !important; }
  25%, 75% { box-shadow: 0 0 0 4px var(--accent-highlight), 6px 6px 0 #000000 !important; }
}

@keyframes sidebarAttention {
  0%, 100% { box-shadow: 4px 4px 0 #000000 !important; }
  25%, 75% { box-shadow: 0 0 0 4px var(--accent-highlight), 6px 6px 0 #000000 !important; }
}

@media (max-width: 1100px) {
  .math-dashboard-panel {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .math-dashboard-main {
    padding: 28px;
  }

  .math-dashboard-hero {
    grid-template-columns: 1fr;
  }

  .math-dashboard-stats,
  .math-dashboard-steps,
  .math-dashboard-profile-grid,
  .math-dashboard-profile-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --header-height: 112px;
  }

  .app-header {
    height: var(--header-height) !important;
    align-items: flex-start !important;
    align-content: flex-start !important;
    flex-wrap: wrap;
    gap: 8px 10px !important;
    padding: 8px 10px !important;
  }

  .header-left {
    order: 1;
    flex: 1 1 calc(100% - 88px);
    min-width: 0;
    gap: 8px;
  }

  .logo-text {
    max-width: 86px;
    overflow: hidden;
    padding-right: 8px;
    margin-right: 0;
    font-size: 12px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .header-back {
    flex: 0 0 auto;
    padding: 6px 8px !important;
  }

  .header-back__label {
    font-size: 11px;
  }

  .breadcrumb-subject {
    display: none;
  }

  .header-right {
    order: 2;
    flex: 0 0 auto;
    gap: 6px;
    margin-left: auto;
  }

  .header-center {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    justify-content: flex-start;
  }

  .steps-tab-bar {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    justify-content: stretch;
    overflow: hidden;
  }

  .step-tab {
    min-width: 0;
    flex: 1 1 0;
    justify-content: center;
    gap: 4px;
    padding: 5px 4px !important;
    font-size: 10px !important;
    letter-spacing: 0;
    white-space: nowrap;
  }

  .step-label-en {
    display: none;
  }

  .step-num {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    margin-right: 0;
  }

  .paper-tray {
    left: 4px;
    right: 4px;
    width: calc(100% - 8px);
    max-width: calc(100% - 8px);
    margin-left: 0;
  }

  .app-layout,
  .app-body,
  .main-content {
    min-width: 0;
    max-width: 100%;
  }

  .math-dashboard-brand {
    display: none !important;
  }

  .math-dashboard-panel {
    grid-template-columns: minmax(0, 1fr);   /* 唔用淨 1fr（=minmax(auto,1fr)）：auto 最小值會被寬內容（如 Classes detail 表格）撐爆 track；minmax(0,…) 令 track 可縮到 viewport，寬表由 .classes-table-wrap 內部 scroll（§3.1 H）。Overview/Profile 內容本身 fit，無影響。 */
    overflow-x: hidden;
  }

  .math-dashboard-nav {
    min-height: auto;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 3px solid var(--glass-border);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: rgba(255, 255, 255, 0.95);
  }

  .math-dashboard-home {
    margin: 0 !important;
    align-self: center !important;
  }

  .math-dashboard-nav__links {
    display: flex;
    flex-direction: row;
    gap: 6px;
  }

  .math-dashboard-nav__item {
    min-height: 38px;
    padding: 0 10px;
    text-align: center;
    font-size: 13px;
  }

  .math-dashboard-quota {
    display: none;
  }

  .math-dashboard-profile-trigger {
    min-height: 38px;
    padding: 6px 10px;
    margin: 0 !important;
    border: 1.5px solid var(--glass-border) !important;
    box-shadow: var(--shadow-xs) !important;
  }

  .math-dashboard-profile-trigger strong,
  .math-dashboard-profile-trigger small {
    display: none !important;
  }

  .math-dashboard-profile-avatar {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    font-size: 13px;
  }

  .math-dashboard-main {
    padding: 18px;
  }

  .math-dashboard-hero,
  .math-dashboard-recent {
    padding: 18px;
  }

  .math-dashboard-hero h1 {
    font-size: 32px;
  }

  .math-dashboard-hero h1 span {
    font-size: 0.86em;
  }

  .math-dashboard-hero p {
    font-size: 16px;
  }

  .math-dashboard-steps,
  .math-dashboard-stats,
  .math-dashboard-class-grid,
  .math-dashboard-profile-grid,
  .math-dashboard-profile-actions {
    grid-template-columns: 1fr;
  }

  .math-dashboard-recent-row {
    grid-template-columns: 1fr;
  }

  .math-dashboard-recent-row__actions {
    width: 100%;
  }

  .math-dashboard-mini-btn {
    flex: 1;
  }
}

/* ==========================================================================
   Teacher angle-adjust panel (in-card, Auto-Gen figure questions)
   ========================================================================== */
.angle-panel {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.85);
}
.angle-panel.hidden { display: none; }
.angle-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.angle-panel__title {
  font-weight: 700;
  font-size: var(--font-size-sm);
}
.angle-panel__reroll {
  border: 1px solid var(--glass-border);
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 14px;
}
.angle-panel__reroll:hover { background: var(--glass-bg-hover); }
.angle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}
.angle-row__label {
  min-width: 58px;
  font-weight: 600;
  font-size: var(--font-size-sm);
}
.angle-row__minmax {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  min-width: 26px;
  text-align: center;
}
.angle-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent-primary);
}
.angle-row__val {
  min-width: 42px;
  text-align: right;
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  font-weight: 700;
}
.angle-row__segs { display: flex; flex-wrap: wrap; gap: 6px; }
.angle-seg {
  padding: 3px 10px;
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  background: var(--bg-secondary);
  font-size: var(--font-size-sm);
  cursor: pointer;
}
.angle-seg:hover { background: var(--glass-bg-hover); }
.angle-seg.active {
  background: var(--accent-primary);
  color: var(--text-inverse);
}
.angle-panel__msg {
  min-height: 16px;
  margin-top: 6px;
  font-size: var(--font-size-sm);
}
.angle-panel__msg--ok { color: var(--color-success); }
.angle-panel__msg--err { color: var(--color-danger); }
.angle-adjusted-badge {
  background: var(--color-warning-muted);
  color: var(--color-warning);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  margin-left: 6px;
  display: inline-block;
  vertical-align: middle;
}

/* angle panel v2: numeric input + feasibility zones */
.angle-row__slider {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.angle-row__slider input[type="range"] { width: 100%; }
.angle-row__zones {
  height: 5px;
  border-radius: 3px;
  background: transparent;
  border: 1px solid var(--border-hairline-08);
}
.angle-row__num {
  width: 62px;
  padding: 3px 6px;
  border: 1px solid var(--glass-border);
  border-radius: 6px;
  background: var(--bg-input);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  font-weight: 700;
  text-align: right;
}
.angle-seg--dead {
  opacity: 0.35;
  cursor: not-allowed;
  text-decoration: line-through;
}
.angle-panel__legend {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: 4px;
}
