:root {
  --bg:        #1d2021;
  --surface:   #282828;
  --surface-2: #32302f;
  --border:    #3c3836;
  --border-2: #504945;
  --fg:        #ebdbb2;
  --fg-bright: #fbf1c7;
  --fg-muted: #a89984;
  --fg-faint: #665c54;
  --red:       #fb4934;
  --green:     #b8bb26;
  --yellow:    #fabd2f;
  --orange:    #fe8019;
  --aqua:      #83a598;

  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-weight: 300;
  font-size: 14px;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "zero" 1, "tnum" 1;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.7 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--border-2);
  text-underline-offset: 3px;
  transition: color 150ms ease, text-decoration-color 150ms ease;
}
a:hover { color: var(--aqua); text-decoration-color: var(--aqua); }

code {
  font-family: var(--mono);
  color: var(--fg-bright);
  background: var(--surface);
  padding: 1px 5px;
  border: 1px solid var(--border);
}

sup { font-size: 0.75em; line-height: 0; }

.page {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 56px 40px 120px;
}

/* ───── masthead ───────────────────────────────────────── */
.masthead {
  margin-bottom: 56px;
}
.masthead h1 {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--fg-bright);
}
.masthead h1::before {
  content: "▌ ";
  color: var(--orange);
  letter-spacing: 0;
}
.tagline {
  margin: 0;
  color: var(--fg-muted);
  font-size: 13px;
  line-height: 1.65;
}

/* ───── section rules ──────────────────────────────────── */
.rule {
  font-size: 15px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--fg-bright);
  margin: 48px 0 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.rule::before {
  content: "───";
  color: var(--border-2);
  letter-spacing: 0;
  flex-shrink: 0;
}
.rule::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--border);
}
.rule-label {
  flex-shrink: 0;
  padding: 0 2px;
}

.block { margin-bottom: 8px; }

.prose {
  margin: 0 0 18px;
  color: var(--fg-muted);
  font-size: 13px;
  max-width: 64ch;
}

.note {
  margin: 0 0 22px;
  padding: 10px 14px 10px 16px;
  color: var(--fg);
  background: var(--surface);
  border-left: 2px solid var(--aqua);
  font-size: 12.5px;
}
.note strong {
  color: var(--aqua);
  font-weight: 500;
}

/* ───── forms ──────────────────────────────────────────── */
.form { margin: 0 0 8px; }

.field { margin-bottom: 22px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--fg-muted);
  margin-bottom: 6px;
}

.help {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--fg-muted);
  line-height: 1.5;
}
.help code {
  font-size: 11px;
  padding: 0 3px;
  background: transparent;
  border: none;
  color: var(--fg);
}

.field input {
  display: block;
  width: 100%;
  max-width: 420px;
  background: transparent;
  color: var(--fg-bright);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 400;
  border: none;
  border-bottom: 1px solid var(--border-2);
  padding: 8px 0;
  caret-color: var(--yellow);
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.field input::placeholder {
  color: var(--fg-faint);
}
.field input:focus {
  border-bottom-color: var(--orange);
  box-shadow: 0 2px 0 -1px var(--orange), 0 6px 0 -4px rgba(250, 189, 47, 0.18);
}
.field input:-webkit-autofill,
.field input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--fg-bright);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--yellow);
}
/* kill number spinners (they fight the mono aesthetic) */
.field input[type=number]::-webkit-inner-spin-button,
.field input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.field input[type=number] { -moz-appearance: textfield; }

.error {
  min-height: 1.5em;
  margin: 4px 0 14px;
  color: var(--red);
  font-size: 12px;
  font-weight: 500;
}
.error:empty { margin: 0; min-height: 0; }
.error:not(:empty)::before {
  content: "! ";
  display: inline-block;
  padding: 0 4px;
  margin-right: 6px;
  background: var(--red);
  color: var(--bg);
  font-weight: 700;
}

