/* =============================================================================
   LUMEN — AI Paper Reader
   4-Panel Workspace: Menu | Paper | Explanation | Context
   ============================================================================= */

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

:root {
  --void: #f1f1f0;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f2f2f3;
  --surface-3: #e9e9eb;
  --border: #d4d4d8;
  --border-dim: #e4e4e7;

  --text: #2a2520;
  --text-2: #5a534a;
  --text-3: #6d6560;
  --text-4: #8a8278;

  --amber: #9a7530;
  --amber-dim: #b08a3e;
  --amber-glow: rgba(154,117,48,0.07);
  --amber-bright: #7a5c20;

  --sage: #3d7a66;
  --sage-glow: rgba(61,122,102,0.06);

  --blue: #3d6a8e;
  --blue-glow: rgba(61,106,142,0.06);

  --rose: #9e4a4a;
  --rose-glow: rgba(158,74,74,0.06);

  --mauve: #8b5a6e;
  --mauve-glow: rgba(139,90,110,0.06);

  --danger: #c45050;

  --font-display: 'Libre Baskerville', Georgia, serif;
  --font-body: 'Source Sans 3', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, monospace;
  --font-wordmark: 'Cormorant Garamond', Georgia, serif;

  --dur: 0.22s;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.0, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --menu-w: 200px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.78;
  -webkit-font-smoothing: antialiased;
}

/* (grain texture removed) */

/* =============================================================================
   MAIN AREA — Landing / Progress / Results states
   ============================================================================= */

.main-area {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

/* CRITICAL: Override hidden attribute for state elements —
   CSS display: flex would otherwise take precedence over [hidden] */
.landing-state[hidden],
.progress-state[hidden],
.results-state[hidden] {
  display: none !important;
}

/* Smooth state entrance animations — cinematic crossfade */
.landing-state.entering {
  animation: landingCrossfade 0.55s var(--ease-out) both;
}
.progress-state.entering {
  animation: stateCrossfade 0.6s var(--ease-out) both;
}

.progress-state.entering .prog-hero {
  animation: heroEntrance 0.7s var(--ease-out) 0.15s both;
}

.progress-state.entering .prog-line-wrap {
  animation: barTrackReveal 0.8s var(--ease-out) 0.25s both;
}

.progress-state.entering .prog-title {
  animation: fadeInUp 0.6s var(--ease-out) 0.35s both;
}

.progress-state.entering .prog-msg {
  animation: fadeInUp 0.5s var(--ease-out) 0.45s both;
}

.progress-state.entering .prog-stats-wrap {
  animation: fadeInUp 0.5s var(--ease-out) 0.5s both;
}

.progress-state.entering .prog-bar-track {
  animation: barTrackReveal 0.8s var(--ease-out) 0.55s both;
}

.progress-state.entering .prog-stages {
  animation: fadeInUp 0.5s var(--ease-out) 0.6s both;
}

.progress-state.entering .prog-footer {
  animation: fadeInUp 0.4s var(--ease-out) 0.7s both;
}

/* Hero percentage entrance */
@keyframes heroEntrance {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Progress bar track slides in from center */
@keyframes barTrackReveal {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

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

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

.results-state.entering {
  animation: resultsCrossfade 0.55s var(--ease-out) both;
}

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

/* LANDING STATE */
.landing-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* Warm radial glow at center — the heart of the orrery */
.landing-state::before {
  content: '';
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 800px;
  height: 600px;
  background:
    radial-gradient(ellipse, rgba(154,117,48,0.045) 0%, rgba(154,117,48,0.015) 35%, transparent 65%),
    radial-gradient(ellipse at 45% 55%, rgba(61,122,102,0.02) 0%, transparent 50%);
  pointer-events: none;
  opacity: 0.8;
  animation: landingGlow 10s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes landingGlow {
  0% { opacity: 0.7; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0.9; transform: translate(-50%, -50%) scale(1.04); }
}

/* =============================================================================
   MATHEMATICAL ORRERY — landing page orbital symbol system
   Concentric elliptical orbits carrying math symbols like a celestial orrery.
   A love letter to mathematics: meditative, ethereal, scholarly.
   ============================================================================= */

.math-orrery {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Warm radial glow at center — the "sun" of our mathematical solar system */
.orrery-glow {
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(154,117,48,0.05) 0%, rgba(154,117,48,0.02) 30%, transparent 60%),
    radial-gradient(circle, rgba(61,122,102,0.03) 0%, transparent 50%);
  animation: orreryGlow 10s ease-in-out infinite alternate;
}

@keyframes orreryGlow {
  0% { opacity: 0.65; transform: scale(1); }
  100% { opacity: 0.85; transform: scale(1.03); }
}

/* --- Orbit rings --- */
.orrery-orbit {
  position: absolute;
  border-radius: 50%;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Each orbit: size, border color, speed, direction */
.orrery-orbit-1 {
  width: 220px;
  height: 220px;
  border-color: rgba(154,117,48,0.08);
  animation: orbitRotate 40s linear infinite;
}

.orrery-orbit-2 {
  width: 320px;
  height: 280px;
  border-color: rgba(61,122,102,0.07);
  animation: orbitRotate 55s linear infinite reverse;
}

.orrery-orbit-3 {
  width: 430px;
  height: 370px;
  border-color: rgba(61,106,142,0.06);
  animation: orbitRotate 70s linear infinite;
}

.orrery-orbit-4 {
  width: 560px;
  height: 470px;
  border-color: rgba(154,117,48,0.04);
  border-style: dashed;
  animation: orbitRotate 90s linear infinite reverse;
}

.orrery-orbit-5 {
  width: 700px;
  height: 580px;
  border-color: rgba(61,122,102,0.035);
  animation: orbitRotate 110s linear infinite;
}

@keyframes orbitRotate {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Symbols on orbits ---
   Each symbol is placed at a point on the orbit perimeter using --angle.
   The parent orbit rotates, carrying symbols along.
   Symbols counter-rotate to stay upright via individual animation.
   We use sin/cos approximations via percentage positioning. */
.orbit-sym {
  position: absolute;
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 15px;
  font-weight: 400;
  font-style: italic;
  color: var(--color);
  opacity: 0.38;
  text-shadow:
    0 0 12px color-mix(in srgb, var(--color) 45%, transparent),
    0 0 24px color-mix(in srgb, var(--color) 18%, transparent);
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
}

/* Hero symbols — larger, slightly more visible */
.orbit-sym-hero {
  font-size: 18px;
  font-weight: 700;
  opacity: 0.48;
  text-shadow:
    0 0 16px color-mix(in srgb, var(--color) 55%, transparent),
    0 0 32px color-mix(in srgb, var(--color) 22%, transparent);
}

/* Euler's identity superscript */
.orbit-sup {
  font-size: 0.6em;
  vertical-align: super;
  font-style: italic;
}

/* Position symbols at specific points on each orbit.
   Each orbit ring is a rotating circle — we position children
   at fixed offsets so the orbit's rotation carries them around.
   top/left are percentages of the orbit ring's bounding box. */

/* Orbit 1: 220×220, 3 symbols at 0°, 120°, 240° */
.orrery-orbit-1 .orbit-sym:nth-child(1) { top: -4px; left: 50%; transform: translateX(-50%); }
.orrery-orbit-1 .orbit-sym:nth-child(2) { bottom: 12%; left: -2px; }
.orrery-orbit-1 .orbit-sym:nth-child(3) { bottom: 12%; right: -2px; }

/* Orbit 2: 320×280, 3 symbols */
.orrery-orbit-2 .orbit-sym:nth-child(1) { top: -4px; right: 22%; }
.orrery-orbit-2 .orbit-sym:nth-child(2) { bottom: -4px; left: 22%; }
.orrery-orbit-2 .orbit-sym:nth-child(3) { top: 50%; left: -6px; transform: translateY(-50%); }

/* Orbit 3: 430×370, 3 symbols */
.orrery-orbit-3 .orbit-sym:nth-child(1) { top: 8%; right: 5%; }
.orrery-orbit-3 .orbit-sym:nth-child(2) { top: 50%; left: -8px; transform: translateY(-50%); }
.orrery-orbit-3 .orbit-sym:nth-child(3) { bottom: 8%; right: 18%; }

/* Orbit 4: 560×470, 4 symbols */
.orrery-orbit-4 .orbit-sym:nth-child(1) { top: -4px; left: 35%; }
.orrery-orbit-4 .orbit-sym:nth-child(2) { top: 30%; right: -6px; }
.orrery-orbit-4 .orbit-sym:nth-child(3) { bottom: -4px; right: 35%; }
.orrery-orbit-4 .orbit-sym:nth-child(4) { bottom: 30%; left: -6px; }

/* Orbit 5: 700×580, 3 symbols */
.orrery-orbit-5 .orbit-sym:nth-child(1) { top: 12%; left: 15%; }
.orrery-orbit-5 .orbit-sym:nth-child(2) { bottom: -4px; left: 50%; transform: translateX(-50%); }
.orrery-orbit-5 .orbit-sym:nth-child(3) { top: 35%; right: -6px; }

/* Gentle breathing animation on each symbol — they softly pulse */
.orbit-sym::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--color) 10%, transparent) 0%, transparent 70%);
  animation: symBreathe 5s ease-in-out infinite;
  pointer-events: none;
}

.orrery-orbit-2 .orbit-sym::after { animation-delay: 0.8s; }
.orrery-orbit-3 .orbit-sym::after { animation-delay: 1.6s; }
.orrery-orbit-4 .orbit-sym::after { animation-delay: 2.4s; }
.orrery-orbit-5 .orbit-sym::after { animation-delay: 3.2s; }

@keyframes symBreathe {
  0%, 100% { opacity: 0; transform: scale(0.7); }
  50% { opacity: 1; transform: scale(1.3); }
}

/* --- Constellation dots — tiny floating particles --- */
.orrery-dot {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: var(--c);
  opacity: 0;
  animation: dotFloat 7s ease-in-out var(--d) infinite;
}

/* Thin connecting line from each dot — subtle constellation threads */
.orrery-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 50px;
  height: 0.5px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 25%, transparent), transparent);
  transform-origin: left center;
  transform: rotate(calc(var(--d) * 50deg));
  opacity: 0.6;
}

.orrery-dot:nth-child(odd)::after {
  width: 70px;
  transform: rotate(calc(var(--d) * -35deg));
}

@keyframes dotFloat {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  15% {
    opacity: 0.5;
    transform: translate(3px, -5px) scale(1);
  }
  50% {
    opacity: 0.3;
    transform: translate(-2px, -8px) scale(0.9);
  }
  85% {
    opacity: 0.15;
    transform: translate(1px, -3px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
}

/* === Entrance animation — orrery fades in with a gentle bloom === */
.landing-state.entering .math-orrery {
  animation: orreryReveal 1.2s var(--ease-out) 0.1s both;
}

@keyframes orreryReveal {
  from { opacity: 0; transform: scale(0.85) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.landing-inner {
  width: 100%;
  max-width: 720px;
  padding: 0 2rem;
  text-align: center;
  position: relative;
  z-index: 1;
}

.landing-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.6rem;
  width: 62px;
  height: 62px;
  border-radius: 17px;
  background: var(--amber-glow);
  border: 1px solid rgba(154,117,48,0.12);
  animation: fadeInUp 0.6s var(--ease-out) both;
}

/* Float is on an inner wrapper to avoid conflicting with fadeInUp transform */
.landing-icon svg {
  animation: iconFloat 5s ease-in-out 0.6s infinite alternate;
}

@keyframes iconFloat {
  0% { transform: translateY(0); }
  100% { transform: translateY(-2px); }
}

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

.landing-icon svg {
  width: 27px;
  height: 27px;
  color: var(--amber);
}

.landing-title {
  font-family: var(--font-display);
  font-size: 2.1rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.6rem;
  animation: fadeInUp 0.6s ease 0.08s both;
}

.landing-sub {
  font-size: 1.1rem;
  color: var(--text-3);
  margin-bottom: 2rem;
  line-height: 1.6;
  animation: fadeInUp 0.6s ease 0.14s both;
}

.landing-highlight {
  color: var(--text-2);
  font-weight: 500;
}

/* Feature hints below the bar */
.landing-features {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.8rem 1.5rem;
  margin-top: 1.6rem;
  animation: fadeInUp 0.6s ease 0.4s both;
}

.landing-feat {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--text-4);
}

.landing-feat svg {
  width: 16px;
  height: 16px;
  color: var(--text-4);
  opacity: 0.5;
  flex-shrink: 0;
}

.landing-feat-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border);
}

/* Landing about note */
.landing-about {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  max-width: 560px;
  margin: 1.8rem auto 0;
  padding: 1.4rem 1.2rem 0.65rem;
  text-align: center;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(154,117,48,0.1);
  border-radius: 10px;
  overflow: hidden;
  animation: fadeInUp 0.5s ease 0.55s both;
}

.landing-about p {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-4);
}

.landing-personal-note {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.74rem;
  color: var(--amber);
  margin-top: 1rem;
  letter-spacing: 0.02em;
  padding: 0.5rem 1.1rem;
  background: rgba(154,117,48,0.05);
  border: 1px solid rgba(154,117,48,0.14);
  border-radius: 20px;
  animation: fadeInUp 0.5s ease 0.65s both;
}

/* Timing note — progress page */
.timing-note {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  max-width: 480px;
  margin: 0.8rem auto 0;
  padding: 0.5rem 0.7rem 0.45rem;
  background: rgba(255,255,255,0.3);
  border: none;
  border-radius: 8px;
  overflow: hidden;
  animation: fadeInUp 0.5s ease 0.55s both;
  opacity: 0.6;
}

.timing-note-icon {
  flex-shrink: 0;
  align-self: center;
}

.timing-note-body {
  flex: 1;
  min-width: 0;
}

.timing-note-line {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-4);
  margin-bottom: 0.3rem;
}

