@import url('https://fonts.googleapis.com/css2?family=Onest:wght@300;400;500;600;700&display=swap');

/* ===== Tooltip Component ===== */
.tooltip {
  position: absolute;
  background: var(--stv-gray-900);
  color: #FFFFFF;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-family);
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 100ms ease-out;
}
.tooltip[data-visible="true"] { opacity: 1; }
.tooltip::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}
.tooltip[data-placement="bottom"]::after {
  top: -5px; left: 50%; transform: translateX(-50%);
  border-bottom: 5px solid var(--stv-gray-900);
}
.tooltip[data-placement="top"]::after {
  bottom: -5px; left: 50%; transform: translateX(-50%);
  border-top: 5px solid var(--stv-gray-900);
}
.tooltip[data-placement="left"]::after {
  right: -5px; top: 50%; transform: translateY(-50%);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  border-left: 5px solid var(--stv-gray-900); border-right: none;
}
.tooltip[data-placement="right"]::after {
  left: -5px; top: 50%; transform: translateY(-50%);
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  border-right: 5px solid var(--stv-gray-900); border-left: none;
}
.tooltip.no-caret::after { display: none; }

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* ==========================================================
     Stuvia Design System — Official Tokens
     Source: StuviaDesignSystem/colors_and_type.css
     ========================================================== */

  /* ---------- Brand Blue ---------- */
  --stv-blue-50:   #E9F5FE;
  --stv-blue-100:  #D1E9FF;
  --stv-blue-200:  #DDF0FC;   /* badge bg, light-blue surface */
  --stv-blue-300:  #B0DCF6;
  --stv-blue-400:  #5DBFF1;
  --stv-blue-500:  #199BE9;   /* PRIMARY — buttons, links */
  --stv-blue-600:  #1F9CFF;   /* hover/lighter */
  --stv-blue-700:  #1570EF;
  --stv-blue-800:  #147CBA;   /* badge text */
  --stv-blue-900:  #102A56;
  --stv-blue-950:  #0A3E5D;   /* footer / deep-blue surface */

  /* ---------- Yellow (CTA) ---------- */
  --stv-yellow-100: #FFF3D1;
  --stv-yellow-300: #FDB022;   /* star fill */
  --stv-yellow-500: #FEBD00;   /* PRIMARY CTA bg */
  --stv-yellow-600: #E8A900;   /* hover */

  /* ---------- Neutrals ---------- */
  --stv-white:     #FFFFFF;
  --stv-gray-25:   #FCFCFD;
  --stv-gray-50:   #F8FAFC;
  --stv-gray-75:   #FAFAFA;
  --stv-gray-100:  #F5F5F5;
  --stv-gray-150:  #EEF2F6;
  --stv-gray-200:  #E9EAEB;   /* default border */
  --stv-gray-250:  #E3E8EF;
  --stv-gray-300:  #D5D7DA;   /* input border */
  --stv-gray-400:  #717680;
  --stv-gray-500:  #535862;   /* body text muted */
  --stv-gray-600:  #475467;
  --stv-gray-700:  #414651;
  --stv-gray-800:  #364152;
  --stv-gray-900:  #181D27;   /* headings */
  --stv-gray-950:  #121926;
  --stv-ink:       #060316;
  --stv-charcoal:  #131316;

  /* ---------- Semantic colors ---------- */
  --stv-success:    #00B67A;   /* Trustpilot green */
  --stv-success-bg: #DCFAE6;
  --stv-success-fg: #067647;
  --stv-error:      #D92D20;
  --stv-warm-100:   #F2EBE8;
  --stv-warm-700:   #44403C;

  /* ---------- Foreground / surface (semantic aliases) ---------- */
  --fg-1: var(--stv-gray-900);          /* heading */
  --fg-2: var(--stv-gray-500);          /* body */
  --fg-3: var(--stv-gray-400);          /* hint / placeholder */
  --fg-on-brand: #FFFFFF;
  --fg-link: var(--stv-blue-500);

  --bg-page: var(--stv-white);
  --bg-subtle: var(--stv-gray-50);
  --bg-promise: var(--stv-gray-75);
  --bg-deep: var(--stv-blue-950);
  --bg-light-blue: var(--stv-blue-200);
  --bg-warm: var(--stv-warm-100);

  --border-subtle: var(--stv-gray-200);
  --border-input: var(--stv-gray-300);

  /* ---------- Typography ---------- */
  --font-sans: 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;

  --text-xs:   12px;
  --text-sm:   14px;
  --text-base: 16px;
  --text-lg:   18px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;
  --text-4xl:  36px;
  --text-5xl:  48px;

  --leading-xs:  18px;
  --leading-sm:  20px;
  --leading-base: 24px;
  --leading-lg:  28px;
  --leading-xl:  30px;
  --leading-2xl: 32px;
  --leading-3xl: 38px;
  --leading-4xl: 44px;
  --leading-5xl: 60px;

  --tracking-tight: -0.020em;

  /* ---------- Radii ---------- */
  --radius-xs:   4px;
  --radius-sm:   6px;   /* badges */
  --radius-md:   8px;   /* buttons, inputs */
  --radius-lg:   10px;  /* featured icon */
  --radius-xl:   12px;  /* cards, images */
  --radius-2xl:  16px;
  --radius-full: 9999px;

  /* ---------- Shadows (DS official) ---------- */
  --shadow-xs: 0px 1px 2px 0px rgba(16,24,40,0.05);
  --shadow-sm: 0px 1px 3px 0px rgba(16,24,40,0.10),
               0px 1px 2px 0px rgba(16,24,40,0.06);
  --shadow-md: 0px 4px 8px -2px rgba(16,24,40,0.10),
               0px 2px 4px -2px rgba(16,24,40,0.06);
  --shadow-lg: 0px 12px 16px -4px rgba(16,24,40,0.08),
               0px 4px 6px -2px rgba(16,24,40,0.03);
  --shadow-focus-brand: 0 0 0 4px rgba(25,155,233,0.20);

  /* ---------- Spacing ---------- */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* ==========================================================
     Legacy aliases — map old token names to DS tokens.
     Keeps existing CSS working while we migrate to --stv-* names.
     ========================================================== */
  --color-brand-primary: var(--stv-blue-500);
  --color-brand-secondary: var(--stv-blue-800);
  --color-cta-yellow: var(--stv-yellow-500);
  --color-cta-yellow-hover: var(--stv-yellow-600);

  --color-text-primary: var(--stv-gray-900);
  --color-text-secondary: var(--stv-gray-700);
  --color-text-tertiary: var(--stv-gray-500);
  --color-text-quaternary: var(--stv-gray-400);

  --color-bg-primary: var(--stv-white);
  --color-bg-secondary: var(--stv-gray-75);
  --color-bg-tertiary: var(--stv-gray-100);

  --color-border-primary: var(--stv-gray-300);
  --color-border-secondary: var(--stv-gray-200);

  /* Semantic status — kept for existing quiz/flashcard UI */
  --color-success: #079455;
  --color-success-50: #ecfdf3;
  --color-success-100: #dcfae6;
  --color-success-200: #abefc6;
  --color-success-300: #75e0a7;
  --color-success-400: #47cd89;
  --color-success-500: #17b26a;
  --color-success-light: #47cd89;
  --color-success-dark: var(--stv-success-fg);
  --color-success-bg: rgba(7, 148, 85, 0.08);

  --color-error: var(--stv-error);
  --color-error-50: #fef3f2;
  --color-error-100: #fee4e2;
  --color-error-200: #fecdca;
  --color-error-300: #fda29b;
  --color-error-400: #f97066;
  --color-error-500: #f04438;
  --color-error-dark: #b42318;
  --color-error-bg: rgba(217, 45, 32, 0.08);

  --color-warning: #dc6803;
  --color-warning-50: #fffaeb;
  --color-warning-100: #fef0c7;
  --color-warning-200: #fedf89;
  --color-warning-300: #fec84b;
  --color-warning-400: #fdb022;
  --color-warning-500: #f79009;
  --color-warning-dark: #b54708;
  --color-warning-bg: rgba(220, 104, 3, 0.08);

  --color-star: var(--stv-yellow-300);
  --color-star-empty: var(--stv-gray-300);

  /* Legacy spacing aliases */
  --space-xxs: 2px;
  --space-xs: var(--space-1);
  --space-sm: 6px;
  --space-md: var(--space-2);
  --space-lg: var(--space-3);
  --space-xl: var(--space-4);
  --space-2xl: var(--space-5);
  --space-3xl: var(--space-6);
  --space-4xl: var(--space-8);

  /* Legacy font aliases */
  --font-family: var(--font-sans);
  --font-xs: var(--text-xs);
  --font-sm: var(--text-sm);
  --font-md: var(--text-base);
  --font-lg: var(--text-lg);
  --font-xl: var(--text-xl);
  --font-2xl: var(--text-2xl);
  --line-height-xs: var(--leading-xs);
  --line-height-sm: var(--leading-sm);
  --line-height-md: var(--leading-base);
  --line-height-lg: var(--leading-lg);

  --transition: 200ms ease-out;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-page);
  color: var(--fg-1);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  height: 56px;
  padding: 12px 16px;
  background: var(--color-bg-primary);
  border-bottom: 0.5px solid var(--color-border-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.topbar-zone-1 {
  flex: 1;
  min-width: 0;
  gap: 16px;
}

.topbar-zone-2 {
  flex-shrink: 0;
  gap: 2px;
}

.topbar-zone-3 {
  flex-shrink: 0;
  gap: 8px;
  padding-left: 8px;
  border-left: 0.5px solid var(--color-border-secondary);
}

.topbar-back-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--stv-gray-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background 200ms ease-out, color 200ms ease-out;
  flex-shrink: 0;
  padding: 0;
  margin-right: -4px; /* tighten gap to logo */
}

.topbar-back-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--stv-gray-700);
}

.topbar-logo {
  height: 28px;
  width: auto;
  flex-shrink: 0;
}

.topbar-doc-title {
  font-size: 13px;
  color: var(--color-text-secondary);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 200ms ease-out, color 200ms ease-out;
  padding: 0;
}

.topbar-btn:hover {
  background: var(--color-bg-tertiary);
}

.topbar-btn:focus-visible {
  background: var(--color-bg-tertiary);
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
}

.topbar-divider {
  width: 0.5px;
  height: 16px;
  background: var(--color-border-secondary);
  margin: 0 4px;
}

.topbar-page-indicator {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  padding: 0 4px;
  min-width: 48px;
  text-align: center;
  user-select: none;
}

.topbar-lang-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: 4px 8px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-family: var(--font-family);
  transition: background 200ms ease-out;
}

.topbar-lang-btn:hover {
  background: var(--color-bg-secondary);
}

/* Language selector */
.lang-selector {
  position: relative;
}

.lang-selector-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  font-size: 12px;
  font-weight: 600;
  color: var(--stv-gray-500);
  padding: 0 8px;
  border: 1px solid var(--stv-gray-200);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: border-color 200ms ease-out;
}