.submit {
  background: transparent;
  color: var(--fg-bright);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 10px 20px;
  border: none;
  border-left: 2px solid var(--orange);
  cursor: pointer;
  transition: background-color 120ms ease, transform 100ms ease;
}
.submit:hover { background: var(--surface-2); }
.submit:active { transform: translate(1px, 1px); }
.submit:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 3px;
}
.submit[data-pending="true"]::after {
  content: "_";
  display: inline-block;
  margin-left: 4px;
  color: var(--yellow);
  animation: blink 900ms steps(1) infinite;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ───── result / figure ────────────────────────────────── */
.result {
  margin: 28px 0 0;
  padding: 0;
  border-top: 1px solid var(--border);
  transition: outline-color 600ms ease, outline-offset 600ms ease;
  outline: 1px solid transparent;
  outline-offset: 4px;
}
.result[data-pulse="success"] { animation: pulse-green 700ms ease-out; }
.result[data-pulse="error"]   { animation: pulse-red 700ms ease-out; }
@keyframes pulse-green {
  0%   { outline-color: var(--green); outline-offset: 2px; }
  100% { outline-color: transparent; outline-offset: 4px; }
}
@keyframes pulse-red {
  0%   { outline-color: var(--red); outline-offset: 2px; }
  100% { outline-color: transparent; outline-offset: 4px; }
}

.cap {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 12px 0 8px;
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: lowercase;
  letter-spacing: 0.5px;
}
.cap-title { flex: 1 1 auto; }
.cap-time { font-variant-numeric: tabular-nums; color: var(--fg-muted); }

.copy {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 2px 0;
  cursor: pointer;
  transition: color 120ms ease;
  min-width: 10ch;
  text-align: left;
}
.copy:hover { color: var(--fg-bright); }
.copy:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 3px;
}
.copy[data-state="working"] { color: var(--fg-bright); }
.copy[data-state="success"] { color: var(--green); }
.copy[data-state="error"]   { color: var(--red); }

/* ───── tables ─────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  padding: 4px 0 12px;
}

.matrix {
  border-collapse: collapse;
  margin: 0;
  min-width: min(100%, max-content);
}

/* header row of column indices */
.matrix thead th {
  font-size: 10px;
  font-weight: 500;
  color: var(--fg-muted);
  padding: 4px 16px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  letter-spacing: 1px;
}
.matrix thead th.corner {
  text-align: left;
  color: var(--fg-faint);
  font-weight: 400;
}

.matrix tbody th {
  font-size: 10px;
  font-weight: 500;
  color: var(--fg-muted);
  padding: 8px 14px 8px 0;
  text-align: right;
  letter-spacing: 1px;
  border-right: 1px solid var(--border);
  vertical-align: middle;
}

.matrix td {
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-bright);
  padding: 8px 16px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  transition: background-color 100ms ease, border-left-color 100ms ease;
}
.matrix tr:last-child td { border-bottom: none; }

.matrix tbody tr:hover td { background: var(--surface-2); }
.matrix tbody tr:hover > th + td { border-left-color: var(--yellow); }

.matrix td.zero {
  color: var(--fg-faint);
  font-weight: 300;
}
.matrix td.diag {
  text-decoration: underline;
  text-decoration-color: var(--orange);
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}

/* print-in animation */
.matrix tbody tr {
  animation: row-in 260ms ease-out both;
  animation-delay: calc(var(--i, 0) * 40ms);
}
@keyframes row-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ───── references ─────────────────────────────────────── */
.refs {
  margin: 0;
  padding: 0 0 0 20px;
  color: var(--fg);
  font-size: 12px;
  font-style: italic;
  font-weight: 300;
  line-height: 1.6;
}
.refs li { margin-bottom: 14px; }
.refs li::marker { color: var(--fg-muted); }
.refs a {
  font-style: normal;
  color: var(--aqua);
  text-decoration-color: var(--border-2);
}

/* ───── modeline footer ────────────────────────────────── */
.modeline {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 40px 40px;
  font-size: 11px;
  color: var(--fg-muted);
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.modeline-inner { color: var(--fg-muted); }
.modeline-inner #modeline-status { color: var(--green); }
.byline {
  color: var(--fg-faint);
  font-size: 10.5px;
}
.byline a { color: var(--fg-muted); }

/* ───── reduced motion ─────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .matrix tbody tr { animation: none; }
  .result[data-pulse] { animation: none; }
  .submit[data-pending="true"]::after { animation: none; }
  *, *::before, *::after {
    transition-duration: 0ms !important;
  }
}

/* ───── mobile ─────────────────────────────────────────── */
@media (max-width: 520px) {
  .page { padding: 40px 20px 80px; }
  .modeline { padding: 20px 20px 32px; }
  .masthead h1 { font-size: 24px; }
  .rule { font-size: 13px; letter-spacing: 1.5px; gap: 10px; }
  .rule::before { content: "──"; }
  .matrix td { padding: 7px 10px; }
  .matrix thead th { padding: 4px 10px 8px; }
  .matrix tbody th { padding-right: 10px; }
  .cap { flex-wrap: wrap; }
}