.timing-note-chips {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.timing-chip {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-4);
  letter-spacing: 0.01em;
}

.timing-chip strong {
  font-weight: 600;
  color: var(--amber);
}

.timing-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  opacity: 0.6;
}

/* PROGRESS STATE */
.progress-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Soft ambient mesh — single gentle glow, no circus */
.prog-mesh {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 40%, rgba(154,117,48,0.05) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 65% 60%, rgba(61,122,102,0.03) 0%, transparent 60%);
  pointer-events: none;
  animation: meshBreath 12s ease-in-out infinite alternate;
}

@keyframes meshBreath {
  0% { opacity: 0.75; }
  100% { opacity: 1; }
}

/* Progress orrery — reuses landing math-orrery styles, positioned as background */
.prog-orrery {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

/* Entrance: orrery fades in as analysis begins */
.progress-state.entering .prog-orrery {
  animation: fadeInSlow 1.2s var(--ease-out) 0.15s both;
}

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

/* (Particles/symbols/constellation removed — clean design) */

.prog-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  max-width: 640px;
  width: 100%;
  padding: 0 2rem;
  position: relative;
  z-index: 2;
}

/* (Ring-wrap and spiral removed — replaced with prog-hero) */

/* (Orbital system and pulse waves removed) */

/* RESULTS STATE */
.results-state {
  flex: 1;
  display: flex;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.results-state.entering .panel {
  animation: resultPanelIn 0.55s var(--ease-out) both;
}
.results-state.entering .panel-paper { animation-delay: 0.05s; }
.results-state.entering .panel-analysis { animation-delay: 0.12s; }

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

/* Chat bar */
.chat-bar {
  width: 100%;
  position: relative;
  animation: barIn 0.6s ease 0.15s both;
  transition: border-color var(--dur), box-shadow var(--dur);
}

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

.chat-bar-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.5rem;
  transition: border-color 0.3s var(--ease), box-shadow 0.4s var(--ease), background 0.3s var(--ease);
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

.chat-bar-inner:hover {
  border-color: var(--border);
  box-shadow: 0 6px 32px rgba(0,0,0,0.08);
}

.chat-bar-inner:focus-within {
  border-color: var(--border);
  box-shadow: 0 6px 32px rgba(0,0,0,0.08);
  outline: none;
}
.chat-bar-inner:focus-visible,
.chat-bar *:focus-visible {
  outline: none !important;
}

.chat-input {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  padding: 0.9rem 0.9rem 0.45rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.05rem;
  outline: none !important;
  line-height: 1.5;
}
.chat-input:focus {
  outline: none;
}
.chat-input:focus-visible {
  outline: 2px solid rgba(154,117,48,0.3);
  outline-offset: -2px;
  border-radius: 2px;
}

.chat-input::placeholder {
  color: var(--text-4);
  font-style: italic;
}

/* File tag inside chat bar */
.chat-file-tag[hidden] { display: none !important; }
.chat-file-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.2rem auto 0.3rem;
  padding: 0.5rem 0.85rem;
  background: var(--sage-glow);
  border: 1px solid rgba(106,158,142,0.22);
  border-radius: 10px;
  font-size: 0.88rem;
  color: var(--sage);
  font-weight: 500;
  animation: tagIn 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.chat-file-tag:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(106,158,142,0.12);
}

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

.chat-file-tag svg { color: var(--sage); flex-shrink: 0; }
.chat-file-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-file-remove {
  background: none; border: none;
  color: var(--sage); cursor: pointer;
  font-size: 1.05rem; line-height: 1;
  padding: 0 0.1rem;
  opacity: 0.5;
  transition: opacity var(--dur), transform 0.15s var(--ease);
}
.chat-file-remove:hover { opacity: 1; transform: scale(1.15); }

/* ── "has-file" state: PDF attached, ready to submit ── */
.chat-bar.has-file .chat-bar-inner {
  border-color: rgba(106,158,142,0.3);
  box-shadow: 0 4px 24px rgba(106,158,142,0.08), 0 0 0 2px rgba(106,158,142,0.06);
}

.chat-bar.has-file .chat-input {
  height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
  transition: height 0.35s var(--ease), padding 0.35s var(--ease), opacity 0.2s ease;
}

.chat-bar.has-file .chat-file-tag {
  display: flex;
  justify-content: center;
  margin: 0.45rem auto 0.25rem;
}

/* Gentle pulse on submit button when file is ready */
.chat-bar.has-file .chat-submit:not(:disabled) {
  animation: readyPulse 2.2s ease-in-out infinite;
}
@keyframes readyPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(154,117,48,0); }
  50% { box-shadow: 0 0 0 6px rgba(154,117,48,0.12); }
}

/* Chat bottom actions row */
.chat-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.35rem;
}

.chat-left-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Attach button */
.chat-attach {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-4);
  cursor: pointer;
  transition: all var(--dur);
}
.chat-attach svg { width: 16px; height: 16px; }
.chat-attach:hover { color: var(--text-2); background: var(--surface-2); border-color: var(--border-dim); }


/* Provider toggle (compact, in chat bar) */
.chat-provider {
  display: flex;
  gap: 1px;
  background: var(--border-dim);
  border-radius: 6px;
  overflow: hidden;
  margin-left: 0.15rem;
}

.chat-prov-btn {
  width: 30px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  color: var(--text-4);
  transition: all var(--dur);
}
.chat-prov-btn svg { width: 13px; height: 13px; }
.chat-prov-btn:hover { color: var(--text-3); }

.chat-prov-btn.active[data-provider="openai"] {
  color: #74aa9c;
  background: rgba(116, 170, 156, 0.1);
}
.chat-prov-btn.active[data-provider="anthropic"] {
  color: #d4a574;
  background: rgba(212, 165, 116, 0.1);
}

.chat-prov-btn.switching {
  pointer-events: none; opacity: 0.5;
}
.chat-prov-btn.switching svg { animation: spin 0.6s linear infinite; }

/* Submit arrow */
.chat-submit {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--amber);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--dur) var(--ease), box-shadow 0.3s var(--ease), opacity 0.4s var(--ease), transform 0.15s var(--ease-spring);
}
.chat-submit svg { width: 18px; height: 18px; transition: transform 0.2s var(--ease); }
.chat-submit:hover:not(:disabled) { background: var(--amber-bright); box-shadow: 0 2px 12px rgba(154,117,48,0.25); }
.chat-submit:hover:not(:disabled) svg { transform: translateX(2px); }
.chat-submit:active:not(:disabled) { transform: scale(0.93); }
.chat-submit:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-submit.loading { pointer-events: none; }
.chat-submit.loading svg { display: none; }
.chat-submit.loading .btn-dots { display: flex; }
.btn-dots { display: none; justify-content: center; gap: 3px; }
.btn-dots span { width: 5px; height: 5px; background: #fff; border-radius: 50%; animation: bounce 1.2s infinite; }
.btn-dots span:nth-child(2) { animation-delay: 0.15s; }
.btn-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%,80%,100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1.1); } }

/* Hints below the bar */
.landing-hints {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
  animation: barIn 0.6s ease 0.3s both;
}

.hint-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.88rem;
  color: var(--text-4);
}
.hint-item svg { color: var(--text-4); opacity: 0.6; }

.hint-sep {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.88rem;
  color: var(--text-4);
  opacity: 0.5;
}

/* =============================================================================
   PROGRESS (inline within main-area)
   ============================================================================= */

/* === Hero Percentage === */
.prog-hero {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.1rem;
  margin-bottom: 0.3rem;
  position: relative;
}

.pct-num {
  font-family: var(--font-display);
  font-size: 4.5rem;
  font-weight: 400;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
  transition: color 0.8s ease;
  font-variant-numeric: lining-nums tabular-nums;
}

.pct-sign {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--text-3);
  letter-spacing: -0.02em;
  transition: color 0.8s ease;
  opacity: 0.45;
  margin-left: 0.05rem;
}

/* === Progress Line === */
.prog-line-wrap {
  width: 100%;
  max-width: 360px;
  margin-bottom: 1rem;
  position: relative;
}

.prog-line-svg {
  width: 100%;
  height: 4px;
  display: block;
}

.prog-line-svg .prog-track {
  stroke: var(--border-dim);
  stroke-width: 1;
  stroke-linecap: round;
  opacity: 0.3;
}

.prog-line-svg .prog-glow {
  stroke: url(#ring-glow);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  transition: stroke-dashoffset 1.8s cubic-bezier(0.22, 0.61, 0.36, 1);
  opacity: 0.4;
}

.prog-line-svg .prog-fill {
  stroke: url(#ring-grad);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  transition: stroke-dashoffset 1.8s cubic-bezier(0.22, 0.61, 0.36, 1);
  filter: drop-shadow(0 0 3px rgba(154,117,48,0.35));
}

.prog-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.1rem;
  animation: titleBreath 4s ease-in-out infinite;
  text-align: center;
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.3s ease;
}

@keyframes titleBreath {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

.prog-msg {
  font-size: 0.82rem;
  color: var(--text-4);
  font-style: italic;
  margin-bottom: 0.5rem;
  min-height: 1.2em;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}

.prog-msg.fading {
  opacity: 0;
  transform: translateY(-4px);
}

/* Stats wrapper — holds skeleton and real stats in same space */
.prog-stats-wrap {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.4rem;
  width: 100%;
}

/* Scanning text placeholder */
.prog-stats-skeleton {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out), filter 0.5s ease;
}

.prog-stats-skeleton.fade-out {
  opacity: 0;
  transform: translate(-50%, -50%) translateY(-4px);
  filter: blur(4px);
  pointer-events: none;
}

.skel-scan-text {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-4);
  letter-spacing: 0.02em;
  opacity: 0.6;
  white-space: nowrap;
}

.skel-scan-cursor {
  display: inline-block;
  width: 1px;
  height: 0.8em;
  background: var(--text-4);
  margin-left: 2px;
  opacity: 0;
  animation: cursorBlink 1.2s ease-in-out infinite;
  vertical-align: text-bottom;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 0.05; }
  50% { opacity: 0.55; }
}

/* Paper stats strip — count-up animation */
.prog-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin: 0;
  padding: 0.15rem 0;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
  position: relative;
  z-index: 1;
}

.prog-stats.has-data {
  opacity: 1;
  transform: translateY(0);
}

.prog-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.05rem;
  padding: 0.15rem 0.75rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.45s var(--ease-out), transform 0.45s var(--ease-out);
}

.prog-stat.visible {
  opacity: 1;
  transform: translateY(0);
}

.prog-stat-val {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--text-2);
  letter-spacing: -0.01em;
  line-height: 1;
}

.prog-stat-label {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--text-4);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
}

.prog-stat-sep {
  width: 1px;
  height: 14px;
  background: var(--border);
  opacity: 0;
  transition: opacity 0.45s var(--ease-out);
  flex-shrink: 0;
}

.prog-stat-sep.visible {
  opacity: 0.2;
}

.prog-domain-badge {
  flex-direction: row !important;
  padding: 0.2rem 0.6rem !important;
}
.prog-domain-val {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--amber);
  background: rgba(154,117,48,0.08);
  border: 1px solid rgba(154,117,48,0.18);
  border-radius: 3px;
  padding: 0.12rem 0.4rem;
  line-height: 1;
}

/* Hide the last separator (before a hidden stat or at the end) */
.prog-stat-sep:last-child {
  display: none;
}

.prog-bar-track {
  display: none;
}

.prog-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--amber-dim), var(--amber), var(--sage));
  background-size: 200% 100%;
  animation: barShimmer 4s ease-in-out infinite;
  transition: width 2s cubic-bezier(0.22, 0.61, 0.36, 1);
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(154,117,48,0.2);
}

@keyframes barShimmer {
  0% { background-position: 0% 0%; }
  50% { background-position: 100% 0%; }
  100% { background-position: 0% 0%; }
}

/* Scanning line effect on the bar track */
.prog-bar-track::after {
  content: '';
  position: absolute;
  top: 0;
  left: -40%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(154,117,48,0.15), transparent);
  animation: barScan 2.5s ease-in-out infinite;
}

@keyframes barScan {
  0% { left: -40%; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { left: 140%; opacity: 0; }
}

.prog-stages {
  display: flex;
  justify-content: center;
  gap: 1.4rem;
  padding: 0.45rem 1.2rem;
  background: transparent;
  border-radius: 10px;
  border: none;
}

.stg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  position: relative;
}

.stg-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  transition: all 0.5s var(--ease);
  position: relative;
}

/* Checkmark inside completed dots */
.stg-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0);
  transition: all 0.35s var(--ease);
}

/* Active: pop-in scale + pulse ring + glow */
.stg.active .stg-dot {
  background: var(--amber);
  border-color: var(--amber);
  box-shadow: 0 0 8px rgba(154,117,48,0.35), 0 0 18px rgba(154,117,48,0.12);
  transform: scale(1.2);
  animation: dotPulse 2.4s ease-in-out infinite;
}

/* Outer ripple rings on active dot */
.stg.active .stg-dot::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1px solid var(--amber);
  opacity: 0;
  animation: dotRipple 2s ease-out infinite;
}

@keyframes dotPulse {
  0%, 100% {
    box-shadow: 0 0 8px rgba(154,117,48,0.35), 0 0 18px rgba(154,117,48,0.12);
    transform: scale(1.2);
  }
  50% {
    box-shadow: 0 0 12px rgba(154,117,48,0.45), 0 0 22px rgba(154,117,48,0.15);
    transform: scale(1.28);
  }
}