.lang-selector-btn:hover {
  border-color: var(--stv-blue-500);
}

.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-page);
  border: 1.5px solid var(--stv-gray-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 140px;
  z-index: 100;
  overflow: hidden;
}

.lang-dropdown.hidden {
  display: none;
}

.lang-option {
  display: block;
  width: 100%;
  padding: 8px 14px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--fg-1);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background 200ms ease-out;
}

.lang-option:hover {
  background: var(--stv-gray-100);
}

.lang-option[data-active="true"] {
  color: var(--stv-blue-500);
  font-weight: 600;
}

.topbar-download-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--stv-blue-500);
  background: var(--bg-page);
  border: 1px solid var(--stv-blue-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: border-color 200ms ease-out;
}

.topbar-download-btn:hover {
  border-color: var(--stv-blue-500);
}

.topbar-download-btn svg {
  flex-shrink: 0;
}

/* ===== Download Modal ===== */
.download-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 18, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  animation: fadeIn 0.15s ease-out;
}

.download-modal {
  background: #FFFFFF;
  border-radius: var(--radius-xl);
  box-shadow: 0px 8px 8px -4px rgba(16, 24, 40, 0.03),
              0px 20px 24px -4px rgba(16, 24, 40, 0.08);
  max-width: 400px;
  width: 100%;
  overflow: hidden;
}

/* ---- Header ---- */
.download-modal-header {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 24px 0;
}

.download-modal-icon {
  position: relative;
  width: 32px;
  height: 32px;
}

.download-modal-icon-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--stv-blue-50);
}

.download-modal-icon-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--stv-blue-500);
  display: flex;
  align-items: center;
  justify-content: center;
}

.download-modal-icon-circle svg {
  width: 20px;
  height: 20px;
}

.download-modal-text-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.download-modal-title {
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
  font-weight: 600;
  color: var(--stv-gray-900);
}

.download-modal-desc {
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 400;
  color: var(--stv-gray-500);
}

.download-modal-close {
  position: absolute;
  top: 12px;
  right: 24px;
  width: 44px;
  height: 44px;
  border: none;
  background: none;
  color: var(--stv-gray-400);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: background 200ms ease-out;
}

.download-modal-close:hover {
  background: var(--stv-gray-100);
}

/* ---- Body ---- */
.download-modal-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 24px;
}

.download-modal-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  color: var(--stv-gray-700);
}

.download-modal-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.download-modal-checkmark {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border: 1px solid var(--stv-gray-300);
  border-radius: var(--radius-xs);
  background: #FFFFFF;
  transition: background 150ms ease, border-color 150ms ease;
  position: relative;
}

.download-modal-checkmark::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 4px;
  height: 8px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  opacity: 0;
  transition: opacity 150ms ease;
}

.download-modal-checkbox input[type="checkbox"]:checked + .download-modal-checkmark {
  background: var(--stv-blue-500);
  border-color: var(--stv-blue-500);
}

.download-modal-checkbox input[type="checkbox"]:checked + .download-modal-checkmark::after {
  opacity: 1;
}

.download-modal-checkbox input[type="checkbox"]:focus-visible + .download-modal-checkmark {
  box-shadow: var(--shadow-focus-brand);
}

/* ---- Footer ---- */
.download-modal-footer {
  display: flex;
  gap: 12px;
  padding: 0 24px 24px;
  padding-top: 8px;
}

/* DS button — modal footer uses canonical .btn / .btn-primary / .btn-secondary.
   These two classes inherit DS styling and just stretch to fill. */
.download-modal-btn-secondary,
.download-modal-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex: 1;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              transform 100ms ease-out,
              box-shadow 100ms ease-out;
}

.download-modal-btn-secondary:active,
.download-modal-btn-primary:active {
  transform: translateY(1px);
  box-shadow: none;
}

.download-modal-btn-secondary {
  background: #FFFFFF;
  border-color: var(--stv-gray-300);
  color: var(--stv-gray-700);
}

.download-modal-btn-secondary:hover {
  background: var(--stv-gray-50);
}

.download-modal-btn-primary {
  background: var(--stv-blue-500);
  border-color: var(--stv-blue-500);
  color: #FFFFFF;
}

.download-modal-btn-primary:hover {
  background: var(--stv-blue-600);
  border-color: var(--stv-blue-600);
}

.download-modal-btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.download-modal-btn-primary:disabled:hover {
  background: var(--stv-blue-500);
  border-color: var(--stv-blue-500);
}

/* Download loading toast */
.download-loading {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-page);
  border: 1px solid var(--stv-blue-300);
  border-radius: var(--radius-md);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  font-size: var(--text-sm);
  color: var(--fg-2);
  animation: fadeIn 0.15s ease-out;
}

.download-loading-dots {
  display: flex;
  gap: 4px;
}

.download-loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--stv-blue-500);
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}

.download-loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.download-loading-dots span:nth-child(3) { animation-delay: 0.3s; }
.download-loading-dots span:nth-child(4) { animation-delay: 0.45s; }

.topbar-icon-btn {
  width: 28px;
  height: 28px;
  border: 0.5px solid var(--color-border-secondary);
  border-radius: 6px;
  background: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 200ms ease-out;
}

.topbar-icon-btn:hover {
  background: var(--color-bg-secondary);
}

/* When PDF is collapsed, dim viewer controls */
.topbar-zone-2.disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Layout ===== */
.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 56px);
  position: relative;
}

.app-layout.tools-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.app-layout.pdf-collapsed {
  grid-template-columns: 1fr;
}

.app-layout.tools-collapsed .sidebar {
  display: none;
}

.app-layout.pdf-collapsed .pdf-viewer {
  display: none;
}

.app-layout.pdf-collapsed .sidebar {
  width: auto;
}

/* ===== Collapse Pills ===== */
.collapse-pill {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 36px;
  background: var(--color-bg-primary);
  border: 0.5px solid var(--color-border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: background 200ms ease-out;
  padding: 0;
  color: var(--color-text-secondary);
}

.collapse-pill:hover {
  background: var(--color-bg-secondary);
}

.collapse-pill.hidden {
  display: none;
}

/* Right panel pill (sits on left edge of sidebar) */
.collapse-pill-tools {
  right: 349px; /* 360px sidebar - 11px overlap */
  border-right: none;
  border-radius: 6px 0 0 6px;
  box-shadow: -1px 1px 4px rgba(0, 0, 0, 0.08);
}

.app-layout.tools-collapsed .collapse-pill-tools {
  right: -11px; /* Sits on the right edge when collapsed */
  border-right: 0.5px solid var(--color-border-primary);
  border-left: none;
  border-radius: 0 6px 6px 0;
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08);
  right: 0;
}

/* Left panel pill (PDF restore — only visible when PDF collapsed) */
.collapse-pill-pdf {
  left: 0;
  border-left: none;
  border-radius: 0 6px 6px 0;
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.08);
  width: 32px;
  height: 56px;
  flex-direction: column;
  gap: 4px;
}

.collapse-pill-pdf-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text-secondary);
  line-height: 1;
}

/* Constrain content when study tools are full width.
   width:100% prevents the flex child from shrinking to fit its content,
   so the column has a consistent width across every view (quiz, results, etc.). */
.app-layout.pdf-collapsed .sidebar-content {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* In pdf-collapsed mode (MC quiz / results / etc.) the sidebar is the whole
   page — let the page scroll naturally instead of forcing scroll inside the
   sidebar. Without this, tall content (e.g. an MC question + 4 options +
   explanation) can extend past the fixed-height sidebar viewport and become
   unreachable. The topbar is position:sticky so it stays put during scroll. */
body:has(.app-layout.pdf-collapsed) {
  overflow: auto;
}

.app-layout.pdf-collapsed {
  height: auto;
  min-height: calc(100vh - 56px);
  overflow: visible;
}

.app-layout.pdf-collapsed .sidebar {
  overflow-y: visible;
  height: auto;
}

/* ===== PDF Viewer ===== */
.pdf-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-tertiary);
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.pdf-container {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center; /* overridden to flex-start via JS when zoomed >100% */
  padding: var(--space-2xl);
  gap: var(--space-xl);
}

.pdf-page-wrapper {
  min-width: 100%;
  width: fit-content;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.pdf-page-wrapper canvas {
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  max-width: none;
  height: auto !important;
  display: block;
}

/* Page number label */
.pdf-page-number {
  width: 100%;
  text-align: center;
  padding: var(--space-sm) 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-quaternary);
  font-family: var(--font-family);
  letter-spacing: 0.02em;
}

/* Source highlight overlay on a page */
.source-highlight-card {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  background: var(--color-bg-primary);
  border: 1.5px solid var(--color-brand-primary);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  box-shadow: 0 8px 24px rgba(25, 155, 233, 0.18), 0 2px 8px rgba(24, 29, 39, 0.08);
  z-index: 5;
  animation: sourceCardIn 0.3s ease-out;
  font-family: var(--font-family);
}

.source-highlight-card-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-brand-primary);
  margin-bottom: 4px;
}

.source-highlight-card-text {
  font-size: var(--font-xs);
  line-height: 1.5;
  color: var(--color-text-secondary);
}

@keyframes sourceCardIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* (old sidebar-toggle removed — replaced by collapse pills) */

/* Focus rings for accessibility */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
}

/* ===== Sidebar (Study Tools Panel) ===== */
.sidebar {
  width: 360px;
  background: var(--color-bg-primary);
  border-left: 0.5px solid var(--color-border-secondary);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-content {
  padding: 16px;
  animation: fadeIn 0.3s ease;
}

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

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

/* ===== Sidebar Home ===== */
.sidebar-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.quiz-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  margin-bottom: var(--space-4xl);
}

/* ==========================================================
   Stuvia Design System — Buttons
   Source: StuviaDesignSystem/preview/components-buttons.html
   Spec: Onest 700 16/24, radius-md (8), padding 12 18, gap 8,
         shadow-xs. Press → drop shadow + translateY(1px).
   Hierarchies: cta (yellow), primary (blue), secondary (white),
   tertiary (transparent blue), link (transparent gray underline),
   danger (filled red).
   ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              color 150ms ease-out,
              transform 100ms ease-out,
              box-shadow 100ms ease-out;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-xs), var(--shadow-focus-brand);
}

/* ---- Primary (blue) ---- */
.btn-primary {
  background: var(--stv-blue-500);
  border-color: var(--stv-blue-500);
  color: #FFFFFF;
}
.btn-primary:hover:not(:disabled) {
  background: var(--stv-blue-600);
  border-color: var(--stv-blue-600);
}

/* ---- CTA (yellow) — also exposed as `.btn-success` for legacy markup ---- */
.btn-cta,
.btn-success {
  background: var(--stv-yellow-500);
  border-color: var(--stv-yellow-500);
  color: var(--stv-gray-900);
}
.btn-cta:hover:not(:disabled),
.btn-success:hover:not(:disabled) {
  background: var(--stv-yellow-600);
  border-color: var(--stv-yellow-600);
}

