@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --ink: #211c17;
  --ink-2: #5b5248;
  --line: #e0d8c8;
  --control-line: #8f8574;
  --grid: #ece5d6;
  --trace: #2d2721;
  --accent: #2b6cb8;
  --on-accent: #ffffff;
  --error: #9b2c1c;
  --font: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --text-xs: 0.72rem;
  --text-sm: 0.8rem;
  --text-md: 0.9rem;
  --text-lg: 1.05rem;
  --text-xl: 1.3rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #171411;
  --surface: #1f1b17;
  --ink: #f2ece1;
  --ink-2: #c4b9a8;
  --line: #3a332b;
  --control-line: #7a6f61;
  --grid: #2d2822;
  --trace: #e9e1d3;
  --accent: #6ea8ec;
  --on-accent: #0d1520;
  --error: #f0a08c;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

body.dropping { outline: 3px dashed var(--accent); outline-offset: -8px; }

h1, h2, h3, p { margin: 0; }

h1, h2, h3 { font-size: var(--text-lg); font-weight: 500; line-height: 1.3; }

button, select, input { font: inherit; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.viewer {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr) 232px;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
}

/* Clipped because the canvases keep their old width for a moment after the window narrows. */
.trace-panel {
  grid-area: 1 / 2 / -1 / 3;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.trace-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-x: none;
}

canvas { display: block; }

/* Positioned so that the cursor's marks stack by document order: shading behind, line in front. */
.traces { position: relative; touch-action: pan-y; cursor: crosshair; }

.cursor-row, .cursor-line { position: absolute; top: 0; pointer-events: none; }

.cursor-row { background: var(--grid); }

.cursor-line { width: 1px; background: var(--accent); }

/* The frame clips anything outside it, so the ring sits inside the canvas. */
.traces:focus-visible { outline-offset: -2px; }

.axis { flex: none; }

.readout {
  position: absolute;
  top: 6px;
  right: 12px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.6;
  pointer-events: none;
}

.readout:empty { display: none; }

.position {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  padding-inline: 12px;
  border-top: 1px solid var(--line);
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.position-text { color: var(--ink-2); font-size: var(--text-sm); line-height: 1; white-space: nowrap; }

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  padding: 12px 14px;
  overflow-y: auto;
}

.panel-controls { grid-area: 1 / 1; border-right: 1px solid var(--line); }

/* Positioned so its hidden table caption scrolls inside the panel, not the page. */
.panel-info {
  grid-area: 1 / 3 / -1 / 4;
  position: relative;
  gap: 0;
  border-left: 1px solid var(--line);
}

.recording-title { padding-bottom: 10px; }

.section { border-top: 1px solid var(--line); }

.section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  list-style: none;
  cursor: pointer;
}

.section > summary::-webkit-details-marker { display: none; }

/* A chevron that points right when closed and down when open. */
.section > summary::after {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  margin-right: 3px;
  border-right: 1.5px solid var(--ink-2);
  border-bottom: 1.5px solid var(--ink-2);
  transform: rotate(-45deg);
}

.section[open] > summary::after { transform: translateY(-2px) rotate(45deg); }

.section[open] { padding-bottom: 12px; }

h3 {
  margin: 10px 0 3px;
  color: var(--ink-2);
  font-size: var(--text-xs);
  line-height: 1.4;
}

.section > summary + h3 { margin-top: 0; }

.channel-list { margin: 2px 0 0; }

.channel-list dt, .properties dt { color: var(--ink-2); font-size: var(--text-sm); }

.channel-list dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-size: var(--text-xs);
  line-height: 1.4;
}

/* The logo and name stand alone. Everything else about the site sits in the footer. */
.masthead { display: flex; align-items: center; min-height: 28px; }

.site-footer {
  grid-area: 2 / 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 8px;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.site-tools { display: flex; align-items: center; margin-right: -5px; }

.tool {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  font-size: var(--text-sm);
  text-decoration: none;
  cursor: pointer;
}

.tool:hover { color: var(--ink); }

.tool svg { fill: currentColor; }

.help-link { margin-right: auto; }

/* The switch shows where it will take you: a moon in light mode, a sun in dark. */
.theme-toggle .to-light { display: none; }
[data-theme="dark"] .theme-toggle .to-dark { display: none; }
[data-theme="dark"] .theme-toggle .to-light { display: block; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-lg);
  font-weight: 500;
  line-height: 1;
}

.brand-disc { fill: var(--accent); }
.brand-v {
  fill: none;
  stroke: var(--on-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

h1 { overflow-wrap: anywhere; }

.properties { display: grid; gap: 2px; margin: 0; }

/* A value too long for its row drops to the next line, still on the right. */
.properties div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 12px; }

.properties dd {
  min-width: 0;
  margin: 0 0 0 auto;
  overflow-wrap: anywhere;
  font-size: var(--text-sm);
  text-align: right;
}

.note { color: var(--ink-2); font-size: var(--text-sm); line-height: 1.45; }

.recording-title .note { margin-top: 6px; }

.control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink-2);
  font-size: var(--text-sm);
}

