:root {
  color-scheme: light;
  --bg: #f2f4f0;
  --panel: #fff;
  --ink: #20392f;
  --muted: #506359;
  --line: #d6dfd9;
  --control-line: #788c80;
  --green: #24664d;
  --blue: #275da2;
  --orange: #a2431b;
  --threshold: #62766b;
  --error: #8b3626;
  --space: clamp(8px, 1.6vmin, 18px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", sans-serif;
}
main {
  display: grid;
  grid-template-rows: auto auto auto minmax(min-content, 1fr);
  gap: var(--space);
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1260px;
  margin: 0 auto;
  padding: var(--space) clamp(8px, 3vw, 36px);
}
h2, h3, p { margin: 0; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
a { color: var(--green); }
:is(a, button, input, select, summary):focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}
button, select, input { font: inherit; color: inherit; }
button, select {
  min-height: 34px;
  padding: 5px 11px;
  border: 1px solid var(--control-line);
  border-radius: 7px;
  background: var(--panel);
}
button { cursor: pointer; white-space: nowrap; }
button:enabled:hover { background: #e7efe9; }
button:disabled { color: var(--muted); background: #edf1ee; border-color: var(--line); cursor: default; }
button.primary:enabled { background: var(--green); color: #fff; border-color: var(--green); font-weight: 700; }
button.primary:enabled:hover { background: #1a543e; }
button#stop:enabled { color: var(--error); border-color: var(--error); }
button#stop:enabled:hover { background: #faeee8; }
.masthead, .session, .history-head, .dialog-head {
  display: flex;
  align-items: center;
  gap: 8px 14px;
}
.masthead, .history-head, .dialog-head { justify-content: space-between; }
.masthead { flex-wrap: wrap; }
.actions, .utilities { display: flex; gap: 6px; }
.utilities button { font-size: 12px; }
.session { flex-wrap: wrap; }
#status { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
#status.error { color: var(--error); font-weight: 600; }
#delayNotice { flex-basis: 100%; color: var(--orange); font-size: 12px; }
.panel {
  min-width: 0;
  padding: clamp(10px, 1.8vmin, 20px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
.script { display: grid; gap: 6px; }
.muted { font-size: 12px; color: var(--muted); }
blockquote {
  margin: 1px 0 0;
  padding: 3px 0 3px 11px;
  border-left: 3px solid #a4bdb0;
  font-size: clamp(15px, 2vw, 21px);
  line-height: 1.55;
  font-weight: 550;
  overflow-wrap: anywhere;
}
.history {
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr);
  gap: 8px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 14px;
  padding: 0;
  margin: 0;
  list-style: none;
  font-size: 12px;
}
.legend li { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend li::before { content: ""; width: 14px; border-top: 2px solid currentColor; }
.legend-bc { color: var(--green); }
.legend .legend-bc::before { border-top-style: dashed; }
.legend-timing { color: var(--orange); }
.legend-turn { color: var(--blue); }
.legend .legend-turn::before { border-top-style: dotted; }
.legend-threshold { color: var(--threshold); }
.legend .legend-threshold::before { border-top: 1px dashed currentColor; }
.plot { position: relative; min-height: 0; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max-content;
  max-width: 95%;
  padding: 2px 6px;
  background: var(--panel);
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
dialog {
  width: min(460px, calc(100% - 20px));
  max-height: calc(100% - 20px);
  padding: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--panel);
  overflow-y: auto;
}
dialog::backdrop { background: rgb(19 38 30 / 40%); }
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 0 8px;
  background: var(--panel);
}
.dialog-section { padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--line); }
.dialog-section :is(p, .input-level, #demo) { margin-top: 5px; }
.input-level {
  display: grid;
  grid-template-columns: 8em minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
meter { width: 100%; }
.metrics {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  margin: 5px 0 0;
  font-size: 12px;
}
.metrics dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
summary { font-size: 13px; min-height: 24px; cursor: pointer; }
details p { font-size: 12px; color: var(--muted); }
.checkbox { display: flex; align-items: center; gap: 8px; min-height: 32px; margin: 8px 0 4px; cursor: pointer; }
.checkbox input { margin: 0; accent-color: var(--green); }
.backchannel-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 8px;
  margin-bottom: 14px;
}
.backchannel-settings output { text-align: right; font-variant-numeric: tabular-nums; }
.interruption-settings { width: min(100%, 380px); margin: 6px 0 0; }
.interruption-settings p { grid-column: 1 / -1; }
.backchannel-settings input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 28px;
  margin: 0;
  accent-color: var(--green);
}
.backchannel-delay { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.backchannel-delay input {
  width: 76px;
  min-height: 34px;
  padding: 4px 7px;
  color: var(--ink);
  border: 1px solid var(--control-line);
  border-radius: 6px;
}

.loading-screen {
  grid-template-rows: 1fr;
  place-items: center;
}
.loading-card {
  width: min(100%, 420px);
  padding: 32px 24px;
  text-align: center;
}
.loading-card h1 { margin: 14px 0 6px; }
.loading-card p { color: var(--muted); }
.loading-card button { margin-top: 16px; }
.loading-indicator {
  display: block;
  width: 32px;
  height: 32px;
  margin: auto;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: loading-spin .85s linear infinite;
}
@keyframes loading-spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) {
  .loading-indicator { animation: none; }
}

@media (max-width: 620px) {
  .history-head { align-items: flex-start; flex-direction: column; gap: 3px; }
  .legend { gap: 3px 10px; font-size: 11px; }
}
@media (max-width: 400px) {
  .session { gap: 4px 8px; }
}
