@font-face {
  font-family: "Lora";
  src: url("/fonts/Lora-Variable.ttf") format("truetype");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Palette taken from a circuit board: solder mask, silkscreen, ENIG gold. */
:root {
  color-scheme: dark;

  --mask: #1c3330;
  --mask-deep: #162a27;
  --silk: #eceae2;
  --silk-soft: rgb(236 234 226 / 0.88);
  --silk-dim: #8fa9a1;
  --enig: #cda85c;
  --alarm: #e8907a;
  --rule: rgb(143 169 161 / 0.28);

  --serif: "Lora", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --gutter: clamp(1.25rem, 9vw, 10rem);
  --measure: 36rem;
  --measure-title: 46rem;
  --measure-wide: 66rem;

  --sweep: 1100ms;
  --fade: 380ms;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--mask);
  color: var(--silk);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
}

sub {
  font-size: 0.72em;
  line-height: 0;
}

/* ---------- Header ---------- */

.site-header {
  padding: 2rem var(--gutter) 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.wordmark {
  color: var(--silk-dim);
  text-decoration: none;
}

.wordmark:hover {
  color: var(--silk);
}

.wordmark:focus-visible,
.tool-name:focus-visible {
  outline: 2px solid var(--enig);
  outline-offset: 3px;
  border-radius: 2px;
}

.crumb {
  color: var(--silk);
}

/* ---------- Page frame ---------- */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 3rem 5rem;
}

.page {
  flex: 1;
  padding-block: 3.5rem 5rem;
}

.column {
  margin-left: var(--gutter);
  margin-right: 1.25rem;
  max-width: var(--measure-title);
}

.column.wide {
  max-width: var(--measure-wide);
}

.lede {
  margin: 0;
  max-width: var(--measure);
  font-size: 1.1875rem;
  line-height: 1.65;
  color: var(--silk-soft);
  text-wrap: pretty;
}

/* ---------- Scope trace (home and tips) ---------- */

.scope {
  width: 100%;
  margin-bottom: 2.25rem;
}

.trace {
  display: block;
  width: 100%;
  height: 112px;
  overflow: visible;
}

.ch {
  fill: none;
  stroke-linejoin: miter;
  stroke-linecap: square;
  vector-effect: non-scaling-stroke;
}

.ch-raw {
  stroke: var(--silk-dim);
  stroke-width: 1.25;
  opacity: 0.75;
}

.ch-clean {
  stroke: var(--enig);
  stroke-width: 2;
  filter: drop-shadow(0 0 5px rgb(205 168 92 / 0.35));
}

.ch-label {
  fill: var(--silk-dim);
  font-family: var(--serif);
  font-size: 13px;
  text-anchor: end;
}

/* ---------- Home ---------- */

