/* pulp design system: tokens, type, and shared components.
   Source of truth lives in web/; `cargo xtask site` copies it to site/. */

@font-face {
  font-family: "IBM Plex Sans";
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url("/fonts/plex-sans.woff2") format("woff2");
}
/* Pulp Mono is a subset of IBM Plex Mono (OFL) renamed as the licence requires;
   the query string changes whenever the subset does, because fonts cache for a year. */
@font-face {
  font-family: "Pulp Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/plex-mono-400.woff2?v=2") format("woff2");
}
@font-face {
  font-family: "Pulp Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/fonts/plex-mono-500.woff2?v=2") format("woff2");
}

:root {
  color-scheme: light dark;
  --ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Pulp Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-sm: 5px;
  --r-md: 6px;
  --r-lg: 9px;
  --row: 26px;
  --key: 30px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --bg: #ebe9e3;
  --panel: #f6f5f1;
  --panel-2: #ffffff;
  --panel-3: #ffffff;
  --sunken: #e3e0d9;
  --line: rgba(17, 17, 17, 0.1);
  --line-2: rgba(17, 17, 17, 0.19);
  --line-3: rgba(17, 17, 17, 0.32);
  --text: #141414;
  --text-2: #3c3c3a;
  --text-3: #5f5e5a;
  --label: #636057;
  --dot: rgba(17, 17, 17, 0.12);
  --paper: #fcfbf8;
  --paper-ink: #141414;
  --paper-rule: rgba(0, 0, 0, 0.07);
  --paper-muted: rgba(20, 20, 20, 0.64);
  --shadow: rgba(0, 0, 0, 0.16);
  --lip: rgba(0, 0, 0, 0.12);
  --hi: rgba(255, 255, 255, 0.9);
  --ok: #4d6b24;
  --warn: #8a5700;
  --warn-ink: #704600;
  --bad: #b23a1c;
  --acc: #b8461f;
  --acc-hover: #a33d1b;
  --acc-on: #fff8f0;
  --acc-text: #a83f1b;
  --acc-tint: rgba(184, 70, 31, 0.1);
  --term: #1b1c1f;
  --term-text: #e6e3db;
  --focus: #b8461f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --panel: #18191c;
    --panel-2: #202226;
    --panel-3: #2a2c31;
    --sunken: #0b0c0d;
    --line: rgba(236, 234, 228, 0.09);
    --line-2: rgba(236, 234, 228, 0.17);
    --line-3: rgba(236, 234, 228, 0.3);
    --text: #eceae4;
    --text-2: #c4c2bb;
    --text-3: #95938d;
    --label: #b7b3a6;
    --dot: rgba(236, 234, 228, 0.1);
    --paper: #e6e3db;
    --paper-ink: #161616;
    --paper-rule: rgba(0, 0, 0, 0.09);
    --paper-muted: rgba(22, 22, 22, 0.64);
    --shadow: rgba(0, 0, 0, 0.55);
    --lip: rgba(0, 0, 0, 0.3);
    --hi: rgba(255, 255, 255, 0.07);
    --ok: #a3bb74;
    --warn: #e2ae55;
    --warn-ink: #e2ae55;
    --bad: #f07f5f;
    --acc-text: #ea8a63;
    --acc-tint: rgba(214, 88, 44, 0.16);
    --term: #0b0c0d;
    --term-text: #d9d6ce;
    --focus: #ea8a63;
  }
}

@media (pointer: coarse) {
  :root {
    --row: 44px;
    --key: 44px;
  }
}

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

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

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 1.4px);
  background-size: 16px 16px;
  font: 400 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: color-mix(in srgb, var(--acc) 32%, transparent);
}

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