@keyframes dotRipple {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Completed: shrink back, turn sage, show checkmark */
.stg.completed .stg-dot {
  background: var(--sage);
  border-color: var(--sage);
  box-shadow: 0 0 10px rgba(61,122,102,0.35);
  transform: scale(1);
  animation: dotComplete 0.6s var(--ease-spring);
}

.stg.completed .stg-dot::before { display: none; }

/* Checkmark removed — sage fill color is sufficient */
.stg.completed .stg-dot::after {
  display: none;
}

@keyframes dotComplete {
  0% { transform: scale(1.3); background: var(--amber); border-color: var(--amber); }
  50% { transform: scale(0.9); }
  100% { transform: scale(1); background: var(--sage); border-color: var(--sage); }
}

.stg span {
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-4);
  transition: color 0.4s var(--ease), transform 0.3s var(--ease);
  opacity: 0.8;
}
.stg.active span {
  color: var(--amber);
  opacity: 1;
  transform: translateY(-1px);
}
.stg.completed span { color: var(--sage); }

/* Connecting lines between stage dots — animated fill */
.stg + .stg::before {
  content: '';
  position: absolute;
  top: 5px;
  right: calc(100% + 0.3rem);
  width: calc(1.4rem - 0.6rem);
  height: 1px;
  background: var(--border-dim);
  border-radius: 1px;
  overflow: hidden;
  opacity: 0.5;
}

/* Animated fill line overlay */
.stg + .stg::after {
  content: '';
  position: absolute;
  top: 5px;
  right: calc(100% + 0.3rem);
  width: 0;
  height: 1px;
  background: var(--sage);
  border-radius: 1px;
  transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* When current dot is active or completed, fill the line leading TO it */
.stg.active + .stg::after,
.stg.completed + .stg::after {
  width: calc(1.4rem - 0.6rem);
}

/* Completed line is sage, active line is amber gradient */
.stg.completed + .stg::after {
  background: var(--sage);
  box-shadow: none;
}

.stg.active + .stg::after {
  background: linear-gradient(90deg, var(--sage), var(--amber));
  box-shadow: none;
}

/* Fix: the line fills from the PREVIOUS completed/active dot */
.stg.completed::after,
.stg.active::after {
  width: calc(1.4rem - 0.6rem);
}

/* (Old ring percentage and inner glow removed — replaced with prog-hero) */

/* (Outer aura and core breath removed) */

/* Footer with timer and cancel */
.prog-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1rem;
}

.prog-timer {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-4);
  letter-spacing: 0.02em;
  padding: 0.3rem 0.6rem;
  background: transparent;
  border-radius: 6px;
  border: none;
}

.prog-timer svg {
  color: var(--text-3);
  opacity: 0.7;
  animation: timerTick 1s steps(1) infinite;
}

@keyframes timerTick {
  0%, 49% { opacity: 0.7; }
  50%, 100% { opacity: 0.3; }
}

.prog-estimate {
  color: var(--text-4);
  font-size: 0.75rem;
  margin-left: 0.15rem;
  font-style: italic;
  font-family: var(--font-body);
  opacity: 0.7;
}

/* Cancel / back button on progress */
.prog-cancel {
  padding: 0.28rem 0.65rem;
  background: transparent;
  border: 1px solid rgba(213,208,200,0.2);
  border-radius: 5px;
  color: var(--text-4);
  font-family: var(--font-body);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color var(--dur), border-color var(--dur), background var(--dur), transform 0.12s var(--ease-spring);
}
.prog-cancel:hover {
  color: var(--text-3);
  border-color: var(--border);
  background: rgba(255,255,255,0.3);
}
.prog-cancel:active {
  transform: scale(0.95);
}

/* Coffee cup animation for notes */
/* Paper + coffee desk scene */
.landing-desk {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.desk-paper {
  width: 12px;
  height: 15px;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--amber-dim);
  border-radius: 1px;
  padding: 3px 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0.35;
  transform: rotate(-5deg);
  margin-bottom: 2px;
}

.desk-paper-line {
  height: 0.8px;
  background: var(--amber-dim);
  border-radius: 1px;
  opacity: 0.45;
}

.desk-paper-line.short {
  width: 55%;
}

.coffee-cup {
  position: relative;
  width: 18px;
  height: 13px;
  background: var(--amber-dim);
  border-radius: 1px 1px 4px 4px;
  opacity: 0.35;
}

/* Cup handle */
.coffee-cup::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 2px;
  width: 7px;
  height: 10px;
  border: 1.5px solid var(--amber-dim);
  border-left: none;
  border-radius: 0 4px 4px 0;
}

/* Saucer */
.coffee-cup::before {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  background: var(--amber-dim);
  border-radius: 0 0 3px 3px;
  opacity: 0.5;
}

/* Steam wisps */
.coffee-steam {
  position: absolute;
  bottom: 100%;
  width: 2px;
  border-radius: 1px;
  opacity: 0;
  background: var(--amber-dim);
  animation: steamRise 2.6s ease-out infinite;
}

.coffee-steam-1 {
  left: 5px;
  animation-delay: 0s;
}

.coffee-steam-2 {
  left: 10px;
  animation-delay: 0.85s;
}

.coffee-steam-3 {
  left: 15px;
  animation-delay: 1.7s;
}

@keyframes steamRise {
  0% {
    opacity: 0;
    height: 4px;
    transform: translateY(0) scaleX(1);
  }
  15% {
    opacity: 0.35;
  }
  50% {
    opacity: 0.2;
    height: 8px;
    transform: translateY(-6px) scaleX(1.3);
  }
  100% {
    opacity: 0;
    height: 5px;
    transform: translateY(-14px) scaleX(0.5);
  }
}

/* ── Stage card containers (shared) ── */
.prog-stage-card[hidden] { display: none !important; }
.prog-stage-card {
  margin-top: 0.55rem;
  max-width: 540px;
  width: 100%;
  padding: 0.45rem 0.55rem 0.4rem;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(213,208,200,0.12);
  border-left: 2px solid var(--amber-dim);
  border-radius: 8px;
  animation: stageCardIn 0.45s var(--ease-out);
}

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

.prog-stage-card-header {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}

.prog-stage-card-header svg {
  color: var(--amber);
  flex-shrink: 0;
}

.prog-stage-card-header > span:first-of-type {
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  color: var(--text-3);
}

/* Stage badge — hidden by default, shown on completion */
.prog-stage-badge {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text-4);
  background: transparent;
  border: 1px solid rgba(213,208,200,0.25);
  border-radius: 3px;
  padding: 0.08rem 0.35rem;
  margin-left: auto;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.4s var(--ease), background 0.4s var(--ease), border-color 0.4s var(--ease);
}

.prog-stage-badge[hidden] { display: none; }

/* Completed card state — sage accent */
.prog-stage-card.completed {
  border-left-color: var(--sage);
  border-color: rgba(61,122,102,0.1);
  border-left-width: 2px;
  background: rgba(61,122,102,0.02);
  opacity: 0.7;
}

.prog-stage-card.completed .prog-stage-card-header svg { color: var(--sage); }
.prog-stage-card.completed .prog-stage-card-header > span:first-of-type { color: var(--sage); opacity: 0.8; }
.prog-stage-card.completed .prog-stage-badge {
  color: var(--sage);
  background: transparent;
  border-color: rgba(61,122,102,0.2);
  animation: badgeReveal 0.4s var(--ease-spring);
}

/* Collapsed completed card — compact inline pill */
.prog-stage-card.collapsed {
  padding: 0.2rem 0.55rem;
  margin-top: 0.2rem;
  opacity: 0.55;
  border-radius: 6px;
  border-width: 1px;
  border-left-width: 2px;
  border-left-color: var(--sage);
  background: rgba(61,122,102,0.03);
  transform: scale(0.98);
  transform-origin: center top;
  transition: padding 0.6s var(--ease), margin 0.6s var(--ease),
              opacity 0.6s var(--ease), transform 0.6s var(--ease),
              border-radius 0.4s var(--ease);
}
.prog-stage-card.collapsed .prog-stage-card-header {
  margin-bottom: 0;
  gap: 0.25rem;
}
.prog-stage-card.collapsed .prog-stage-card-header svg {
  width: 10px;
  height: 10px;
}
.prog-stage-card.collapsed .prog-agents,
.prog-stage-card.collapsed .prog-formula-steps,
.prog-stage-card.collapsed .prog-math-grid,
.prog-stage-card.collapsed .prog-math-counter {
  display: none;
}
.prog-stage-card.collapsed:hover {
  opacity: 0.75;
  transform: scale(0.99);
}
.prog-stage-card.collapsed .prog-stage-card-header > span:first-of-type {
  font-size: 0.62rem;
}
.prog-stage-card.collapsed .prog-stage-badge {
  font-size: 0.52rem;
  padding: 0.03rem 0.22rem;
  opacity: 0.7;
}

@keyframes badgeReveal {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* Per-agent progress tracker */
.prog-agents {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.25rem;
}

.prog-agent[hidden] { display: none !important; }
.prog-agent {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(213,208,200,0.12);
  border-radius: 4px;
  font-size: 0.72rem;
  transition: background 0.4s var(--ease), border-color 0.4s var(--ease), transform 0.3s var(--ease-spring);
}

.prog-agent-icon {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.4s var(--ease), box-shadow 0.4s var(--ease);
}

.prog-agent-name {
  font-weight: 500;
  color: var(--text-3);
  font-size: 0.72rem;
  transition: color 0.3s var(--ease);
}

.prog-agent-status {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--text-4);
  transition: color 0.3s var(--ease);
}

/* Agent states */
.prog-agent.running {
  background: var(--amber-glow);
  border-color: rgba(154,117,48,0.2);
}
.prog-agent.running .prog-agent-icon {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(154,117,48,0.5);
  animation: agentPulse 1.5s ease-in-out infinite;
}
.prog-agent.running .prog-agent-name { color: var(--amber); }
.prog-agent.running .prog-agent-status { color: var(--amber-dim); }

.prog-agent.done {
  background: var(--sage-glow);
  border-color: rgba(61,122,102,0.15);
  animation: agentDone 0.4s var(--ease-spring);
}
.prog-agent.done .prog-agent-icon {
  background: var(--sage);
  box-shadow: 0 0 6px rgba(61,122,102,0.3);
}
.prog-agent.done .prog-agent-name { color: var(--sage); }
.prog-agent.done .prog-agent-status { color: var(--sage); }

.prog-agent.error .prog-agent-icon { background: var(--danger); }
.prog-agent.error .prog-agent-name { color: var(--danger); }

@keyframes agentPulse {
  0%, 100% { box-shadow: 0 0 6px rgba(154,117,48,0.3); }
  50% { box-shadow: 0 0 10px rgba(154,117,48,0.5); }
}

@keyframes agentDone {
  0% { transform: scale(1.04); }
  50% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

/* ── Per-formula Math explainer progress grid ── */
.prog-stage-card--math-formulas {
  border-left-color: var(--amber-dim);
}
.prog-stage-card--math-formulas.completed {
  border-left-color: var(--sage);
}

.prog-math-counter {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--amber-dim);
  margin-left: auto;
  letter-spacing: 0.03em;
  transition: color 0.4s var(--ease);
}
.prog-stage-card--math-formulas.completed .prog-math-counter {
  color: var(--sage);
}

.prog-math-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
  margin-top: 2px;
}

.prog-math-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  border-radius: 4px;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(213,208,200,0.15);
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 500;
  color: var(--text-4);
  cursor: default;
  transition: background 0.35s var(--ease), border-color 0.35s var(--ease),
              color 0.35s var(--ease), transform 0.25s var(--ease-spring),
              box-shadow 0.35s var(--ease);
  overflow: hidden;
}

/* Pending — faint, quiet */
.prog-math-tile.pending {
  opacity: 0.4;
}

/* Running — subtle amber dot blink, no shimmer */
.prog-math-tile.running {
  background: rgba(154,117,48,0.05);
  border-color: rgba(154,117,48,0.18);
  color: var(--amber-dim);
  opacity: 1;
}
.prog-math-tile.running::before {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--amber);
  animation: mathDotBlink 1.4s ease-in-out infinite;
}

/* Done — solid sage fill, clearly distinct */
.prog-math-tile.done {
  background: rgba(61,122,102,0.12);
  border-color: rgba(61,122,102,0.25);
  color: var(--sage);
  font-weight: 600;
  opacity: 1;
  animation: mathTileDone 0.35s var(--ease-spring);
}

/* Error — muted red */
.prog-math-tile.error {
  background: rgba(196,80,80,0.06);
  border-color: rgba(196,80,80,0.15);
  color: var(--danger);
  opacity: 0.8;
}

.prog-math-tile[title] {
  cursor: help;
}

@keyframes mathDotBlink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

@keyframes mathTileDone {
  0% { transform: scale(1.06); }
  60% { transform: scale(0.97); }
  100% { transform: scale(1); }
}

/* ── Formula pipeline progress (parallel track) ── */
/* Card styling inherited from .prog-stage-card */

/* Step pills — mirrors .prog-agent pill styling exactly */
.prog-formula-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.25rem;
}

.prog-formula-step {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(213,208,200,0.12);
  border-radius: 4px;
  font-size: 0.72rem;
  transition: background 0.4s var(--ease), border-color 0.4s var(--ease), transform 0.3s var(--ease-spring);
}

.prog-formula-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.4s var(--ease), box-shadow 0.4s var(--ease);
}

.prog-formula-name {
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--text-3);
  transition: color 0.3s var(--ease);
  white-space: nowrap;
}

.prog-formula-st {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-4);
  transition: color 0.3s var(--ease);
  white-space: nowrap;
}

/* Active step — amber glow (matches prog-agent.running) */
.prog-formula-step.active {
  background: var(--amber-glow);
  border-color: rgba(154,117,48,0.2);
}
.prog-formula-step.active .prog-formula-dot {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(154,117,48,0.5);
  animation: agentPulse 1.5s ease-in-out infinite;
}
.prog-formula-step.active .prog-formula-name { color: var(--amber); }
.prog-formula-step.active .prog-formula-st { color: var(--amber-dim); }

