/* ============================================================
   AM / FDM Modulation Demo — style.css
   Dark-mode, glassmorphic, premium educational UI
   ============================================================ */

/* ── Tokens ── */
:root {
  --bg: #0b0d14;
  --surface: #12151f;
  --surface2: #1a1e2e;
  --surface3: #222740;
  --border: rgba(255,255,255,0.07);
  --border-glow: rgba(99,102,241,0.35);

  --msg: #38bdf8;          /* sky-400 */
  --msg-glow: rgba(56,189,248,0.25);
  --carrier: #f97316;      /* orange-500 */
  --carrier-glow: rgba(249,115,22,0.25);
  --output: #a78bfa;       /* violet-400 */
  --output-glow: rgba(167,139,250,0.25);
  --envelope: #34d399;     /* emerald-400 */

  /* FDM channel colors */
  --ch1: #38bdf8;          /* sky */
  --ch1-glow: rgba(56,189,248,0.3);
  --ch2: #4ade80;          /* green */
  --ch2-glow: rgba(74,222,128,0.3);
  --ch3: #fb923c;          /* orange */
  --ch3-glow: rgba(251,146,60,0.3);

  --accent: #6366f1;       /* indigo-500 */
  --accent-light: #818cf8;
  --accent-glow: rgba(99,102,241,0.3);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;

  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 5px;

  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;

  --sidebar-w: 310px;
  --header-h: 54px;
  --fdm-ctrl-w: 260px;
  --transition: 0.2s cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 99px; }

/* ════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════ */
.app-header {
  height: var(--header-h);
  background: linear-gradient(180deg, #142233, #0d1620);
  border-bottom: 1px solid #22303f;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

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

.header-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.header-badge {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1.5px;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  box-shadow: 0 0 20px var(--accent-glow);
  flex-shrink: 0;
}

.header-title h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: 0;
}

.header-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
  display: block;
}

/* ── Mode Toggle ── */
.mode-toggle-wrap {
  display: flex;
  justify-content: center;
}

.mode-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px;
  gap: 2px;
}

.mode-btn {
  background: transparent;
  border: none;
  border-radius: 99px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 18px;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.mode-btn:hover { color: var(--text-secondary); }

.mode-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 14px var(--accent-glow);
}

/* Modulation status pills */
.mod-status-strip {
  display: flex;
  gap: 8px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 13px 5px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: var(--transition);
}

.status-pill .status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--surface3);
  transition: var(--transition);
}

.status-pill.active-undermod .status-dot { background: var(--msg); box-shadow: 0 0 8px var(--msg); }
.status-pill.active-undermod { color: var(--msg); border-color: rgba(56,189,248,0.3); }

.status-pill.active-fullmod .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-pill.active-fullmod { color: var(--green); border-color: rgba(34,197,94,0.3); }

.status-pill.active-overmod .status-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.status-pill.active-overmod { color: var(--red); border-color: rgba(239,68,68,0.3); }

/* ════════════════════════════════════════════
   SINGLE AM — main layout
   ════════════════════════════════════════════ */
.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 14px;
  overflow-y: auto;
}

/* Gauge Card */
.gauge-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.gauge-wrap {
  position: relative;
  width: 180px;
  height: 110px;
  flex-shrink: 0;
}

.gauge-center-label {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.1;
}

#mu-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  background: linear-gradient(90deg, var(--accent-light), var(--msg));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.gauge-unit {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.gauge-metrics {
  display: flex;
  gap: 12px;
  width: 100%;
}

.metric {
  flex: 1;
  background: var(--surface3);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}

.metric-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.metric-val {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-light);
}

/* Equation Card */
.equation-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.eq-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.eq-text {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-secondary);
  background: var(--surface3);
  border-radius: var(--radius-xs);
  padding: 7px 10px;
  line-height: 1.5;
}

/* Controls sections */
.controls-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.section-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.message-dot { background: var(--msg); box-shadow: 0 0 6px var(--msg-glow); }
.carrier-dot { background: var(--carrier); box-shadow: 0 0 6px var(--carrier-glow); }
.output-dot  { background: var(--output); box-shadow: 0 0 6px var(--output-glow); }

/* Slider Groups */
.slider-group { display: flex; flex-direction: column; gap: 5px; }

.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.slider-header label {
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.slider-header label sub { font-size: 9px; vertical-align: sub; }

.slider-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent-light);
  font-weight: 500;
  min-width: 70px;
  text-align: right;
}

/* Custom range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--surface3);
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: 0 0 10px var(--accent-glow);
  cursor: pointer;
  transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 16px var(--accent);
}

/* Single mode thumb colors */
#msg-amp::-webkit-slider-thumb  { background: var(--msg);      box-shadow: 0 0 10px var(--msg-glow); }
#msg-freq::-webkit-slider-thumb { background: var(--msg);      box-shadow: 0 0 10px var(--msg-glow); }
#msg-bias::-webkit-slider-thumb { background: var(--envelope); box-shadow: 0 0 10px rgba(52,211,153,0.3); }
#carr-amp::-webkit-slider-thumb { background: var(--carrier);  box-shadow: 0 0 10px var(--carrier-glow); }
#carr-freq::-webkit-slider-thumb{ background: var(--carrier);  box-shadow: 0 0 10px var(--carrier-glow); }

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9.5px;
  color: var(--text-muted);
  padding: 0 1px;
}

/* Reset button */
.reset-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 12px;
  padding: 9px 16px;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