/* ---- Secondary (white + gray border) ---- */
.btn-secondary {
  background: #FFFFFF;
  border-color: var(--stv-gray-300);
  color: var(--stv-gray-700);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--stv-gray-50);
  border-color: var(--stv-gray-300);
}

/* ---- Tertiary (transparent + brand blue) ---- */
.btn-tertiary {
  background: transparent;
  border-color: transparent;
  color: var(--stv-blue-500);
  box-shadow: none;
}
.btn-tertiary:hover:not(:disabled) {
  background: var(--stv-blue-50);
  text-decoration: none;
}

/* ---- Link (transparent + gray + underline on hover) ---- */
.btn-link {
  background: transparent;
  border-color: transparent;
  color: var(--stv-gray-500);
  box-shadow: none;
  font-weight: 500;
}
.btn-link:hover:not(:disabled) {
  color: var(--stv-gray-700);
  text-decoration: underline;
}

/* ---- Danger (filled red) ---- */
.btn-danger {
  background: var(--stv-error);
  border-color: var(--stv-error);
  color: #FFFFFF;
}
.btn-danger:hover:not(:disabled) {
  background: var(--color-error-dark);
  border-color: var(--color-error-dark);
}

/* ---- Sizes ---- */
.btn-small {
  padding: 8px 12px;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  border-radius: var(--radius-sm);
}
.btn-large {
  padding: 14px 22px;
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
}

/* ---- Block ---- */
.btn-block {
  width: 100%;
}

/* ===== Active Exam (full-width takeover) ===== */
.exam-active-content {
  max-width: 720px;
  margin: 0 auto;
}

.exam-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.exam-header-left {
  display: flex;
  gap: 10px;
  align-items: center;
}

.exam-header-icon {
  width: 28px;
  height: 28px;
  background: var(--stv-blue-200);
  color: var(--color-brand-primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.exam-header-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.exam-header-subtitle {
  font-size: 11px;
  color: var(--color-text-secondary);
}

.exam-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.exam-question-counter {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.exam-question-counter strong {
  font-weight: 500;
  color: var(--color-text-primary);
}

/* DS secondary-sm; hover ramps to destructive for "Stop". */
.exam-stop-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: 6px 12px;
  border: 1px solid var(--stv-gray-300);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  color: var(--stv-gray-500);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              color 150ms ease-out;
}

.exam-stop-pill:hover {
  background: var(--color-error-50);
  color: var(--stv-error);
  border-color: var(--stv-error);
}

.exam-progress-bar {
  height: 4px;
  background: var(--color-bg-secondary);
  border-radius: 2px;
  margin-bottom: 28px;
  overflow: hidden;
}

.exam-progress-fill {
  height: 100%;
  background: var(--color-brand-primary);
  border-radius: 2px;
  transition: width 300ms ease-out;
}

.exam-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 0.5px solid var(--color-border-secondary);
  margin-top: 24px;
}

/* DS link (transparent gray, underline on hover). */
.exam-ask-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  color: var(--stv-gray-500);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color 150ms ease-out;
}

.exam-ask-link:hover {
  color: var(--stv-blue-500);
  text-decoration: underline;
}

/* ===== Quiz Header Row (progress + stop button) ===== */
.quiz-header-row {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.quiz-header-row .progress-bar-container {
  flex: 1;
  margin-bottom: 0;
}

/* DS secondary-sm button. Hover ramps to destructive — communicates "stop". */
.btn-stop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 6px 12px;
  border: 1px solid var(--stv-gray-300);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  color: var(--stv-gray-500);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              color 150ms ease-out;
}

.btn-stop:hover {
  color: var(--stv-error);
  border-color: var(--stv-error);
  background: var(--color-error-50);
}

.btn-stop:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ===== Progress Bar ===== */
.progress-bar-container {
  margin-bottom: var(--space-2xl);
}

.progress-label {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  margin-bottom: var(--space-sm);
  font-weight: 500;
}

.progress-bar {
  height: 6px;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-brand-primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ===== Quiz Question ===== */
.question-card {
  animation: fadeIn 0.35s ease;
}

.question-text {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  margin-bottom: 20px;
  color: var(--color-text-primary);
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.option-card {
  position: relative;
  border: 1.5px solid var(--color-border-secondary);
  border-radius: 6px;
  padding: 12px 36px 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.5;
  color: var(--color-text-secondary);
  transition: border-color 200ms ease-out, background 200ms ease-out;
}

.option-letter {
  font-weight: 500;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  width: 16px;
}

.option-card:hover {
  border: 1.5px solid var(--stv-blue-500);
}

.option-card.selected {
  border: 1.5px solid var(--stv-blue-500);
  background: var(--stv-blue-200);
  color: var(--stv-blue-800);
}

.option-card.selected .option-letter {
  color: var(--stv-blue-800);
}

.option-card.correct {
  border-color: var(--color-success);
  background: var(--stv-success-bg);
  color: var(--stv-success-fg);
  pointer-events: none;
}

.option-card.incorrect {
  border-color: var(--color-error);
  background: var(--color-error-100);
  color: var(--color-error-dark);
  pointer-events: none;
}

.option-card.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.option-card.correct::after,
.option-card.incorrect::after {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  pointer-events: none;
}

.option-card.correct::after {
  content: '\2713';
  color: var(--color-success);
}

.option-card.incorrect::after {
  content: '\2717';
  color: var(--color-error);
}

/* ===== Open Question ===== */
.open-question-area {
  animation: fadeIn 0.35s ease;
}

.answer-textarea {
  width: 100%;
  min-height: 140px;
  padding: var(--space-lg);
  border: 1.5px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-sm);
  line-height: 1.55;
  resize: vertical;
  transition: border-color var(--transition);
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
}

.answer-textarea:focus {
  outline: none;
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px rgba(25, 155, 233, 0.12);
}

/* DS card pattern — 1px border, radius-xl, tinted brand surface. */
.model-answer-box {
  margin-top: var(--space-3);
  padding: 14px 16px;
  background: var(--stv-blue-50);
  border: 1px solid var(--stv-blue-200);
  border-radius: var(--radius-xl);
  animation: slideUp 0.3s ease;
}

.model-answer-label {
  display: inline-block;
  padding: 2px 10px;
  margin-bottom: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  line-height: var(--leading-xs);
  font-weight: 700;
  color: var(--stv-blue-800);
  background: var(--stv-blue-200);
  border-radius: var(--radius-sm);
  letter-spacing: 0;
  text-transform: none;
}

.model-answer-text {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--stv-gray-700);
}

.self-assess-group {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  flex-wrap: wrap;
}

/* DS outlined-button group with semantic state colors — Onest 700, radius-md. */
.btn-assess {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 14px;
  border: 1px solid var(--stv-gray-300);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              color 150ms ease-out;
}

.btn-assess.correct {
  border-color: var(--stv-success);
  color: var(--stv-success-fg);
}

.btn-assess.correct:hover,
.btn-assess.correct.active {
  background: var(--stv-success);
  border-color: var(--stv-success);
  color: #FFFFFF;
}

.btn-assess.partial {
  border-color: var(--color-warning);
  color: var(--color-warning-dark);
}

.btn-assess.partial:hover,
.btn-assess.partial.active {
  background: var(--color-warning);
  border-color: var(--color-warning);
  color: #FFFFFF;
}

.btn-assess.wrong {
  border-color: var(--stv-error);
  color: var(--stv-error);
}

.btn-assess.wrong:hover,
.btn-assess.wrong.active {
  background: var(--stv-error);
  border-color: var(--stv-error);
  color: #FFFFFF;
}

/* ===== Results ===== */
/* ===== Results Screen (DS-aligned) ===== */
.results-screen {
  animation: slideUp 0.4s ease;
  text-align: center;
}

.results-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-6);
  color: var(--fg-1);
}

.score-circle {
  width: 120px;
  height: 120px;
  margin: 0 auto var(--space-6);
  position: relative;
}

.score-circle svg {
  transform: rotate(-90deg);
  width: 120px;
  height: 120px;
}

.score-circle-bg {
  fill: none;
  stroke: var(--stv-gray-200);
  stroke-width: 8;
}

.score-circle-fill {
  fill: none;
  stroke: var(--stv-blue-500);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease;
}

.score-circle-fill.good {
  stroke: var(--stv-success-fg);
}

.score-circle-fill.bad {
  stroke: var(--stv-error);
}

.score-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--fg-1);
}

.score-text small {
  display: block;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--fg-3);
  line-height: 1rem;
  margin-top: 0.5rem;
}

.results-questions {
  text-align: left;
  margin: var(--space-6) 0;
}

.result-item {
  padding: 14px 16px;
  border-radius: var(--radius-xl);
  margin-bottom: 8px;
  font-size: var(--text-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--stv-gray-200);
  background: var(--bg-page);
}

.result-item.correct {
  border-color: var(--stv-gray-200);
}

.result-item.incorrect {
  border-color: var(--stv-gray-200);
}

.result-item.partial {
  border-color: var(--stv-gray-200);
}

.result-item-header {
  display: flex;
  align-items: center;
}

.result-status-badge {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-sm);
}

.result-status-badge.correct {
  color: var(--stv-success);
  background: var(--stv-success-bg);
}

.result-status-badge.incorrect {
  color: var(--stv-error);
  background: var(--color-error-50);
}

.result-status-badge.partial {
  color: var(--stv-warm-700);
  background: var(--stv-yellow-100);
}

.result-question {
  font-weight: 500;
  color: var(--fg-1);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.result-answer-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-answer-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--fg-3);
  display: block;
  margin-bottom: 2px;
}

.result-answer-text {
  font-size: var(--text-sm);
  line-height: 1.5;
  display: block;
  color: var(--fg-2);
}

.result-your-answer.wrong .result-answer-text {
  color: var(--stv-error);
  text-decoration: line-through;
  text-decoration-color: rgba(217, 45, 32, 0.3);
}

.result-your-answer.right .result-answer-text {
  color: var(--stv-success);
}

.result-correct-answer .result-answer-text {
  color: var(--stv-success);
  font-weight: 600;
}

.result-actions {
  display: flex;
  gap: 12px;
  margin-top: var(--space-6);
}

.result-actions .btn {
  flex: 1;
  padding: 10px 16px;
  font-size: var(--text-base);
  line-height: var(--leading-base);
  box-shadow: var(--shadow-xs);
}

/* ===== MC Results — Single-column navigator ===== */
.mcr-screen {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  animation: slideUp 0.4s ease;
}

.mcr-card {
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.mcr-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--fg-2);
  text-transform: uppercase;
}

.mcr-header-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.mcr-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.mcr-header-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.mcr-header-actions .btn {
  padding: 8px 14px;
  font-size: var(--text-sm);
  line-height: 20px;
}

.mcr-score-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
}

.mcr-score-pct {
  font-size: 40px;
  font-weight: 700;
  color: var(--fg-1);
  line-height: 1;
  letter-spacing: var(--tracking-tight);
  display: flex;
  align-items: baseline;
}

.mcr-pct-sign {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg-1);
  margin-left: 1px;
}