/* Done step — sage (matches prog-agent.done) */
.prog-formula-step.done {
  background: var(--sage-glow);
  border-color: rgba(61,122,102,0.15);
  animation: agentDone 0.4s var(--ease-spring);
}
.prog-formula-step.done .prog-formula-dot {
  background: var(--sage);
  box-shadow: 0 0 6px rgba(61,122,102,0.3);
}
.prog-formula-step.done .prog-formula-name { color: var(--sage); }
.prog-formula-step.done .prog-formula-st { color: var(--sage); }

/* Error step */
.prog-formula-step.error {
  border-color: rgba(196,80,80,0.15);
}
.prog-formula-step.error .prog-formula-dot { background: var(--danger); }
.prog-formula-step.error .prog-formula-name { color: var(--danger); }

/* ── Error pipeline ── */
.prog-formula-pipeline.error-state {
  border-left-color: var(--danger);
}
.prog-formula-pipeline.error-state .prog-stage-card-header svg { color: var(--danger); }

/* =============================================================================
   SEARCH BAR
   ============================================================================= */

.search-bar[hidden] { display: none !important; }
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-dim);
  animation: searchIn 0.2s var(--ease-out);
}

@keyframes searchIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-bar svg { color: var(--text-4); flex-shrink: 0; }

.search-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--text);
  outline: none;
  min-width: 0;
  transition: border-color var(--dur);
}
.search-input:focus { border-color: var(--amber-dim); }
.search-input::placeholder { color: var(--text-4); }

.search-count {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-4);
  white-space: nowrap;
  min-width: 3em;
  text-align: center;
}

.search-nav-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  color: var(--text-3);
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--dur), color var(--dur);
}
.search-nav-btn:hover { background: var(--surface-2); color: var(--text); }

.search-close {
  background: none;
  border: none;
  color: var(--text-4);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  transition: color var(--dur);
}
.search-close:hover { color: var(--text); }

/* Search highlight */
.search-highlight {
  background: rgba(154,117,48,0.2);
  border-radius: 2px;
  scroll-margin: 60px;
}
.search-highlight.current {
  background: rgba(154,117,48,0.45);
  box-shadow: 0 0 0 2px rgba(154,117,48,0.3);
}

/* Search toggle button in toolbar */
.search-toggle {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-dim);
  border-radius: 5px;
  color: var(--text-4);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.search-toggle:hover { color: var(--amber); border-color: var(--amber-dim); background: var(--amber-glow); }
.search-toggle.active { color: var(--amber); border-color: var(--amber-dim); background: var(--amber-glow); }

/* (pdf-sync-btn removed — legacy) */

/* =============================================================================
   ERROR TOAST
   ============================================================================= */

.error-toast[hidden] { display: none !important; }

.error-toast {
  position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 200;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1rem; background: var(--surface); border: 1px solid rgba(196,80,80,0.2);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.08);
  animation: toastIn 0.4s var(--ease-spring) both;
  max-width: 500px;
  overflow: hidden;
}

.error-toast.exiting {
  animation: toastOut 0.25s var(--ease-in) both;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.97); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  to { opacity: 0; transform: translateX(-50%) translateY(-10px) scale(0.97); }
}
.error-toast svg { width: 18px; height: 18px; color: var(--danger); flex-shrink: 0; }
.error-toast span { flex: 1; font-size: 0.82rem; color: var(--danger); }
.error-toast button { background: none; border: none; color: var(--text-3); font-size: 1.2rem; cursor: pointer; padding: 0; line-height: 1; }
.error-toast button:hover { color: var(--text); }

/* Auto-dismiss progress bar at bottom of toast */
.error-toast::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  background: var(--danger);
  opacity: 0.4;
  animation: errorCountdown 6s linear forwards;
}

@keyframes errorCountdown {
  from { width: 100%; }
  to { width: 0%; }
}


/* =============================================================================
   4-PANEL WORKSPACE
   ============================================================================= */

.workspace {
  display: flex;
  height: 100vh;
  width: 100%;
  background: var(--void);
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  border-right: 1px solid var(--border-dim);
}

.panel:last-child { border-right: none; }

.panel-divider {
  width: 5px;
  background: transparent;
  border-left: 1px solid var(--border-dim);
  cursor: col-resize;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  transition: all var(--dur);
}

.panel-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 28px;
  border-radius: 2px;
  background: var(--border);
  opacity: 0;
  transition: opacity var(--dur);
}

.panel-divider:hover::after,
.panel-divider.dragging::after {
  opacity: 1;
}

.panel-divider:hover {
  background: rgba(201,165,90,0.04);
  border-left-color: var(--amber-dim);
}

.panel-divider.dragging {
  background: rgba(201,165,90,0.08);
  border-left-color: var(--amber);
}

body.resizing {
  cursor: col-resize !important;
  user-select: none !important;
}

body.resizing .workspace {
  cursor: col-resize !important;
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--amber-dim);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
  outline: none;
}

/* Workspace entrance */
.workspace.entering .panel {
  animation: panelSlideIn 0.5s var(--ease) both;
}
.workspace.entering .panel:nth-child(1) { animation-delay: 0s; }
.workspace.entering .panel:nth-child(3) { animation-delay: 0.08s; }
.workspace.entering .panel:nth-child(5) { animation-delay: 0.16s; }
.workspace.entering .panel:nth-child(7) { animation-delay: 0.24s; }

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

/* Toolbar */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-dim);
  flex-shrink: 0;
  min-height: 38px;
  position: relative;
}

.panel-paper .panel-toolbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--sage), transparent 60%);
  opacity: 0.3;
}

.panel-analysis .panel-toolbar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--amber), transparent 60%);
  opacity: 0.3;
}

.toolbar-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
  flex-shrink: 0;
  margin-right: 0.5rem;
}

.panel-paper .toolbar-label { color: var(--sage); }
.panel-analysis .toolbar-label { color: var(--amber); }

.toolbar-badge {
  font-size: 0.72rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.toolbar-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.toolbar-tabs::-webkit-scrollbar { display: none; }

.tool-tab {
  padding: 0.35rem 0.7rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 4px 4px 0 0;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--text-3);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.tool-tab:hover { color: var(--text-2); background: rgba(154,117,48,0.04); }
.tool-tab:active { opacity: 0.8; }
.tool-tab.active { color: var(--amber); border-bottom-color: var(--amber); font-weight: 600; background: rgba(154,117,48,0.05); }

.rerun-btn {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--border-dim); border-radius: 5px;
  color: var(--text-4); cursor: pointer; flex-shrink: 0;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform 0.12s var(--ease-spring), opacity 0.3s var(--ease);
}
.rerun-btn svg { width: 13px; height: 13px; transition: transform 0.3s var(--ease); }
.rerun-btn:hover { color: var(--amber); border-color: var(--amber-dim); background: var(--amber-glow); }
.rerun-btn:hover svg { transform: rotate(-45deg); }
.rerun-btn:active { transform: scale(0.9); }
.rerun-btn.loading { pointer-events: none; opacity: 0.3; }
.rerun-btn.loading svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Per-formula LaTeX copy button */
.tab-pane .katex-display {
  position: relative;
}

.latex-copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  color: var(--text-4);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, border-color 0.2s, background 0.2s, transform 0.1s;
  z-index: 2;
}
.latex-copy-btn svg { width: 11px; height: 11px; flex-shrink: 0; }

.katex-display:hover .latex-copy-btn { opacity: 1; }
.latex-copy-btn:hover {
  color: var(--sage);
  border-color: rgba(106,158,142,0.3);
  background: rgba(106,158,142,0.06);
}
.latex-copy-btn:active { transform: scale(0.92); }

.latex-copy-btn.copied {
  opacity: 1;
  color: var(--sage);
  border-color: rgba(106,158,142,0.35);
  background: rgba(106,158,142,0.08);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.panel-scroll > .tab-pane:not(.tab-pane-ask) {
  flex: none;
}
.panel-scroll:has(.tab-pane-ask.active) {
  overflow-y: hidden;
}
.panel-scroll > .tab-pane-ask.active {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- Panel 1: Menu --- */
.panel-menu {
  width: var(--menu-w);
  min-width: 140px;
  max-width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.menu-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border-dim);
}

.menu-logo { width: 22px; height: 22px; color: var(--amber); }
.menu-title { font-family: var(--font-wordmark); font-size: 1.15rem; font-weight: 600; color: var(--amber); letter-spacing: 0.03em; }

.beta-pill {
  font-family: var(--font-mono);
  font-size: 0.52rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--amber);
  background: rgba(154,117,48,0.08);
  border: 1px solid rgba(154,117,48,0.18);
  border-radius: 3px;
  padding: 0.12rem 0.35rem;
  margin-left: auto;
  line-height: 1;
}

/* User auth area */
.user-area {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border-dim);
}
.user-area[data-state="signed-out"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem;
}
.signin-btn-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}
.signin-label {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--text-4);
  letter-spacing: 0.02em;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
}
.user-info[hidden] { display: none !important; }
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--amber-glow);
  box-shadow: 0 0 0 1px rgba(154,117,48,0.12);
  flex-shrink: 0;
  transition: border-color var(--dur) var(--ease);
}
.user-info:hover .user-avatar {
  border-color: rgba(154,117,48,0.25);
}
.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: 0.1rem;
}
.user-name {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.usage-count {
  font-size: 0.62rem;
  color: var(--text-4);
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
  line-height: 1;
}
.usage-count .usage-num {
  color: var(--amber);
  font-weight: 500;
}
.logout-btn {
  background: none;
  border: none;
  color: var(--text-4);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 5px;
  flex-shrink: 0;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
}
.logout-btn:hover {
  color: var(--rose);
  background: var(--rose-glow);
}
.user-actions {
  padding-top: 0.25rem;
}
.user-actions[hidden] { display: none !important; }
.delete-account-btn {
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.65rem;
  color: var(--text-4);
  cursor: pointer;
  padding: 0.15rem 0;
  transition: color var(--dur) var(--ease);
}
.delete-account-btn:hover {
  color: var(--rose);
}

/* Auth gate — covers input bar when signed out */
.auth-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  margin-bottom: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-4);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
}
.auth-gate svg { color: var(--amber-dim); flex-shrink: 0; }
.auth-gate[hidden] { display: none; }

.paper-loading-overlay {
  position: absolute; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem;
  background: rgba(28, 27, 24, 0.85); backdrop-filter: blur(4px);
  color: var(--amber); font-family: var(--font-body); font-size: 0.85rem; font-weight: 500;
}
.paper-loading-spinner {
  width: 28px; height: 28px;
  border: 2.5px solid rgba(201,165,90,0.2);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.menu-new-btn {
  display: flex; align-items: center; gap: 0.4rem;
  width: calc(100% - 1rem); margin: 0.5rem auto;
  padding: 0.45rem 0.7rem;
  background: var(--amber-glow); border: 1px solid rgba(201,165,90,0.15);
  border-radius: 6px; color: var(--amber);
  font-family: var(--font-body); font-size: 0.75rem; font-weight: 500;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 0.12s var(--ease-spring);
}
.menu-new-btn svg { width: 14px; height: 14px; transition: transform 0.2s var(--ease-spring); }
.menu-new-btn:hover { background: rgba(201,165,90,0.15); }
.menu-new-btn:hover svg { transform: rotate(90deg); }
.menu-new-btn:active { transform: scale(0.97); }
.menu-new-btn.analyzing-pulse {
  background: rgba(61,122,102,0.08);
  border-color: rgba(61,122,102,0.2);
  color: var(--sage);
  animation: analyzePulse 2s ease-in-out infinite;
}
.menu-new-btn.analyzing-pulse svg { animation: none; }
@keyframes analyzePulse {
  0%, 100% { background: rgba(61,122,102,0.06); }
  50% { background: rgba(61,122,102,0.14); }
}

/* Engine Badge — single Gemini indicator */
.engine-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border-dim);
}

.engine-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: #4285f4;
  opacity: 0.8;
}

.engine-name {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

.engine-model {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-4);
  letter-spacing: 0.02em;
  margin-left: auto;
}

.menu-section-label {
  padding: 0.6rem 0.85rem 0.3rem;
  font-size: 0.68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--text-4);
}

.paper-list {
  padding: 0 0.4rem 0.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.paper-group {
  margin-bottom: 2px;
}

.paper-item {
  display: flex; align-items: flex-start; gap: 0.35rem;
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: none; border: none; border-radius: 5px;
  text-align: left; cursor: pointer;
  font-family: var(--font-body); font-size: 0.72rem; color: var(--text-2);
  line-height: 1.4;
  transition: all var(--dur);
}
.paper-item:hover { background: var(--surface-2); }
.paper-item.active { background: var(--amber-glow); color: var(--amber); font-weight: 500; }

.paper-item-title {
  flex: 1; min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-chevron {
  flex-shrink: 0;
  width: 10px; height: 10px;
  color: var(--text-4);
  margin-top: 3px;
  opacity: 0.4;
  transition: transform 0.2s var(--ease);
}
.paper-group.expanded .paper-chevron { transform: rotate(0deg); }
.paper-group:not(.expanded) .paper-chevron { transform: rotate(-90deg); }

.section-nav {
  padding: 0 0 0 1.4rem;
  overflow: hidden;
  max-height: 300px;
  transition: max-height 0.25s var(--ease), opacity 0.2s var(--ease);
}
.section-nav.collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.nav-item {
  display: flex; align-items: center; gap: 0.5rem;
  width: 100%; padding: 0.3rem 0.5rem 0.3rem 1.1rem;
  background: none; border: none; border-radius: 5px;
  text-align: left; cursor: pointer;
  font-family: var(--font-body); font-size: 0.72rem; color: var(--text-3);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.12s var(--ease-spring);
}
.nav-item:hover { background: var(--surface-2); color: var(--text-2); }
.nav-item:active { transform: scale(0.97); }
.nav-item.active { background: var(--amber-glow); color: var(--text); }

.nav-num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-4);
  width: 16px;
  flex-shrink: 0;
}
.nav-item.active .nav-num { color: var(--amber); }