.reset-btn:hover {
  background: var(--surface3);
  color: var(--text-primary);
  border-color: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

/* ── Plot panel ── */
.plot-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Tab bar */
.tab-bar {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 9px 18px 10px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  bottom: -1px;
}

.tab-btn svg { flex-shrink: 0; }
.tab-btn:hover { color: var(--text-secondary); background: var(--surface2); }
.tab-btn.active {
  color: var(--accent-light);
  background: var(--bg);
  border-color: var(--border);
  border-bottom-color: var(--bg);
}

/* Tab content */
.tab-content {
  display: none;
  flex: 1;
  overflow: hidden;
  padding: 0;
}

.tab-content.active { display: flex; flex-direction: column; }

/* Chart grid */
.chart-grid {
  flex: 1;
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 0;
  padding: 14px 16px;
  overflow: hidden;
  height: 100%;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  transition: border-color 0.2s;
}

.chart-card:hover { border-color: var(--border-glow); }

.chart-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.chart-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.env-legend {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 400;
  text-transform: none;
}

.env-dot {
  width: 14px;
  height: 2px;
  background: var(--envelope);
  border-radius: 99px;
  opacity: 0.8;
}

.chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ════════════════════════════════════════════
   FDM PANEL
   ════════════════════════════════════════════ */
.fdm-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  gap: 0;
}

/* Channel rows area */
.fdm-channels {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

/* Single channel row: controls | chart */
.fdm-row {
  flex: 1;
  display: flex;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

.fdm-row:last-child { border-bottom: none; }

/* ── Left control column ── */
.fdm-ctrl-col {
  width: var(--fdm-ctrl-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

/* Channel badge */
.channel-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  align-self: flex-start;
  /* button reset */
  background: none;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.18s, transform 0.12s, filter 0.18s;
  user-select: none;
}
.channel-badge:hover  { opacity: 0.8; transform: scale(0.97); }
.channel-badge:active { transform: scale(0.93); }

.ch1-badge { background: rgba(56,189,248,0.15); color: var(--ch1); border: 1px solid rgba(56,189,248,0.3); }
.ch2-badge { background: rgba(74,222,128,0.15); color: var(--ch2); border: 1px solid rgba(74,222,128,0.3); }
.ch3-badge { background: rgba(251,146,60,0.15); color: var(--ch3); border: 1px solid rgba(251,146,60,0.3); }

/* Channel disabled state — badge goes gray, row dims */
.ch-badge-off.ch1-badge,
.ch-badge-off.ch2-badge,
.ch-badge-off.ch3-badge {
  background: rgba(148,163,184,0.1);
  color: var(--text-muted);
  border-color: rgba(148,163,184,0.2);
  text-decoration: line-through;
  letter-spacing: 1px;
}

.fdm-row-disabled .fdm-ctrl-col > *:not(.channel-badge) {
  opacity: 0.3;
  pointer-events: none;
}
.fdm-row-disabled .fdm-chart-col {
  opacity: 0.15;
}

/* Message type toggle */
.fdm-ctrl-group { display: flex; flex-direction: column; gap: 5px; }

.fdm-ctrl-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
}

.type-toggle {
  display: flex;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  overflow: hidden;
}

.type-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  padding: 5px 4px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.type-btn:hover { color: var(--text-secondary); background: var(--surface3); }
.type-btn.active { background: var(--surface3); color: var(--text-primary); font-weight: 600; }

/* Sliders in FDM */
.fdm-slider-row {
  display: grid;
  grid-template-columns: 28px 1fr 62px;
  align-items: center;
  gap: 6px;
}

.fdm-slider-row label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.fdm-slider-row label sub { font-size: 8px; vertical-align: sub; }

.fdm-val {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--accent-light);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

/* Toggle pills (Bias / Noise / LPF) */
.fdm-toggles {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.toggle-pill input[type="checkbox"] { display: none; }

.toggle-track {
  width: 30px;
  height: 16px;
  border-radius: 99px;
  background: var(--surface3);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.toggle-pill input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.toggle-pill input:checked + .toggle-track::after {
  left: calc(100% - 13px);
  background: #fff;
}

.toggle-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* LPF cutoff row (shown when LPF is on) */
.lpf-cutoff-row {
  display: grid;
  grid-template-columns: 55px 1fr 62px;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius-xs);
}

.lpf-cutoff-row label {
  font-size: 10.5px;
  color: var(--accent-light);
  white-space: nowrap;
}

.lpf-cutoff-row label sub { font-size: 8px; vertical-align: sub; }

/* ── Right chart column ── */
.fdm-chart-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  gap: 4px;
  background: var(--bg);
}

.fdm-chart-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.ch1-color { color: var(--ch1); }
.ch2-color { color: var(--ch2); }
.ch3-color { color: var(--ch3); }

.fdm-chart-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ch1-dot { background: var(--ch1); box-shadow: 0 0 6px var(--ch1-glow); }
.ch2-dot { background: var(--ch2); box-shadow: 0 0 6px var(--ch2-glow); }
.ch3-dot { background: var(--ch3); box-shadow: 0 0 6px var(--ch3-glow); }

.fdm-chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.fdm-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Combined FDM Spectrum ── */
.fdm-combined {
  height: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 16px 10px;
  gap: 4px;
}

.fdm-combined-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  flex-shrink: 0;
  opacity: 0.85;
}

.fdm-combined-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.fdm-combined-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sidebar     { animation: fadeInUp 0.4s ease both; }
.plot-panel  { animation: fadeInUp 0.4s 0.1s ease both; }
.fdm-panel   { animation: fadeInUp 0.35s ease both; }

/* ── Overmod flash ── */
@keyframes overmodPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--red); }
  50%       { box-shadow: 0 0 12px 3px rgba(239,68,68,0.35); }
}

.status-pill.active-overmod { animation: overmodPulse 1.4s infinite; }

/* ── Back-to-library button ── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
}

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

.back-btn svg {
  flex-shrink: 0;
  opacity: 0.7;
}
