/* ================================================================
   Fourier Drawing Machine — Style v2
   Thesis-inspired design (matches hamzehhamdan.com)
   ================================================================ */

/* ── 1. Design Tokens ─────────────────────────────────────────── */
:root {
  /* Colors — matches thesis palette exactly */
  --bg:         #f9f8f6;   /* stone warm off-white */
  --bg-white:   #ffffff;
  --bg-dim:     #f4f3f1;
  --border:     #e7e5e4;   /* stone-200 */
  --border-md:  #a8a29e;   /* stone-400 */
  --text:       #1c1917;   /* stone-900 */
  --text-mid:   #57534e;   /* stone-600 */
  --text-faint: #a8a29e;   /* stone-400 */
  --accent:     #A51C30;   /* Harvard crimson */
  --accent-dim: rgba(165, 28, 48, 0.07);
  --canvas-bg:  #0d0c0b;   /* near-black canvas */

  /* Typography */
  --serif: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --mono:  'SF Mono', 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
  --sans:  system-ui, -apple-system, BlinkMacSystemFont, sans-serif;

  /* Easing */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Layout */
  --header-h:  44px;
  --bar-h:     2px;
  --sidebar-w: 268px;
  --top-offset: calc(var(--header-h) + var(--bar-h));
}

/* ── 2. Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
body { display: flex; flex-direction: column; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { text-decoration: none; }

/* ── 3. Noise Background ──────────────────────────────────────── */
.noise-bg {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 300px 300px;
  opacity: 0.028;
}

/* ── 4. Step Progress Bar ─────────────────────────────────────── */
.step-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--bar-h);
  background: var(--border);
  z-index: 100;
}
.step-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.6s var(--ease);
}

/* ── 5. App Header ────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: var(--bar-h);
  left: 0;
  right: 0;
  height: var(--header-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  flex-shrink: 0;
}
.app-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-crumb {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.01em;
  transition: color 0.15s;
}
.nav-crumb:hover { color: var(--text-mid); }
.nav-sep {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--border-md);
}
.nav-current {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mid);
}
.header-writeup-link {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 4px 10px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.header-writeup-link:hover { opacity: 1; }

/* ── 6. App Container + Sections ─────────────────────────────── */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-top: var(--top-offset);
  height: calc(100dvh - var(--top-offset));
  position: relative;
  z-index: 1;
}
section {
  display: none;
  flex: 1;
  overflow: hidden;
}
section.active { display: flex; }

/* ── 7. Upload Section ────────────────────────────────────────── */
#upload-section {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}
.upload-scroll {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 36px 24px 52px;
}
.upload-layout {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Section label row — matches ThesisSection label exactly */
.section-label-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 36px;
}
.mono-label {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}
.label-hr {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Upload hero */
.upload-hero {
  text-align: center;
  margin-bottom: 32px;
}
.upload-icon {
  width: 46px;
  height: 46px;
  margin: 0 auto 18px;
  color: var(--accent);
}
.upload-icon svg { width: 46px; height: 46px; }
.upload-heading {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 400;
  line-height: 1.22;
  color: var(--text);
  letter-spacing: -0.01em;
  margin-bottom: 10px;
}
.upload-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.65;
  letter-spacing: 0.01em;
  max-width: 360px;
  margin: 0 auto;
}

/* Drop zone */
.drop-zone {
  border: 1.5px dashed var(--border-md);
  background: var(--bg-white);
  padding: 36px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  outline: none;
  margin-bottom: 20px;
}
.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.dz-icon { width: 28px; height: 28px; color: var(--text-faint); }
.dz-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
}
.dz-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  text-align: center;
}

/* OR divider */
.or-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 14px;
}
.or-line { flex: 1; height: 1px; background: var(--border); }
.or-text {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-faint);
  white-space: nowrap;
}

/* Draw mode button (secondary CTA, thesis-style) */
.draw-mode-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  transition: all 0.2s var(--ease);
  margin-bottom: 20px;
}
.draw-mode-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Sample shape cards */
.sample-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.sample-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: center;
}
.sample-card:hover {
  border-color: var(--border-md);
  background: var(--bg-dim);
}
.sample-name {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--text);
  font-weight: 400;
}
.sample-desc {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── 8. Split Layout (Preview + Viz) ─────────────────────────── */
#preview-section,
#viz-section { flex-direction: row; }

.split-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.split-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 14px 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  flex-shrink: 0;
}
.split-sidebar::-webkit-scrollbar { width: 3px; }
.split-sidebar::-webkit-scrollbar-track { background: transparent; }
.split-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Sidebar header row */
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 2px;
}
.sidebar-label-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

/* Back button */
.back-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s var(--ease);
}
.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Sidebar hint text */
.sidebar-hint {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.55;
  padding: 0 2px;
}

