/* public/css/app.css - Rich, Posh, Minimalist Mobile-First Design System */

@import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@400;500;600;700&family=Noto+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Raleway:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  /* Rich & Posh Dynamic Palette */
  --primary: #1e40af;
  --primary-hover: #172554;
  --primary-glow: rgba(30, 64, 175, 0.2);
  --primary-light: rgba(30, 64, 175, 0.06);
  --primary-border: rgba(30, 64, 175, 0.22);
  
  --secondary: #0f766e;
  --secondary-hover: #134e4a;
  --secondary-light: rgba(15, 118, 110, 0.07);
  
  --accent: #f59e0b;
  --accent-light: rgba(245, 158, 11, 0.1);
  
  --success: #10b981;
  --success-light: rgba(16, 185, 129, 0.09);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.09);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.09);
  --info: #06b6d4;
  
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-muted: #f1f5f9;
  --bg-input: #ffffff;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;
  --border-focus: #3b82f6;

  /* Typography */
  --font-bengali: 'SolaimanLipi', 'Hind Siliguri', 'Kalpurush', sans-serif;
  --font-english: 'Noto Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-main: var(--font-english);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 1px 2px -1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.06), 0 2px 4px -2px rgba(15, 23, 42, 0.03);
  --shadow-lg: 0 16px 32px -4px rgba(15, 23, 42, 0.08), 0 4px 8px -2px rgba(15, 23, 42, 0.03);
  --shadow-glow: 0 0 20px -2px var(--primary-glow);
}

html[lang="bn"] {
  font-family: var(--font-bengali), var(--font-english);
}

html[lang="en"] {
  font-family: var(--font-english), var(--font-bengali);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-page);
  background-image: radial-gradient(at 0% 0%, rgba(30, 64, 175, 0.03) 0px, transparent 50%), radial-gradient(at 100% 100%, rgba(15, 118, 110, 0.03) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Typography & Hierarchy */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-main);
  line-height: 1.25;
}

.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 0.95rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; letter-spacing: -0.02em; }
.text-2xl { font-size: 1.6rem; letter-spacing: -0.03em; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--secondary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.flex { display: flex; }
.inline-flex { display: inline-flex; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.flex-1 { flex: 1 1 0%; }

/* Buttons with Tactile Depth & Touch Area */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
  line-height: 1.25;
  min-height: 42px;
  user-select: none;
  -webkit-user-select: none;
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px var(--primary-glow);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-secondary {
  background-color: #fff;
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-muted);
  border-color: #cbd5e1;
}

.btn-success { background-color: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background-color: #059669; }

.btn-danger { background-color: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background-color: #dc2626; }

.btn-warning { background-color: var(--warning); color: #fff; border-color: var(--warning); }
.btn-warning:hover:not(:disabled) { background-color: #d97706; }

.btn-outline {
  background: #fff;
  color: var(--primary);
  border-color: var(--primary-border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--primary-light);
  border-color: var(--primary);
}

.btn-sm { padding: 6px 12px; font-size: 0.82rem; min-height: 36px; border-radius: var(--radius-xs); }
.btn-lg { padding: 12px 24px; font-size: 1.02rem; min-height: 48px; border-radius: var(--radius-md); }
.btn-block { width: 100%; display: flex; }

/* Custom Google Button */
.btn-google {
  background: #ffffff;
  color: #1f2937;
  border: 1.5px solid #e5e7eb;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.btn-google:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #d1d5db;
  box-shadow: var(--shadow-md);
}

/* Forms & High-Precision Inputs */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 5px; color: var(--text-main); }
.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 16px; /* Prevents auto-zoom on iOS */
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  color: var(--text-main);
  transition: all 0.18s ease;
  font-family: inherit;
  min-height: 44px;
}
@media (min-width: 768px) {
  .form-control { font-size: 0.92rem; }
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--primary-light);
}
textarea.form-control { min-height: 84px; resize: vertical; }

/* Taxonomies: subjects with their chapters nested inside */
.tax-subject { border: 1px solid var(--border-color); border-radius: var(--radius-sm); margin-bottom: 8px; background: #fff; }
.tax-subject[open] { border-color: var(--primary-border); }
.tax-subject-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; cursor: pointer; list-style: none; user-select: none;
  min-height: 44px;
}
.tax-subject-head::-webkit-details-marker { display: none; }
.tax-subject-head:hover { background: var(--bg-muted); border-radius: var(--radius-sm); }
.tax-subject-caret { display: flex; flex-shrink: 0; color: var(--text-muted); transition: transform .15s ease; }
.tax-subject[open] > .tax-subject-head .tax-subject-caret { transform: rotate(90deg); }
.tax-chapter-list { padding: 2px 12px 10px 34px; border-top: 1px dashed var(--border-color); }
.tax-chapter-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border-color);
}
.tax-chapter-row:last-child { border-bottom: none; }