a {
  color: var(--acc-text);
  text-underline-offset: 3px;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.p-grow {
  flex: 1 1 auto;
}

/* icons: duotone strokes */
.p-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  fill: color-mix(in srgb, currentColor 22%, transparent);
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* mark and wordmark */
.p-mark {
  display: inline-block;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid var(--label);
  background: radial-gradient(
    circle,
    transparent 0 25%,
    var(--acc) 26% 38%,
    transparent 39% 53%,
    var(--label) 54% 58%,
    transparent 59%
  );
}

.p-word {
  font: 650 18px/1 var(--ui);
  letter-spacing: -0.035em;
  color: var(--text);
  text-decoration: none;
}

.p-label {
  font: 500 10.5px/1.2 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--label);
  white-space: nowrap;
}

.p-meta {
  font: 500 11px/1.3 var(--mono);
  color: var(--text-3);
}

.p-kbd {
  font: 500 10px/1 var(--mono);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 5px;
  color: var(--text-3);
  background: var(--panel-2);
}

/* keys: letterpress buttons in the typewriter voice */
.p-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--key);
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font: 500 11px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: inset 0 1px 0 var(--hi), inset 0 -2px 0 var(--lip);
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  -webkit-tap-highlight-color: transparent;
}
.p-key:hover:not([aria-disabled="true"]) {
  border-color: var(--line-3);
  background: var(--panel-3);
}
.p-key:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(1px);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 -1px 0 var(--lip);
}
.p-key:disabled,
.p-key[aria-disabled="true"] {
  opacity: 0.42;
  cursor: not-allowed;
}
.p-key.is-primary {
  background: var(--acc);
  color: var(--acc-on);
  border-color: color-mix(in srgb, var(--acc) 72%, #000);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.28),
    0 1px 0 rgba(0, 0, 0, 0.18);
}
.p-key.is-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--acc-hover);
  border-color: color-mix(in srgb, var(--acc) 72%, #000);
}
.p-key.is-quiet {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-2);
  padding: 0 8px;
}
.p-key.is-quiet:hover:not(:disabled):not([aria-disabled="true"]) {
  color: var(--text);
  background: color-mix(in srgb, var(--text) 7%, transparent);
}
.p-key[aria-expanded="true"] {
  background: var(--panel-3);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
  transform: translateY(1px);
}
.p-key.is-sm {
  min-height: 26px;
  padding: 0 9px;
  font-size: 10.5px;
}
.p-key.is-lg {
  min-height: 40px;
  padding: 0 18px;
  font-size: 12px;
}
.p-key.is-xl {
  min-height: 48px;
  padding: 0 22px;
  font-size: 12.5px;
}
.p-key.is-sq {
  width: var(--key);
  padding: 0;
}
.p-key.is-block {
  width: 100%;
}
.p-key .p-kbdhint {
  opacity: 0.9;
  font-size: 10px;
  letter-spacing: 0.02em;
}
.p-key .p-count {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0;
  background: color-mix(in srgb, currentColor 16%, transparent);
}
@media (pointer: coarse) {
  .p-key.is-sm,
  .p-key.is-lg {
    min-height: 44px;
    min-width: 44px;
  }
}

/* key groups: a radio group drawn as a row of keys */
.p-seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  margin: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  background: var(--sunken);
  min-width: 0;
}
.p-seg label {
  position: relative;
  display: inline-flex;
}
.p-seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.p-seg span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 4px;
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  cursor: pointer;
}
.p-seg input:hover + span {
  color: var(--text);
}
.p-seg input:checked + span {
  background: var(--panel-3);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 -2px 0 var(--lip), 0 0 0 1px var(--line-2);
}
.p-seg input:focus-visible + span,
.p-seg.is-kbd input:focus + span {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.p-seg input:disabled + span {
  opacity: 0.45;
  cursor: not-allowed;
}
@media (pointer: coarse) {
  .p-seg span {
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    padding: 0 12px;
  }
}

/* fields */
.p-field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: var(--key);
  padding: 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--sunken);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
  color: var(--text);
}
.p-field:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 30%, transparent);
}
.p-field .p-icon {
  color: var(--text-3);
}
.p-field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  min-height: calc(var(--key) - 2px);
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  font: 400 12.5px/1 var(--mono);
}
.p-field input::placeholder {
  color: var(--text-3);
  opacity: 1;
}
@media (pointer: coarse) {
  .p-field input {
    font-size: 16px;
  }
}