select {
  width: 100%;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
}

.button:hover { border-color: var(--ink-2); }

.button:disabled { color: var(--ink-2); cursor: not-allowed; opacity: 0.6; }

.open-recording { min-height: 34px; padding: 0 8px; font-size: var(--text-sm); white-space: nowrap; }

.stepper { display: flex; gap: 6px; }
.stepper .button { flex: 1; min-height: 34px; padding: 0; font-size: var(--text-lg); }

table { width: 100%; margin-top: 6px; border-collapse: collapse; }

th {
  width: 78px;
  padding: 5px 8px 5px 0;
  font-size: var(--text-md);
  font-weight: 500;
  text-align: left;
}

th span {
  display: block;
  color: var(--ink-2);
  font-size: var(--text-xs);
  line-height: 1.3;
  white-space: nowrap;
}

.bar-cell { padding-block: 5px; }

.bar {
  --share: 0;
  display: block;
  width: calc(var(--share) * 100%);
  min-width: 2px;
  height: 10px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}

.value {
  width: 42px;
  padding-left: 6px;
  font-size: var(--text-md);
  line-height: 1;
  text-align: right;
}

.section-note { margin-top: 8px; font-size: var(--text-xs); }

.annotations { margin: 0; padding: 0; list-style: none; }

.annotations button {
  width: 100%;
  min-height: 28px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: var(--text-sm);
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-align: left;
  cursor: pointer;
}

.annotations button:hover { color: var(--accent); }

.annotations span { color: var(--ink-2); }

.error { margin-top: 12px; color: var(--error); font-weight: 500; }

noscript .error { margin: 16px; }

.loader {
  width: min(480px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
}

.loader::backdrop { background: rgb(23 20 17 / 0.45); }

.loader-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.loader-head h2 {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  font-size: var(--text-xl);
}

.close { width: 36px; min-height: 36px; padding: 0; font-size: var(--text-xl); }

.dropzone {
  display: grid;
  justify-items: center;
  gap: 4px;
  width: 100%;
  margin-top: 14px;
  padding: 44px 16px;
  border: 1px dashed var(--ink-2);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.dropzone:hover, .dropping .dropzone { border-color: var(--accent); }

.dropping .dropzone { outline: 2px solid var(--accent); outline-offset: -2px; }

.dropzone:disabled { cursor: progress; opacity: 0.7; }

.dropzone strong { font-weight: 500; }

.dropzone span { color: var(--ink-2); font-size: var(--text-md); }

.loader-note { margin-top: 12px; font-size: var(--text-md); }

.loader-demo {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.help-page {
  max-width: 44rem;
  margin-inline: auto;
  padding: 24px 16px 48px;
  font-size: var(--text-md);
  line-height: 1.6;
}

.help-page a { color: var(--accent); }

.help-page .brand { color: inherit; text-decoration: none; }

.help-page h1 { margin-top: 24px; font-size: var(--text-xl); }

.help-page h2 { margin-top: 28px; font-size: var(--text-lg); }

.help-page p { margin-top: 8px; }

.help-page ul { margin: 8px 0 0; padding-left: 20px; }

.help-page table { margin-top: 10px; }

.help-page th, .help-page td {
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: inherit;
  line-height: 1.5;
  text-align: left;
  vertical-align: top;
}

.help-page th { width: 34%; padding-right: 16px; }

kbd {
  padding: 1px 5px;
  border: 1px solid var(--control-line);
  border-radius: 4px;
  background: var(--surface);
  font: inherit;
  font-size: var(--text-sm);
  white-space: nowrap;
}

@media (hover: none) {
  .dropzone span { display: none; }
}

/* Too narrow for side panels: controls on top, traces, then details. */
@media (max-width: 960px) {
  .viewer { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; height: auto; }
  .panel-controls, .trace-panel, .panel-info, .site-footer { grid-area: auto; }
  .trace-frame { flex: none; height: 56vh; min-height: 240px; }
  .position { height: 44px; }
  .panel { border-inline: 0; }
  select, .open-recording, .stepper .button { min-height: 44px; }
  .close { width: 44px; min-height: 44px; }
  .annotations button { min-height: 44px; }
  .panel-info { border-top: 1px solid var(--line); }
  .section > summary { min-height: 44px; }

  .panel-controls {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
  }

  .masthead { flex: 1 1 calc(100% - 152px); }
  .open-recording { flex: none; width: 140px; }
  .panel-controls .control { flex: 1 1 40%; }

  .site-footer {
    flex-flow: row wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0 16px;
    padding: 4px 12px;
    border-right: 0;
  }

  .site-tools { flex: 1 1 auto; }
  .tool { min-width: 40px; height: 44px; }
}
