/* ===== Design tokens ===== */
:root {
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.45, 0.64, 1);
  --t-fast: 200ms;
  --t-med: 360ms;
  --t-slow: 520ms;
  --font: ui-sans-serif, system-ui, "Segoe UI", Roboto, Inter, sans-serif;
  --accent: #0ea5e9;
  --accent-glow: rgba(14, 165, 233, 0.38);
  --accent-2: #6366f1;
  --glass-bg: rgba(255, 255, 255, 0.58);
  --glass-border: rgba(255, 255, 255, 0.55);
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 12px 40px -8px rgba(15, 23, 42, 0.1);
  --shadow-elevated: var(--glass-highlight), 0 10px 36px -10px rgba(15, 23, 42, 0.12),
    0 32px 64px -20px rgba(15, 23, 42, 0.14);
  --text: #0f172a;
  --text-muted: #64748b;
  --surface: rgba(248, 250, 252, 0.9);
  --inset: rgba(241, 245, 249, 0.95);
  --ring: 0 0 0 3px rgba(14, 165, 233, 0.28);
}

[data-theme="dark"] {
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.32);
  --accent-2: #818cf8;
  --glass-bg: rgba(15, 23, 42, 0.58);
  --glass-border: rgba(148, 163, 184, 0.14);
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 18px 48px -8px rgba(0, 0, 0, 0.5);
  --shadow-elevated: var(--glass-highlight), 0 12px 40px -8px rgba(0, 0, 0, 0.55),
    0 36px 72px -16px rgba(0, 0, 0, 0.45);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --surface: rgba(15, 23, 42, 0.78);
  --inset: rgba(2, 6, 23, 0.62);
  --ring: 0 0 0 3px rgba(56, 189, 248, 0.25);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  color: var(--text);
  background: linear-gradient(165deg, #dbeafe 0%, #f8fafc 42%, #eef2ff 100%);
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}

[data-theme="dark"] body {
  background: linear-gradient(165deg, #020617 0%, #0f172a 48%, #1e1b4b 100%);
}

.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(14, 165, 233, 0.22), transparent 50%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(99, 102, 241, 0.18), transparent 45%);
  opacity: 0.92;
}

@media (prefers-reduced-motion: no-preference) {
  .bg-orbs {
    animation: orbDrift 28s ease-in-out infinite alternate;
  }
}

@keyframes orbDrift {
  from {
    opacity: 0.88;
    transform: scale(1) translate(0, 0);
  }
  to {
    opacity: 1;
    transform: scale(1.03) translate(1%, 0.5%);
  }
}

[data-theme="dark"] .bg-orbs {
  background:
    radial-gradient(ellipse 70% 45% at 15% -5%, rgba(56, 189, 248, 0.2), transparent 50%),
    radial-gradient(ellipse 50% 35% at 95% 5%, rgba(129, 140, 248, 0.15), transparent 45%);
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 52px;
  opacity: 0;
  transform: translateY(16px) scale(0.992);
  filter: blur(4px);
  transition: opacity var(--t-slow) var(--ease-out), transform var(--t-slow) var(--ease-out),
    filter var(--t-slow) var(--ease-out);
}

body.is-loaded .app-shell {
  opacity: 1;
  transform: translateY(0) scale(1);
  filter: blur(0);
}

@media (prefers-reduced-motion: reduce) {
  .app-shell {
    opacity: 1;
    transform: none;
    filter: none;
    transition: none;
  }

  .bg-orbs {
    animation: none;
  }
}

.app-shell.reset-flash {
  animation: resetFlash 0.55s var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .app-shell.reset-flash {
    animation: none;
  }
}