.mcr-score-fraction {
  display: flex;
  flex-direction: column;
  font-size: var(--text-xs);
  line-height: 1.35;
  color: var(--fg-2);
}

.mcr-score-fraction strong {
  color: var(--fg-1);
  font-weight: 600;
}

.mcr-score-bar-wrap {
  position: relative;
  padding: 0 4px;
}

.mcr-score-bar {
  position: relative;
  height: 8px;
  background: var(--stv-gray-150);
  border-radius: var(--radius-full);
  overflow: visible;
}

.mcr-score-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

.mcr-score-bar-fill.good {
  background: var(--stv-success-fg);
}

.mcr-score-bar-fill.bad {
  background: var(--stv-error);
}

.mcr-grid-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.mcr-grid-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.mcr-legend {
  display: flex;
  gap: var(--space-4);
}

.mcr-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--fg-2);
  font-weight: 500;
}

.mcr-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.mcr-legend-dot.good {
  background: var(--stv-success-fg);
}

.mcr-legend-dot.bad {
  background: var(--stv-error);
}

.mcr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
  gap: var(--space-2);
}

.mcr-tile {
  height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid;
  background: var(--bg-page);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mcr-tile.good {
  color: var(--stv-success-fg);
  border-color: #ABEFC6;
  background: #F6FEF9;
}

.mcr-tile.bad {
  color: var(--stv-error);
  border-color: #FECDCA;
  background: #FEF3F2;
}

.mcr-tile:hover,
.mcr-tile.active {
  border-width: 2px;
}

.mcr-tile.good:hover,
.mcr-tile.good.active {
  border-color: var(--stv-success-fg);
}

.mcr-tile.bad:hover,
.mcr-tile.bad.active {
  border-color: var(--stv-error);
}

.mcr-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: var(--space-2) var(--space-1);
  font-size: var(--text-sm);
}

.mcr-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 6px 8px;
  color: #5358626b;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 120ms ease, color 120ms ease;
  width: max-content;
}

.mcr-nav-btn:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--fg-1);
}

.mcr-nav-btn:disabled {
  color: var(--stv-gray-300);
  cursor: default;
}

.mcr-nav-btn:first-of-type {
  justify-self: start;
}

.mcr-nav-btn:last-of-type {
  justify-self: end;
}

.mcr-nav-center {
  font-size: var(--text-sm);
  color: var(--fg-2);
  text-align: center;
}

.mcr-nav-center strong {
  color: var(--fg-1);
  font-weight: 600;
}

.mcr-detail-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.mcr-status-pill {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}

.mcr-status-pill.good {
  color: var(--stv-success-fg);
  background: var(--stv-success-bg);
}

.mcr-status-pill.bad {
  color: var(--stv-error);
  background: var(--color-error-50);
}

.mcr-question {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--fg-1);
  line-height: 1.45;
}

.mcr-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.mcr-option {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--stv-gray-200);
  border-radius: var(--radius-md);
  background: var(--bg-page);
  font-size: var(--text-sm);
}

.mcr-option-letter {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--stv-gray-200);
  border-radius: var(--radius-xs);
  background: var(--bg-page);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-2);
}

.mcr-option-text {
  color: var(--fg-1);
  line-height: 1.4;
}

.mcr-option-correct {
  border-color: #ABEFC6;
  background: #F6FEF9;
}

.mcr-option-correct .mcr-option-letter {
  border-color: #ABEFC6;
  background: var(--stv-success-bg);
  color: var(--stv-success-fg);
}

.mcr-option-user-wrong {
  border-color: #FECDCA;
  background: #FEF3F2;
}

.mcr-option-user-wrong .mcr-option-letter {
  border-color: #FECDCA;
  background: var(--color-error-50);
  color: var(--stv-error);
}

.mcr-option-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-on-brand);
  white-space: nowrap;
}

.mcr-option-pill.good {
  background: var(--stv-success-fg);
}

.mcr-option-pill.bad {
  background: var(--stv-error);
}

/* ===== MC Explanation block — used in live quiz and results detail =====
   Light blue card with lightbulb icon + "Why this is the answer" header. */
.mc-explanation {
  margin-top: var(--space-4);
  padding: 14px 16px;
  background: #F5FAFF;              /* brand-25 */
  border: 1px solid var(--stv-blue-100);  /* brand-100 (#D1E9FF) */
  border-radius: var(--radius-lg);
  animation: fadeIn 0.3s ease;
}

.mc-explanation-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1849A9;                   /* brand-800 */
  margin-bottom: 6px;
}

.mc-explanation-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-2, var(--color-text-secondary));
  margin: 0;
}

/* Compact MCR layout — applied when sidebar is narrow (PDF visible)
   or on mobile viewports. Uses the parent layout class plus a media query. */
.app-layout:not(.pdf-collapsed) .mcr-card {
  padding: var(--space-4);
}
.app-layout:not(.pdf-collapsed) .mcr-header-top {
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-3);
}
.app-layout:not(.pdf-collapsed) .mcr-header-actions {
  justify-content: flex-end;
}
.app-layout:not(.pdf-collapsed) .mcr-score-row {
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "pct fraction"
    "bar bar";
  row-gap: var(--space-3);
}
.app-layout:not(.pdf-collapsed) .mcr-score-pct { grid-area: pct; }
.app-layout:not(.pdf-collapsed) .mcr-score-fraction { grid-area: fraction; align-self: end; }
.app-layout:not(.pdf-collapsed) .mcr-score-bar-wrap { grid-area: bar; }
.app-layout:not(.pdf-collapsed) .mcr-tile {
  height: 40px;
  font-size: var(--text-sm);
}
.app-layout:not(.pdf-collapsed) .mcr-option {
  grid-template-columns: 28px 1fr;
  grid-template-areas:
    "letter text"
    "pill pill";
  row-gap: var(--space-2);
}
.app-layout:not(.pdf-collapsed) .mcr-option-letter { grid-area: letter; }
.app-layout:not(.pdf-collapsed) .mcr-option-text { grid-area: text; }
.app-layout:not(.pdf-collapsed) .mcr-option-pill {
  grid-area: pill;
  justify-self: start;
}

@media (max-width: 640px) {
  .mcr-card {
    padding: var(--space-4);
  }
  .mcr-header-top {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }
  .mcr-header-actions {
    justify-content: flex-end;
  }
  .mcr-score-row {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "pct fraction"
      "bar bar";
    row-gap: var(--space-3);
  }
  .mcr-score-pct { grid-area: pct; }
  .mcr-score-fraction { grid-area: fraction; align-self: end; }
  .mcr-score-bar-wrap { grid-area: bar; }
  .mcr-tile {
    height: 40px;
    font-size: var(--text-sm);
  }
  .mcr-option {
    grid-template-columns: 28px 1fr;
    grid-template-areas:
      "letter text"
      "pill pill";
    row-gap: var(--space-2);
  }
  .mcr-option-letter { grid-area: letter; }
  .mcr-option-text { grid-area: text; }
  .mcr-option-pill {
    grid-area: pill;
    justify-self: start;
  }
}

/* ===== History ===== */
.history-section {
  margin-top: var(--space-md);
}

.history-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.history-entry {
  padding: var(--space-lg) var(--space-xl);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.history-entry:hover {
  border-color: var(--color-brand-primary);
  background: rgba(25, 155, 233, 0.03);
}

.history-badge {
  font-size: var(--font-xs);
  font-weight: 500;
  padding: var(--space-xxs) var(--space-md);
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
  flex-shrink: 0;
  border: 1px solid;
}

.history-badge.mc {
  background: rgba(25, 155, 233, 0.08);
  color: var(--color-brand-secondary);
  border-color: rgba(25, 155, 233, 0.2);
}

.history-badge.open {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: rgba(7, 148, 85, 0.2);
}

.history-info {
  flex: 1;
}

.history-date {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
}

.history-score {
  font-size: var(--font-md);
  font-weight: 700;
  color: var(--color-text-primary);
}

.history-empty {
  font-size: var(--font-sm);
  color: var(--color-text-quaternary);
  text-align: center;
  padding: var(--space-2xl) 0;
}

.clear-history-wrapper {
  margin-top: var(--space-xl);
  text-align: center;
}

/* ===== History Detail ===== */
/* DS tertiary (transparent + brand blue). */
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 8px;
  margin-bottom: var(--space-xl);
  margin-left: -8px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
  color: var(--stv-blue-500);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 150ms ease-out;
}

.detail-back:hover {
  background: var(--stv-blue-50);
}

.detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

/* ===== Floating Chat Surface ===== */
.chat-surface {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 720px;
  z-index: 10;
}

.app-layout.pdf-collapsed .chat-surface {
  display: none;
}

/* --- Resting pill --- */
.chat-pill {
  background: #FFFFFF;
  border: 1px solid var(--stv-gray-300);
  border-radius: 999px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.10), 0 2px 4px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-pill:hover {
  border-color: var(--stv-blue-500);
}

.chat-pill:focus-within {
  border-color: var(--color-brand-primary);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.10), 0 2px 4px rgba(0, 0, 0, 0.06), 0 0 0 3px rgba(43, 166, 224, 0.18);
}

.chat-surface.panel-open .chat-pill {
  display: none;
}

.chat-pill-icon {
  flex-shrink: 0;
  color: var(--color-brand-primary);
}

.chat-pill-input,
.chat-panel-input {
  outline: none !important;
}

.chat-pill-input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: var(--color-text-primary);
  min-width: 0;
  padding: 2px 0;
}

.chat-pill-input::placeholder {
  color: var(--color-text-tertiary);
}

.chat-mic-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 200ms ease-out;
  padding: 0;
}

.chat-mic-btn:hover {
  background: var(--color-bg-tertiary);
}

/* Chat mic recording — matches exam/open question mic style */
.chat-mic-btn.mic-recording {
  background: var(--color-bg-tertiary);
  color: var(--color-brand-primary);
  width: auto;
  padding: 0 12px;
  gap: 4px;
  border-radius: var(--radius-full);
  box-shadow: inset 0 0 0 1.5px var(--color-brand-primary);
  animation: mic-glow 1.5s ease-in-out infinite;
}

.chat-mic-btn.mic-processing {
  background: var(--color-text-quaternary);
  color: white;
  width: auto;
  padding: 0 12px;
  gap: 6px;
  border-radius: var(--radius-full);
  pointer-events: none;
}

.chat-mic-btn.mic-processing::before {
  content: '';
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: mic-spin 0.7s linear infinite;
}

.chat-send-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--color-brand-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 200ms ease-out;
  padding: 0;
}

.chat-send-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.chat-pill-expand {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 4px;
  border: none;
  background: none;
  transition: background 200ms ease-out;
  flex-shrink: 0;
  padding: 0;
}

.chat-pill-expand:hover {
  background: var(--color-bg-secondary);
}

.chat-pill-expand.hidden {
  display: none;
}

/* --- Expanded panel --- */
.chat-panel {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
  max-height: min(480px, 70vh);
  height: auto;
  display: flex;
  flex-direction: column;
}

.chat-panel.hidden {
  display: none;
}