/* Math fallback rendering (public/js/math.js) — used when KaTeX isn't loaded, and for bare
   undelimited LaTeX that KaTeX doesn't touch. */
.math-inline { font-family: 'Times New Roman', Times, serif; font-style: italic; padding: 0 1px; }
.math-display { display: block; margin: 8px 0; text-align: center; font-family: 'Times New Roman', Times, serif; font-style: italic; }
.mfrac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .9em; padding: 0 3px; }
.mfrac-n { border-bottom: 1px solid currentColor; padding: 0 3px; }
.mfrac-d { padding: 0 3px; }
.msqrt { white-space: nowrap; }
.msqrt-r { border-top: 1px solid currentColor; padding: 0 2px; }
/* KaTeX display blocks can be wider than a phone; let them scroll rather than stretch the page. */
.katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; }

/* Lightweight rich text editor (public/js/rich-editor.js) */
.rich-editor { border: 1.5px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-input); }
.rich-editor-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 5px; background: var(--bg-muted); border-bottom: 1px solid var(--border-color); }
.rich-editor-btn { min-width: 32px; min-height: 32px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-xs); background: transparent; color: var(--text-main); font-size: 0.8rem; font-family: inherit; cursor: pointer; }
.rich-editor-btn:hover { background: var(--bg-card); border-color: var(--border-color); }
.rich-editor-body { min-height: 84px; max-height: 320px; overflow-y: auto; border: none; border-radius: 0; outline: none; line-height: 1.6; }
.rich-editor-body:empty:before { content: attr(data-placeholder); color: var(--text-muted); }
.rich-editor-body:focus { box-shadow: none; }

/* Refined Cards & Containers */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
  transition: box-shadow 0.2s ease;
}
.card:hover {
  box-shadow: var(--shadow-md);
}
.card-header {
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.card-title { font-size: 1.08rem; font-weight: 700; letter-spacing: -0.02em; }

/* Frosted Glass Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}
.badge-primary { background-color: var(--primary-light); color: var(--primary); border: 1px solid var(--primary-border); }
.badge-success { background-color: var(--success-light); color: var(--success); }
.badge-warning { background-color: var(--warning-light); color: var(--warning); }
.badge-danger { background-color: var(--danger-light); color: var(--danger); }
.badge-secondary { background-color: var(--bg-muted); color: var(--text-muted); }

/* Header Navigation Bar */
.app-header {
  background-color: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top, 0);
}
.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 8px;
}
.app-logo {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.main-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 12px;
  width: 100%;
  flex: 1;
}
@media (min-width: 768px) {
  .main-container {
    padding: 24px 20px;
  }
}

/* Admin Responsive Sliding Drawer Navigation */
.admin-layout {
  display: flex;
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  position: relative;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

.admin-sidebar {
  width: 250px;
  background-color: #fff;
  border-right: 1px solid var(--border-color);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.admin-sidebar-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 14px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  min-height: 46px;
  touch-action: manipulation;
}
.admin-nav-item:hover { background-color: var(--bg-muted); color: var(--text-main); }
.admin-nav-item.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--primary);
}

.admin-content {
  flex: 1;
  padding: 20px 24px;
  overflow-x: hidden;
  max-width: 100%;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

@media (max-width: 768px) {
  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 285px;
    z-index: 100;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
  }
  .admin-sidebar.open {
    transform: translateX(0);
  }
  .admin-sidebar-header {
    display: flex;
  }
  .admin-content {
    padding: 14px 10px;
  }
}