.home-title {
  margin: 0 0 1rem;
  font-size: clamp(1.875rem, 1.1rem + 3vw, 3.125rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

.tool-list {
  list-style: none;
  margin: 3rem 0 0;
  padding: 0;
  max-width: var(--measure);
}

.tool + .tool {
  margin-top: 1.75rem;
}

.tool-name {
  font-size: 1.4375rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--silk);
  text-decoration: underline;
  text-decoration-color: rgb(205 168 92 / 0.6);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
  transition: color 160ms ease, text-decoration-color 160ms ease;
}

.tool-name:hover {
  color: var(--enig);
  text-decoration-color: var(--enig);
}

.tool-desc {
  margin: 0.3rem 0 0;
  color: var(--silk-dim);
}

/* ---------- Tips ---------- */

.tip-body,
.tip-category {
  max-width: var(--measure);
}

.tip-title {
  margin: 0 0 1rem;
  font-size: clamp(1.875rem, 1.1rem + 3vw, 3.125rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

.nowrap {
  white-space: nowrap;
}

.tip-title.is-pending {
  color: var(--silk-dim);
  font-weight: 400;
}

.tip-body {
  margin: 0;
  font-size: 1.1875rem;
  line-height: 1.65;
  color: var(--silk-soft);
  text-wrap: pretty;
}

.tip-category {
  margin: 1.25rem 0 0;
  font-size: 0.9375rem;
  color: var(--silk-dim);
}

.tip-category:empty {
  display: none;
}

.controls {
  margin-top: 2.5rem;
}

.button {
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--enig);
  background: transparent;
  border: 1px solid rgb(205 168 92 / 0.55);
  border-radius: 999px;
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease;
}

.button:hover {
  background: rgb(205 168 92 / 0.1);
  border-color: var(--enig);
}

.button:active {
  background: rgb(205 168 92 / 0.18);
}

.button:focus-visible {
  outline: 2px solid var(--enig);
  outline-offset: 3px;
}

/* ---------- Debounce calculator ---------- */

.page-title {
  margin: 0 0 1rem;
  font-size: clamp(1.875rem, 1.2rem + 2.4vw, 2.75rem);
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.012em;
}

.section-title {
  margin: 0 0 1rem;
  font-size: 1.1875rem;
  font-weight: 600;
  color: var(--silk);
}

.calc {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3rem;
  margin-top: 3rem;
}

@media (min-width: 62rem) {
  .calc {
    grid-template-columns: minmax(18rem, 24rem) minmax(0, 1fr);
    gap: 4rem;
  }
}

.schematic {
  margin: 0 0 2.5rem;
  max-width: 22.5rem;
}

.schematic svg {
  display: block;
  width: 100%;
  height: auto;
}

.schematic .wire path {
  fill: none;
  stroke: var(--silk-dim);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.schematic .part path {
  fill: none;
  stroke: var(--silk);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.schematic .part path.thin {
  stroke-width: 1.1;
}

.schematic .node circle {
  fill: var(--silk-dim);
}

.schematic .label text {
  fill: var(--silk);
  font-family: var(--serif);
  font-size: 13px;
}

.schematic .label .sub,
.scope-svg .sub {
  font-size: 9.5px;
}

.fields {
  display: grid;
  gap: 0.9rem;
}

.field label {
  display: block;
  font-size: 0.9375rem;
  color: var(--silk-dim);
}

.input-wrap {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  border-bottom: 1px solid var(--rule);
  transition: border-color 160ms ease;
}

.input-wrap:focus-within {
  border-bottom-color: var(--enig);
}

.input-wrap input {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 0;
  font: inherit;
  font-size: 1.125rem;
  color: var(--silk);
  background: transparent;
  border: 0;
  outline: none;
  font-variant-numeric: tabular-nums;
}

.input-wrap input[aria-invalid="true"] {
  color: var(--alarm);
}

.field:has(input[aria-invalid="true"]) .input-wrap {
  border-bottom-color: var(--alarm);
}

.unit {
  color: var(--silk-dim);
  font-size: 1rem;
}

.field-note {
  min-height: 1.35em;
  margin: 0.2rem 0 0;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--silk-dim);
}

.field-note.is-error {
  color: var(--alarm);
}

.fields-hint {
  margin: 1.25rem 0 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--silk-dim);
}

.results-error {
  margin: 0;
  color: var(--alarm);
}

.readouts {
  display: grid;
  gap: 1.5rem;
  margin: 0 0 2.25rem;
}

@media (min-width: 46rem) {
  .readouts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.readout dt {
  font-size: 0.9375rem;
  color: var(--silk-dim);
}

.readout dd {
  margin: 0;
}

.readout-value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.readout .readout-note {
  margin-top: 0.35rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--silk-soft);
  text-wrap: pretty;
}

.readout .readout-note[data-state="ok"] {
  color: var(--enig);
}

.readout .readout-note[data-state="bad"] {
  color: var(--alarm);
}

.scope-panel {
  margin: 0;
  padding: 0.75rem 0 0.25rem;
  background: var(--mask-deep);
  border-radius: 6px;
}

.scope-panel + .scope-panel {
  margin-top: 1.25rem;
}

.scope-panel figcaption {
  padding: 0 0.75rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.scope-svg {
  display: block;
  width: 100%;
  height: 214px;
  overflow: visible;
}

.scope-svg .graticule line {
  stroke: rgb(143 169 161 / 0.12);
  stroke-width: 1;
}

.scope-svg .threshold {
  stroke: var(--silk-dim);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.7;
}

.scope-svg .threshold-label,
.scope-svg .trace-label,
.scope-svg .timebase {
  fill: var(--silk-dim);
  font-family: var(--serif);
  font-size: 12px;
}

.scope-svg .trace-label:not([text-anchor]),
.scope-svg .timebase:not([text-anchor]) {
  text-anchor: end;
}

.scope-svg .sig {
  fill: none;
  stroke-linejoin: round;
}

.scope-svg .sig-contact {
  stroke: var(--silk-dim);
  stroke-width: 1.25;
}

.scope-svg .sig-cap {
  stroke: var(--silk);
  stroke-width: 1.5;
}

.scope-svg .sig-reads {
  stroke: var(--enig);
  stroke-width: 2;
}

.method {
  margin-top: 4.5rem;
  max-width: var(--measure);
}

.method p {
  margin: 0 0 1rem;
  color: var(--silk-soft);
  text-wrap: pretty;
}

.method .formula .fn {
  font-style: normal;
}

.method .formula {
  margin: 0.25rem 0 1.5rem;
  padding-left: 1.25rem;
  border-left: 2px solid var(--enig);
  font-style: italic;
  color: var(--silk);
}

/* ---------- Shared calculator parts ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.input-wrap select {
  flex: 1;
  min-width: 0;
  padding: 0.3rem 1.5rem 0.3rem 0;
  font: inherit;
  font-size: 1.0625rem;
  color: var(--silk);
  background: transparent;
  border: 0;
  outline: none;
  appearance: none;
  cursor: pointer;
}

.input-wrap select option {
  color: var(--silk);
  background: var(--mask-deep);
}

.input-wrap:has(select) {
  position: relative;
}

.input-wrap:has(select)::after {
  content: "";
  position: absolute;
  right: 0.25rem;
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--silk-dim);
  border-bottom: 1.5px solid var(--silk-dim);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.result-body[hidden],
.readouts[hidden],
.scope-panel[hidden] {
  display: none;
}

.table-title {
  margin: 2.5rem 0 0.35rem;
  font-size: 1.0625rem;
  font-weight: 600;
}

.table-hint,
.table-more,
.frame-note {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--silk-dim);
}

.table-more {
  margin-top: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  font-variant-numeric: tabular-nums;
}

.result-table th {
  padding: 0.4rem 0.6rem 0.4rem 0;
  text-align: left;
  font-weight: 400;
  color: var(--silk-dim);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

.result-table td {
  padding: 0.45rem 0.6rem 0.45rem 0;
  border-bottom: 1px solid rgb(143 169 161 / 0.12);
  white-space: nowrap;
}

.result-table tbody tr:has(input) {
  cursor: pointer;
}

.result-table tbody tr:hover td {
  background: rgb(236 234 226 / 0.04);
}

.result-table tbody tr.is-selected td {
  background: rgb(205 168 92 / 0.1);
}

.result-table td:first-child:has(input) {
  width: 1.75rem;
  padding-left: 0.4rem;
}

.result-table input[type="radio"] {
  margin: 0;
  accent-color: var(--enig);
}

.result-table input[type="radio"]:focus-visible {
  outline: 2px solid var(--enig);
  outline-offset: 2px;
}

.result-table td[data-state="bad"] {
  color: var(--alarm);
}

.result-table td[data-state="ok"] {
  color: var(--enig);
}

.registers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 1rem 1.5rem;
  margin: 1.75rem 0 0;
}

.reg dt {
  font-size: 0.875rem;
  color: var(--silk-dim);
}

.reg dd {
  margin: 0;
  font-size: 1.125rem;
  font-variant-numeric: tabular-nums;
}

.reg.is-register dd {
  color: var(--enig);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* CAN bit diagram */

.bit-figure {
  margin: 0;
  padding: 0.75rem 0 0.5rem;
  background: var(--mask-deep);
  border-radius: 6px;
}

.bit-figure figcaption {
  padding: 0 0.75rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.bit-svg {
  display: block;
  width: 100%;
  height: 128px;
  overflow: visible;
}

.bit-svg .seg {
  stroke-width: 1;
}

.bit-svg .seg-sync {
  fill: rgb(143 169 161 / 0.4);
  stroke: var(--silk-dim);
}

.bit-svg .seg-tseg1 {
  fill: rgb(236 234 226 / 0.1);
  stroke: var(--silk-dim);
}

.bit-svg .seg-tseg2 {
  fill: rgb(205 168 92 / 0.22);
  stroke: var(--enig);
}

.bit-svg .quanta line {
  stroke: var(--mask-deep);
  stroke-width: 1;
  opacity: 0.8;
}

.bit-svg .seg-split {
  stroke: var(--silk);
  stroke-width: 1;
  stroke-dasharray: 2 3;
}

.bit-svg .sample-line {
  stroke: var(--enig);
  stroke-width: 2;
}

.bit-svg .bit-label {
  fill: var(--silk-dim);
  font-family: var(--serif);
  font-size: 12px;
}

.bit-svg .bit-label.strong,
.bit-svg .sample-label {
  fill: var(--silk);
}

/* UART frame */

.frame-svg {
  height: 150px;
}

.frame-note {
  margin: 0;
  padding: 0 0.75rem 0.5rem;
}

.scope-svg .sample-tick {
  stroke: var(--enig);
  stroke-width: 1;
  stroke-dasharray: 2 3;
  opacity: 0.7;
}

.scope-svg .sample-dot {
  fill: var(--enig);
}

.scope-svg .sample-tick.is-bad {
  stroke: var(--alarm);
  opacity: 1;
}

.scope-svg .sample-dot.is-bad {
  fill: var(--alarm);
}

/* Divider */

.divider-schematic {
  max-width: 15rem;
}

.schematic .label text.value {
  fill: var(--enig);
  font-size: 12px;
}

.pair-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 1.5rem;
  margin-bottom: 1.5rem;
}

.range-svg {
  height: 116px;
}

.scope-svg .axis {
  stroke: var(--silk-dim);
  stroke-width: 1;
}

.scope-svg .band {
  fill: rgb(205 168 92 / 0.18);
  stroke: rgb(205 168 92 / 0.55);
  stroke-width: 1;
}

.scope-svg .marker {
  stroke: var(--enig);
  stroke-width: 2.5;
}

.scope-svg .trace-label.strong {
  fill: var(--silk);
}

/* ---------- Motion: one sweep, then the content settles in ---------- */

.scope.is-sweeping .trace {
  animation: sweep var(--sweep) linear both;
}

@keyframes sweep {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

.tip.is-leaving {
  opacity: 0;
  transition: opacity 150ms ease-in;
}

.tip.is-entering {
  animation: settle var(--fade) ease-out both;
  animation-delay: var(--reveal-delay, 0ms);
}

@keyframes settle {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Background remover ---------- */

.drop {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-top: 2.5rem;
  padding: 1.5rem;
  border: 1px dashed var(--rule);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.drop:hover,
.drop.is-over {
  border-color: var(--enig);
}

.drop.is-over {
  background: rgb(205 168 92 / 0.06);
}

.drop:has(input:focus-visible) .button {
  outline: 2px solid var(--enig);
  outline-offset: 3px;
}

.drop:has(input:disabled) {
  cursor: progress;
  opacity: 0.6;
}

.drop + .fields-hint {
  max-width: var(--measure-title);
}

.drop-hint {
  color: var(--silk-dim);
  font-size: 0.9375rem;
}

.cutout-status {
  margin: 1.5rem 0 0.5rem;
  min-height: 1.6em;
  color: var(--silk-soft);
}

.cutout-status.is-error {
  color: var(--alarm);
}

.cutout-progress {
  display: block;
  width: 100%;
  max-width: var(--measure);
  height: 0.375rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--mask-deep);
  accent-color: var(--enig);
  overflow: hidden;
}

.cutout-progress::-webkit-progress-bar {
  background: var(--mask-deep);
}

.cutout-progress::-webkit-progress-value {
  background: var(--enig);
}

.cutout-progress::-moz-progress-bar {
  background: var(--enig);
}

.cutout-progress[hidden],
.cutout-panels[hidden],
.cutout-save[hidden] {
  display: none;
}

.cutout-panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  margin-top: 2rem;
}

@media (min-width: 46rem) {
  .cutout-panels {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.cutout-panel {
  margin: 0;
  padding: 0.75rem;
  background: var(--mask-deep);
  border-radius: 6px;
}

.cutout-panel figcaption {
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
}

.cutout-panel canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* Shows transparent areas of the result. */
.checker {
  background-color: #d8d6ce;
  background-image: conic-gradient(#b4b2aa 25%, transparent 0 50%, #b4b2aa 0 75%, transparent 0);
  background-size: 16px 16px;
}

.cutout-save {
  display: inline-block;
  text-decoration: none;
}

.method a {
  color: var(--enig);
  text-decoration-color: rgb(205 168 92 / 0.45);
  text-underline-offset: 0.15em;
}

.method a:hover {
  text-decoration-color: var(--enig);
}

@media (prefers-reduced-motion: reduce) {
  .scope.is-sweeping .trace,
  .tip.is-entering {
    animation: none;
  }

  .tip.is-leaving,
  .tool-name,
  .button,
  .input-wrap,
  .drop {
    transition: none;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 34rem) {
  body {
    font-size: 1.0625rem;
  }

  .site-header {
    padding-top: 1.5rem;
  }

  .stage {
    justify-content: flex-start;
    padding-block: 3.5rem 3rem;
  }

  .page {
    padding-block: 2.5rem 3rem;
  }

  .tip-body,
  .lede {
    font-size: 1.125rem;
  }
}