/* checkboxes */
.p-check {
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  margin: 0;
  border-radius: 3px;
  border: 1.5px solid color-mix(in srgb, var(--text) 36%, transparent);
  background: var(--sunken);
  cursor: pointer;
}
.p-check:checked,
.p-check:indeterminate {
  border-color: var(--acc);
  background-color: var(--acc);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px 10px;
}
.p-check:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m3.5 8.5 3 3 6-7' fill='none' stroke='%23fff8f0' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.p-check:indeterminate {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8h8' fill='none' stroke='%23fff8f0' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}
.p-check:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
@media (pointer: coarse) {
  .p-check {
    width: 20px;
    height: 20px;
    flex-basis: 20px;
    background-size: 14px 14px;
  }
}

/* chips */
.p-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-2);
  font: 500 11px/1 var(--mono);
  white-space: nowrap;
  cursor: pointer;
}
.p-chip em {
  font-style: normal;
  color: var(--text-3);
}
.p-chip .p-icon {
  width: 12px;
  height: 12px;
  color: var(--acc-text);
}
.p-chip:hover {
  border-color: var(--line-3);
  color: var(--text);
}
.p-chip[data-state="on"] {
  background: var(--acc-tint);
  border-color: color-mix(in srgb, var(--acc) 50%, transparent);
  color: var(--text);
}
.p-chip[data-state="mix"] {
  border-style: dashed;
  border-color: var(--label);
  color: var(--text);
}
@media (pointer: coarse) {
  .p-chip {
    min-height: 44px;
    padding: 0 12px;
  }
}

/* raised panes */
.p-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: inset 0 1px 0 var(--hi), 0 18px 34px -20px var(--shadow),
    0 2px 6px color-mix(in srgb, var(--shadow) 55%, transparent);
}

/* the ledger sheet: numbered, ruled paper for dumps */
.p-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: var(--r-md);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 10px 24px -14px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.p-ledger {
  --lh: 20px;
  --gutter: 44px;
  margin: 0;
  padding: 8px 0;
  font: 400 12px/var(--lh) var(--mono);
  font-variant-ligatures: none;
  tab-size: 4;
  color: var(--paper-ink);
  background-image: linear-gradient(
      to right,
      transparent var(--gutter),
      color-mix(in srgb, var(--acc) 55%, transparent) var(--gutter) calc(var(--gutter) + 1px),
      transparent calc(var(--gutter) + 1px)
    ),
    linear-gradient(to bottom, transparent calc(var(--lh) - 1px), var(--paper-rule) calc(var(--lh) - 1px));
  background-size: 100% 100%, 100% var(--lh);
  background-position: 0 0, 0 8px;
  background-repeat: repeat-y, repeat;
  background-attachment: local, local;
}
.p-ledger .ln {
  display: block;
  position: relative;
  min-height: var(--lh);
  padding: 0 14px 0 calc(var(--gutter) + 12px);
  white-space: pre;
}
.p-ledger .ln::before {
  content: attr(data-n);
  /* line numbers are decoration: screen readers skip them where the engine allows */
  content: attr(data-n) / "";
  position: absolute;
  left: 0;
  width: calc(var(--gutter) - 10px);
  text-align: right;
  color: var(--paper-muted);
  user-select: none;
  -webkit-user-select: none;
}
.p-ledger.is-wrap .ln {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.p-ledger .chunk {
  content-visibility: auto;
}

/* status dot + label */
.p-status {
  --c: var(--ok);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 500 12.5px/1.2 var(--ui);
  color: var(--text);
  white-space: nowrap;
}
.p-status::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent);
}
.p-status[data-tone="warn"] {
  --c: var(--warn);
}
.p-status[data-tone="bad"] {
  --c: var(--bad);
}
.p-status[data-tone="busy"] {
  --c: var(--acc-text);
}
.p-status[data-tone="idle"],
.p-status[data-tone="stale"] {
  --c: var(--text-3);
}
.p-status[data-tone="idle"]::before,
.p-status[data-tone="stale"]::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--c);
}
.p-status[data-tone="busy"]::before {
  animation: p-pulse 1.1s ease-in-out infinite;
}