/* KPI Metrics Cards Responsive Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
  }
}
.kpi-card {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}
.kpi-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

/* Responsive Table & Card-Style Switcher */
.table-container, .responsive-table {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #fff;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}

table.data-table, table.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}
table.data-table th, table.table th {
  background-color: #fafbfc;
  padding: 12px 14px;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
table.data-table td, table.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}
table.data-table tr:last-child td, table.table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td, table.table tr:hover td { background-color: #fafbfc; }

@media (max-width: 768px) {
  .responsive-table table.data-table,
  .responsive-table thead,
  .responsive-table tbody,
  .responsive-table th,
  .responsive-table td,
  .responsive-table tr {
    display: block;
  }
  .responsive-table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  .responsive-table tr {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 12px;
    background: #fff;
    box-shadow: var(--shadow-sm);
  }
  .responsive-table td {
    border: none;
    padding: 8px 0;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    font-size: 0.86rem;
    gap: 8px;
  }
  .responsive-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
}

/* Modals (Responsive Bottom-Sheet on Mobile) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 12px;
}
.modal-content {
  background-color: #fff;
  border-radius: var(--radius-lg);
  max-width: 620px;
  width: 100%;
  /* A flex item defaults to min-width:auto, so a single wide child (a long formula, an
     unbreakable token) can force the dialog wider than the viewport and push the header's
     close button off-screen. min-width:0 lets it shrink to the viewport instead. */
  min-width: 0;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.8);
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fafbfc;
  flex-shrink: 0;
}
.modal-header h3 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* The close control must never be squeezed away by a long title. */
#modal-close-btn { flex-shrink: 0; }
.modal-body {
  padding: 18px;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}
/* Wide, genuinely non-wrappable content (tables, long formulas) scrolls inside its own box
   rather than stretching the dialog. */
.modal-body .responsive-table,
.modal-body pre,
.modal-body .katex-display { max-width: 100%; overflow-x: auto; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-color);
  background-color: #fafbfc;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

@media (max-width: 640px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-content {
    border-radius: 20px 20px 0 0;
    max-height: 88vh;
    max-height: 88dvh;
    max-width: 100%;
  }
}

/* Responsive Form Grids */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* Toasts (Mobile Responsive) */
#toast-container {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: 16px;
  left: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
@media (min-width: 640px) {
  #toast-container {
    left: auto;
    width: 380px;
    right: 20px;
  }
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.2s ease-out;
}
@keyframes toastIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast-info { background-color: var(--primary); }
.toast-success { background-color: var(--success); }
.toast-error { background-color: var(--danger); }
.toast-warning { background-color: var(--warning); }

