/* Feedback Systems, Chapter 2 deck.
   Style A, "night instrument": a dark oscilloscope-like ground, thin rules, mono labels.
   Layout: text column + visual column on wide screens; one column on phones (text head, visual, text body). */

:root {
  color-scheme: dark;
  /* ground and ink */
  --bg: #0b0e13;
  --panel: #10151c;
  --panel-2: #151b24;
  --line: #222a35;
  --line-2: #2f3947;
  --ink: #e7eaf0;
  --muted: #919bab;
  --faint: #5d6878;
  /* signal colors: one per role, used everywhere the signal appears */
  --sig-r: #dde3ec;   /* reference / command */
  --sig-e: #ff7096;   /* error */
  --sig-u: #44dda0;   /* control signal */
  --sig-v: #5aaaff;   /* disturbance (the outside push) */
  --sig-y: #ffa64d;   /* output */
  --sig-x: #b49cff;   /* internal states */
  --good: #44dda0;
  --bad: #ff6b6b;
  --accent: #ffa64d;
  /* type */
  --font-ui: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-3: clamp(1.6rem, 1.2rem + 1.6vw, 2.35rem);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- app frame ---------- */
.app {
  display: grid;
  grid-template-rows: 3px 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
}
.progress { background: var(--line); position: relative; overflow: hidden; }
.progress > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width .3s ease; }

.deck {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 28px;
}

/* ---------- slide ---------- */
.slide {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  gap: 18px 36px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "viz" "body";
}
@media (min-width: 980px) {
  .slide.has-viz {
    grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
    grid-template-areas: "head viz" "body viz";
    grid-template-rows: auto 1fr;
    align-items: start;
    padding-top: 2vh;
  }
  .slide:not(.has-viz) { max-width: 860px; padding-top: 6vh; }
}
.slide-head { grid-area: head; display: grid; gap: 12px; min-width: 0; }
.slide-body { grid-area: body; display: grid; gap: 16px; min-width: 0; align-content: start; }
.slide-viz { grid-area: viz; min-width: 0; }