@keyframes resetFlash {
  0% {
    filter: brightness(1.1);
  }
  40% {
    filter: brightness(1.25) saturate(1.08);
  }
  100% {
    filter: none;
  }
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Glass surfaces ===== */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(20px) saturate(1.45);
  -webkit-backdrop-filter: blur(20px) saturate(1.45);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.glass-inset {
  background: var(--inset);
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

[data-theme="dark"] .glass-inset {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* ===== Top bar ===== */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  background: linear-gradient(145deg, #7dd3fc 0%, var(--accent) 38%, var(--accent-2) 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35) inset, 0 10px 32px var(--accent-glow);
  transition: transform var(--t-med) var(--ease-out), box-shadow var(--t-med) var(--ease);
}

body.is-loaded .brand-mark {
  animation: markSettle 0.85s var(--ease-out) both;
}

@keyframes markSettle {
  from {
    transform: scale(0.86) rotate(-4deg);
    opacity: 0.6;
  }
  to {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.is-loaded .brand-mark {
    animation: none;
  }
}

.brand-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* ===== Toggles (theme / sound) ===== */
.toggle.pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle.pill input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-ui {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: var(--inset);
  border: 1px solid var(--glass-border);
  transition: box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
  position: relative;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff, #e2e8f0);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.14);
  transition: transform var(--t-med) var(--ease-spring);
}

[data-theme="dark"] .toggle-ui::after {
  background: linear-gradient(145deg, #334155, #1e293b);
}

.toggle.pill input:checked + .toggle-ui::after {
  transform: translateX(20px);
}

.toggle.pill input:checked + .toggle-ui {
  box-shadow: 0 0 0 2px var(--accent-glow), 0 8px 24px rgba(14, 165, 233, 0.2);
}

.toggle-ui.tone {
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.sound-toggle input:checked + .toggle-ui {
  color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ===== Buttons ===== */
a.btn {
  text-decoration: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.92rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-spring), box-shadow var(--t-fast) var(--ease),
    background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(145deg, #38bdf8 0%, var(--accent) 40%, #0369a1 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 10px 32px var(--accent-glow);
}

.btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 16px 44px var(--accent-glow);
}

.btn.secondary {
  background: var(--surface);
  border-color: var(--glass-border);
  color: var(--text);
}

.btn.secondary:hover {
  transform: translateY(-1px);
  border-color: rgba(14, 165, 233, 0.35);
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.1);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--glass-border);
  color: var(--text);
}

.btn.ghost:hover {
  border-color: rgba(14, 165, 233, 0.45);
  background: rgba(14, 165, 233, 0.06);
  transform: translateY(-1px);
}

[data-theme="dark"] .btn.ghost {
  background: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .btn.ghost:hover {
  background: rgba(56, 189, 248, 0.08);
}

.btn.sm {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.icon-btn.ghost {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}

.icon-btn.ghost:hover {
  color: var(--text);
  background: var(--inset);
}

/* ===== Intro ===== */
.intro-banner {
  padding: 16px 20px;
  margin-bottom: 22px;
  font-size: 0.94rem;
  line-height: 1.6;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.intro-banner strong {
  color: var(--text);
  font-weight: 700;
}

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: minmax(280px, 348px) 1fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.column {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-tilt {
  padding: 22px 20px;
}

.main-column {
  gap: 18px;
}

.panel-heading {
  margin: 4px 0 0;
  padding-bottom: 10px;
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(100, 116, 139, 0.16);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

[data-theme="dark"] .panel-heading {
  border-bottom-color: rgba(148, 163, 184, 0.12);
}

.panel-heading.tight {
  margin: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

/* ===== Presets ===== */
.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-chip {
  position: relative;
  padding: 15px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  background: var(--surface);
  font-weight: 600;
  font-size: 0.87rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-align: center;
  transition: transform var(--t-fast) var(--ease-spring), box-shadow var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}

.preset-chip::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 0 0 1px var(--accent);
  transition: opacity var(--t-fast) var(--ease);
}

.preset-chip:hover {
  transform: translateY(-3px);
  border-color: rgba(14, 165, 233, 0.5);
  box-shadow: 0 12px 36px -6px var(--accent-glow);
}

.preset-chip:hover::after {
  opacity: 0.35;
}

.preset-chip:active {
  transform: translateY(-1px) scale(0.99);
  transition-duration: 80ms;
}

.preset-chip:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

.preset-chip:focus-visible::after {
  opacity: 0.5;
}

.preset-chip.accent {
  border-color: rgba(14, 165, 233, 0.42);
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.08), var(--surface));
}

.ai-strip {
  padding: 14px;
}

.mini-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.select-full,
select,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}

select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

select:focus-visible,
input[type="text"]:focus-visible,
input[type="number"]:focus-visible {
  box-shadow: var(--ring);
}

.ai-text {
  margin: 10px 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ===== Controls ===== */
.control-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: block;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-row.gap {
  margin-top: 8px;
}

.unit {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.check-row,
.check-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.save-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.save-row input {
  flex: 1;
}

.footer-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 8px;
}

/* ===== Range inputs (thumb-friendly) ===== */
input[type="range"] {
  width: 100%;
  height: 40px;
  margin: 4px 0 8px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: 12px;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--inset), rgba(14, 165, 233, 0.15));
  border: 1px solid var(--glass-border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -9px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff, #e0f2fe);
  border: 2px solid var(--accent);
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.15s var(--ease);
}

[data-theme="dark"] input[type="range"]::-webkit-slider-thumb {
  background: linear-gradient(145deg, #334155, #0ea5e9);
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.12);
}

input[type="range"]::-moz-range-track {
  height: 10px;
  border-radius: 999px;
  background: var(--inset);
  border: 1px solid var(--glass-border);
}

input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(145deg, #fff, #e0f2fe);
  border: 2px solid var(--accent);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.thumb-range {
  height: 48px;
}

.thumb-range::-webkit-slider-thumb {
  width: 32px;
  height: 32px;
  margin-top: -12px;
}

.thumb-range::-moz-range-thumb {
  width: 32px;
  height: 32px;
}

@media (max-width: 600px) {
  input[type="range"]::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
    margin-top: -12px;
  }
}

/* Haptic-style bump (visual) */
@keyframes hapticBump {
  0% {
    transform: scale(1);
  }
  22% {
    transform: scale(1.035);
  }
  55% {
    transform: scale(0.99);
  }
  100% {
    transform: scale(1);
  }
}

.haptic-bump {
  animation: hapticBump 0.38s var(--ease-spring);
}

@media (prefers-reduced-motion: reduce) {
  .haptic-bump {
    animation: none;
  }
}

/* ===== Graph card ===== */
.main-column > .graph-card.glass {
  box-shadow: var(--shadow-elevated);
}

.graph-card {
  position: relative;
  padding: 20px 20px 18px;
}

.graph-card::before {
  content: "";
  position: absolute;
  left: 24px;
  right: 24px;
  top: 0;
  height: 3px;
  border-radius: 0 0 4px 4px;
  background: linear-gradient(90deg, transparent 5%, var(--accent) 50%, transparent 95%);
  opacity: 0.55;
  pointer-events: none;
}

.graph-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.hud {
  display: flex;
  gap: 22px;
  padding: 11px 18px;
  font-size: 0.84rem;
}

.hud-k {
  color: var(--text-muted);
  margin-right: 6px;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-v {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: 0.02em;
  color: var(--accent);
  transition: color var(--t-fast) var(--ease);
}

.canvas-frame {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--inset);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 0 0 1px rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] .canvas-frame {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

canvas#graph {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
  cursor: crosshair;
}

canvas#graph:focus {
  outline: none;
  box-shadow: var(--ring);
}

canvas#graph:focus-visible {
  box-shadow: var(--ring);
}

.graph-hint {
  margin: 12px 0 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ===== Compare / play ===== */
.compare-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 15px 18px;
  align-items: center;
}

.frozen-legend {
  padding: 12px 16px;
  min-height: 48px;
  transition: border-color var(--t-fast) var(--ease);
}

.legend-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  margin: 0 -6px;
  border-radius: 10px;
  border-bottom: 1px solid var(--glass-border);
  transition: background var(--t-fast) var(--ease);
}

.legend-row:hover {
  background: rgba(14, 165, 233, 0.05);
}

.legend-row:last-child {
  border-bottom: none;
}

.legend-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
  font-size: 0.88rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
}

.playback {
  padding: 16px;
}

.play-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ===== Throttle / output ===== */
.throttle-card {
  padding: 20px;
}

.throttle-label {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
  display: block;
}

.output-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 18px;
  margin-top: 16px;
  align-items: stretch;
}

@media (max-width: 600px) {
  .output-grid {
    grid-template-columns: 1fr;
  }
}

.output-gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}