/* Control cards — thesis-style bordered containers */
.ctrl-card {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
  padding: 11px 11px 9px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ctrl-card-label {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-faint);
}
.ctrl-card-footer {
  padding-top: 6px;
  border-top: 1px solid var(--border);
}
.ctrl-subsection {
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Sliders */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--border);
  outline: none;
  border-radius: 1px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-white);
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-white);
  box-shadow: 0 0 0 1px var(--accent);
}
.slider-val {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Toggles */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}
.toggle-cb { display: none; }
.toggle-track {
  width: 28px;
  height: 15px;
  background: var(--bg-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  position: relative;
  flex-shrink: 0;
  transition: all 0.18s var(--ease);
}
.toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: all 0.18s var(--ease);
}
.toggle-cb:checked + .toggle-track {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.toggle-cb:checked + .toggle-track .toggle-knob {
  left: 15px;
  background: var(--accent);
}
.toggle-text {
  font-size: 11px;
  color: var(--text-mid);
}

/* Mode segmented control */
.mode-seg {
  display: flex;
  border: 1px solid var(--border);
  overflow: hidden;
}
.mode-btn {
  flex: 1;
  padding: 5px 6px;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--bg-white);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-faint);
  cursor: pointer;
  transition: all 0.12s var(--ease);
  white-space: nowrap;
}
.mode-btn:last-child { border-right: none; }
.mode-btn:hover { color: var(--text-mid); background: var(--bg-dim); }
.mode-btn.active { background: var(--accent-dim); color: var(--accent); }

/* Processing result stats */
.process-stats {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pstat { display: flex; justify-content: space-between; align-items: baseline; }
.pstat-label {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-faint);
}
.pstat-val {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mid);
}

/* Stats chips (like thesis StatChips component) */
.stat-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.stat-chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
  padding: 8px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chip-val {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.chip-label {
  font-family: var(--mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-faint);
}

/* Sidebar action buttons */
.sidebar-actions {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Primary button — thesis stone-900 style */
.btn-primary {
  width: 100%;
  padding: 10px 16px;
  background: var(--text);
  border: 1px solid var(--text);
  color: #fff;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.btn-primary:hover {
  background: var(--text-mid);
  border-color: var(--text-mid);
}

/* Small secondary button */
.btn-sm-secondary {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.btn-sm-secondary:hover {
  border-color: var(--border-md);
  color: var(--text-mid);
}

/* Icon-only secondary button (reset) */
.btn-icon-secondary {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.btn-icon-secondary:hover {
  border-color: var(--border-md);
  color: var(--text-mid);
}

/* ── 9. Canvas Areas ──────────────────────────────────────────── */
.split-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}
.canvas-panel {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}
.canvas-panel--dual { flex-wrap: wrap; }

.canvas-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
  min-width: 0;
}
.canvas-label {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--text-faint);
}

/* Standard preview canvas */
.preview-canvas {
  border: 1px solid var(--border);
  background: #000;
  max-width: 100%;
  max-height: min(65vh, 420px);
  display: block;
}
.preview-canvas--dark {
  background: #0a0a0f;
}

/* Whole image canvas */
#whole-preview-canvas {
  border: 1px solid var(--border);
  background: #000;
  max-width: 100%;
  max-height: min(65vh, 420px);
  display: block;
}

/* Paint stack (stacked canvases for select mode) */
.paint-stack {
  position: relative;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #000;
  cursor: crosshair;
  display: block;
}
.paint-stack canvas { display: block; max-width: 100%; }
.paint-stack #paint-overlay {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}
.paint-stack #paint-cursor {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none; /* overridden by app.js to 'auto' */
}

/* Freehand draw canvas */
.draw-canvas-wrap {
  position: relative;
  border: 1px solid var(--border);
  overflow: hidden;
  background: #000;
  cursor: crosshair;
  display: block;
}
.draw-canvas-wrap canvas { display: block; }
.draw-canvas-wrap.drawing { border-color: var(--accent); }

/* ── 10. Viz Section ──────────────────────────────────────────── */
.viz-main {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-width: 0;
  background: var(--canvas-bg);
}
#fourier-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Playback row */
.playback-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.play-btn {
  flex: 1;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  cursor: pointer;
  transition: all 0.15s var(--ease);
}
.play-btn:hover { background: var(--accent); color: #fff; }
/* Play/Pause icon toggle (app.js adds/removes .playing class) */
.play-btn .pause-icon { display: none; }
.play-btn.playing .play-icon { display: none; }
.play-btn.playing .pause-icon { display: block; }

/* Color picker */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; }
input[type="color"]::-moz-color-swatch { border: none; }
.color-presets { display: flex; gap: 5px; flex-wrap: wrap; }
.color-preset {
  width: 18px;
  height: 18px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.12s var(--ease);
  padding: 0;
  outline: none;
}
.color-preset:hover { transform: scale(1.2); border-color: rgba(0, 0, 0, 0.2); }
.color-preset.active { border-color: var(--text); }

/* ── 11. Reference Photo Panel ────────────────────────────────── */
.ref-panel {
  width: 260px;
  min-width: 180px;
  max-width: 300px;
  background: var(--bg-white);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  flex-shrink: 0;
}
.ref-label {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-faint);
  align-self: flex-start;
}
.ref-panel canvas {
  border: 1px solid var(--border);
  max-width: 100%;
  max-height: calc(100% - 28px);
  object-fit: contain;
  display: block;
}