/* tabs */
.p-tabs {
  display: flex;
  align-items: stretch;
  gap: 18px;
  min-height: 42px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--line);
}
@media (pointer: coarse) {
  .p-tabs {
    min-height: 45px;
  }
}
.p-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0 0;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font: 500 10.5px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.p-tab:focus-visible {
  outline-offset: -2px;
}
.p-tab:hover {
  color: var(--text);
}
.p-tab[aria-selected="true"] {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--acc);
}
.p-tab .p-badge {
  padding: 2px 5px;
  border-radius: 4px;
  letter-spacing: 0;
  color: var(--warn-ink);
  background: color-mix(in srgb, var(--warn) 20%, transparent);
}

/* notes: inline alerts */
.p-note > .p-key {
  flex: none;
}
.p-note {
  --c: var(--warn);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}
.p-note[data-tone="bad"] {
  --c: var(--bad);
}
.p-note > .p-icon {
  margin-top: 2px;
  color: var(--c);
}
.p-note-body {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.p-note-body pre {
  margin: 6px 0 0;
  max-height: 10rem;
  overflow: auto;
  white-space: pre-wrap;
  font: 12px/1.45 var(--mono);
  color: var(--text-2);
}
.p-note-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

/* toasts */
.p-toasts {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(20px + var(--safe-b));
  z-index: 60;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
}
.p-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font: 500 12.5px/1.3 var(--ui);
  box-shadow: 0 16px 36px -12px var(--shadow);
  animation: p-rise 0.18s ease-out;
}
.p-toast .p-icon {
  color: var(--ok);
}

/* progress rule */
.p-progress {
  position: relative;
  height: 3px;
  overflow: hidden;
  background: color-mix(in srgb, var(--acc) 18%, transparent);
}
.p-progress::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 38%;
  background: linear-gradient(90deg, transparent, var(--acc), transparent);
  animation: p-sweep 1.2s ease-in-out infinite;
}
.p-progress[data-p]::before {
  width: calc(var(--p, 0) * 100%);
  background: linear-gradient(90deg, var(--acc), color-mix(in srgb, var(--acc) 60%, #fff));
  animation: none;
  transition: width 0.2s ease;
}

@keyframes p-sweep {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(270%);
  }
}
@keyframes p-pulse {
  50% {
    opacity: 0.35;
  }
}
@keyframes p-rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
@keyframes p-spin {
  to {
    transform: rotate(360deg);
  }
}

.p-spin {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  animation: p-spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .p-progress:not([data-p])::before {
    width: 100%;
    transform: none;
    background: color-mix(in srgb, var(--acc) 45%, transparent);
  }
}

/* Forced colors (Windows High Contrast) drop backgrounds and shadows, which is
   how ticks and selected keys are drawn; give them system colors and outlines. */
@media (forced-colors: active) {
  .p-check {
    forced-color-adjust: none;
    border-color: CanvasText;
    background-color: Canvas;
  }
  .p-check:checked,
  .p-check:indeterminate {
    border-color: Highlight;
    background-color: Highlight;
  }
  .p-seg input:checked + span {
    outline: 2px solid Highlight;
    outline-offset: -2px;
  }
  .p-tab[aria-selected="true"] {
    border-bottom: 2px solid Highlight;
  }
  .p-chip[data-state="on"] {
    border-color: Highlight;
  }
  .p-progress::before,
  .p-status::before {
    forced-color-adjust: none;
    background: Highlight;
  }
  .p-status[data-tone="idle"]::before,
  .p-status[data-tone="stale"]::before {
    background: Canvas;
    box-shadow: inset 0 0 0 1.5px CanvasText;
  }
}