/* Option Cards for Exams (Mobile Touch Optimized) */
.option-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.16s ease;
  background-color: #fff;
  min-height: 52px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.option-card:hover { border-color: var(--primary-border); background-color: #fafbfc; }
.option-card:active { transform: scale(0.985); }
.option-card.selected { border-color: var(--primary); background-color: var(--primary-light); box-shadow: 0 0 0 1px var(--primary); }
.option-badge {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  background-color: var(--bg-muted);
  color: var(--text-main);
  flex-shrink: 0;
  transition: all 0.15s ease;
}
.option-card.selected .option-badge {
  background-color: var(--primary);
  color: #fff;
}

/* Examination experience — calm, focused, and optimized for touch */
.exam-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 10% 0%, var(--primary-light), transparent 28rem),
    linear-gradient(180deg, #f8fafc 0%, #f4f7fb 100%);
}
.exam-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: max(10px, env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid rgba(226, 232, 240, .86);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.exam-header-inner, .exam-main-inner, .exam-footer-inner { width: 100%; max-width: 780px; margin: 0 auto; }
.exam-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.exam-title-wrap { min-width: 0; flex: 1; }
.exam-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .95rem; font-weight: 750; letter-spacing: -.015em; }
.exam-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; color: var(--text-muted); font-size: .76rem; font-weight: 650; }
.exam-progress-track { height: 3px; max-width: 780px; margin: 9px auto 0; overflow: hidden; border-radius: 99px; background: var(--bg-muted); }
.exam-progress-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #6366f1); transition: width .25s ease; }
.exam-tools { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.exam-sync { padding: 5px 8px; }
.exam-timer { display: inline-flex; align-items: center; gap: 5px; padding: 7px 9px; border-radius: 10px; background: #f8fafc; color: var(--text-main); font-size: .8rem; font-weight: 800; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.exam-timer.is-urgent { color: var(--danger); background: var(--danger-light); }
.exam-palette-trigger { width: 44px; min-width: 44px; height: 44px; padding: 0; }
.exam-lang-toggle { min-width: 44px; height: 44px; padding: 0 8px; font-weight: 800; font-size: .8rem; }
.exam-main { flex: 1; width: 100%; padding: 20px 14px 118px; }
.exam-question-card { position: relative; overflow: hidden; padding: clamp(20px, 4vw, 30px); margin: 0; border: 1px solid rgba(226, 232, 240, .9); border-radius: 22px; box-shadow: 0 14px 35px -24px rgba(15, 23, 42, .32); }
.exam-question-card::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: linear-gradient(180deg, var(--primary), #818cf8); }
.exam-question-label { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 14px; color: var(--primary); font-size: .78rem; font-weight: 800; letter-spacing: .055em; text-transform: uppercase; }
.exam-question-label::after { content: ''; width: 26px; height: 1px; background: currentColor; opacity: .35; }
.exam-question-text { font-size: clamp(1.05rem, 2vw, 1.22rem); font-weight: 650; line-height: 1.65; overflow-wrap: anywhere; }
.exam-question-image { display: block; max-width: 100%; max-height: 300px; margin: 22px auto 4px; border: 1px solid var(--border-color); border-radius: 14px; }
.exam-options { display: grid; gap: 10px; margin-top: 24px; }
.exam-options .option-card { margin: 0; padding: 13px 15px; border-radius: 14px; min-height: 58px; box-shadow: 0 1px 1px rgba(15, 23, 42, .02); }
.exam-options .option-card:hover { border-color: var(--primary); background: var(--primary-light); transform: translateY(-1px); }
.exam-options .option-card.selected { box-shadow: 0 8px 18px -14px var(--primary); }
.exam-footer { position: fixed; right: 0; bottom: 0; left: 0; z-index: 40; padding: 10px 14px max(12px, env(safe-area-inset-bottom, 12px)); background: rgba(255, 255, 255, .92); border-top: 1px solid rgba(226, 232, 240, .9); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.exam-footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.exam-footer-group { display: flex; align-items: center; gap: 8px; }
.exam-footer .btn { min-height: 44px; }
.exam-submit { box-shadow: 0 6px 14px -10px var(--danger); }
.exam-palette-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.exam-palette-stat { padding: 10px 8px; border: 1px solid var(--border-color); border-radius: 12px; text-align: center; background: #fff; }
.exam-palette-stat strong { display: block; font-size: 1.05rem; line-height: 1.1; }
.exam-palette-stat span { display: block; margin-top: 3px; color: var(--text-muted); font-size: .72rem; font-weight: 650; }
.exam-palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 9px; max-height: 52vh; overflow-y: auto; padding: 2px; }
.palette-q-btn { position: relative; min-height: 44px; padding: 4px; border: 1.5px solid var(--border-color); border-radius: 12px; background: #fff; color: var(--text-main); font-weight: 700; }
.palette-q-btn.is-current { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.palette-q-btn.is-answered { border-color: var(--success); color: var(--success); background: var(--success-light); }
.palette-q-btn.is-answered::before { content: ''; position: absolute; bottom: 5px; left: 5px; width: 5px; height: 5px; border-radius: 1px; background: currentColor; }
.palette-q-btn.is-review { border-color: var(--warning); color: #b45309; background: var(--warning-light); }
.palette-q-btn.is-review::after { content: ''; position: absolute; top: 5px; right: 5px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
@media (max-width: 640px) {
  .exam-header { padding-right: 12px; padding-left: 12px; }
  .exam-sync { padding: 5px 7px; font-size: 0; }
  .exam-sync svg { display: block; }
  .exam-main { padding: 14px 10px 104px; }
  .exam-question-card { border-radius: 17px; }
  .exam-footer { padding-right: 10px; padding-left: 10px; }
  .exam-footer-group { gap: 5px; }
  .exam-footer .btn { padding-right: 10px; padding-left: 10px; }
}

/* Color Picker Chips */
.color-picker-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.color-chip {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px var(--border-color);
  transition: transform 0.15s, box-shadow 0.15s;
}
.color-chip:hover { transform: scale(1.1); }
.color-chip.active { box-shadow: 0 0 0 2.5px var(--text-main); }

/* Math Container Auto-Scroll for long equations on Mobile */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px 0;
  -webkit-overflow-scrolling: touch;
}

/* Utilities */
@media (max-width: 640px) {
  .hidden-mobile { display: none !important; }
}
@media (min-width: 641px) {
  .hidden-desktop { display: none !important; }
}

/* Respect the OS-level reduced-motion preference across every animation/transition in the
   system, rather than relying on individual components to opt out. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