.output-gauge .big {
  font-size: 2.1rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.02em;
  color: var(--accent);
  transition: transform var(--t-fast) var(--ease-spring), color var(--t-fast) var(--ease);
}

.output-gauge .muted {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.feel-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.feel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.feel-tag {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.feel-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: var(--inset);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}

.feel-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    #34d399 0%,
    #22d3ee 28%,
    #38bdf8 52%,
    #fbbf24 78%,
    #f97316 100%
  );
  transition: width 0.48s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.38);
}

.feel-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.spike-block {
  margin-top: 6px;
}

.spike-meter {
  height: 8px;
  border-radius: 999px;
  background: var(--inset);
  border: 1px solid var(--glass-border);
  overflow: hidden;
}

.spike-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
  transition: width 0.42s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s var(--ease);
}

/* ===== Export ===== */
.export-bar {
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.share-inline {
  display: flex;
  flex: 1;
  min-width: 220px;
  gap: 8px;
}

.share-field {
  flex: 1;
  font-size: 0.78rem;
}

/* ===== Tool extra ===== */
.tool-extra-actions {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

.tool-toggle-btn {
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(1.2);
  color: var(--text);
  border: 1px solid var(--glass-border);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform var(--t-fast) var(--ease-spring), box-shadow var(--t-fast) var(--ease),
    border-color var(--t-fast) var(--ease);
}

.tool-toggle-btn:hover {
  transform: translateY(-3px);
  border-color: rgba(14, 165, 233, 0.4);
  box-shadow: 0 16px 48px -8px var(--accent-glow);
}

.tool-toggle-btn:focus-visible {
  outline: none;
  box-shadow: var(--ring), var(--shadow);
}

/* ===== Tooltip ===== */
.tooltip-pop {
  position: fixed;
  z-index: 100000;
  max-width: min(300px, calc(100vw - 24px));
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.45;
  letter-spacing: 0.01em;
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08), 0 20px 48px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px) scale(0.98);
  transform-origin: top center;
  transition: opacity 0.22s var(--ease-out), transform 0.26s var(--ease-spring);
}