.chat-panel-header {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--color-border-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-panel-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.chat-panel-header-left svg {
  color: var(--color-brand-primary);
  flex-shrink: 0;
}

.chat-panel-close {
  border: none;
  background: none;
  font-size: 16px;
  color: var(--color-text-tertiary);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.chat-panel-close:hover {
  color: var(--color-text-primary);
}

/* Conversation area — shrinks with content, scrolls at max-height */
.chat-messages {
  overflow-y: auto;
  padding: 14px 16px;
  min-height: 0;
  flex: 0 1 auto;
}

/* User message */
.chat-msg-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.chat-msg-user-bubble {
  background: var(--stv-blue-200);
  color: var(--stv-blue-800);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 80%;
  line-height: 1.5;
}

/* AI response */
.chat-msg-ai {
  margin-bottom: 6px;
}

.chat-msg-ai-text {
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text-primary);
  margin-bottom: 6px;
}

.chat-msg-ai-text p { margin: 0 0 12px 0; }
.chat-msg-ai-text p:last-child { margin-bottom: 0; }
.chat-msg-ai-text strong { font-weight: 600; color: var(--fg-1); }

/* Top-level lists */
.chat-msg-ai-text ul, .chat-msg-ai-text ol { margin: 8px 0 12px 0; padding-left: 20px; }
.chat-msg-ai-text li { margin-bottom: 4px; }
.chat-msg-ai-text li:last-child { margin-bottom: 0; }

/* Nested lists */
.chat-msg-ai-text li > ul, .chat-msg-ai-text li > ol { margin: 4px 0 4px 0; padding-left: 20px; }
.chat-msg-ai-text li > ul > li, .chat-msg-ai-text li > ol > li { margin-bottom: 2px; }

/* Headings in AI answers */
.chat-msg-ai-text h1, .chat-msg-ai-text h2, .chat-msg-ai-text h3, .chat-msg-ai-text h4 {
  font-size: 14px; font-weight: 600; margin: 16px 0 8px 0; color: var(--fg-1);
}
.chat-msg-ai-text h1:first-child, .chat-msg-ai-text h2:first-child, .chat-msg-ai-text h3:first-child { margin-top: 0; }

/* Inline code */
.chat-msg-ai-text code {
  font-family: 'Menlo', 'Monaco', monospace; font-size: 12px;
  background: var(--color-bg-secondary); padding: 1px 6px; border-radius: 4px;
}

/* Source pills */
.chat-sources {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.chat-source-pill {
  padding: 4px 8px;
  background: var(--color-bg-secondary);
  border-radius: 6px;
  font-size: 11px;
  color: var(--color-text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 200ms ease-out;
  border: none;
  font-family: inherit;
}

.chat-source-pill:hover {
  background: var(--color-border-secondary);
}

.chat-source-pill svg {
  flex-shrink: 0;
}

/* Out-of-scope response */
.chat-msg-outofscope {
  margin-bottom: 18px;
  padding: 12px;
  background: var(--color-bg-secondary);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text-secondary);
}

/* Chat empty-state example prompts */
.chat-empty-state {
  padding: 16px 0;
}

.chat-empty-state-label {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-bottom: 10px;
}

.chat-prompt-suggestion {
  padding: 10px 14px;
  background: var(--color-bg-secondary);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 200ms ease-out, border-color 200ms ease-out;
  font-family: inherit;
  margin-bottom: 6px;
  display: block;
}

.chat-prompt-suggestion:hover {
  background: var(--stv-blue-200);
  border-color: var(--color-brand-primary);
}

/* Chat typing indicator */
.chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 0;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  background: var(--color-text-tertiary);
  border-radius: 50%;
  animation: typing 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.chat-typing-text {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
}

/* Chat error */
.chat-error {
  padding: 12px;
  background: #FEF2F2;
  border: 1px solid var(--color-error-200);
  border-radius: 8px;
  color: var(--color-error-dark);
  font-size: 13px;
  margin-bottom: 18px;
}

.chat-error button {
  margin-top: 8px;
  padding: 8px 12px;
  background: #FFFFFF;
  border: 1px solid var(--color-error-200);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
  color: var(--color-error-dark);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out;
}

.chat-error button:hover { background: var(--color-error-50); }

/* Onboarding popover */
.onboarding-popover {
  position: absolute;
  background: var(--stv-gray-900);
  color: #FFFFFF;
  padding: 14px 18px;
  border-radius: 10px;
  max-width: 280px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  z-index: 100;
}

.onboarding-popover-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: 10px;
  padding: 8px 14px;
  background: #FFFFFF;
  color: var(--stv-gray-900);
  border: 1px solid #FFFFFF;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out;
}
.onboarding-popover-button:hover { background: var(--stv-gray-50); }

.onboarding-popover::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 32px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--stv-gray-900);
}

/* Loading dots */
.chat-loading {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.chat-loading .dot {
  width: 6px;
  height: 6px;
  background: var(--color-text-tertiary);
  border-radius: 50%;
  animation: chatDotPulse 1.2s ease-in-out infinite;
}

.chat-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatDotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Panel footer */
.chat-panel-footer {
  padding: 10px 12px;
  border-top: 0.5px solid var(--color-border-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-panel-input {
  flex: 1;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 13px;
  outline: none;
  color: var(--color-text-primary);
  min-width: 0;
  padding: 2px 0;
}

.chat-panel-input::placeholder {
  color: var(--color-text-tertiary);
}

/* PDF stays fully interactive when chat is open — no dim, no pointer-events block */

/* Chat scrollbar */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border-primary);
  border-radius: 999px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-quaternary);
}

/* OLD Chat styles below — kept for compatibility during migration */
/* ===== Chat Reopen Button (legacy) ===== */
.chat-reopen-btn {
  position: fixed;
  bottom: 20px;
  left: calc(65% / 2);
  transform: translateX(-50%);
  z-index: 24;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-brand-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(25, 155, 233, 0.35), 0 2px 6px rgba(24, 29, 39, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-reopen-btn:hover {
  transform: translateX(-50%) scale(1.08);
  box-shadow: 0 6px 20px rgba(25, 155, 233, 0.45), 0 2px 8px rgba(24, 29, 39, 0.12);
}

.chat-reopen-btn.visible {
  display: flex;
}

.chat-reopen-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--color-error);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-bg-primary);
}

/* ===== Chat Overlay (Floating Panel) ===== */
.chat-overlay {
  position: fixed;
  bottom: 16px;
  left: calc(65% / 2);
  transform: translateX(-50%);
  width: 50%;
  max-width: 500px;
  z-index: 25;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              background 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
  max-height: 58px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(25, 155, 233, 0.08);
  border: 1px solid rgba(25, 155, 233, 0.2);
  box-shadow: 0 2px 12px rgba(25, 155, 233, 0.08);
  backdrop-filter: blur(8px);
}

.chat-overlay.expanded {
  max-height: min(520px, calc(100vh - 100px));
  width: 55%;
  max-width: 580px;
  background: var(--color-bg-primary);
  border-color: var(--color-border-secondary);
  box-shadow: 0 16px 48px rgba(24, 29, 39, 0.18), 0 4px 12px rgba(24, 29, 39, 0.08);
}

/* Hide collapsed input bar when reopen button is shown */
.chat-overlay.hidden-for-reopen {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Chat header (visible when expanded) */
.chat-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  background: #e8f4fd;
  color: #1a6fa8;
  flex-shrink: 0;
}

.chat-overlay.expanded .chat-header {
  display: flex;
}

.chat-header-title {
  font-size: var(--font-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.chat-close-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(25, 155, 233, 0.12);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.chat-close-btn:hover {
  background: rgba(25, 155, 233, 0.2);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-height: 0;
  scroll-behavior: smooth;
}

.chat-overlay:not(.expanded) .chat-messages {
  display: none;
}

.chat-overlay.expanded {
  display: flex;
  flex-direction: column;
}

/* Fade in header and messages on expand */
.chat-overlay.expanded .chat-header,
.chat-overlay.expanded .chat-messages {
  animation: chatFadeIn 0.25s ease 0.1s both;
}

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

/* Input bar */
.chat-input-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 10px var(--space-xl);
  background: var(--color-bg-primary);
  flex-shrink: 0;
  border-top: 1px solid var(--color-border-secondary);
}

.chat-overlay:not(.expanded) .chat-input-bar {
  border-top: none;
  border-radius: var(--radius-lg);
  background: #ecf4fa;
}

.chat-overlay:not(.expanded) .chat-input {
  background: white;
  border-color: rgba(25, 155, 233, 0.2);
  color: var(--color-text-primary);
  padding-left: 40px;
}

/* Chat icon inside collapsed input */
.chat-overlay:not(.expanded) .chat-input-wrap::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23717680' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  z-index: 1;
  pointer-events: none;
}

.chat-overlay:not(.expanded) .chat-input::placeholder {
  color: var(--color-text-quaternary);
}

.chat-overlay:not(.expanded) .chat-input:focus {
  background: white;
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px rgba(25, 155, 233, 0.12);
}

.chat-overlay:not(.expanded) .chat-send-btn {
  background: var(--color-brand-primary);
}

.chat-overlay:not(.expanded) .chat-send-btn:hover {
  background: var(--color-brand-secondary);
}

