/* ─────────────────────────────────────────────────────────
   Math Sonifier — light, elegant, scientific
   ───────────────────────────────────────────────────────── */

:root {
  /* Palette */
  --bg:        #f5f3ef;
  --surface:   #ffffff;
  --surface-2: #f0ede8;
  --border:    #e4e0d9;
  --border-2:  #ccc8c0;

  --ink:   #1b1917;
  --ink-2: #57534e;
  --ink-3: #a8a29e;
  --ink-4: #d4cfc8;

  --violet:       #5344c2;
  --violet-mid:   #7c6fda;
  --violet-light: #eceafc;
  --amber:        #c97c12;
  --amber-mid:    #e09030;
  --amber-light:  #fef3c7;
  --emerald:      #047857;
  --emerald-light:#d1fae5;
  --red:          #dc2626;
  --red-light:    #fef2f2;

  /* Typography */
  --font-ui:      'DM Sans', system-ui, sans-serif;
  --font-mono:    'Space Mono', 'Courier New', monospace;
  --font-display: 'Syne', sans-serif;

  /* Radii & shadows */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 16px;
  --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); }

/* ── Header ─────────────────────────────────────────────── */
header {
  width: 100%;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

/* The way back to the page that links here. */
.brand-back {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-decoration: none;
  transition: color 0.18s ease;
}

.brand-back:hover {
  color: var(--violet);
}

h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--violet);
}

.header-sub {
  font-size: 0.7rem;
  color: var(--ink-3);
  letter-spacing: 0.02em;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ink-3);
  letter-spacing: 0.06em;
}

/* ── Main container ─────────────────────────────────────── */
main {
  width: 100%;
  max-width: 1040px;
  padding: 20px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Card base ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-card);
}

/* ── Equation card ──────────────────────────────────────── */
.eq-card {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.eq-display-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  user-select: none;
}

.eq-render {
  flex: 1;
  font-size: 1.1rem;
  color: var(--violet);
  min-height: 28px;
  overflow-x: auto;
  padding: 2px 0;
  /* KaTeX renders inline; this lets it scroll if too wide */
}

.eq-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.input-field-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

math-field#eqInput {
  /* MathLive theme variables */
  --caret-color: var(--violet);
  --selection-background-color: rgba(83, 68, 194, 0.13);
  --selection-color: var(--ink);
  --contains-highlight-background-color: rgba(83, 68, 194, 0.05);
  --smart-fence-color: var(--violet-mid);
  --placeholder-color: var(--ink-4);
  --highlight-inactive-color: rgba(83, 68, 194, 0.08);
  /* Force light rendering inside the shadow DOM */
  color-scheme: light;
  width: 100%;
  font-size: 1rem;
  padding: 6px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--ink);
  box-sizing: border-box;
  transition: border-color 0.15s;
}
math-field#eqInput:focus-within {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(83, 68, 194, 0.08);
  outline: none;
}

.input-hint {
  font-size: 0.62rem;
  color: var(--ink-3);
  padding-left: 2px;
}
.input-hint code {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 3px;
  color: var(--violet);
}

/* ── Math symbol toolbar ───────────────────────────── */
.math-toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  align-items: center;
}
.math-tb-btn {
  font-size: 0.68rem;
  padding: 3px 8px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  cursor: pointer;
  font-family: var(--font-mono);
  line-height: 1;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  white-space: nowrap;
}
.math-tb-btn:hover {
  border-color: var(--violet-mid);
  color: var(--violet);
  background: var(--violet-light);
}
.math-tb-sep {
  width: 1px;
  height: 18px;
  background: var(--border-2);
  margin: 0 3px;
  flex-shrink: 0;
}

.presets-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.preset-btn {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 4px 11px;
  border-radius: 99px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.preset-btn:hover {
  border-color: var(--violet-mid);
  color: var(--violet);
  background: var(--violet-light);
}
.preset-btn.active {
  background: var(--violet);
  border-color: var(--violet);
  color: #fff;
}

.eq-meta {
  font-size: 0.62rem;
  color: var(--ink-3);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.card-error {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--red);
  background: var(--red-light);
  border: 1px solid #fecaca;
  border-radius: var(--r-sm);
  padding: 8px 12px;
}

/* ── Visual grid ────────────────────────────────────────── */
.visuals-grid {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 14px;
}

/* ── Canvas cards ───────────────────────────────────────── */
.canvas-card {
  position: relative;
  overflow: hidden;
  padding: 0;
}

canvas { display: block; }

.canvas-label {
  position: absolute;
  top: 11px;
  left: 14px;
  font-size: 0.57rem;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 2;
}

/* ── Controls card ──────────────────────────────────────── */
.controls-card {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sliders-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.slider-label {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--violet);
}

input[type=range] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  accent-color: var(--violet);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--violet);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(83, 68, 194, .25);
  transition: box-shadow 0.12s;
}
input[type=range]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px var(--violet-light);
}
input[type=range]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: none;
  border-radius: 50%;
  background: var(--violet);
  cursor: pointer;
}

/* ── Actions row ────────────────────────────────────────── */
.actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.12s, box-shadow 0.12s;
  padding: 9px 20px;
  white-space: nowrap;
}

.btn-primary {
  background: var(--violet);
  color: #fff;
}
.btn-primary:hover { background: #4334a8; }

.btn-play {
  background: var(--emerald);
  color: #fff;
}
.btn-play:hover { background: #036647; }

.btn-stop {
  background: transparent;
  border: 1.5px solid var(--border-2);
  color: var(--ink-2);
}
.btn-stop:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-light);
}

/* ── Readouts ───────────────────────────────────────────── */
.readouts {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-left: 4px;
}

.readout {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.readout-key {
  font-size: 0.55rem;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.readout-val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--violet);
}

/* ── Status dot ─────────────────────────────────────────── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-4);
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.2s, box-shadow 0.2s;
}
.status-dot.active {
  background: var(--emerald);
  box-shadow: 0 0 0 3px var(--emerald-light);
  animation: blink 1.4s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { box-shadow: 0 0 0 3px var(--emerald-light); }
  50%       { box-shadow: 0 0 0 6px rgba(4, 120, 87, .08); }
}

/* ── EQ bars ────────────────────────────────────────────── */
.eq-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 28px;
  padding-left: 6px;
}
.eq-bar {
  width: 3px;
  height: 3px;
  background: var(--violet-mid);
  border-radius: 2px 2px 0 0;
  opacity: 0.7;
  transition: height 0.06s ease;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 680px) {
  .visuals-grid {
    grid-template-columns: 1fr;
  }
  .header-inner { padding: 10px 16px; }
  main { padding: 14px 12px 40px; }
  .eq-card, .controls-card { padding: 16px; }
}