.nav-delete-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.35rem 0.55rem;
  margin-top: 0.25rem;
  border-top: 1px solid var(--border-dim);
  background: none;
  border-left: none; border-right: none; border-bottom: none;
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--text-4);
  cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.nav-delete-btn:hover {
  color: var(--rose);
  background: var(--rose-glow);
}

/* --- Panel 2: Paper Source (PDF Viewer) --- */
.panel-paper {
  flex: 4;
  min-width: 120px;
}

.pdf-viewer {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* PDF.js Custom Renderer */
.pdf-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  background: #3a3a3c;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.pdf-container[hidden] { display: none !important; }

.pdf-page {
  position: relative;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-shrink: 0;
}

.pdf-page canvas {
  display: block;
}

/* Text layer for selection */
.pdf-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 1;
  line-height: 1;
}
.pdf-text-layer span {
  position: absolute;
  white-space: pre;
  color: transparent !important;
  -webkit-text-fill-color: transparent !important;
  text-shadow: none !important;
  cursor: text;
}
.pdf-text-layer ::selection {
  background: rgba(59, 130, 246, 0.3);
  color: transparent;
}

/* Annotation overlay layer */
.pdf-annot-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.pdf-annotation {
  position: absolute;
  border: 1.5px solid;
  border-radius: 3px;
  pointer-events: auto;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.pdf-annotation:hover {
  box-shadow: 0 0 0 2px var(--ann-glow, rgba(59, 130, 246, 0.08));
  filter: brightness(0.95);
}

.pdf-annot-layer.debug-mode .pdf-annotation {
  border-style: dashed;
}

.pdf-annotation-debug {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.55);
}

.pdf-ann-debug-pill {
  position: absolute;
  left: 4px;
  top: 4px;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.01em;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 3px;
  padding: 2px 4px;
  pointer-events: none;
  z-index: 11;
}

/* Annotation tag — hidden by default, revealed on hover */
.pdf-ann-tag {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateX(100%) translateY(-50%) scale(0.85);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid;
  background: white;
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s var(--ease-spring), box-shadow 0.15s;
  z-index: 10;
}

/* Reveal tag when hovering the annotation box */
.pdf-annotation:hover .pdf-ann-tag {
  opacity: 1;
  transform: translateX(100%) translateY(-50%) scale(1);
  pointer-events: auto;
}

.pdf-ann-tag:hover {
  transform: translateX(100%) translateY(-50%) scale(1.06);
  box-shadow: 0 3px 12px rgba(0,0,0,0.18);
}

/* Tag type colors */
.pdf-ann-tag-equation { background: #eff6ff; }
.pdf-ann-tag-theorem  { background: #fef2f2; }
.pdf-ann-tag-section  { background: #fffbeb; }
.pdf-ann-tag-algorithm { background: #fefce8; }

/* ── User highlights ── */
.pdf-user-highlight {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 2px;
  mix-blend-mode: multiply;
  -webkit-mix-blend-mode: multiply;
  transition: opacity 0.18s ease, filter 0.18s ease;
  z-index: 3;
}
.pdf-user-highlight:hover {
  opacity: 0.75;
  filter: brightness(1.08);
}

/* Highlight color picker popup */
.pdf-hl-popup {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06),
              0 0 0 0.5px rgba(0,0,0,0.04);
  z-index: 50;
  animation: hlPopIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.pdf-hl-popup.below {
  transform: translate(-50%, 0%);
}
/* Arrow */
.pdf-hl-popup::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  transform: translateX(-50%) rotate(45deg);
  width: 8px;
  height: 8px;
  background: rgba(255,255,255,0.92);
  border-right: 1px solid rgba(0,0,0,0.08);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.pdf-hl-popup.below::after {
  bottom: auto;
  top: -5px;
  border-right: none;
  border-bottom: none;
  border-left: 1px solid rgba(0,0,0,0.08);
  border-top: 1px solid rgba(0,0,0,0.08);
}

@keyframes hlPopIn {
  from { opacity: 0; transform: translate(-50%, -100%) scale(0.85) translateY(4px); }
  to   { opacity: 1; transform: translate(-50%, -100%) scale(1) translateY(0); }
}
.pdf-hl-popup.below {
  animation-name: hlPopInBelow;
}
@keyframes hlPopInBelow {
  from { opacity: 0; transform: translate(-50%, 0%) scale(0.85) translateY(-4px); }
  to   { opacity: 1; transform: translate(-50%, 0%) scale(1) translateY(0); }
}

.pdf-hl-color-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1),
              border-color 0.12s ease,
              box-shadow 0.15s ease;
  padding: 0;
  flex-shrink: 0;
}
.pdf-hl-color-btn:hover {
  transform: scale(1.22);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
}
.pdf-hl-color-btn.active {
  border-color: var(--text-3);
  box-shadow: 0 0 0 2px rgba(0,0,0,0.08);
}

/* Separator + remove button inside edit popup */
.pdf-hl-popup-sep {
  width: 1px;
  height: 18px;
  background: rgba(0,0,0,0.1);
  margin: 0 3px;
  flex-shrink: 0;
}
.pdf-hl-remove-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-4);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pdf-hl-remove-btn:hover {
  background: rgba(220, 50, 50, 0.1);
  color: #c53030;
  transform: scale(1.1);
}

/* Toolbar highlight indicator */
.pdf-hl-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
  opacity: 0.5;
}
.pdf-hl-indicator:has(#highlight-count:not([hidden])) {
  opacity: 0.8;
}
.pdf-hl-count {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--amber);
  min-width: 12px;
  text-align: center;
}

/* PDF loading state */
.pdf-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  color: #999;
  font-family: var(--font-body);
  font-size: 0.85rem;
}

/* PDF controls in toolbar */
.pdf-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.pdf-ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s;
}
.pdf-ctrl-btn:hover { background: var(--surface-3); color: var(--text-2); }

.pdf-zoom-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-3);
  min-width: 32px;
  text-align: center;
}

.pdf-nav-sep {
  width: 1px;
  height: 14px;
  background: var(--border-dim);
  margin: 0 4px;
}

.pdf-page-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-3);
}

.pdf-page-input {
  width: 24px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border-dim);
  border-radius: 3px;
  padding: 2px 0;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.pdf-page-input:focus {
  border-color: var(--sage);
  background: var(--surface);
}
/* Hide number spinner arrows */
.pdf-page-input::-webkit-outer-spin-button,
.pdf-page-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.pdf-page-input[type="number"] {
  -moz-appearance: textfield;
}

.pdf-page-total {
  color: var(--text-4);
  white-space: nowrap;
}

.paper-placeholder {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 0.8rem;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      var(--border-dim) 27px,
      var(--border-dim) 28px
    );
  background-size: 100% 28px;
  background-position: 0 14px;
  opacity: 0.85;
}
.paper-placeholder[hidden] { display: none !important; }

.paper-placeholder::before {
  content: '';
  width: 48px;
  height: 60px;
  border: 1.5px dashed var(--border);
  border-radius: 4px;
  opacity: 0.4;
  background:
    linear-gradient(var(--border-dim) 1px, transparent 1px) 8px 12px / calc(100% - 16px) 8px no-repeat,
    linear-gradient(var(--border-dim) 1px, transparent 1px) 8px 22px / calc(100% - 24px) 8px no-repeat,
    linear-gradient(var(--border-dim) 1px, transparent 1px) 8px 32px / calc(100% - 16px) 8px no-repeat;
}

.paper-placeholder p {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-4);
  font-size: 0.92rem;
}

/* --- Page Badges on analysis headings --- */
.page-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: 0.5rem;
  padding: 0.15rem 0.5rem;
  background: color-mix(in srgb, var(--badge-color, var(--text-3)) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--badge-color, var(--text-3)) 18%, transparent);
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--badge-color, var(--text-3));
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.18s, transform 0.12s, border-color 0.18s;
  line-height: 1.4;
  white-space: nowrap;
  flex-shrink: 0;
}
.page-badge svg {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  opacity: 0.7;
}

.page-badge:hover {
  background: color-mix(in srgb, var(--badge-color, var(--text-3)) 18%, transparent);
  border-color: color-mix(in srgb, var(--badge-color, var(--text-3)) 35%, transparent);
  transform: scale(1.05);
}
.page-badge:hover svg {
  opacity: 1;
}

/* --- Flash highlights for bidirectional sync --- */

/* Flash on PDF when jumping from analysis */
.pdf-flash {
  position: absolute;
  background: rgba(59, 130, 246, 0.15);
  border: 2px solid rgba(59, 130, 246, 0.4);
  border-radius: 4px;
  pointer-events: none;
  z-index: 20;
  animation: pdfFlash 1.2s ease-out forwards;
}

@keyframes pdfFlash {
  0%   { opacity: 1; }
  60%  { opacity: 0.8; }
  100% { opacity: 0; }
}

/* Flash on analysis content when jumping from PDF */
.flash-highlight {
  position: relative;
  animation: analysisFlash 1.5s ease-out;
}

@keyframes analysisFlash {
  0%   { background-color: rgba(154, 117, 48, 0.18); }
  30%  { background-color: rgba(154, 117, 48, 0.12); }
  100% { background-color: transparent; }
}


/* --- Panel 2: Analysis (merged) --- */
.panel-analysis {
  flex: 5;
  min-width: 300px;
}

.tab-pane {
  display: none;
  padding: 2rem 2.2rem 4rem;
  max-width: 960px;
}

.tab-pane.active {
  display: block;
  animation: paneIn 0.3s var(--ease-out) both;
}

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

.exp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--text-4);
  font-size: 0.88rem;
  gap: 0.6rem;
}

/* Softer style for formulas with no explanation (not an error) */
.exp-empty.exp-empty-no-explanation {
  min-height: 80px;
  font-size: 0.82rem;
  opacity: 0.7;
}

.exp-empty::before {
  content: '';
  width: 36px;
  height: 36px;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  opacity: 0.35;
  animation: emptyPulse 3s ease-in-out infinite;
}

.exp-empty.exp-empty-no-explanation::before {
  width: 24px;
  height: 24px;
  animation: none;
  opacity: 0.25;
}

@keyframes emptyPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.96); }
  50% { opacity: 0.45; transform: scale(1); border-color: var(--amber-dim); }
}

/* Loading shimmer for regenerating state */
.exp-empty.loading::before {
  animation: shimmerPulse 1.5s ease-in-out infinite;
}

@keyframes shimmerPulse {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.6; border-color: var(--amber-dim); }
}

/* =============================================================================
   RENDERED MARKDOWN / LATEX — Editorial reading experience
   Principle: visual hierarchy IS readability. Every section breathes.
   ============================================================================= */

.tab-pane, .rendered-content {
  font-family: var(--font-body);
  font-size: 0.94rem;
  line-height: 1.76;
  color: var(--text);
  letter-spacing: 0.005em;
}

/* ─── SECTION CARDS — wraps each h2 section for visual separation ─── */

.tab-pane .section-card {
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-radius: 10px;
  padding: 1.6rem 1.8rem 1.4rem;
  margin-bottom: 1.2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
  animation: sectionCardIn 0.35s ease-out both;
}

.tab-pane .section-card:first-child { margin-top: 0; }

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

/* Stagger card entrance */
.tab-pane .section-card:nth-child(2) { animation-delay: 0.05s; }
.tab-pane .section-card:nth-child(3) { animation-delay: 0.1s; }
.tab-pane .section-card:nth-child(4) { animation-delay: 0.15s; }
.tab-pane .section-card:nth-child(5) { animation-delay: 0.2s; }
.tab-pane .section-card:nth-child(6) { animation-delay: 0.25s; }
.tab-pane .section-card:nth-child(n+7) { animation-delay: 0.3s; }

/* ─── HEADINGS ─── */

.tab-pane h1, .tab-pane h2, .tab-pane h3, .tab-pane h4 {
  font-family: var(--font-display);
  color: var(--text);
  line-height: 1.3;
}

/* H1 — page-level, rarely used */
.tab-pane h1 {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* H2 — MAJOR section headers — bold, colored, with left accent */
.tab-pane h2 {
  font-size: 1.12rem;
  font-weight: 650;
  margin: 0 0 1rem;
  padding: 0 0 0.6rem;
  color: var(--text);
  border-bottom: 2px solid var(--amber-dim);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* When h2 is NOT in a section-card, restore top spacing */
.tab-pane h2:not(.section-card h2) {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border-dim);
  border-bottom: none;
  padding-bottom: 0;
}
.tab-pane h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }

/* H2 section number badge */
.tab-pane h2 .section-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--amber);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: var(--font-mono);
  flex-shrink: 0;
}

/* H3 — subsection headers — pill-style background */
.tab-pane h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.8rem 0 0.6rem;
  padding: 0.4rem 0.75rem;
  color: var(--text);
  background: rgba(154,117,48,0.04);
  border-left: 3px solid var(--amber-dim);
  border-radius: 0 6px 6px 0;
}

.tab-pane .section-card h3:first-child,
.tab-pane h3:first-child { margin-top: 0; }

/* Equation section headings — prominent separator between equations */
.tab-pane h3.eq-heading {
  font-size: 1.05rem;
  font-weight: 550;
  color: var(--text);
  margin-top: 2.2rem;
  padding: 0.6rem 0.85rem;
  background: rgba(61,122,102,0.04);
  border-left: 3px solid var(--sage);
  border-top: 1px solid var(--border-dim);
}
.tab-pane h3.eq-heading:first-child,
.tab-pane h3.eq-heading:first-of-type {
  border-top: none;
  margin-top: 0;
}

/* H4 — labeled subsections — visible inline tag */
.tab-pane h4 {
  font-size: 0.78rem;
  font-weight: 700;
  margin: 1.5rem 0 0.4rem;
  padding: 0.25rem 0.6rem;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--void);
  border: 1px solid var(--border-dim);
  border-radius: 4px;
  display: inline-block;
}

/* Reset h4 for adjacent content */
.tab-pane h4 + p,
.tab-pane h4 + ul,
.tab-pane h4 + ol,
.tab-pane h4 + blockquote { margin-top: 0.5rem; }