.tooltip-pop.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

[data-theme="dark"] .tooltip-pop {
  background: rgba(2, 6, 23, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

@media (prefers-reduced-motion: reduce) {
  .tooltip-pop {
    transition: none;
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

/* ===== High contrast ===== */
body.high-contrast .glass,
body.high-contrast .graph-card,
body.high-contrast .playback,
body.high-contrast .throttle-card {
  border-width: 2px;
}

body.high-contrast .btn.primary {
  box-shadow: none;
}

/* ===== Legal popup ===== */
.legal-popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
  animation: fadeIn 0.35s var(--ease);
}

.legal-popup-box {
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-radius: 22px;
  padding: 28px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.04), 0 28px 72px rgba(0, 0, 0, 0.22);
  text-align: center;
  animation: dialogLift 0.4s var(--ease-out) both;
}

@keyframes dialogLift {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .legal-popup-box {
    animation: none;
  }
}

[data-theme="dark"] .legal-popup-box {
  background: #0f172a;
  color: #f1f5f9;
}

.legal-popup-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

.legal-popup-box h3 {
  margin: 0 0 14px;
  font-size: 1.35rem;
}

.legal-popup-box p {
  color: #4b5563;
  font-size: 0.95rem;
  line-height: 1.65;
  margin: 0 0 14px;
}

[data-theme="dark"] .legal-popup-box p {
  color: #94a3b8;
}

.legal-popup-box button {
  margin-top: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px 24px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.legal-popup-box button:hover {
  transform: translateY(-2px);
}

/* ===== Embed popup ===== */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
  min-height: 100vh;
}

.popup-overlay.active {
  display: flex;
  animation: fadeIn 0.28s var(--ease);
}

.popup-box {
  width: 100%;
  max-width: 640px;
  background: #fff;
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 32px 80px rgba(0, 0, 0, 0.28);
  position: relative;
  max-height: calc(100vh - 40px);
  overflow: auto;
  color: #111827;
  animation: dialogLift 0.38s var(--ease-out) both;
}

@media (prefers-reduced-motion: reduce) {
  .popup-box {
    animation: none;
  }
}

[data-theme="dark"] .popup-box {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #1e293b;
}

.popup-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  font-size: 18px;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease-spring),
    box-shadow var(--t-fast) var(--ease);
}

