/* Grad — Swiss editorial-technical. One accent (#FF4F00), used only for the
   node and edges of the current step. */

@font-face {
  font-family: 'Geist';
  src: url('fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Geist Mono';
  src: url('fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666666;
  --faint: #999999;
  --rule: #e5e5e5;
  --accent: #ff4f00;
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --gutter: 16px;
  --gap: 24px;
  color-scheme: light;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: 'ss01';
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

h1, h2, p {
  margin: 0;
}

button, input {
  font: inherit;
  color: inherit;
}

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

/* ---------- header / footer ------------------------------------------- */

.site-header,
.layout,
.site-footer {
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.site-header {
  padding-top: max(28px, env(safe-area-inset-top));
}

.header-inner {
  max-width: 1376px;
  margin: 0 auto;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--fg);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.wordmark {
  font-size: 44px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.035em;
}

.version {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.tagline {
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
  max-width: 36em;
}

.site-footer {
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}

.site-footer p {
  max-width: 1376px;
  margin: 0 auto;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.02em;
}

/* ---------- layout -------------------------------------------------------- */

.layout {
  display: flex;
  flex-direction: column;
  max-width: calc(1376px + 2 * var(--gutter));
  margin: 0 auto;
  padding-bottom: 40px;
}

/* Mobile: the two columns dissolve and panels are re-ordered into one stack. */
.col {
  display: contents;
}

.panel {
  min-width: 0;
  padding: 20px 0 24px;
  border-bottom: 1px solid var(--rule);
}

.p-expr { order: 1; }
.p-presets { order: 2; }
.p-values { order: 3; }
.p-controls { order: 4; }
.p-graph { order: 5; }
.p-readout { order: 6; }
.p-grads { order: 7; }
.p-torch { order: 8; border-bottom: 0; }

@media (min-width: 960px) {
  :root {
    --gutter: 32px;
  }

  .layout {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gap);
    align-items: start;
  }

  .col {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  .col-left {
    grid-column: 1 / span 4;
  }

  .col-right {
    grid-column: 5 / span 8;
  }

  .p-torch {
    border-bottom: 1px solid var(--rule);
  }

  .p-readout {
    border-bottom: 0;
  }

  .wordmark {
    font-size: 64px;
  }
}

/* ---------- labels ------------------------------------------------------- */

.label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg);
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
}

.label .idx {
  color: var(--faint);
}

.help {
  margin-top: 10px;
  color: var(--faint);
  font-size: 12px;
}

.head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.head-row .label {
  margin-bottom: 0;
}

/* ---------- buttons ------------------------------------------------------ */

.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    background: var(--fg);
    color: var(--bg);
  }
}

.btn:active:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
}

.btn:disabled {
  color: var(--faint);
  border-color: var(--rule);
  cursor: default;
}

.btn[aria-pressed='true'] {
  background: var(--fg);
  color: var(--bg);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.presets .btn {
  flex: 1 1 auto;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.controls .btn {
  padding: 0 6px;
}

/* ---------- expression --------------------------------------------------- */

.expr-input {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 18px;
  border: 1px solid var(--fg);
  border-radius: 2px;
  background: var(--bg);
  -webkit-appearance: none;
  appearance: none;
}

.expr-input:focus {
  outline: none;
  box-shadow: none;
  border-width: 1px;
}

.expr-input:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

.expr-error {
  margin-top: 12px;
}

.caret-echo {
  margin: 0;
  padding: 0 13px;
  font-size: 18px;
  line-height: 1.3;
  overflow-x: auto;
  white-space: pre;
  color: var(--muted);
}

.err-msg {
  margin-top: 8px;
  font-size: 13px;
  color: var(--fg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ---------- values ------------------------------------------------------- */

.values,
.grads {
  border-top: 1px solid var(--rule);
}

.value-row {
  display: grid;
  grid-template-columns: minmax(56px, auto) minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}

.value-row .name {
  font-family: var(--mono);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.value-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--bg);
  -webkit-appearance: none;
  appearance: textfield;
  -moz-appearance: textfield;
}

.value-input::-webkit-outer-spin-button,
.value-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.value-input:focus {
  outline: none;
  border-color: var(--fg);
}

.btn.sign {
  padding: 0;
  font-size: 15px;
}

.empty {
  padding: 12px 0;
  color: var(--faint);
  font-size: 13px;
  border-bottom: 1px solid var(--rule);
}

/* ---------- gradients ---------------------------------------------------- */

.grad-row {
  display: grid;
  grid-template-columns: minmax(56px, auto) minmax(0, 1fr);
  align-items: baseline;
  gap: 4px 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}

.grad-row .name {
  font-family: var(--mono);
  font-size: 15px;
}

.grad-row .big {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  line-height: 1.1;
  text-align: right;
  letter-spacing: -0.02em;
}

.grad-row .check {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.check .k {
  color: var(--faint);
  margin-right: 6px;
}

.check .status {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.check .status.is-bad {
  color: var(--fg);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--fg);
  border-radius: 2px;
  background: var(--bg);
  display: inline-grid;
  place-content: center;
  cursor: pointer;
}

.toggle input::before {
  content: '';
  width: 10px;
  height: 10px;
  background: var(--fg);
  transform: scale(0);
}

.toggle input:checked::before {
  transform: scale(1);
}

/* ---------- export ------------------------------------------------------- */

.code {
  margin-top: 14px;
  border-top: 1px solid var(--rule);
}

.code summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  list-style: none;
}

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

.code summary::before {
  content: '+';
  width: 18px;
  color: var(--faint);
}

.code[open] summary::before {
  content: '−';
}

.code pre {
  margin: 0;
  padding: 14px 0 4px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.6;
  border-top: 1px solid var(--rule);
}

.offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

/* ---------- graph -------------------------------------------------------- */

.graph-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--rule);
}

.graph {
  display: block;
  margin: 0 auto;
}

.edge {
  fill: none;
  stroke: var(--faint);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.edge.is-current {
  stroke: var(--accent);
  stroke-width: 1.5;
}

.arrow {
  fill: var(--faint);
}

.arrow-current {
  fill: var(--accent);
}

.node-box {
  fill: var(--bg);
  stroke: var(--fg);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.node.is-current .node-box {
  stroke: var(--accent);
  stroke-width: 2;
}

.node-sep {
  stroke: var(--rule);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.node-op {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  fill: var(--fg);
}

.node-tag {
  font-family: var(--mono);
  font-size: 10px;
  fill: var(--faint);
  letter-spacing: 0.04em;
}

.node-key {
  font-family: var(--mono);
  font-size: 9.5px;
  fill: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.node-num {
  font-family: var(--mono);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  fill: var(--fg);
  letter-spacing: -0.02em;
}

.node-num.is-empty {
  fill: var(--faint);
}

.edge-label {
  font-family: var(--mono);
  font-size: 11px;
  fill: var(--muted);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
}

.edge-label.is-current {
  fill: var(--accent);
}

.notice {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- step readout ------------------------------------------------- */

.readout-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}

.readout-head .label {
  margin-bottom: 0;
}

.counter {
  font-size: 15px;
  color: var(--fg);
}

.step-text {
  min-height: 4.8em;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.step-text .line {
  padding: 2px 0;
}

.step-text .line.head {
  font-size: 16px;
  padding-bottom: 6px;
}

.step-text .line.sub {
  color: var(--faint);
  padding-left: 1.5em;
}

.step-text .line.muted {
  color: var(--muted);
  font-family: var(--sans);
}

.keys {
  margin-top: 14px;
}

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