.chat-input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.chat-input {
  width: 100%;
  padding: var(--space-md) 40px var(--space-md) var(--space-xl);
  border: 1.5px solid var(--color-border-secondary);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: var(--font-sm);
  color: var(--color-text-primary);
  background: var(--color-bg-secondary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input:focus {
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px rgba(25, 155, 233, 0.12);
}

.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-brand-primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.chat-send-btn:hover {
  background: var(--stv-blue-600);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* Mic / Speech-to-text buttons */
.mic-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-bg-tertiary);
  color: var(--color-text-tertiary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  position: relative;
}

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

/* CSS Tooltip — left of button, only on hover (idle state) */
.mic-btn[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  top: 50%;
  right: calc(100% + 8px);
  transform: translateY(-50%);
  background: var(--color-text-primary);
  color: white;
  font-size: 11px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  z-index: 50;
  pointer-events: none;
}

/* Hide hover tooltip during recording/processing — button has inline label */
.mic-btn.mic-recording[data-tooltip]:hover::after,
.mic-btn.mic-processing[data-tooltip]:hover::after {
  display: none;
}

/* Inline label inside the button during recording/processing */
.mic-btn-label {
  font-size: 12px;
  font-weight: 600;
  margin-left: 4px;
  white-space: nowrap;
}

/* Recording state — grey pill with blue border + blue pulse */
.mic-btn.mic-recording {
  background: var(--color-bg-tertiary);
  color: var(--color-brand-primary);
  width: auto;
  padding: 0 12px;
  gap: 4px;
  border-radius: var(--radius-full);
  box-shadow: inset 0 0 0 1.5px var(--color-brand-primary);
  animation: mic-glow 1.5s ease-in-out infinite;
}

@keyframes mic-glow {
  0%, 100% { box-shadow: inset 0 0 0 1.5px var(--color-brand-primary), 0 0 0 0 rgba(25, 155, 233, 0.45); }
  50% { box-shadow: inset 0 0 0 1.5px var(--color-brand-primary), 0 0 0 8px rgba(25, 155, 233, 0); }
}

/* Processing state — pill with "Transcribing..." and spinner */
.mic-btn.mic-processing {
  background: var(--color-text-quaternary);
  color: white;
  width: auto;
  padding: 0 12px;
  gap: 6px;
  border-radius: var(--radius-full);
  pointer-events: none;
}

.mic-btn.mic-processing::before {
  content: '';
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: mic-spin 0.7s linear infinite;
}

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

/* No accent border on the textarea while recording — the pulsing "Stop" pill
   carries the active state. The focus ring takes over once the transcript is
   inserted and the input regains focus. */

/* Textarea with mic */
.textarea-with-mic {
  position: relative;
}

.textarea-with-mic .answer-textarea {
  padding-right: 48px;
  resize: none;
}

.mic-btn-textarea {
  position: absolute;
  right: 10px;
  bottom: 14px;
  width: 36px;
  height: 36px;
  background: transparent;
  color: var(--color-text-tertiary);
}

.mic-btn-textarea:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

/* Chat mic */
.mic-btn-chat {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  background: transparent;
  color: var(--color-text-tertiary);
}

.mic-btn-chat:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

/* Override glow for chat mic (preserves translateY) */
.mic-btn-chat.mic-recording {
  animation: mic-glow-chat 1.5s ease-in-out infinite;
}

@keyframes mic-glow-chat {
  0%, 100% { transform: translateY(-50%); box-shadow: inset 0 0 0 1.5px var(--color-brand-primary), 0 0 0 0 rgba(25, 155, 233, 0.45); }
  50% { transform: translateY(-50%); box-shadow: inset 0 0 0 1.5px var(--color-brand-primary), 0 0 0 8px rgba(25, 155, 233, 0); }
}

/* Chat bubbles */
.chat-bubble {
  max-width: 88%;
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-lg);
  font-size: var(--font-sm);
  line-height: 1.6;
  animation: chatSlideIn 0.2s ease-out;
  word-wrap: break-word;
}

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

.chat-bubble.user {
  align-self: flex-end;
  background: var(--color-brand-primary);
  color: white;
  border-bottom-right-radius: var(--space-xs);
  box-shadow: 0 2px 8px rgba(25, 155, 233, 0.25);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: linear-gradient(135deg, rgba(25, 155, 233, 0.06), rgba(25, 155, 233, 0.02));
  color: var(--color-text-primary);
  border-bottom-left-radius: var(--space-xs);
  border: 1px solid rgba(25, 155, 233, 0.1);
}

.chat-bubble.assistant p {
  margin: 0 0 var(--space-md) 0;
}

.chat-bubble.assistant p:last-child {
  margin-bottom: 0;
}

.chat-bubble.assistant ul,
.chat-bubble.assistant ol {
  margin: var(--space-md) 0;
  padding-left: var(--space-2xl);
}

.chat-bubble.assistant li {
  margin-bottom: var(--space-xs);
}

.chat-bubble.assistant li:last-child {
  margin-bottom: 0;
}

.chat-bubble.assistant strong {
  font-weight: 600;
}

.chat-bubble.system {
  align-self: center;
  background: transparent;
  color: var(--color-text-quaternary);
  font-size: var(--font-xs);
  padding: var(--space-md);
}

.chat-bubble.error {
  align-self: center;
  background: var(--color-error-bg);
  color: var(--color-error);
  font-size: var(--font-xs);
  padding: var(--space-md) var(--space-xl);
  border-radius: var(--radius-md);
}

/* Source chips */
.chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  align-self: flex-start;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 3px var(--space-md);
  background: rgba(25, 155, 233, 0.08);
  color: var(--color-brand-secondary);
  border: 1px solid rgba(25, 155, 233, 0.2);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.source-chip:hover {
  background: rgba(25, 155, 233, 0.18);
  border-color: var(--color-brand-primary);

}

/* Loading dots */
.chat-loading {
  display: flex;
  gap: 5px;
  padding: var(--space-lg) var(--space-xl);
  align-self: flex-start;
  background: linear-gradient(135deg, rgba(25, 155, 233, 0.06), rgba(25, 155, 233, 0.02));
  border-radius: var(--radius-lg);
  border: 1px solid rgba(25, 155, 233, 0.1);
}

.chat-loading .dot {
  width: 7px;
  height: 7px;
  background: var(--color-brand-primary);
  border-radius: var(--radius-full);
  animation: chatBounce 1.4s ease-in-out infinite;
}

.chat-loading .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-loading .dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes chatBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Scrollbar styling for chat */
.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--color-border-primary);
  border-radius: var(--radius-full);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-quaternary);
}

/* ===== LLM Feedback (Open Questions) ===== */
.check-loading {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-xl);
  padding: var(--space-xl);
  color: var(--color-text-quaternary);
  font-size: var(--font-sm);
  animation: fadeIn 0.3s ease;
}

.check-loading .dots {
  display: flex;
  gap: 4px;
}

.check-loading .dots .dot {
  width: 6px;
  height: 6px;
  background: var(--color-brand-primary);
  border-radius: var(--radius-full);
  animation: chatBounce 1.4s ease-in-out infinite;
}

.check-loading .dots .dot:nth-child(2) {
  animation-delay: 0.2s;
}

.check-loading .dots .dot:nth-child(3) {
  animation-delay: 0.4s;
}

/* DS feedback card — full 1px border, radius-xl, soft tint per state.
   Header uses a DS badge instead of the heavy circular icon + colored title. */
.llm-feedback {
  margin-top: var(--space-3);
  padding: 14px 16px;
  border: 1px solid;
  border-radius: var(--radius-xl);
  animation: slideUp 0.3s ease;
}

.llm-feedback.correct {
  background: var(--stv-success-bg);
  border-color: rgba(7, 148, 85, 0.20);
}

.llm-feedback.partial {
  background: var(--stv-yellow-100);
  border-color: rgba(220, 104, 3, 0.20);
}

.llm-feedback.incorrect {
  background: var(--color-error-50);
  border-color: rgba(217, 45, 32, 0.20);
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

/* Badge-style status pill — replaces the heavy circular icon. */
.feedback-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  color: #FFFFFF;
  flex-shrink: 0;
}

.llm-feedback.correct .feedback-icon {
  background: var(--stv-success);
}

.llm-feedback.partial .feedback-icon {
  background: var(--color-warning);
}

.llm-feedback.incorrect .feedback-icon {
  background: var(--stv-error);
}

.feedback-label {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
}

.llm-feedback.correct .feedback-label {
  color: var(--stv-success-fg);
}

.llm-feedback.partial .feedback-label {
  color: var(--color-warning-dark);
}

.llm-feedback.incorrect .feedback-label {
  color: var(--color-error-dark);
}

.feedback-text {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--stv-gray-700);
}

/* ===== Home Tool Cards ===== */
.tool-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border: 1.5px solid var(--color-border-secondary);
  border-radius: 6px;
  background: var(--color-bg-primary);
  cursor: pointer;
  transition: background 200ms ease-out, border-color 200ms ease-out;
  text-align: left;
  font-family: inherit;
  width: 100%;
}

.tool-card:hover {
  border: 1.5px solid var(--stv-blue-500);
}

.tool-card-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Per-tool icon colors (briefing spec) */
.tool-card-mc .tool-card-icon { background: var(--stv-blue-200); color: var(--color-brand-primary); }
.tool-card-open .tool-card-icon { background: #FAEEDA; color: #854F0B; }
.tool-card-flash .tool-card-icon { background: var(--stv-success-bg); color: var(--color-success); }
.tool-card-concept .tool-card-icon { background: var(--color-success-bg); color: var(--color-success); }
.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sidebar-progress-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--color-text-quaternary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.sidebar-progress-link:hover {
  color: var(--color-brand-primary);
  background: rgba(25, 155, 233, 0.06);
}

.tool-card-body {
  flex: 1;
  min-width: 0;
}

.tool-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.tool-card-desc {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  line-height: 1.4;
}


/* ===== Exam Selection ===== */
.exam-select-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-3xl);
}

.exam-select-header .sidebar-title {
  margin: 0;
}

.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

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

.exam-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.exam-card {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-lg) var(--space-xl);
  border: 1.5px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  background: var(--color-bg-primary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
  width: 100%;
}

.exam-card:hover {
  border: 1.5px solid var(--stv-blue-500);
}

.exam-card-number {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-sm);
  flex-shrink: 0;
}

.exam-card-mc .exam-card-number {
  background: rgba(25, 155, 233, 0.1);
  color: var(--color-brand-primary);
}

.exam-card-open .exam-card-number {
  background: rgba(254, 189, 0, 0.15);
  color: var(--color-cta-yellow-hover);
}

.exam-card-body {
  flex: 1;
  min-width: 0;
}

.exam-card-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: 1px;
}

.exam-card-detail {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
}

.exam-card-score {
  font-size: var(--font-sm);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.exam-card-score.good {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.exam-card-score.bad {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.exam-card-new {
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--color-text-quaternary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  background: var(--color-bg-tertiary);
  flex-shrink: 0;
}

.history-badge.concept {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: rgba(7, 148, 85, 0.2);
}

/* ===== Flashcard ===== */
.flashcard {
  perspective: 1000px;
  cursor: pointer;
  margin-top: var(--space-xl);
}

.flashcard-inner {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-areas: "stack";
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  grid-area: stack;
  width: 100%;
  min-height: 220px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3xl);
  box-sizing: border-box;
}

.flashcard-front {
  background: var(--bg-page);
  border: 1.5px solid var(--stv-blue-500);
  color: var(--fg-1);
  box-shadow: var(--shadow-sm);
}

.flashcard-front-text {
  font-size: var(--text-lg);
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}

.flashcard-back {
  background: var(--bg-page);
  border: 1.5px solid var(--stv-gray-200);
  transform: rotateY(180deg);
  align-items: flex-start;
  box-shadow: var(--shadow-sm);
}

.flashcard-back-text {
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--fg-2);
}

.flashcard-flip-btn {
  margin-top: var(--space-4);
}

.flashcard-kbd-hint {
  margin-top: var(--space-2);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--fg-3);
  user-select: none;
}

.flashcard-flip-back-btn {
  margin-top: var(--space-3);
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.flashcard-flip-back-btn:hover {
  background: var(--bg-2);
  border-color: var(--border-1);
}

.flashcard-front-text,
.flashcard-back-text {
  user-select: text;
  -webkit-user-select: text;
}

.flashcard-actions {
  display: flex;
  gap: 8px;
  margin-top: var(--space-4);
}

/* DS outlined buttons (success / error) — Onest 700 16/24, radius-md, shadow-xs. */
.btn-knew,
.btn-didnt-know {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 12px 18px;
  border: 1px solid;
  border-radius: var(--radius-md);
  background: #FFFFFF;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              color 150ms ease-out,
              border-color 150ms ease-out;
}

.btn-knew {
  color: var(--stv-success-fg);
  border-color: var(--stv-success);
}

.btn-knew:hover {
  background: var(--stv-success);
  border-color: var(--stv-success);
  color: #FFFFFF;
}

.btn-didnt-know {
  color: var(--stv-error);
  border-color: var(--stv-error);
}

.btn-didnt-know:hover {
  background: var(--stv-error);
  border-color: var(--stv-error);
  color: #FFFFFF;
}

.flashcard-box-indicator {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-text-quaternary);
  text-align: center;
}

