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

body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: #f3f4f7;
  color: #222;
}

.app {
  max-width: 1920px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.audio-group,
.preset-group,
.top-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.audio-group .audio-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.audio-group .audio-controls input[type="range"] {
  width: 80px;
}

.audio-group .checkbox {
  margin: 0;
}

.top-title {
  font-weight: 600;
  color: #2c3e50;
  flex: 1;
  text-align: center;
}


.top-actions button,
.control-row button,
.audio-group button {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: #667eea;
  color: #fff;
  cursor: pointer;
}

.explainer-btn {
  padding: 8px 14px;
  border-radius: 8px;
  background: #2ecc71;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

.explainer-btn:hover {
  background: #27ae60;
}

.top-actions button:active,
.control-row button:active,
.audio-group button:active {
  transform: translateY(1px);
}

.main {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  min-width: 0;
}

.main > .controls {
  min-width: 0;
  overflow: hidden;
}

.controls {
  display: grid;
  gap: 12px;
}

.main > .plots {
  min-width: 0;
}

.control-section {
  background: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  display: grid;
  gap: 8px;
}

.control-section h3 {
  font-size: 1rem;
  color: #444;
}

.control-row {
  display: grid;
  gap: 6px;
}

.control-row.inline {
  display: flex;
  gap: 16px;
}

.control-row input[type="range"],
.control-row select,
.control-row input[type="number"] {
  width: 100%;
}

.checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
}

.tab-row {
  display: flex;
  gap: 8px;
}

.tab {
  flex: 1;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #ccc;
  background: #f6f6f6;
  cursor: pointer;
}

.tab.active {
  background: #667eea;
  color: #fff;
  border-color: #667eea;
}

.hidden {
  display: none;
}


.plots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.plot-card {
  background: #fff;
  padding: 12px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.waveform-card {
  position: relative;
}

.waveform-readout {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  pointer-events: none;
}

.spectrum-card {
  position: relative;
  display: inline-block;
}

.spectrum-readout {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
  pointer-events: none;
}

.spectrum-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 8px;
  font-size: 0.9rem;
  color: #444;
}

.spectrum-legend .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.spectrum-legend .legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.spectrum-legend .legend-mag {
  background: #4ade80;
}

.spectrum-legend .legend-phi {
  background: #a855f7;
}

.spectrum-legend .legend-tex {
  display: inline-flex;
  align-items: center;
}

.spectrum-legend .legend-tex .katex {
  font-size: 1.25em;
}

.phasor-caption {
  font-size: 0.9rem;
  color: #555;
  margin: 0 0 8px 0;
  line-height: 1.4;
}

.build-wave-terms {
  margin-top: 10px;
  overflow-x: auto;
  font-size: 0.95rem;
  color: #333;
}

.build-wave-terms .katex-display {
  margin: 0;
}

.build-wave-term-mode {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 0.9rem;
  color: #444;
}

.build-wave-term-mode .radio-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.build-wave-term-mode .radio-label input {
  cursor: pointer;
}

.plot-card canvas {
  width: 100%;
  height: auto;
  display: block;
}

.audio-controls {
  display: grid;
  gap: 4px;
}

.explainer-page .app {
  max-width: 980px;
}

.explainer-content {
  background: #fff;
  padding: 22px 24px;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  display: grid;
  gap: 16px;
  line-height: 1.6;
}

.explainer-content h2 {
  font-size: 1.5rem;
  color: #2c3e50;
}

.explainer-content h3 {
  font-size: 1.1rem;
  color: #444;
}

.explainer-content ul {
  padding-left: 18px;
  display: grid;
  gap: 8px;
}

.tex-block {
  margin: 8px 0 12px;
  overflow-x: auto;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
}

@media (max-width: 980px) {
  .main {
    grid-template-columns: 1fr;
  }
  .plots {
    grid-template-columns: 1fr;
  }
}
