/* =========================================================
   Aacoustic — rich theory section (engaging, interactive)
   Loaded after calculator.css; reuses its CSS variables.
   ========================================================= */

.theory-rich { padding: 0; }
.theory-rich > summary {
  font-size: 1.1rem;
}
.theory-rich__inner {
  padding: 4px 22px 24px;
}

/* ── Tabs ───────────────────────────────────────────────── */
.theory-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--color-border);
  margin: 6px 0 20px;
  flex-wrap: wrap;
}
.theory-tab {
  appearance: none;
  border: none;
  background: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text-soft);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.theory-tab:hover { color: var(--color-text); }
.theory-tab.is-active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}
.theory-tab:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

.theory-panel { animation: theory-fade 0.25s var(--ease); }
.theory-panel[hidden] { display: none; }
@keyframes theory-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.theory-panel h3 {
  font-size: 1.12rem;
  margin: 26px 0 8px;
  color: var(--color-text);
}
.theory-panel p { color: var(--color-text-muted); line-height: 1.65; margin: 0 0 14px; }
.theory-panel .lead {
  font-size: 1.05rem;
  color: var(--color-text);
}
.theory-panel a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.theory-panel a:hover { text-decoration: underline; }

/* ── Formula blocks ─────────────────────────────────────── */
.formula-block {
  background: var(--color-surface-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 6px 0 16px;
  overflow-x: auto;
  text-align: center;
}

/* ── Callouts ───────────────────────────────────────────── */
.callout {
  border-radius: var(--radius-md);
  padding: 14px 18px;
  margin: 18px 0;
  line-height: 1.6;
  color: var(--color-text);
}
.callout-key {
  background: var(--color-primary-soft);
  border-left: 4px solid var(--color-primary);
}
.callout-warn {
  background: var(--color-danger-soft);
  border-left: 4px solid var(--color-danger);
}
.callout-warn ul { margin: 8px 0 0; padding-left: 20px; }
.callout-warn li { margin: 4px 0; color: var(--color-text-muted); }

/* ── Widgets (shared) ───────────────────────────────────── */
.widget {
  margin: 18px 0;
  padding: 18px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #ffffff, var(--color-surface-subtle));
  box-shadow: var(--shadow-sm);
}
.widget-title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--color-text);
  margin-bottom: 12px;
}
.widget-canvas { width: 100%; display: block; }
.widget-note { font-size: 0.86rem; color: var(--color-text-soft); margin: 8px 0 0; }

.slider-row { margin: 10px 0; }
.slider-row label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 6px;
}
.slider-row output { color: var(--color-primary); font-variant-numeric: tabular-nums; }
.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
  height: 22px;
  cursor: pointer;
}

/* readouts */
.combiner-readout, .doubler-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: baseline;
  margin-top: 12px;
}
.ro { display: flex; flex-direction: column; gap: 2px; }
.ro-lab { font-size: 0.78rem; color: var(--color-text-soft); text-transform: uppercase; letter-spacing: 0.02em; }
.ro-val { font-size: 1.5rem; font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums; }
.ro-val.small { font-size: 1.1rem; color: var(--color-primary); }
.ro-main .ro-val { color: var(--color-success-hover); }
.ro-val.wrong { color: var(--color-danger); text-decoration: line-through; font-size: 1rem; font-weight: 600; }
.ro-wrong { margin-left: auto; text-align: right; }
.ro-wrong .ro-lab { text-decoration: none; }

.addchart-read {
  background: var(--color-surface-soft);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 8px 0 0;
  color: var(--color-text);
  font-size: 0.95rem;
}