/* Flashcard Results */
.flashcard-summary {
  display: flex;
  gap: var(--space-xl);
  justify-content: center;
  margin-bottom: var(--space-3xl);
}

.flashcard-summary-stat {
  text-align: center;
  padding: var(--space-xl) var(--space-3xl);
  border-radius: var(--radius-lg);
}

.flashcard-summary-stat.correct {
  background: var(--color-success-bg);
}

.flashcard-summary-stat.incorrect {
  background: var(--color-error-bg);
}

.flashcard-summary-number {
  font-size: var(--font-2xl);
  font-weight: 700;
}

.flashcard-summary-stat.correct .flashcard-summary-number {
  color: var(--color-success);
}

.flashcard-summary-stat.incorrect .flashcard-summary-number {
  color: var(--color-error);
}

.flashcard-summary-label {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  margin-top: var(--space-xs);
}

/* Flashcard Box Distribution */
.flashcard-box-distribution {
  margin-bottom: var(--space-3xl);
}

.flashcard-box-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-md);
}

.flashcard-box-explainer {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  line-height: 1.5;
  margin-bottom: var(--space-lg);
}

.flashcard-progress-bar {
  display: flex;
  height: 32px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg-tertiary);
}

.box-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-xs);
  font-weight: 700;
  color: white;
  min-width: 24px;
  transition: width 0.4s ease;
}

.box-segment span {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.box-segment.box-1 {
  background: var(--color-error);
}

.box-segment.box-2 {
  background: var(--color-warning);
}

.box-segment.box-3 {
  background: var(--color-success);
}

.box-legend {
  display: flex;
  gap: var(--space-xl);
  margin-top: var(--space-md);
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
}

.box-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.box-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.box-dot.box-1 { background: var(--color-error); }
.box-dot.box-2 { background: var(--color-warning); }
.box-dot.box-3 { background: var(--color-success); }

/* ===== Leitner Explainer ===== */
.leitner-explainer {
  animation: fadeIn 0.3s ease;
}

.leitner-intro {
  font-size: var(--font-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-bottom: var(--space-2xl);
}

.leitner-steps {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.leitner-step {
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
}

.leitner-step-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.leitner-step-icon.box-1 { background: var(--color-error); }
.leitner-step-icon.box-2 { background: var(--color-warning); }
.leitner-step-icon.box-3 { background: var(--color-success); }

.leitner-step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.leitner-step-text strong {
  font-size: var(--font-sm);
  color: var(--color-text-primary);
}

.leitner-step-text span {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  line-height: 1.4;
}

.leitner-rules {
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.leitner-rules p {
  font-size: var(--font-sm);
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.leitner-rules p + p {
  margin-top: var(--space-sm);
}

.leitner-tip {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  font-style: italic;
}

/* ===== Concept Quiz ===== */
.concept-term {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-md);
  line-height: var(--line-height-lg);
}

.concept-instruction {
  font-size: var(--font-sm);
  color: var(--color-text-quaternary);
  margin-bottom: var(--space-xl);
}

.concept-loading {
  text-align: center;
  padding: var(--space-4xl) 0;
}

.concept-loading .check-loading {
  justify-content: center;
  margin-top: 0;
}

.concept-loading-hint {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  margin-top: var(--space-lg);
}

/* ===== Dashboard ===== */

/* Hero Mastery */
.mastery-hero {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  margin-bottom: var(--space-xl);
}

.mastery-ring-wrapper {
  flex-shrink: 0;
}

.mastery-info {
  flex: 1;
  min-width: 0;
}

.mastery-summary {
  font-size: var(--font-sm);
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: var(--space-sm);
}

.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-warning);
  background: var(--color-warning-bg);
  padding: var(--space-xxs) var(--space-md);
  border-radius: var(--radius-full);
}

.streak-badge svg {
  stroke: var(--color-warning);
}

.streak-nudge {
  color: var(--color-text-quaternary);
  background: var(--color-bg-tertiary);
}

.streak-nudge svg {
  stroke: var(--color-text-quaternary);
}

/* Activity Calendar */
.activity-calendar-section {
  margin-bottom: var(--space-xl);
}

.activity-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  max-width: 180px;
}

.activity-day {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--color-bg-tertiary);
  transition: background 0.2s;
  cursor: default;
  position: relative;
}

/* GitHub-style intensity levels */
.activity-day.level-0 { background: var(--color-bg-tertiary); }
.activity-day.level-1 { background: var(--color-success-200); }
.activity-day.level-2 { background: var(--color-success-300); }
.activity-day.level-3 { background: var(--color-success); }

.activity-day.today {
  box-shadow: inset 0 0 0 1.5px var(--color-text-quaternary);
}

/* Tooltip */
.activity-day:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: white;
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 3px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
}

.activity-calendar-label {
  font-size: 10px;
  color: var(--color-text-quaternary);
  margin-top: var(--space-xxs);
}

/* Recommendation Card */
.recommendation-card {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-xl);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  flex-wrap: wrap;
}

.recommendation-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: rgba(25, 155, 233, 0.1);
  color: var(--color-brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.recommendation-text {
  flex: 1;
  min-width: 120px;
}

.recommendation-text strong {
  display: block;
  font-size: var(--font-sm);
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.recommendation-text span {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  line-height: 1.4;
}

.recommendation-cta {
  flex-shrink: 0;
}

/* Section Cards (clickable drill-down cards) */
.section-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xl);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: var(--space-md);
}

.section-card:hover {
  border-color: var(--color-brand-primary);
  box-shadow: var(--shadow-sm);
}

.section-card-warning:hover {
  border-color: var(--color-warning);
}

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

.section-card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: rgba(25, 155, 233, 0.1);
  color: var(--color-brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section-card-icon.warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.section-card-info {
  flex: 1;
  min-width: 0;
}

.section-card-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-primary);
}

.section-card-sub {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  margin-top: 1px;
}

.section-card-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.section-card-count {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--color-warning);
}

.section-chevron {
  color: var(--color-text-quaternary);
  flex-shrink: 0;
}

/* Sparkline dots */
.sparkline-dots {
  display: flex;
  gap: 3px;
  align-items: center;
}

.sparkline-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
}

.sparkline-dot.good { background: var(--color-success); }
.sparkline-dot.bad { background: var(--color-error); }

/* Mini progress ring */
.mini-progress-ring {
  flex-shrink: 0;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.filter-tabs {
  display: flex;
  gap: var(--space-xs);
}

.filter-tab {
  padding: var(--space-xs) var(--space-lg);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-full);
  background: var(--color-bg-primary);
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--color-text-quaternary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.filter-tab:hover { border-color: var(--color-brand-primary); color: var(--color-brand-primary); }
.filter-tab.active { background: var(--color-brand-primary); color: white; border-color: var(--color-brand-primary); }

.sort-select {
  padding: var(--space-xs) var(--space-md);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-sm);
  background: var(--color-bg-primary);
  font-size: var(--font-xs);
  color: var(--color-text-secondary);
  font-family: inherit;
  cursor: pointer;
}

/* Quiz List */
.quiz-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.quiz-list-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
}

.quiz-list-entry:hover {
  border-color: var(--color-brand-primary);
  box-shadow: var(--shadow-sm);
}

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

.quiz-list-info {
  flex: 1;
  min-width: 0;
}

.quiz-list-date {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  margin-bottom: var(--space-xs);
}

.quiz-list-score-bar {
  height: 4px;
  background: var(--color-bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.quiz-list-score-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.quiz-list-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

.quiz-list-score {
  font-size: var(--font-sm);
  font-weight: 700;
  color: var(--color-text-primary);
}

/* Flashcard Detail - Box Groups */
.fc-box-group {
  margin-bottom: var(--space-lg);
}

.fc-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-lg);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
  font-size: var(--font-sm);
  color: var(--color-text-primary);
}

.fc-box-header:hover {
  border-color: var(--color-brand-primary);
}

.fc-box-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.fc-box-count {
  font-size: var(--font-xs);
  color: var(--color-text-quaternary);
  font-weight: 400;
}

.fc-box-chevron {
  color: var(--color-text-quaternary);
  transition: transform 0.2s;
}

.fc-box-cards {
  padding: var(--space-md) 0 0 var(--space-3xl);
  max-height: 400px;
  overflow-y: auto;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.fc-box-cards.collapsed {
  max-height: 0;
  overflow: hidden;
  padding-top: 0;
  opacity: 0;
}

.fc-card-item {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border-secondary);
  font-size: var(--font-xs);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.fc-card-item:last-child { border-bottom: none; }

/* Weak Spot Detail */
.weak-spots-detail-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.ws-detail-item {
  padding: var(--space-xl);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
}

.ws-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-sm);
}

.ws-detail-number {
  font-size: var(--font-xs);
  font-weight: 700;
  color: var(--color-text-quaternary);
}

.ws-detail-stats {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-error);
}

.ws-detail-question {
  font-size: var(--font-sm);
  color: var(--color-text-primary);
  line-height: 1.5;
  margin-bottom: var(--space-md);
}

.ws-detail-attempts {
  display: flex;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
}

.ws-attempt-dot {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: white;
}

.ws-attempt-dot.correct { background: var(--color-success); }
.ws-attempt-dot.partial { background: var(--color-warning); }
.ws-attempt-dot.incorrect { background: var(--color-error); }

/* DS link — brand blue, transparent. */
.ws-reveal-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 600;
  color: var(--stv-blue-500);
  background: transparent;
  border: none;
  cursor: pointer;
}

.ws-reveal-btn:hover { text-decoration: underline; color: var(--stv-blue-600); }

.ws-correct-answer {
  margin-top: var(--space-md);
  padding: var(--space-lg);
  background: var(--color-success-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-success);
  transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease, padding 0.3s ease;
}

.ws-correct-answer.collapsed {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  margin-top: 0;
  padding: 0 var(--space-lg);
}

.ws-answer-label {
  display: block;
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-success);
  margin-bottom: var(--space-xxs);
}

.ws-answer-text {
  font-size: var(--font-sm);
  color: var(--color-text-primary);
  line-height: 1.5;
}

/* Practice badge color */
.history-badge.practice {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-color: rgba(220, 104, 3, 0.2);
}

.dashboard-section {
  margin-bottom: var(--space-3xl);
}

.dashboard-section-title {
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-lg);
}

/* Score Chart */
.score-chart {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  height: 140px;
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border-secondary);
}

.score-bar-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.score-bar {
  width: 100%;
  min-height: 4px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: relative;
  transition: height 0.4s ease;
}