/* ── 12. Floating Formula Panel (dark theme) ──────────────────── */
.fml-float {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.fml-trigger {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(13, 12, 11, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 18px;
  backdrop-filter: blur(12px);
  transition: all 0.18s var(--ease);
  flex-shrink: 0;
}
.fml-trigger:hover,
.fml-trigger.active {
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}
.fml-panel {
  width: 290px;
  max-height: 520px;
  overflow-y: auto;
  background: rgba(13, 12, 11, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
}
.fml-panel::-webkit-scrollbar { width: 4px; }
.fml-panel::-webkit-scrollbar-track { background: transparent; }
.fml-panel::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 2px; }

.fml-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
}
.fml-header-title {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.4);
}
.fml-latex-btn {
  font-family: var(--mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: none;
  color: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.fml-latex-btn:hover { border-color: rgba(255, 255, 255, 0.3); color: rgba(255, 255, 255, 0.85); }
.fml-latex-btn.copied { border-color: #22c55e66; color: #22c55e; }

.fml-formula-block {
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.fml-formula-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.fml-lhs { font-family: var(--serif); font-size: 14px; color: rgba(255, 255, 255, 0.85); }
.fml-eq { font-size: 13px; color: rgba(255, 255, 255, 0.3); }
.fml-sigma-grp { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.fml-sigma-lim { font-family: var(--mono); font-size: 7px; color: rgba(255, 255, 255, 0.35); letter-spacing: 0; }
.fml-sigma-big { font-size: 24px; color: rgba(165, 140, 255, 0.75); line-height: 0.85; }
.fml-cn-accent { font-family: var(--serif); font-size: 14px; color: var(--accent); }
.fml-dot { font-size: 12px; color: rgba(255, 255, 255, 0.25); }
.fml-exp-part { font-family: var(--serif); font-size: 14px; color: rgba(255, 255, 255, 0.7); }
.fml-exp-part sup { font-family: var(--mono); font-size: 8px; color: rgba(255, 255, 255, 0.45); }
.fml-sub-formula-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.fml-sub { font-family: var(--mono); font-size: 10px; color: rgba(255, 255, 255, 0.4); }
.fml-sub sup { font-size: 7px; }

.fml-terms-section { padding: 10px 14px; }
.fml-expand-btn {
  width: 100%;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 5px 8px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.35);
  text-align: left;
  margin-bottom: 8px;
  transition: all 0.15s;
}
.fml-expand-btn:hover { border-color: rgba(255, 255, 255, 0.2); color: rgba(255, 255, 255, 0.65); }

.formula-term-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.formula-term-ellipsis { border-bottom: none; }
.formula-term-plus { font-family: var(--mono); font-size: 10px; color: rgba(255, 255, 255, 0.2); min-width: 10px; }
.formula-term-expr { font-family: var(--mono); font-size: 10px; color: rgba(165, 140, 255, 0.8); min-width: 100px; flex-shrink: 0; }
.formula-term-expr sup { font-size: 7px; }
.formula-cn-sm { color: var(--accent); font-family: var(--mono); }
.formula-term-live-info { font-family: var(--mono); font-size: 8px; color: rgba(255, 255, 255, 0.25); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.formula-approx { font-family: var(--mono); font-size: 9px; color: rgba(255, 255, 255, 0.35); margin-bottom: 6px; }
.formula-approx-note { font-family: var(--mono); font-size: 8px; color: rgba(255, 255, 255, 0.2); }

.fml-key {
  padding: 10px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.fml-key-row { display: flex; align-items: baseline; gap: 8px; }
.fml-key-sym { font-family: var(--mono); font-size: 10px; color: rgba(165, 140, 255, 0.7); min-width: 52px; flex-shrink: 0; }
.fml-key-sym sub, .fml-key-sym sup { font-size: 7px; }
.fml-key-def { font-family: var(--mono); font-size: 8px; color: rgba(255, 255, 255, 0.3); line-height: 1.4; }

.fml-blog-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-family: var(--mono);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-decoration: none;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.fml-blog-link:hover { opacity: 1; }

/* ── 13. Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .canvas-panel { flex-direction: column; }
  .canvas-panel--dual { flex-direction: row; flex-wrap: wrap; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 100%; }
  .split-layout { flex-direction: column; }
  .split-sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 230px;
    padding: 10px 14px;
    gap: 8px;
  }
  .split-main { padding: 12px; }
  .ref-panel {
    width: 100%;
    min-width: unset;
    max-width: unset;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 180px;
  }
  .stat-chips { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 480px) {
  .nav-crumb--hide-sm,
  .nav-sep--hide-sm { display: none; }
  .upload-scroll { padding: 24px 16px 40px; }
  .upload-heading { font-size: 22px; }
  .fml-panel { width: min(290px, calc(100vw - 32px)); max-height: 70vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, .step-fill { transition-duration: 0.01s !important; }
}