/* doubler machines */
.doubler-machines {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 1.4rem;
  line-height: 1.2;
  min-height: 30px;
  margin: 6px 0;
}
.speaker { animation: pop 0.25s var(--ease); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Sound-level ladder ─────────────────────────────────── */
.ladder { margin: 22px 0; }
.ladder-svg { width: 100%; height: auto; }
.lad-grid { stroke: var(--color-border); stroke-width: 1; stroke-dasharray: 3 3; }
.lad-db { fill: var(--color-text); font: 700 13px Inter, system-ui, sans-serif; }
.lad-lab { fill: var(--color-text-muted); font: 500 12.5px Inter, system-ui, sans-serif; }

/* ── Rules list ─────────────────────────────────────────── */
.rules-list { margin: 6px 0 14px; padding-left: 20px; }
.rules-list li { margin: 6px 0; color: var(--color-text-muted); }

/* ── Examples table ─────────────────────────────────────── */
.examples-table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 16px;
  font-size: 0.95rem;
}
.examples-table th, .examples-table td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
}
.examples-table thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-soft);
}
.examples-table .ex-calc { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--color-text); }
.examples-table .ex-res { font-weight: 700; color: var(--color-success-hover); white-space: nowrap; }

/* ── Related-tool link cards ────────────────────────────── */
.theory-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 6px 0 16px;
}
.theory-link-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.theory-link-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  text-decoration: none !important;
}
.tl-title { font-weight: 700; color: var(--color-primary); }
.tl-desc { font-size: 0.88rem; color: var(--color-text-muted); font-weight: 400; }

.theory-sources {
  font-size: 0.82rem;
  color: var(--color-text-soft);
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
  margin-top: 20px;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 560px) {
  .theory-rich__inner { padding: 4px 14px 20px; }
  .ro-wrong { margin-left: 0; text-align: left; }
  .ro-val { font-size: 1.3rem; }
}

/* ── Prominent, inviting theory header (refinement) ─────── */
.card.theory-rich { overflow: hidden; }
.theory-rich > summary {
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--color-primary-hover);
  background: var(--color-primary-soft);
  border-radius: var(--radius-lg);
  transition: background 0.15s var(--ease);
}
.theory-rich > summary:hover { background: #e0ecff; }
details.theory-rich[open] > summary {
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: 1px solid var(--color-border);
}
.theory-badge {
  margin-left: auto;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--color-primary);
  color: #ffffff;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ── Result card header row (share button inline, no gap before theory) ── */
.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.card-head-row h2 { margin: 0; }
.card-head-row .tool-actions { margin: 0; }

/* ── "Comprendre la théorie" jump link — top-left of the formula card, discreet ── */
.theory-jump {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-soft);
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s var(--ease);
}
.theory-jump:hover { color: var(--color-primary); }
.theory-jump svg { transition: transform 0.15s var(--ease); }
.theory-jump:hover svg { transform: translateY(1px); }
.theory-jump:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* Theory jump on the same line as the "Formula" title */
.formula-head {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.formula-head h2 { margin: 0; }
.formula-head .theory-jump { margin: 0 0 0 auto; }

/* ── Directivity (Q) widget: config buttons + schematic grid ── */
.dir-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.dir-btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.dir-btn:hover { border-color: var(--color-primary); }
.dir-btn.is-active { border-color: var(--color-primary); background: var(--color-primary-soft); }
.dir-btn__q { font-weight: 700; font-size: 0.9rem; color: var(--color-primary); }
.dir-btn__name { font-size: 0.78rem; color: var(--color-text-muted); }
.dir-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.dir-grid {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

/* ── Directivity 3D stage (Three.js mount) ── */
.dir-stage {
  width: 320px;
  max-width: 100%;
  height: 280px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  overflow: hidden;
  touch-action: none;
  position: relative;
}
.dir-stage canvas { display: block; }
.dir-fallback {
  margin: 0; padding: 16px;
  font-size: 0.9rem; color: var(--color-text-muted);
}

/* ── Octave spectrum widget toolbar + legend ── */
.spec-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 12px;
}
.spec-legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.spec-legend .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.spec-legend .dot-third { background: var(--color-primary); }
.spec-legend .dot-oct { background: var(--color-success); }