.tab-pane h1:first-child { margin-top: 0; }
.tab-pane h2:first-child { margin-top: 0; }
.tab-pane h3:first-child { margin-top: 0; }

/* ─── PARAGRAPHS ─── */

.tab-pane p {
  margin: 0 0 1.1rem;
}

/* Bold labels at start of paragraph — only .label-strong gets accent treatment */
.tab-pane p > strong.label-strong {
  color: var(--amber-bright);
  font-size: 0.82em;
  letter-spacing: 0.02em;
  font-weight: 700;
}

/* ─── LISTS ─── */

.tab-pane ul, .tab-pane ol {
  margin: 0 0 1.2rem;
  padding-left: 1.4rem;
}

.tab-pane ol { list-style: none; counter-reset: ol-counter; padding-left: 0; }

.tab-pane ul > li {
  margin-bottom: 0.55rem;
  position: relative;
  list-style: none;
  padding-left: 1.1rem;
  line-height: 1.7;
}

.tab-pane ul > li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.6em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--amber);
}

/* Numbered list — step-style with mono numbers */
.tab-pane ol > li {
  counter-increment: ol-counter;
  margin-bottom: 0.6rem;
  padding: 0.15rem 0 0.15rem 2.2rem;
  position: relative;
  background: none;
  border: none;
  border-radius: 0;
  line-height: 1.7;
}

.tab-pane ol > li::before {
  content: counter(ol-counter);
  position: absolute;
  left: 0;
  top: 0.15rem;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(154,117,48,0.08);
  color: var(--amber-bright);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Card treatment ONLY in algorithm flowcharts */
.algo-flowchart ol > li {
  padding: 0.55rem 0.8rem 0.55rem 2.6rem;
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-radius: 8px;
  margin-bottom: 0.65rem;
}

.algo-flowchart ol > li::before {
  left: 0.7rem;
  top: 0.55rem;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--amber);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  content: counter(ol-counter);
}

/* Nested lists — minimal */
.tab-pane li ul, .tab-pane li ol { margin-top: 0.4rem; margin-bottom: 0.1rem; }
.tab-pane li li { background: none; border: none; padding: 0.1rem 0 0.1rem 1rem; margin-bottom: 0.15rem; }
.tab-pane ol > li li::before { display: none; }
.tab-pane ul > li li::before { width: 3px; height: 3px; background: var(--text-4); top: 0.7em; }

/* ─── INLINE ─── */

.tab-pane strong { color: var(--text); font-weight: 650; }
.tab-pane em { color: var(--text-2); }

/* ─── BLOCKQUOTES ─── */

.tab-pane blockquote {
  border-left: 3px solid var(--amber-dim);
  padding: 0.9rem 1.3rem;
  margin: 1.4rem 0;
  background: rgba(154,117,48,0.025);
  border-radius: 0 8px 8px 0;
  color: var(--text-2);
  font-style: italic;
  font-size: 0.92em;
  line-height: 1.7;
}

/* Stepped walkthrough blockquotes (detected by Step 1:, Step 2: pattern) */
.tab-pane blockquote.walkthrough-steps {
  border-left: 3px solid var(--sage);
  background: rgba(61,122,102,0.03);
  padding: 1rem 1.3rem;
  font-style: normal;
  color: var(--text);
}

.tab-pane blockquote.walkthrough-steps strong {
  color: var(--sage);
  font-weight: 700;
}

/* KEY FORMULA — prominent callout */
.tab-pane blockquote.key-formula {
  border-left: 3px solid var(--sage);
  background: rgba(61,122,102,0.05);
  padding: 0.75rem 1.1rem;
  font-style: normal;
  font-weight: 500;
  color: var(--text);
}

.tab-pane blockquote.key-formula strong:first-child {
  color: var(--sage);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,122,102,0.1);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: middle;
}

/* KEY IDEA — for future research directions */
.tab-pane blockquote.key-idea {
  border-left: 3px solid var(--blue);
  background: rgba(61,106,142,0.04);
  padding: 0.75rem 1.1rem;
  font-style: normal;
  font-weight: 500;
  color: var(--text);
}

.tab-pane blockquote.key-idea strong:first-child {
  color: var(--blue);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,106,142,0.1);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: middle;
}

/* ─── REAL-WORLD ANALOGY BOX ─── */

.tab-pane p.analogy-box {
  border-left: 3px solid var(--mauve);
  background: rgba(139,90,110,0.045);
  padding: 0.85rem 1.2rem;
  margin: 1.3rem 0;
  border-radius: 0 8px 8px 0;
  font-style: normal;
  line-height: 1.7;
  color: var(--text-2);
}

.tab-pane p.analogy-box > strong:first-child {
  color: var(--mauve);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(139,90,110,0.1);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  margin-right: 0.4rem;
  vertical-align: middle;
}

/* ─── UNIFIED FORMULA JSON SECTIONS (Math & Formulas tab) ─── */
.formula-unified-section {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border-dim);
}
.formula-unified-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.formula-unified-section h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
}
.formula-latex-block {
  margin: 0.75rem 0 1rem;
  padding: 0.5rem 0;
}
/* Fallback styling when KaTeX render fails — show raw LaTeX readably */
.formula-latex-block .formula-fallback {
  display: block;
  padding: 0.8rem 1rem;
  background: var(--void);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--amber);
  border-radius: 0 6px 6px 0;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-3);
  overflow-x: auto;
  word-break: break-word;
}
.formula-unified-section p {
  margin: 0 0 1rem;
  line-height: 1.72;
}

/* ─── FUTURE TAB — traced examples ─── */

#pane-future blockquote:not(.key-idea):not(.key-formula):not(.algo-flow) {
  border-left: 3px solid var(--sage);
  background: rgba(61,122,102,0.03);
  border-radius: 0 8px 8px 0;
  padding: 0.9rem 1.2rem;
  margin: 1rem 0;
  font-style: normal;
  color: var(--text);
}

/* ─── SUMMARY TAB — Background / Problem / Solution card ─── */
#pane-summary .bps-card {
  border-left: 3px solid var(--blue);
  background: rgba(61,106,142,0.035);
  border-radius: 0 8px 8px 0;
  padding: 0.8rem 1.05rem 0.85rem;
  margin: 1rem 0 1.25rem;
}

#pane-summary .bps-head {
  margin: 0 0 0.5rem;
  color: var(--text);
}

#pane-summary .bps-head > strong:first-child {
  color: var(--blue);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,106,142,0.1);
  padding: 0.12rem 0.5rem;
  border-radius: 3px;
}

#pane-summary .bps-list {
  margin: 0;
  padding-left: 0.1rem;
}

#pane-summary .bps-list > li {
  margin-bottom: 0.5rem;
  padding-left: 1rem;
}

#pane-summary .bps-list > li:last-child {
  margin-bottom: 0;
}

#pane-summary .bps-list > li::before {
  background: var(--blue);
}

#pane-summary .bps-list > li > strong:first-child {
  color: var(--blue);
}

/* ─── SUMMARY TAB — Core Intuition card ─── */
#pane-summary .core-intuition-card {
  border-left: 3px solid var(--amber);
  background: rgba(154,117,48,0.04);
  border-radius: 0 8px 8px 0;
  padding: 0.8rem 1.05rem 0.85rem;
  margin: 1rem 0 1.25rem;
}

#pane-summary .core-intuition-head {
  margin: 0 0 0.55rem;
  color: var(--text);
}

#pane-summary .core-intuition-head > strong:first-child {
  color: var(--amber-bright);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(154,117,48,0.11);
  padding: 0.12rem 0.5rem;
  border-radius: 3px;
}

#pane-summary .core-intuition-card p:last-child,
#pane-summary .core-intuition-card ul:last-child,
#pane-summary .core-intuition-card ol:last-child {
  margin-bottom: 0;
}

/* ─── LINKS ─── */

.tab-pane a { color: var(--amber); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: rgba(154,117,48,0.3); }
.tab-pane a:hover { text-decoration-color: var(--amber); }

/* ─── HORIZONTAL RULES ─── */

.tab-pane hr {
  border: none;
  height: 1px;
  margin: 2.2rem 0;
  background: var(--border-dim);
}

/* ─── CODE ─── */

.tab-pane code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--void);
  padding: 0.12em 0.4em;
  border-radius: 3px;
  color: var(--sage);
  border: 1px solid var(--border-dim);
}

.tab-pane pre {
  background: #2a2520;
  border-radius: 8px;
  border: 1px solid rgba(154,117,48,0.15);
  padding: 1.1rem 1.3rem;
  overflow-x: auto;
  margin: 1.3rem 0;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #e8e1d6;
}

.tab-pane pre code {
  background: none;
  padding: 0;
  border: none;
  color: #e8e1d6;
  font-size: 0.82rem;
  display: block;
  letter-spacing: 0.01em;
}

/* ─── TABLES ─── */

.tab-pane table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.3rem 0;
  font-size: 0.84rem;
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  overflow: hidden;
}

.tab-pane th {
  padding: 0.6rem 0.85rem;
  text-align: left;
  font-weight: 700;
  color: var(--amber-bright);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  background: rgba(154,117,48,0.03);
}

.tab-pane td {
  padding: 0.55rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border-dim);
}

.tab-pane tr:last-child td { border-bottom: none; }
.tab-pane tbody tr:nth-child(even) td { background: rgba(154,117,48,0.015); }
.tab-pane tbody tr:hover td { background: rgba(154,117,48,0.04); }

/* ─── KATEX DISPLAY MATH ─── */

.tab-pane .katex-display {
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  background: var(--void);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--amber);
  border-radius: 0 6px 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Merge consecutive display-math blocks into one visual card */
.tab-pane .katex-display + .katex-display {
  margin-top: -1.5rem;          /* collapse the gap */
  border-top: none;             /* remove doubled border */
  border-radius: 0 0 6px 0;    /* only round bottom */
  padding-top: 0.3rem;
}
.tab-pane .katex-display:has(+ .katex-display) {
  margin-bottom: 0;
  border-bottom: none;
  border-radius: 0;
  padding-bottom: 0.3rem;
}

.tab-pane .katex {
  font-size: 1.05em;
  color: var(--text);
}

/* ─── IMAGES ─── */

.tab-pane img {
  max-width: 100%;
  border-radius: 6px;
  margin: 1rem 0;
}

/* =============================================================================
   ALGORITHM FLOWCHART — Vertical timeline with typed nodes
   New DOM structure (built by JS):
     .algo-flowchart
       blockquote.algo-flow.algo-flow-start  → .af-terminal-text
       blockquote.algo-flow.algo-flow-step   → .af-card > .af-header + .af-body
       blockquote.algo-flow.algo-flow-end    → .af-terminal-text
   ============================================================================= */

/* ─── WRAPPER ─── */

.algo-flowchart {
  position: relative;
  margin: 1.8rem 0 2.2rem;
  padding: 0 0 0 3rem;
}

/* Continuous vertical rail */
.algo-flowchart::before {
  content: '';
  position: absolute;
  left: 0.9rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}

/* ─── BASE NODE ─── */

.tab-pane blockquote.algo-flow {
  font-style: normal;
  border-left: none;
  background: none;
  padding: 0;
  margin: 0 0 0.6rem;
  border-radius: 0;
  position: relative;
  color: var(--text);
}

/* Rail dot — default (blue, step) */
.tab-pane blockquote.algo-flow::before {
  content: '';
  position: absolute;
  left: -2.1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--surface);
  border: 2.5px solid var(--blue);
  z-index: 2;
}

/* Horizontal arm from dot to card */
.tab-pane blockquote.algo-flow::after {
  content: '';
  position: absolute;
  left: -1.4rem;
  top: 50%;
  width: 1.1rem;
  height: 2px;
  background: var(--border);
  z-index: 1;
}

/* ─── TERMINAL — START / END ─── */

.tab-pane blockquote.algo-flow-start,
.tab-pane blockquote.algo-flow-end {
  margin-bottom: 0.8rem;
  text-align: center;
}

.tab-pane blockquote.algo-flow-end {
  margin-bottom: 0;
  margin-top: 0.2rem;
}

.tab-pane blockquote.algo-flow-start::before,
.tab-pane blockquote.algo-flow-end::before {
  width: 14px;
  height: 14px;
  left: -2.15rem;
  border: none;
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(61,122,102,0.12);
}

.tab-pane blockquote.algo-flow-start::after,
.tab-pane blockquote.algo-flow-end::after {
  background: rgba(61,122,102,0.25);
}

.tab-pane blockquote.algo-flow-start > p,
.tab-pane blockquote.algo-flow-end > p {
  margin: 0;
  background: none;
  border: none;
  padding: 0;
}

.af-terminal-text {
  display: inline-block;
  background: rgba(61,122,102,0.06);
  border: 1.5px solid rgba(61,122,102,0.2);
  border-radius: 100px;
  padding: 0.35rem 1.6rem;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--sage);
}

/* ─── CARD (af-card) — the rebuilt inner structure ─── */

.af-card {
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.tab-pane blockquote.algo-flow:hover .af-card {
  border-color: var(--border);
  box-shadow: 0 2px 12px rgba(0,0,0,0.045);
}

/* Header row: number badge + icon + label */
.af-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border-dim);
  background: var(--surface-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Step number badge */
.af-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: #fff;
  flex-shrink: 0;
}

/* Type icon */
.af-icon {
  font-size: 0.7rem;
  line-height: 1;
  flex-shrink: 0;
}

/* Label text */
.af-label {
  flex: 1;
  min-width: 0;
  text-transform: none;
}

/* Body / description */
.af-body {
  padding: 0.6rem 1rem 0.7rem;
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-2);
  text-transform: none;
}

/* ─── STEP — blue theme ─── */

.af-type-step { border-left: 3.5px solid var(--blue); }

.af-type-step .af-header {
  background: rgba(61,106,142,0.04);
  color: var(--blue);
}

