:root {
  color-scheme: light;
  --ink: #182724;
  --muted: #66736f;
  --line: #d9ddd7;
  --blue: #0072b2;
  --blue-dark: #005a8c;
  --coral: #d55e00;
  --gold: #e69f00;
  --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: 20px; 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 8px; }
.intro { display: flex; align-items: flex-end; 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; }
.book-reference { margin-top: 6px; display: inline-block; color: var(--blue); font-size: 0.72rem; font-weight: 700; text-decoration: none; }
.book-reference:hover { text-decoration: underline; }
.demo-qr { flex: 0 0 auto; line-height: 0; }
.demo-qr img { width: 88px; height: 88px; display: block; }

.equations { margin-top: 8px; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto 1.55fr; gap: 14px; align-items: center; background: var(--soft); border: 1px solid var(--line); border-radius: 8px; font-size: 0.82rem; }
.equations > div { min-width: 0; overflow: hidden; text-align: center; }

.controls { margin-top: 8px; padding: 8px 12px; display: grid; grid-template-columns: minmax(260px, 0.85fr) minmax(260px, 1.15fr) auto auto minmax(210px, 0.75fr); gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; }
.controls label { min-width: 0; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.controls output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; margin: 0; accent-color: var(--blue); cursor: pointer; }
button { min-height: 36px; padding: 0 14px; color: #fff; background: var(--blue); border: 0; border-radius: 6px; font: inherit; font-size: 0.76rem; font-weight: 750; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled) { background: var(--blue-dark); }
button:disabled { cursor: default; opacity: 0.45; }
.secondary-button { color: var(--ink); background: #e5e7eb; }
.secondary-button:hover:not(:disabled) { background: #d1d5db; }
.runtime-status { min-width: 0; color: var(--muted); font-size: 0.69rem; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.runtime-status.is-error { color: #9c2f00; }

.workspace { height: clamp(430px, calc(100vh - 326px), 590px); margin-top: 8px; display: grid; grid-template-columns: minmax(340px, 0.78fr) minmax(0, 1.22fr); gap: 8px; }
.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, .plot-heading { min-height: 28px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-heading h2, .plot-heading h2 { margin: 0; font: 500 1rem Georgia, "Times New Roman", serif; }
.card-heading span, .plot-heading span { color: var(--muted); font-size: 0.65rem; }
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; }

.plot-stack { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(180px, 0.82fr) minmax(220px, 1.18fr); gap: 8px; }
.plot-card { padding: 9px; display: flex; flex-direction: column; }
.sum-card { border-color: #b5cbd7; }
.canvas-wrap { position: relative; min-height: 0; flex: 1; }
canvas { width: 100%; height: 100%; display: block; }
.axis-label { position: absolute; color: var(--muted); font: italic 0.72rem Georgia, "Times New Roman", serif; pointer-events: none; }
.axis-y { left: 5px; top: 5px; }
.axis-x { right: 7px; bottom: 2px; }
.component-labels { position: absolute; inset: 0; pointer-events: none; }
.component-labels span { position: absolute; left: 4px; color: var(--muted); font: 0.62rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; transform: translateY(-50%); }

.metrics { min-height: 28px; padding: 6px 12px 0; display: flex; justify-content: flex-end; gap: 24px; color: var(--muted); font-size: 0.69rem; font-variant-numeric: tabular-nums; }
.metrics b { color: var(--ink); }
.site-footer { padding: 0 20px 8px; color: var(--muted); font-size: 0.7rem; text-align: center; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

@media (max-width: 800px) {
  .controls { grid-template-columns: 1fr 1fr auto auto; }
  .runtime-status { grid-column: 1 / -1; text-align: left; }
  .workspace { grid-template-columns: minmax(300px, 0.72fr) minmax(0, 1.28fr); }
}

@media (max-width: 650px) {
  .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: 8px; }
  .intro { align-items: flex-start; }
  h1 { font-size: 1.9rem; }
  .book-reference { font-size: 0.64rem; }
  .demo-qr img { width: 64px; height: 64px; }
  .equations { margin-top: 6px; padding: 6px; display: block; font-size: 0.68rem; }
  .equations > div { margin: 3px 0; overflow-x: auto; text-align: left; }
  .controls { padding: 6px; grid-template-columns: 1fr 1fr; gap: 6px; }
  .controls label, .controls input { grid-column: 1 / -1; }
  button { min-height: 34px; padding: 0 8px; font-size: 0.68rem; }
  .runtime-status { grid-column: 1 / -1; }
  .workspace { height: auto; grid-template-columns: 1fr; grid-template-rows: 210px 650px; gap: 6px; }
  .code-card { padding: 5px; }
  .card-heading { min-height: 22px; }
  .card-heading h2, .plot-heading h2 { font-size: 0.78rem; }
  .card-heading span { display: none; }
  textarea { padding: 6px; font-size: 0.64rem; line-height: 1.35; }
  .plot-stack { grid-template-rows: 250px 394px; gap: 6px; }
  .plot-card { padding: 5px; }
  .component-labels span { font-size: 0.54rem; }
  .metrics { padding: 5px 4px 0; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; font-size: 0.64rem; }
}

@media (prefers-reduced-motion: reduce) {
  input[type="range"] { scroll-behavior: auto; }
}