.kicker {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.title {
  margin: 0;
  font-size: var(--step-3);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.lines { display: grid; gap: 8px; max-width: 62ch; }
.lines p { margin: 0; color: #cdd3dc; font-size: var(--step-1); line-height: 1.45; }
.slide:not(.has-viz) .lines p { font-size: 1.3rem; }

.math {
  display: grid;
  gap: 6px;
  padding: 10px 14px;
  border-left: 2px solid var(--line-2);
  overflow-x: auto;
  font-size: 1.12rem;
}
.math .eq { display: flex; align-items: center; gap: 14px; justify-content: space-between; }
.math .eqno { font-family: var(--font-mono); font-size: 0.75rem; color: var(--faint); white-space: nowrap; }
math { color: var(--ink); }
.lines math, .vote math, .table math { font-size: 1.04em; }

.quote {
  margin: 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 62ch;
}
.quote .label {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.quote blockquote { margin: 6px 0 6px; color: #d9dee6; font-size: 0.98rem; }
.quote figcaption { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); }

.ours {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sig-x);
}

.table-wrap { overflow-x: auto; max-width: 100%; }
.table { border-collapse: collapse; font-size: 0.95rem; min-width: 100%; }
.table th, .table td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.table td:first-child { color: var(--muted); }
.table-source { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); margin-top: 6px; }

/* ---------- vote ---------- */
.vote { display: grid; gap: 10px; max-width: 62ch; }
.vote .q { font-weight: 600; font-size: var(--step-1); }
.vote .opts { display: grid; gap: 8px; }
.vote button.opt {
  position: relative;
  overflow: hidden;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: var(--panel);
  cursor: pointer;
  display: flex; gap: 10px; align-items: baseline;
  transition: border-color .15s, background .15s;
}
.vote button.opt > * { position: relative; }
.vote button.opt .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: color-mix(in srgb, var(--sig-v) 16%, transparent); transition: width .5s ease; pointer-events: none; }
.vote button.opt .label { flex: 1; min-width: 0; }
.vote button.opt .count { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); min-width: 1.5em; text-align: right; }
.vote button.opt.chosen { border-color: var(--sig-v); background: color-mix(in srgb, var(--sig-v) 10%, var(--panel)); }
.vote button.opt[disabled].chosen, .vote button.opt[disabled].correct, .vote button.opt[disabled].wrong { color: var(--ink); }
.vote button.opt:hover:not([disabled]) { border-color: var(--muted); }
.vote button.opt .key { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); min-width: 1.2em; }
.vote button.opt[disabled] { cursor: default; }
.vote button.opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--panel)); }
.vote button.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--panel)); }
.vote .reveal { padding: 12px 14px; border-radius: var(--radius); background: var(--panel-2); color: #d9dee6; }
.vote .hint { font-family: var(--font-mono); font-size: 0.72rem; color: var(--faint); letter-spacing: .06em; }

/* ---------- bottom bar ---------- */
.bar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-block: 8px calc(8px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, black);
}
.bar .where { flex: 1; min-width: 0; font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .where b { color: var(--ink); font-weight: 500; }
.bar button {
  border: 1px solid var(--line-2);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.bar button:hover { border-color: var(--muted); }
.bar button.primary { background: var(--accent); color: #1b1006; border-color: var(--accent); font-weight: 600; }
.bar button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.bar .stepdots { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.bar .stepdots i { width: 5px; height: 5px; border-radius: 50%; background: rgba(0,0,0,.3); display: inline-block; }
.bar .stepdots i.on { background: #1b1006; }
@media (max-width: 560px) { .bar .hide-sm { display: none; } }

/* ---------- notes + contents drawers ---------- */
.drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(440px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line-2);
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) 80px 18px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: -20px 0 40px rgba(0,0,0,.4);
}
.drawer h2 { margin: 0 0 10px; font-size: 0.75rem; font-family: var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.drawer .close { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.notes-list { display: grid; gap: 10px; padding: 0; margin: 0 0 18px; list-style: none; }
.notes-list li { color: #d5dae2; font-size: 0.95rem; }
.notes-list li.next { border-left: 2px solid var(--accent); padding-left: 10px; }
.notes-list li.current { color: var(--ink); }
.notes-list .tag { font-family: var(--font-mono); font-size: 0.7rem; color: var(--accent); margin-right: 6px; }
.contents-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.contents-list .sec { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 14px 0 4px; }
.contents-list a, .contents-list .row { display: flex; gap: 10px; padding: 6px 8px; border-radius: 6px; color: #d5dae2; text-decoration: none; font-size: .92rem; }
.contents-list a:hover { background: var(--panel-2); }
.contents-list a.here, .contents-list .row.here { background: var(--panel-2); color: var(--accent); }
.contents-list a .n, .contents-list .row .n { font-family: var(--font-mono); font-size: .75rem; color: var(--faint); min-width: 2em; padding-top: 2px; }
.contents-list a .poll, .contents-list .row .poll { font-family: var(--font-mono); font-size: .66rem; color: var(--sig-v); margin-left: auto; padding-top: 3px; }

/* ---------- visuals ---------- */
.viz {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 10px;
}
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-diagram { border-bottom: 1px solid var(--line); padding-bottom: 6px; overflow-x: auto; overscroll-behavior-x: contain; }
@media (max-width: 640px) {
  .viz-diagram svg { min-width: 560px; }
  .math { font-size: 1rem; }
  .viz { padding: 10px; }
}
.viz-diagram svg text { font-family: var(--font-mono); }
.viz-panels { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.viz-panels.cols-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; }
.viz-panels .panel.wide { grid-column: 1 / -1; }
.viz-panels:not(.cols-2) .panel-splane svg { max-width: 380px; margin: 0 auto; }
.panel-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin: 0 0 2px 4px; }
.panel-title { font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-family: var(--font-mono); font-size: 0.7rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 0; border-top: 2px solid; display: inline-block; }
.legend i.dash { border-top-style: dashed; }
.axis text, .tick { font-family: var(--font-mono); font-size: 10px; fill: var(--faint); }
.axis-label { font-family: var(--font-mono); font-size: 10px; fill: var(--muted); letter-spacing: .06em; }
.grid line { stroke: var(--line); stroke-width: 1; }
.viz-readout { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 100%;
}
@media (max-width: 560px) { .chip { white-space: normal; } }
.chip b { color: var(--ink); font-weight: 500; }
.chip sub, .slider sub, .legend sub, .panel-title sub, .viz-btn sub, .viz-note sub { font-size: 0.75em; }
.chip.good { border-color: color-mix(in srgb, var(--good) 60%, transparent); }
.chip.good b { color: var(--good); }
.chip.bad { border-color: color-mix(in srgb, var(--bad) 60%, transparent); }
.chip.bad b { color: var(--bad); }
.viz-controls { display: grid; gap: 8px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: center; }
.slider { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.slider .lab { white-space: nowrap; color: #cdd3dc; }
.slider .val { color: var(--ink); min-width: 4.5ch; text-align: right; font-variant-numeric: tabular-nums; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); min-width: 0; }
.viz-buttons { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.viz-btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  cursor: pointer;
  color: #cdd3dc;
}
.viz-btn:hover { border-color: var(--muted); }
.viz-btn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.viz-note { font-family: var(--font-mono); font-size: 0.7rem; color: var(--faint); letter-spacing: .03em; }
.diagram-label { font-size: 11px; }
.block-rect { fill: var(--panel-2); stroke: var(--line-2); stroke-width: 1.2; }
.block-sub { font-size: 9px; fill: var(--faint); letter-spacing: .08em; text-transform: uppercase; }
.wire { fill: none; stroke: var(--line-2); stroke-width: 1.6; }
.wire.dim { stroke-dasharray: 3 4; opacity: .5; }
.sum-circle { fill: var(--panel-2); stroke: var(--line-2); stroke-width: 1.2; }
.sum-sign { font-size: 12px; fill: var(--muted); }
.drag-handle { cursor: grab; }
.splane-unstable { fill: var(--bad); opacity: .07; }
.tex-fo { overflow: visible; }
.tex-fo div { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--ink); font-size: 18px; line-height: 1; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .progress > span { transition: none; }
}

/* ---------- live sync ---------- */
.bar .pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
  padding: 6px 11px;
  border: 1px solid var(--line-2); border-radius: 999px;
  white-space: nowrap;
}
.bar .pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); display: inline-block; }
.bar .pill.online { color: var(--ink); }
.bar .pill.online i { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.bar .pill.offline i { background: var(--bad); animation: pill-blink 1.2s ease-in-out infinite; }
.bar .pill.control { border-color: color-mix(in srgb, var(--accent) 55%, var(--line-2)); color: var(--accent); }
@keyframes pill-blink { 50% { opacity: .35; } }
.bar .pill .pill-short { display: none; }
@media (max-width: 560px) {
  .bar .pill.control .pill-text { display: none; }
  .bar .pill.control .pill-short { display: inline; }
}
.drawer .live-line { display: flex; gap: 12px; align-items: baseline; margin: 0 0 8px; font-size: 0.92rem; color: #d5dae2; flex-wrap: wrap; }
.drawer .live-line .k { font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); min-width: 9em; }
.drawer .live-line code { font-family: var(--font-mono); font-size: 0.82rem; color: var(--ink); word-break: break-all; }
.drawer button.danger {
  margin: 10px 0 8px; padding: 8px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--bad) 55%, var(--line-2)); background: var(--panel-2); color: var(--bad);
}
.drawer button.danger[disabled] { opacity: .6; cursor: default; }
@media (prefers-reduced-motion: reduce) { .bar .pill.offline i { animation: none; } }

/* ---------- terms (glossary) ---------- */
.terms { max-width: 62ch; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.terms .label { font-family: var(--font-mono); font-size: 0.6875rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.terms dl { margin: 0; display: grid; gap: 8px; }
.terms .term { display: grid; grid-template-columns: minmax(9em, 13em) 1fr; gap: 12px; align-items: baseline; }
.terms dt { font-weight: 600; font-size: 0.9rem; color: var(--ink); }
.terms dd { margin: 0; font-size: 0.9rem; color: #c9cfd8; }
@media (max-width: 560px) { .terms .term { grid-template-columns: 1fr; gap: 2px; } }

/* speaker notes open on the left, over the text column, so the visual on the right stays in view */
.drawer.drawer-left {
  left: 0; right: auto;
  border-left: none; border-right: 1px solid var(--line-2);
  box-shadow: 20px 0 40px rgba(0,0,0,.4);
  padding-left: max(18px, env(safe-area-inset-left, 0px));
}

.drawer .notes-slide { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line-2); padding-right: 64px; }
.drawer .notes-slide .kicker { margin-bottom: 4px; }
.drawer .notes-title { font-size: 1.25rem; font-weight: 600; line-height: 1.25; color: var(--ink); }

.drawer dl.say { margin: 0 0 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line-2); display: grid; gap: 4px; }
.drawer dl.say > div { display: grid; grid-template-columns: 4.5em 1fr; gap: 10px; align-items: baseline; }
.drawer dl.say dt { font-family: var(--font-mono); font-size: 0.85rem; color: var(--accent); }
.drawer dl.say dd { margin: 0; font-size: 0.86rem; color: #c9cfd8; }