.af-type-step .af-num {
  background: var(--blue);
}

.af-type-step .af-icon {
  color: var(--blue);
  opacity: 0.5;
}

.tab-pane blockquote.algo-flow-step::before {
  border-color: var(--blue);
}

/* ─── DECISION — amber theme ─── */

.af-type-decision { border-left: 3.5px solid var(--amber); }

.af-type-decision .af-header {
  background: rgba(154,117,48,0.05);
  color: var(--amber-bright);
}

.af-type-decision .af-icon {
  color: var(--amber);
}

.tab-pane blockquote.algo-flow-decision::before {
  border-color: var(--amber);
  border-radius: 2px;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
}

.tab-pane blockquote.algo-flow-decision::after {
  background: rgba(154,117,48,0.3);
}

/* ─── LOOP — rose theme ─── */

.af-type-loop { border-left: 3.5px solid var(--rose); }

.af-type-loop .af-header {
  background: rgba(158,74,74,0.04);
  color: var(--rose);
}

.af-type-loop .af-icon {
  color: var(--rose);
}

.tab-pane blockquote.algo-flow-loop::before {
  border-color: var(--rose);
}

.tab-pane blockquote.algo-flow-loop::after {
  background: rgba(158,74,74,0.3);
}

/* ─── STANDALONE fallback ─── */

blockquote.algo-flow:not(.algo-flowchart blockquote) {
  padding-left: 1.2rem;
  border-left: 2px solid var(--border);
}

/* ─── TRACED EXAMPLE blockquotes in algo tab ─── */

#pane-algorithms blockquote:not(.algo-flow):not(.key-formula) {
  border-left: 3px solid var(--blue);
  background: rgba(61,106,142,0.03);
  border-radius: 0 8px 8px 0;
  padding: 0.9rem 1.2rem;
  margin: 1rem 0;
  font-style: normal;
  color: var(--text);
}

#pane-algorithms blockquote:not(.algo-flow):not(.key-formula) strong:first-child {
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,106,142,0.08);
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  margin-right: 0.4rem;
}

/* ─── PSEUDOCODE in algo tab ─── */

#pane-algorithms pre {
  background: #1e1c19;
  border: 1px solid rgba(154,117,48,0.12);
  border-left: 3px solid var(--amber);
  border-radius: 2px 8px 8px 2px;
  padding: 1.1rem 1.3rem;
  font-size: 0.82rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: #ddd6cb;
}

#pane-algorithms pre code {
  color: #ddd6cb;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* =============================================================================
   PREREQUISITES TAB — Formula-Forward Editorial Design
   ============================================================================= */

/* ─── TIER HEADERS (Required / Helpful / Optional) ─── */

#pane-prerequisites h2.prereq-tier {
  border-top: none;
  padding: 0.4rem 1rem 0.4rem 0.75rem;
  margin: 2.5rem 0 1rem;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 5px;
  display: inline-block;
  width: auto;
}
#pane-prerequisites h2.prereq-tier:first-child { margin-top: 0; }
#pane-prerequisites h2.prereq-tier-required {
  background: rgba(61,122,102,0.09);
  color: var(--sage);
  border-left: 3px solid var(--sage);
}
#pane-prerequisites h2.prereq-tier-helpful {
  background: rgba(61,106,142,0.08);
  color: var(--blue);
  border-left: 3px solid var(--blue);
}
#pane-prerequisites h2.prereq-tier-optional {
  background: rgba(139,90,110,0.08);
  color: var(--mauve);
  border-left: 3px solid var(--mauve);
}
#pane-prerequisites h2.prereq-tier-reading {
  background: var(--amber-glow);
  color: var(--amber);
  border-left: 3px solid var(--amber);
  margin-top: 3rem;
}

/* ─── CONCEPT CARDS ─── */

#pane-prerequisites .prereq-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-left: 3.5px solid var(--sage);
  border-radius: 2px 10px 10px 2px;
  padding: 1.5rem 1.7rem 1.3rem;
  margin-bottom: 1.3rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
  transition: box-shadow 0.3s var(--ease), border-color 0.3s var(--ease);
}
#pane-prerequisites .prereq-card:hover {
  box-shadow: 0 3px 14px rgba(0,0,0,0.06);
}
/* Tier-colored left accent */
#pane-prerequisites .prereq-card[data-tier="required"] { border-left-color: var(--sage); }
#pane-prerequisites .prereq-card[data-tier="helpful"]  { border-left-color: var(--blue); }
#pane-prerequisites .prereq-card[data-tier="optional"] { border-left-color: var(--mauve); }

/* Concept name (h3) */
#pane-prerequisites .prereq-card > h3 {
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.2rem;
  padding: 0;
  border-bottom: none;
}

/* ─── SUB-SECTION HEADINGS (h4) ─── */

#pane-prerequisites .prereq-card h4 {
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 1.5rem 0 0.45rem;
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  display: inline-block;
  color: var(--text-3);
  background: var(--surface-2);
  border-left: 2.5px solid var(--border);
}

/* "In one sentence" — first thing in card, acts as subtitle */
#pane-prerequisites h4.prereq-sentence {
  display: none; /* hide heading — content becomes the subtitle */
}
#pane-prerequisites h4.prereq-sentence + p {
  color: var(--text-3);
  font-size: 0.88em;
  font-style: italic;
  margin: 0 0 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-dim);
  line-height: 1.6;
}

/* THE CORE FORMULAS — hero section with prominent styling */
#pane-prerequisites h4.prereq-formulas {
  color: var(--amber);
  background: rgba(154,117,48,0.06);
  border-left-color: var(--amber);
  font-size: 0.72rem;
  letter-spacing: 0.09em;
}

/* Formula zone — the wrapped content under "core formulas" h4 */
#pane-prerequisites .prereq-formula-zone {
  background: linear-gradient(135deg, rgba(154,117,48,0.02) 0%, rgba(61,122,102,0.015) 100%);
  border: 1px solid rgba(154,117,48,0.1);
  border-radius: 8px;
  padding: 1rem 1.3rem;
  margin: 0.4rem 0 1.2rem;
}

/* Display math inside formula zone — extra prominence */
#pane-prerequisites .prereq-formula-zone .katex-display {
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-left: 3px solid var(--amber);
  border-radius: 2px 8px 8px 2px;
  padding: 0.8rem 1.2rem;
  margin: 0.8rem 0;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

/* "Reading this formula" walkthrough — inside formula zone */
#pane-prerequisites .prereq-formula-zone blockquote.prereq-formula-reading,
#pane-prerequisites .prereq-card blockquote.prereq-formula-reading {
  border-left: 3px solid var(--sage);
  background: rgba(61,122,102,0.03);
  border-radius: 0 7px 7px 0;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0 0.8rem;
  font-style: normal;
  font-size: 0.9em;
  color: var(--text-2);
  line-height: 1.7;
}
#pane-prerequisites blockquote.prereq-formula-reading strong:first-child {
  color: var(--sage);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,122,102,0.1);
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.35rem;
}

/* Intuition & explanation */
#pane-prerequisites h4.prereq-intuition {
  color: var(--sage);
  background: var(--sage-glow);
  border-left-color: var(--sage);
}

/* What it is (legacy compat) */
#pane-prerequisites h4.prereq-whatis {
  color: var(--blue);
  background: var(--blue-glow);
  border-left-color: var(--blue);
}

/* Worked example */
#pane-prerequisites h4.prereq-example {
  color: var(--mauve);
  background: var(--mauve-glow);
  border-left-color: var(--mauve);
}

/* Connection to the paper */
#pane-prerequisites h4.prereq-connects {
  color: var(--amber-bright);
  background: var(--amber-glow);
  border-left-color: var(--amber-bright);
}

/* Recap */
#pane-prerequisites h4.prereq-recap {
  color: var(--text-3);
  background: var(--surface-2);
  border-left-color: var(--text-4);
}

/* Legacy compat */
#pane-prerequisites h4.prereq-mistakes {
  color: var(--danger);
  background: rgba(196,80,80,0.06);
  border-left-color: var(--danger);
}
#pane-prerequisites h4.prereq-check {
  color: var(--sage);
  background: rgba(61,122,102,0.06);
  border-left-color: var(--sage);
}
#pane-prerequisites h4.prereq-bridge {
  color: var(--blue);
  background: var(--blue-glow);
  border-left-color: var(--blue);
}
#pane-prerequisites h4.prereq-why {
  color: var(--amber);
  background: var(--amber-glow);
  border-left-color: var(--amber);
}

/* ─── SYMBOL TABLES ─── */

#pane-prerequisites .prereq-symbol-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0 1rem;
  font-size: 0.88em;
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  overflow: hidden;
}
#pane-prerequisites .prereq-symbol-table th {
  background: var(--surface-2);
  color: var(--text-3);
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.4rem 0.8rem;
  text-align: left;
  border-bottom: 1.5px solid var(--border);
}
#pane-prerequisites .prereq-symbol-table td {
  padding: 0.4rem 0.8rem;
  border-bottom: 1px solid var(--border-dim);
  vertical-align: top;
}
#pane-prerequisites .prereq-symbol-table td:first-child {
  font-family: var(--font-mono);
  color: var(--amber);
  white-space: nowrap;
  width: 1%;
}
#pane-prerequisites .prereq-symbol-table tr:last-child td {
  border-bottom: none;
}
#pane-prerequisites .prereq-symbol-table tr:hover td {
  background: rgba(154,117,48,0.03);
}

/* ─── SPECIAL CALLOUT PARAGRAPHS ─── */

#pane-prerequisites p.prereq-everyday {
  background: rgba(61,122,102,0.035);
  border: 1px solid rgba(61,122,102,0.1);
  border-left: 3px solid var(--sage);
  border-radius: 0 7px 7px 0;
  padding: 0.75rem 1rem;
  margin: 0.6rem 0 0.8rem;
}
#pane-prerequisites p.prereq-everyday > strong:first-child {
  color: var(--sage);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,122,102,0.1);
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.35rem;
}

#pane-prerequisites p.prereq-idea-math {
  background: rgba(61,106,142,0.03);
  border: 1px solid rgba(61,106,142,0.1);
  border-left: 3px solid var(--blue);
  border-radius: 0 7px 7px 0;
  padding: 0.75rem 1rem;
  margin: 0.4rem 0 0.6rem;
}
#pane-prerequisites p.prereq-idea-math > strong:first-child {
  color: var(--blue);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: rgba(61,106,142,0.1);
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.35rem;
}

#pane-prerequisites p.prereq-hard-at-first {
  background: rgba(154,117,48,0.035);
  border: 1px solid rgba(154,117,48,0.1);
  border-left: 3px solid var(--amber-dim);
  border-radius: 0 7px 7px 0;
  padding: 0.75rem 1rem;
  margin: 0.6rem 0 0.8rem;
}
#pane-prerequisites p.prereq-hard-at-first > strong:first-child {
  color: var(--amber);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-block;
  background: var(--amber-glow);
  padding: 0.08rem 0.4rem;
  border-radius: 3px;
  margin-right: 0.35rem;
}

#pane-prerequisites p.prereq-progression-label {
  color: var(--text-3);
  font-weight: 600;
  margin-bottom: 0.3rem;
}

/* ─── DISPLAY MATH (outside formula zone) ─── */

#pane-prerequisites .prereq-card > .katex-display,
#pane-prerequisites .prereq-card > p > .katex-display {
  background: var(--surface-2);
  border-left: 3px solid var(--amber-dim);
  border-radius: 0 6px 6px 0;
  padding: 0.8rem 1.1rem;
  margin: 0.8rem 0;
  overflow-x: auto;
}

/* ─── BLOCKQUOTES (worked examples) ─── */

#pane-prerequisites .prereq-card blockquote {
  border-left: 3px solid var(--mauve);
  background: rgba(139,90,110,0.025);
  border-radius: 0 7px 7px 0;
  padding: 0.8rem 1.1rem;
  font-style: normal;
  font-size: 0.9em;
  color: var(--text-2);
  margin: 0.6rem 0;
}
#pane-prerequisites .prereq-card blockquote strong:first-child {
  color: var(--mauve);
  font-size: 0.88em;
}
#pane-prerequisites .prereq-card blockquote em {
  color: var(--text);
}
/* Result line in examples */
#pane-prerequisites .prereq-card blockquote p.prereq-result {
  background: rgba(61,122,102,0.05);
  border: 1px solid rgba(61,122,102,0.1);
  border-radius: 5px;
  padding: 0.5rem 0.8rem;
  margin-top: 0.5rem;
}

/* ─── ORDERED LISTS (numbered progressions) ─── */

#pane-prerequisites .prereq-card ol {
  counter-reset: prereq-step;
}
#pane-prerequisites .prereq-card ol > li {
  counter-increment: prereq-step;
  position: relative;
  padding-left: 2rem;
  margin-bottom: 0.7rem;
}
#pane-prerequisites .prereq-card ol > li::before {
  content: counter(prereq-step);
  position: absolute;
  left: 0;
  top: 0.05em;
  width: 1.4rem;
  height: 1.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
}

/* ─── UNORDERED LISTS ─── */

#pane-prerequisites .prereq-card ul > li::before {
  background: var(--sage);
}

/* ─── RECAP section ─── */

#pane-prerequisites h4.prereq-recap ~ ul,
#pane-prerequisites h4.prereq-recap ~ p {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 0.55rem 0.9rem;
  margin: 0.25rem 0 0.6rem;
  font-size: 0.87em;
  border: 1px solid var(--border-dim);
}
#pane-prerequisites h4.prereq-recap ~ ul {
  padding: 0.55rem 0.9rem 0.55rem 2rem;
}
#pane-prerequisites h4.prereq-recap ~ ul > li::before {
  background: var(--text-4);
}

/* ─── Entrance animation ─── */