.score-bar.good {
  background: var(--color-success);
}

.score-bar.bad {
  background: var(--color-error);
}

.score-bar-label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-quaternary);
  white-space: nowrap;
}

.score-bar-date {
  font-size: 9px;
  color: var(--color-text-quaternary);
  margin-top: var(--space-xs);
  white-space: nowrap;
}

/* Weak Spots */
.weak-spots {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.weak-spot-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  padding: var(--space-lg);
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--radius-md);
}

.weak-spot-question {
  font-size: var(--font-xs);
  color: var(--color-text-secondary);
  flex: 1;
  line-height: 1.4;
}

.weak-spot-stats {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--color-error);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== Header action links ===== */
/* (old header-actions, lang-indicator, btn-export removed — replaced by topbar) */

/* ===== State Retry Toast ===== */
.state-retry-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-family);
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* (old desktop zoom controls removed — zoom now in topbar) */

/* ===== Mobile-only elements (hidden on desktop) ===== */
.mobile-tab-bar { display: none; }
.mobile-ask-card { display: none; }
.pdf-zoom-controls { display: none; }

/* Mobile mode pill — hidden on desktop */
.mobile-mode-pill {
  display: none;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  /* --- Topbar: simplified for mobile --- */
  .topbar {
    height: 44px;
    padding: 0 12px;
    gap: 8px;
  }

  .topbar-back-btn {
    width: 24px;
    height: 24px;
  }

  .topbar-logo {
    height: 20px;
  }

  /* Hide doc title on mobile — not enough room */
  .topbar-doc-title {
    display: none;
  }

  /* Hide zoom buttons on mobile — mobile has its own zoom controls */
  .topbar-zone-2 .topbar-btn:nth-child(1),
  .topbar-zone-2 .topbar-btn:nth-child(2),
  .topbar-zone-2 .topbar-divider:first-of-type {
    display: none;
  }

  .topbar-zone-3 {
    gap: 6px;
    padding-left: 6px;
  }

  /* --- Hide desktop-only elements --- */
  .collapse-pill { display: none !important; }
  .desktop-zoom-controls { display: none !important; }

  /* --- Layout: absolute stacking, not grid --- */
  .app-layout {
    display: block;
    position: relative;
    height: calc(100vh - 44px);
    overflow: hidden;
    grid-template-columns: unset !important;
  }

  .pdf-viewer,
  .sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    flex: none;
    width: 100%;
    border: none;
    overflow-y: auto;
  }

  .sidebar {
    z-index: 2;
    padding-top: 36px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .pdf-viewer {
    z-index: 1;
    padding-top: 0;
    padding-bottom: env(safe-area-inset-bottom);
    touch-action: pan-x pan-y;
    -webkit-touch-callout: none;
  }

  .mobile-hidden {
    display: none !important;
  }

  /* Hide sidebar toggle and header row on mobile (pill replaces them) */
  .sidebar-toggle,
  .sidebar-header-row {
    display: none !important;
  }

  /* Collapsed sidebar should still show on mobile when Study tab is active */
  .sidebar.collapsed {
    flex: none;
    width: 100%;
    overflow-y: auto;
    padding: 0;
  }

  /* --- Mobile Tab Bar --- */
  /* --- Floating Mode Pill --- */
  .mobile-mode-pill {
    display: flex;
    position: fixed;
    top: 52px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    padding: 3px;
    box-shadow: 0 1px 8px rgba(24, 29, 39, 0.08);
    border: 1px solid rgba(233, 234, 235, 0.5);
  }

  .mode-pill-option {
    padding: 6px 20px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-tertiary);
    border-radius: 17px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
  }

  .mode-pill-option.active {
    background: var(--color-brand-primary);
    color: #fff;
    font-weight: 600;
  }

  /* --- Chat overlay mobile --- */
  /* Legacy chat overlay — hidden on mobile, replaced by chat-surface */
  .chat-overlay { display: none !important; }

  /* Chat surface mobile adjustments */
  .chat-surface {
    bottom: 12px;
    max-width: none;
    width: calc(100% - 24px);
    left: 50%;
    transform: translateX(-50%);
  }

  .chat-panel {
    max-height: calc(100vh - 120px);
    bottom: 12px;
  }

  /* Onboarding popover: smaller on mobile */
  .onboarding-popover {
    max-width: 240px;
    font-size: 12px;
  }

  /* Hide page number label below PDF pages — topbar has it */
  .pdf-page-number { display: none; }

  /* --- Sidebar content spacing --- */
  .sidebar-content {
    padding: var(--space-xl);
  }

  /* --- Tool cards --- */
  .tool-card {
    padding: var(--space-lg);
  }

  .tool-card-icon {
    width: 38px;
    height: 38px;
  }

  .tool-card-icon svg {
    width: 18px;
    height: 18px;
  }

  /* --- Quiz adjustments --- */
  .score-circle {
    width: 120px;
    height: 120px;
  }

  .score-circle svg {
    width: 120px;
    height: 120px;
  }

  /* --- Flashcard sizing --- */
  .flashcard-inner,
  .flashcard-front,
  .flashcard-back {
    min-height: 180px;
  }

  /* --- PDF scroll & zoom --- */
  .pdf-container {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .pdf-page-wrapper {
    justify-content: flex-start;
  }

  .pdf-page-wrapper canvas {
    max-width: none;
  }

  .pdf-zoom-controls {
    position: fixed;
    bottom: 90px;
    right: 16px;
    z-index: 26;
    display: flex;
    gap: 2px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    box-shadow: 0 1px 8px rgba(24, 29, 39, 0.08);
    border: 1px solid rgba(233, 234, 235, 0.5);
    padding: 3px;
  }

  .pdf-zoom-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
    font-size: 16px;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
  }

  .pdf-zoom-btn:active {
    background: rgba(0, 0, 0, 0.06);
  }

  .pdf-zoom-level {
    display: flex;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--color-text-tertiary);
    min-width: 32px;
    justify-content: center;
  }

  /* --- "Ask about PDF" card on Study tab --- */
  .mobile-ask-card {
    display: flex;
  }

  /* --- Review widget --- */
  /* review-widget mobile override moved after base styles — see end of file */

  /* --- PDF container spacing --- */
  .pdf-container {
    padding: var(--space-lg);
  }
}

/* Review widget */
.review-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 900;
  width: 380px;
  background: var(--color-bg-primary);
  border-radius: 16px;
  padding: 28px 32px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
  animation: reviewSlideIn 0.35s ease;
}

.review-widget.hidden {
  display: none;
}

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

.review-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-quaternary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.review-close:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

.review-close svg {
  width: 16px;
  height: 16px;
}

.review-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 6px;
  padding-right: 28px;
}

.review-subtitle {
  font-size: 14px;
  color: var(--color-text-tertiary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.review-stars-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.review-stars {
  display: flex;
  gap: 6px;
}

.review-star {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.review-star svg {
  width: 28px;
  height: 28px;
  stroke: var(--color-star-empty);
  fill: none;
  stroke-width: 1.5;
  transition: stroke 0.15s, fill 0.15s;
}

.review-star:hover svg,
.review-star.hovered svg {
  stroke: var(--color-star);
  fill: var(--color-star);
}

.review-star.active svg {
  stroke: var(--color-star);
  fill: var(--color-star);
}

.review-star:hover {
  transform: scale(1.12);
}

.review-label {
  font-size: 14px;
  color: var(--color-star);
  font-weight: 600;
  white-space: nowrap;
}

/* Step 2: review text */
.review-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.review-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.review-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-brand-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.review-user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.review-rating-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-star);
}

.review-rating-badge .mini-stars {
  display: flex;
  gap: 1px;
  font-size: 14px;
}

.review-textarea {
  width: 100%;
  min-height: 110px;
  padding: 14px 16px;
  border: 1.5px solid var(--color-border-secondary);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 14px;
  color: var(--color-text-primary);
  resize: vertical;
  line-height: 1.5;
  margin-bottom: 20px;
  background: var(--color-bg-primary);
}

.review-textarea::placeholder {
  color: var(--color-text-quaternary);
}

.review-textarea:focus {
  outline: none;
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px rgba(25, 155, 233, 0.12);
}

.review-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Review widget — DS link style for "Cancel/Skip", DS primary for "Post". */
.review-btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--stv-gray-500);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  cursor: pointer;
  transition: color 150ms ease-out;
}

.review-btn-secondary:hover {
  color: var(--stv-gray-700);
  text-decoration: underline;
}

.review-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 18px;
  border: 1px solid var(--stv-blue-500);
  border-radius: var(--radius-md);
  background: var(--stv-blue-500);
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              transform 100ms ease-out,
              box-shadow 100ms ease-out;
}

.review-btn-primary:hover:not(:disabled) {
  background: var(--stv-blue-600);
  border-color: var(--stv-blue-600);
}

.review-btn-primary:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.review-btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Review widget mobile modal (must be after base styles) ===== */
@media (max-width: 768px) {
  .review-widget {
    width: 100%;
    right: 0;
    left: 0;
    bottom: 0;
    border-radius: 20px 20px 0 0;
    padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12), 0 0 0 9999px rgba(0, 0, 0, 0.3);
    animation: reviewSlideUp 0.35s ease;
  }

  @keyframes reviewSlideUp {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* ===== Confirm Modal (Stuvia style) ===== */
.confirm-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
  padding: var(--space-xl);
}

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

@keyframes modalSlideIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.confirm-modal {
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.04);
  width: 100%;
  max-width: 400px;
  animation: modalSlideIn 0.25s ease;
  overflow: hidden;
}

.confirm-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2xl) var(--space-3xl) 0;
}

.confirm-modal-title {
  font-size: var(--font-md);
  font-weight: 600;
  color: var(--color-text-primary);
}

.confirm-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-quaternary);
  padding: var(--space-xs);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.confirm-modal-close:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

.confirm-modal-body {
  padding: var(--space-lg) var(--space-3xl) var(--space-3xl);
  color: var(--color-text-secondary);
  font-size: var(--font-sm);
  line-height: var(--line-height-md);
}

.confirm-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-lg);
  padding: 0 var(--space-3xl) var(--space-3xl);
}

/* DS secondary button (default) + DS danger variant for destructive confirm. */
.confirm-modal-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 18px;
  border: 1px solid var(--stv-gray-300);
  border-radius: var(--radius-md);
  background: #FFFFFF;
  color: var(--stv-gray-700);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background-color 150ms ease-out,
              border-color 150ms ease-out,
              color 150ms ease-out,
              transform 100ms ease-out,
              box-shadow 100ms ease-out;
}

.confirm-modal-btn:hover {
  background: var(--stv-gray-50);
  color: var(--stv-gray-900);
}

.confirm-modal-btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.confirm-modal-btn-danger {
  background: var(--stv-error);
  color: #FFFFFF;
  border-color: var(--stv-error);
}

.confirm-modal-btn-danger:hover {
  background: var(--color-error-dark);
  border-color: var(--color-error-dark);
  color: #FFFFFF;
  color: #fff;
}
