:root {
  color-scheme: light;
  --ink: #182724;
  --muted: #66736f;
  --line: #d9ddd7;
  --blue: #0072b2;
  --blue-dark: #005a8c;
  --soft: #f4f5f3;
  --focus: #0072b2;
}

* { box-sizing: border-box; }
html, body { margin: 0; color: var(--ink); background: #fff; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
.site-header { min-height: 62px; padding: 8px clamp(20px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid rgba(24, 39, 36, 0.1); }
.course-title { display: flex; flex-direction: column; color: var(--ink); font-size: 1.05rem; font-weight: 750; line-height: 1.05; text-decoration: none; }
.course-title small { margin-top: 4px; color: var(--muted); font-size: 0.68rem; font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-link { padding: 8px 12px; color: var(--ink); background: #e5e7eb; border-radius: 7px; font-size: 0.8rem; font-weight: 700; line-height: 1; text-decoration: none; }
.top-link:hover { background: #d1d5db; }

main { width: min(1280px, calc(100% - 28px)); margin: 0 auto; padding: 12px 0 10px; }
.intro { min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
h1 { margin: 0; font: 500 clamp(2rem, 3.6vw, 3.5rem)/0.98 Georgia, "Times New Roman", serif; letter-spacing: -0.045em; }
.intro p { margin: 7px 0 0; color: var(--muted); font-size: 0.78rem; }
.demo-qr { flex: 0 0 auto; line-height: 0; }
.demo-qr img { width: 88px; height: 88px; display: block; }

.source-controls { padding: 8px 10px; display: grid; grid-template-columns: minmax(240px, 420px) auto auto minmax(220px, 1fr); gap: 9px; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
audio { width: 100%; height: 36px; display: block; }
button, .audio-upload { min-height: 36px; padding: 0 13px; display: grid; place-items: center; color: #fff; background: var(--blue); border: 0; border-radius: 6px; font: inherit; font-size: 0.74rem; font-weight: 750; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled), .audio-upload:hover { background: var(--blue-dark); }
button:disabled { cursor: default; opacity: 0.45; }
.audio-upload input { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
#microphone-button[aria-pressed="true"] { color: var(--ink); background: #e5e7eb; }
#source-status { color: var(--muted); font-size: 0.68rem; text-align: right; }
#source-status.is-error, .runtime-status.is-error { color: #9c2f00; }

.analyzer-controls { margin-top: 7px; padding: 8px 10px; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); column-gap: 14px; row-gap: 3px; border: 1px solid var(--line); border-radius: 8px; }
.analyzer-controls label { display: flex; justify-content: space-between; gap: 8px; color: var(--ink); font-size: 0.69rem; font-weight: 750; }
.analyzer-controls output { color: var(--blue-dark); font-variant-numeric: tabular-nums; text-align: right; }
.analyzer-controls input { width: 100%; accent-color: var(--blue); cursor: pointer; }
.analyzer-controls label:nth-of-type(1), #fft-size { grid-column: 1; }
.analyzer-controls label:nth-of-type(2), #update-rate { grid-column: 2; }
.analyzer-controls label:nth-of-type(3), #color-min { grid-column: 3; }
.analyzer-controls label:nth-of-type(4), #color-max { grid-column: 4; }
.analyzer-controls label:nth-of-type(5), #time-min { grid-column: 5; }
.analyzer-controls label:nth-of-type(6), #time-max { grid-column: 6; }
.analyzer-controls label { grid-row: 1; }
.analyzer-controls input { grid-row: 2; }

.workspace { height: clamp(520px, calc(100vh - 286px), 720px); margin-top: 7px; display: grid; grid-template-columns: minmax(320px, 0.72fr) minmax(0, 1.28fr); gap: 7px; }
.code-card, .plot-card { min-width: 0; min-height: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.code-card { padding: 10px; display: flex; flex-direction: column; }
.card-heading { min-height: 38px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-heading h2, .plot-heading h2 { margin: 0; font: 500 1.05rem Georgia, "Times New Roman", serif; }
.card-heading span, .plot-heading span { color: var(--muted); font-size: 0.64rem; }
#run-code { min-height: 30px; padding: 0 10px; }
textarea { width: 100%; flex: 1; min-height: 0; padding: 10px; resize: none; color: #dfe7e4; background: #17211f; border: 0; border-radius: 5px; font: 500 0.72rem/1.42 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 4; }
.runtime-status { min-height: 24px; padding-top: 6px; color: var(--muted); font-size: 0.67rem; }

.analyzer { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(110px, 0.2fr) minmax(130px, 0.25fr) minmax(240px, 0.55fr); gap: 7px; }
.plot-card { padding: 8px; display: flex; flex-direction: column; }
.plot-heading { min-height: 26px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.plot-heading span { text-align: right; font-variant-numeric: tabular-nums; }
canvas { display: block; background: var(--soft); }
#waveform-canvas { width: 100%; flex: 1; min-height: 100px; }
#spectrum-canvas { width: 100%; flex: 1; min-height: 110px; }
.waterfall-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 54px; gap: 7px; }
#waterfall-canvas { width: 100%; height: 100%; min-height: 180px; }
.colorbar-wrap { min-height: 0; display: grid; grid-template-rows: auto 1fr auto; gap: 4px; color: var(--muted); font-size: 0.58rem; font-variant-numeric: tabular-nums; text-align: center; }
#colorbar-canvas { width: 18px; height: 100%; min-height: 100px; justify-self: center; }
.site-footer { padding: 5px 20px 8px; color: var(--muted); font-size: 0.7rem; text-align: center; }
button:focus-visible, input:focus-visible, textarea:focus-visible, audio:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

@media (max-width: 760px) {
  .site-header { align-items: flex-start; flex-direction: column; gap: 8px; }
  .top-actions { width: 100%; }
  .top-link { flex: 1; text-align: center; }
  main { width: calc(100% - 12px); padding-top: 7px; }
  .intro { min-height: 70px; }
  h1 { font-size: 1.9rem; }
  .intro p { font-size: 0.66rem; }
  .demo-qr img { width: 58px; height: 58px; }
  .source-controls { padding: 6px; grid-template-columns: 1fr 1fr; gap: 6px; }
  .source-controls audio { grid-column: 1 / 3; }
  #source-status { grid-column: 1 / 3; min-height: 16px; text-align: left; }
  .analyzer-controls { padding: 6px; grid-template-columns: 1fr 1fr; column-gap: 12px; row-gap: 3px; }
  .analyzer-controls label:nth-of-type(1), #fft-size { grid-column: 1; }
  .analyzer-controls label:nth-of-type(2), #update-rate { grid-column: 2; }
  .analyzer-controls label:nth-of-type(3), #color-min { grid-column: 1; }
  .analyzer-controls label:nth-of-type(4), #color-max { grid-column: 2; }
  .analyzer-controls label:nth-of-type(5), #time-min { grid-column: 1; }
  .analyzer-controls label:nth-of-type(6), #time-max { grid-column: 2; }
  .analyzer-controls label:nth-of-type(1), .analyzer-controls label:nth-of-type(2) { grid-row: 1; }
  #fft-size, #update-rate { grid-row: 2; }
  .analyzer-controls label:nth-of-type(3), .analyzer-controls label:nth-of-type(4) { grid-row: 3; }
  #color-min, #color-max { grid-row: 4; }
  .analyzer-controls label:nth-of-type(5), .analyzer-controls label:nth-of-type(6) { grid-row: 5; }
  #time-min, #time-max { grid-row: 6; }
  .analyzer-controls label { font-size: 0.61rem; flex-direction: column; gap: 1px; }
  .analyzer-controls output { text-align: left; }
  .workspace { height: auto; grid-template-columns: 1fr; gap: 6px; }
  .code-card { height: 245px; padding: 6px; }
  .card-heading { min-height: 34px; }
  .card-heading h2, .plot-heading h2 { font-size: 0.83rem; }
  .card-heading span { display: none; }
  textarea { padding: 7px; font-size: 0.65rem; line-height: 1.36; }
  .analyzer { height: 700px; grid-template-rows: 150px 180px 358px; gap: 6px; }
  .plot-card { padding: 5px; }
  .plot-heading { min-height: 23px; }
  .plot-heading span { font-size: 0.55rem; }
  .waterfall-layout { grid-template-columns: minmax(0, 1fr) 46px; gap: 4px; }
}