@keyframes prereqCardIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
#pane-prerequisites .prereq-card {
  animation: prereqCardIn 0.35s var(--ease-out) both;
}
#pane-prerequisites .prereq-card:nth-child(2) { animation-delay: 0.04s; }
#pane-prerequisites .prereq-card:nth-child(3) { animation-delay: 0.08s; }
#pane-prerequisites .prereq-card:nth-child(4) { animation-delay: 0.12s; }
#pane-prerequisites .prereq-card:nth-child(5) { animation-delay: 0.16s; }
#pane-prerequisites .prereq-card:nth-child(6) { animation-delay: 0.2s; }

/* =============================================================================
   SCROLLBARS
   ============================================================================= */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-4); }

::selection { background: rgba(154,117,48,0.15); color: var(--text); }

/* =============================================================================
   RESPONSIVE — collapse to stacked on small screens
   ============================================================================= */

@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .panel {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    border-right: none;
    border-bottom: 1px solid var(--border-dim);
  }

  .panel-menu { height: auto; }
  .panel-paper, .panel-math, .panel-context { height: 50vh; }
  .panel-divider { display: none; }

  .section-nav:not(.collapsed) { display: flex; flex-wrap: wrap; gap: 2px; padding-left: 0.3rem; }
  .nav-item { flex: 0 0 auto; padding-left: 0.5rem; }
}

/* =============================================================================
   REDUCED MOTION — accessibility support
   Disables all decorative animations while preserving essential state changes.
   ============================================================================= */

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

  /* Preserve essential state transitions (just make them instant) */
  .prog-fill {
    transition: stroke-dashoffset 0.3s ease !important;
  }

  .prog-bar-fill {
    transition: width 0.3s ease !important;
  }

  .stg-dot {
    transition: background 0.2s ease, border-color 0.2s ease !important;
  }

  .prog-agent {
    transition: background 0.2s ease, border-color 0.2s ease !important;
  }

  /* Remove purely decorative animations */
  .prog-mesh {
    animation: none !important;
  }

  /* Orrery — show static, no rotation (landing + progress) */
  .math-orrery,
  .orrery-glow,
  .orrery-orbit,
  .orrery-dot,
  .orbit-sym::after {
    animation: none !important;
  }

  .orrery-orbit {
    opacity: 0.5;
  }

  .orbit-sym {
    opacity: 0.25 !important;
  }

  .orrery-dot {
    opacity: 0.2 !important;
  }

  .landing-icon svg {
    animation: none !important;
  }

  .landing-state::before {
    animation: none !important;
  }

  .prog-title {
    animation: none !important;
    opacity: 1 !important;
  }

}

/* =============================================================================
   IMPROVEMENT #1: Results page transition — graceful progress exit
   ============================================================================= */

.progress-state.exiting {
  animation: progressExit 0.45s var(--ease-in) forwards;
  pointer-events: none;
}

@keyframes progressExit {
  0% { opacity: 1; transform: scale(1) translateY(0); }
  100% { opacity: 0; transform: scale(0.97) translateY(-12px); }
}

/* =============================================================================
   IMPROVEMENT #4: Progress completion celebration
   ============================================================================= */

.prog-hero.celebrating .pct-num {
  color: var(--sage) !important;
  animation: celebrateNum 0.7s var(--ease-spring);
}

.prog-hero.celebrating .pct-sign {
  color: var(--sage) !important;
  opacity: 0.8;
}

@keyframes celebrateNum {
  0% { transform: scale(1); }
  35% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Sage flash overlay on the progress area */
.progress-state.celebrate-flash::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(61,122,102,0.08) 0%, transparent 70%);
  animation: sageFlash 0.8s var(--ease-out) forwards;
  pointer-events: none;
  z-index: 5;
}

@keyframes sageFlash {
  0% { opacity: 0; transform: scale(0.8); }
  40% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.5); }
}

/* Progress line turns sage on completion */
.progress-state.celebrate-flash .prog-line-svg .prog-glow {
  stroke: var(--sage) !important;
  transition: stroke 0.5s ease;
}

/* =============================================================================
   IMPROVEMENT #5: Landing drag-drop state — enhanced visual feedback
   ============================================================================= */

.chat-bar.dragover .chat-bar-inner {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(201,165,90,0.15), 0 8px 40px rgba(0,0,0,0.08);
  background: rgba(201,165,90,0.03);
  animation: dropPulse 1.5s ease infinite;
}

@keyframes dropPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(201,165,90,0.15), 0 8px 40px rgba(0,0,0,0.08); }
  50% { box-shadow: 0 0 0 6px rgba(201,165,90,0.22), 0 8px 40px rgba(0,0,0,0.12); }
}

/* Orrery brightens on file drag */
.landing-state.file-dragging .math-orrery {
  transition: filter 0.3s ease, transform 0.3s ease;
  filter: brightness(1.3) saturate(1.2);
  transform: scale(1.02);
}

.landing-state.file-dragging .orrery-glow {
  opacity: 1 !important;
  transition: opacity 0.3s ease;
}

/* Drop hint text */
.chat-bar.dragover .chat-drop-hint {
  opacity: 1;
  transform: translateY(0);
}

.chat-drop-hint {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--amber);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  pointer-events: none;
}


/* =============================================================================
   IMPROVEMENT #7: Stats strip count bounce
   ============================================================================= */

.prog-stat-val.count-done {
  animation: countBounce 0.4s var(--ease-spring);
}

@keyframes countBounce {
  0% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* =============================================================================
   IMPROVEMENT #2: Sidebar paper list — metadata line
   ============================================================================= */

.paper-item-body {
  flex: 1; min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.paper-item-meta {
  font-family: var(--font-mono);
  font-size: 0.56rem;
  color: var(--text-4);
  letter-spacing: 0.02em;
  opacity: 0.7;
  line-height: 1.2;
}

.paper-item.active .paper-item-meta {
  color: var(--amber-dim);
  opacity: 0.8;
}

.paper-item-icon {
  flex-shrink: 0;
  width: 14px; height: 14px;
  color: var(--text-4);
  margin-top: 1px;
  opacity: 0.5;
}

.paper-item.active .paper-item-icon {
  color: var(--amber);
  opacity: 0.8;
}

/* =============================================================================
   SYMBOL TABLE (formula explainer)
   ============================================================================= */

.symbol-table-wrapper {
  margin: 0.6rem 0;
}

.symbol-table-wrapper > p {
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
}

.symbol-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.3rem 0 0.6rem;
}

.symbol-table th,
.symbol-table td {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border-dim);
  text-align: left;
}

.symbol-table th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.symbol-table td {
  color: var(--text-2);
}

.symbol-table tr:nth-child(even) td {
  background: rgba(0,0,0,0.015);
}

/* =============================================================================
   FORMULA MARKDOWN BODY (markdown-rendered formula explanations)
   ============================================================================= */

.formula-markdown-body {
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
  line-height: 1.55;
}

.formula-markdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.3rem 0 0.6rem;
}

.formula-markdown-body th,
.formula-markdown-body td {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border-dim);
  text-align: left;
}

.formula-markdown-body th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.formula-markdown-body td {
  color: var(--text-2);
}

.formula-markdown-body tr:nth-child(even) td {
  background: rgba(0,0,0,0.015);
}

/* =============================================================================
   ASK AI — Chat with the paper
   ============================================================================= */

/* Tab accent */
.tool-tab-ask {
  color: var(--sage) !important;
}
.tool-tab-ask.active {
  color: var(--sage) !important;
  border-bottom-color: var(--sage) !important;
  background: rgba(61,122,102,0.06) !important;
}

/* Chat pane — full height flex layout */
.tab-pane-ask {
  padding: 0 !important;
  max-width: none !important;
  width: 100% !important;
  display: none;
}
.tab-pane-ask.active {
  display: flex !important;
}

/* =============================================================================
   ASK AI — Research Assistant Chat
   ============================================================================= */

.ask-chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
}

.ask-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1.8rem 1.2rem 1.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

/* ---- Welcome state ---- */
.ask-welcome {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  flex: 1;
  padding: 2rem 0 1rem;
  width: 100%;
  animation: askWelcomeIn 0.5s var(--ease-out) both;
}

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

.ask-welcome-header {
  margin-bottom: 1.8rem;
}

.ask-welcome-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--sage);
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 0.7rem;
}

.ask-welcome h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  margin: 0 0 0.35rem;
  letter-spacing: -0.01em;
}

.ask-welcome p {
  font-size: 0.82rem;
  color: var(--text-4);
  margin: 0;
  line-height: 1.5;
}

/* ---- Suggestion categories ---- */
.ask-categories {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 520px;
}

.ask-cat {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  animation: askCatIn 0.4s var(--ease-out) both;
}

.ask-cat:nth-child(1) { animation-delay: 0.08s; }
.ask-cat:nth-child(2) { animation-delay: 0.16s; }
.ask-cat:nth-child(3) { animation-delay: 0.24s; }

@keyframes askCatIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.ask-cat-label {
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  width: 68px;
  flex-shrink: 0;
}

.ask-suggestion {
  background: var(--surface);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  font-family: var(--font-body);
  font-size: 0.76rem;
  color: var(--text-3);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  line-height: 1.4;
}

.ask-suggestion:hover {
  border-color: var(--sage);
  color: var(--sage);
  background: var(--sage-glow);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(61,122,102,0.08);
}

/* ---- Message items ---- */
.ask-msg {
  max-width: 88%;
  font-size: 0.88rem;
  line-height: 1.68;
  animation: askMsgIn 0.25s var(--ease-out) both;
}

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

/* User message */
.ask-msg-user {
  align-self: flex-end;
  max-width: 72%;
  background: var(--surface-2);
  color: var(--text);
  padding: 0.5rem 0.85rem;
  border-radius: 10px 10px 2px 10px;
  font-weight: 450;
  font-size: 0.86rem;
  border: 1px solid var(--border-dim);
}

/* AI message */
.ask-msg-ai {
  align-self: flex-start;
  max-width: 94%;
  padding: 0;
  margin-top: 0.5rem;
  position: relative;
}

.ask-msg-ai-inner {
  border-left: 2px solid var(--sage);
  padding: 0.5rem 0 0.5rem 1rem;
  position: relative;
}

.ask-msg-ai .ask-msg-body {
  font-size: 0.88rem;
  line-height: 1.72;
}
.ask-msg-ai .ask-msg-body p { margin: 0 0 0.55rem; }
.ask-msg-ai .ask-msg-body p:last-child { margin-bottom: 0; }
.ask-msg-ai .ask-msg-body strong { color: var(--text); font-weight: 600; }
.ask-msg-ai .ask-msg-body em { color: var(--text-2); font-style: italic; }
.ask-msg-ai .ask-msg-body code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: var(--surface-2);
  padding: 0.12em 0.38em;
  border-radius: 3px;
  border: 1px solid var(--border-dim);
}
.ask-msg-ai .ask-msg-body pre {
  background: var(--surface-2);
  border: 1px solid var(--border-dim);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  overflow-x: auto;
  margin: 0.4rem 0 0.6rem;
}
.ask-msg-ai .ask-msg-body pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8em;
}
.ask-msg-ai .ask-msg-body ul,
.ask-msg-ai .ask-msg-body ol { margin: 0.3rem 0 0.6rem; padding-left: 1.3rem; }
.ask-msg-ai .ask-msg-body li { margin-bottom: 0.2rem; }
.ask-msg-ai .ask-msg-body h1,
.ask-msg-ai .ask-msg-body h2,
.ask-msg-ai .ask-msg-body h3 {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  margin: 0.7rem 0 0.25rem;
  color: var(--text);
}
.ask-msg-ai .ask-msg-body h1:first-child,
.ask-msg-ai .ask-msg-body h2:first-child,
.ask-msg-ai .ask-msg-body h3:first-child { margin-top: 0; }

/* AI message tables (for structured answers) */
.ask-msg-ai .ask-msg-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.4rem 0 0.6rem;
  font-size: 0.84rem;
}
.ask-msg-ai .ask-msg-body th,
.ask-msg-ai .ask-msg-body td {
  border: 1px solid var(--border-dim);
  padding: 0.3rem 0.55rem;
  text-align: left;
}
.ask-msg-ai .ask-msg-body th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-2);
}

/* Copy button on AI messages */
.ask-msg-copy {
  position: absolute;
  top: 0.35rem;
  right: 0;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-dim);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text-4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ask-msg-ai:hover .ask-msg-copy { opacity: 1; }
.ask-msg-copy:hover { color: var(--sage); border-color: var(--sage); }
.ask-msg-copy.copied { color: var(--sage); border-color: var(--sage); opacity: 1; }

/* ---- Thinking indicator ---- */
.ask-thinking {
  padding: 0;
}

.ask-thinking .ask-msg-ai-inner {
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.ask-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.ask-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--sage);
  animation: askDot 1.2s ease-in-out infinite;
}
.ask-dots span:nth-child(2) { animation-delay: 0.15s; }
.ask-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes askDot {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.7); }
  40% { opacity: 0.7; transform: scale(1.1); }
}

/* ---- Input area ---- */
.ask-input-area {
  border-top: 1px solid var(--border-dim);
  padding: 0.7rem 1.5rem 0.55rem;
  background: var(--bg);
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.ask-clear {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-dim);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
  margin-bottom: 1px;
}

.ask-clear:hover {
  color: var(--text-2);
  border-color: var(--border);
  background: var(--surface-2);
}

.ask-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.35rem 0.45rem 0.35rem 0.85rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ask-input-wrap:focus-within {
  border-color: var(--sage);
  box-shadow: 0 0 0 2px rgba(61,122,102,0.07);
}

.ask-input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.87rem;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  padding: 0.25rem 0;
  max-height: 140px;
}

.ask-input::placeholder {
  color: var(--text-4);
}

.ask-send {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 7px;
  background: var(--sage);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.ask-send:disabled {
  opacity: 0.3;
  cursor: default;
}

.ask-send:not(:disabled):hover {
  opacity: 0.88;
  transform: scale(1.04);
}

.ask-send:not(:disabled):active {
  transform: scale(0.94);
}