.popup-close:hover {
  transform: scale(1.06);
  background: #e2e8f0;
}

.popup-close:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

[data-theme="dark"] .popup-close {
  background: #1e293b;
  color: #f8fafc;
}

[data-theme="dark"] .popup-close:hover {
  background: #334155;
}

.embed-box h3 {
  margin-top: 0;
}

.embed-box p {
  color: #64748b;
  font-size: 0.95rem;
}

[data-theme="dark"] .embed-box p {
  color: #94a3b8;
}

textarea#embedCode {
  width: 100%;
  min-height: 140px;
  margin-top: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 14px;
  resize: vertical;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
}

[data-theme="dark"] textarea#embedCode {
  background: #020617;
  color: #e2e8f0;
  border-color: #334155;
}

.copy-btn {
  margin-top: 14px;
  background: #10b981;
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform var(--t-fast) var(--ease-spring), filter var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

.copy-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.copy-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.45);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  body.is-loaded .layout > aside > *,
  body.is-loaded .layout > main > * {
    animation: riseIn 0.52s var(--ease-out) backwards;
  }

  body.is-loaded .layout > aside > *:nth-child(1) {
    animation-delay: 0.02s;
  }
  body.is-loaded .layout > aside > *:nth-child(2) {
    animation-delay: 0.05s;
  }
  body.is-loaded .layout > aside > *:nth-child(3) {
    animation-delay: 0.08s;
  }
  body.is-loaded .layout > aside > *:nth-child(4) {
    animation-delay: 0.1s;
  }
  body.is-loaded .layout > aside > *:nth-child(5) {
    animation-delay: 0.12s;
  }
  body.is-loaded .layout > aside > *:nth-child(6) {
    animation-delay: 0.14s;
  }
  body.is-loaded .layout > aside > *:nth-child(7) {
    animation-delay: 0.16s;
  }
  body.is-loaded .layout > aside > *:nth-child(8) {
    animation-delay: 0.18s;
  }
  body.is-loaded .layout > aside > *:nth-child(9) {
    animation-delay: 0.2s;
  }

  body.is-loaded .layout > main > *:nth-child(1) {
    animation-delay: 0.04s;
  }
  body.is-loaded .layout > main > *:nth-child(2) {
    animation-delay: 0.07s;
  }
  body.is-loaded .layout > main > *:nth-child(3) {
    animation-delay: 0.09s;
  }
  body.is-loaded .layout > main > *:nth-child(4) {
    animation-delay: 0.11s;
  }
  body.is-loaded .layout > main > *:nth-child(5) {
    animation-delay: 0.13s;
  }
  body.is-loaded .layout > main > *:nth-child(6) {
    animation-delay: 0.15s;
  }
}

@media (max-width: 600px) {
  .preset-grid {
    grid-template-columns: 1fr;
  }

  .top-bar {
    padding: 14px;
  }
}
