/* ==========================================================================
   Assay — tokens + shared primitives
   Imported by the landing (styles.css) and the app (app/app.css).
   Part 1: brand tokens (brand.md). Part 2: derived tokens. Part 3: base and
   primitives that must look identical in both places.
   ========================================================================== */

:root {
  color-scheme: dark;

  /* ---- brand (brand.md: Assay — graphite touchstone, gold, pyrite) ----
     Variable names are kept from the first palette so the landing and app
     need no renames: ledger = page, sheet = card, ink = text, moss = kept. */
  --ledger: #1B1C1F;   /* page background — graphite touchstone */
  --sheet: #26282C;    /* cards, sheets — slate */
  --rule: #3C3F45;     /* dividers, table lines */
  --ink: #F2EEE6;      /* primary text — chalk */
  --ink-2: #A7A39B;    /* secondary text */
  --redline: #E4533F;  /* the cut: strikes, brackets, cut counts */
  --moss: #D9A441;     /* kept / verified — gold */
  --gold: #D9A441;
  --gold-bright: #F0C45C;
  --pyrite: #8A8F7A;   /* farms: dull brass-grey rows */

  /* ---- derived ---- */
  --redline-text: #F07A68;                 /* red for small text: 6.1:1 on slate */
  --redline-wash: rgb(228 83 63 / 0.10);   /* struck rows */
  --moss-wash: rgb(217 164 65 / 0.14);     /* kept chips */
  --ink-press: #FFFFFF;                    /* hover on chalk-filled controls */
  --field-edge: #73777F;                   /* input borders: 3.3:1 on slate, 3.8:1 on graphite */
  --row-hover: #303338;                    /* table row hover on sheet */
  --ledger-2: #232529;                     /* hover on page bg */
  --placeholder: #96928A;                  /* 4.8:1 on slate */
  --scrim: rgb(0 0 0 / 0.55);
  --on-gold: #1B1C1F;                      /* text on gold buttons */

  /* ---- shape ---- */
  --r-card: 8px;
  --r-ctl: 6px;
  --r-chip: 999px;
  --shadow-rule: 0 1px 0 var(--rule);

  /* ---- type ---- */
  --font-display: "Funnel Display", "Funnel Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Funnel Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Martian Mono", ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;

  /* ---- spacing: one scale, sections use --section ---- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;
  --section: clamp(72px, 9vw, 128px);
  --gutter: clamp(20px, 4vw, 48px);
  --measure: 1240px;

  /* ---- motion ---- */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --t-ui: 180ms;
}

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

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

body {
  margin: 0;
  background: var(--ledger);
  color: var(--ink);
  font: 400 17px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, ul, ol, figure, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

::selection { background: var(--ink); color: var(--ledger); }

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

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

.skip-link {
  position: fixed;
  left: 12px; top: 12px;
  z-index: 200;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--sheet);
  border-radius: var(--r-ctl);
  font: 500 14px/1 var(--font-body);
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--t-ui) var(--ease);
}
.skip-link:focus-visible { transform: none; }

/* ---------- type primitives ---------- */
.mono {
  font-family: var(--font-mono);
  font-stretch: 87.5%;
  font-variant-numeric: tabular-nums;
}

.label {
  font: 500 12px/1.3 var(--font-mono);
  font-stretch: 87.5%;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
}

.small { font-size: 14px; line-height: 1.5; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-ctl);
  background: transparent;
  color: var(--ink);
  font: 500 15px/1 var(--font-body);
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t-ui) var(--ease), border-color var(--t-ui) var(--ease), color var(--t-ui) var(--ease);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn--primary { background: var(--gold); color: var(--on-gold); }
.btn--primary:hover { background: var(--gold-bright); }
.btn--secondary { border-color: var(--ink-2); color: var(--ink); }
.btn--secondary:hover { background: var(--row-hover); border-color: var(--ink); }
.btn--quiet { padding: 0 8px; min-height: 36px; color: var(--ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; text-decoration-color: var(--ink-2); }
.btn--quiet:hover { text-decoration-thickness: 2px; }
.btn--sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.sheet .btn--secondary:hover { background: var(--row-hover); }

/* ---------- surfaces ---------- */
.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--r-card);
  box-shadow: none; /* brand: no shadows, depth = surface steps */
}

/* ledger total line: used under product sheets, card footers, price rows */
.total-rule { border-top: 3px double var(--ink); }

/* ---------- chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-chip);
  background: var(--sheet);
  color: var(--ink-2);
  font: 500 12px/1 var(--font-mono);
  font-stretch: 87.5%;
  white-space: nowrap;
}
.chip svg { width: 12px; height: 12px; flex: none; }
.chip--keep { color: var(--gold-bright); background: var(--moss-wash); border-color: rgb(217 164 65 / 0.4); }
.chip--cut { color: var(--redline-text); background: var(--redline-wash); border-color: rgb(228 83 63 / 0.4); }
.chip--ink { color: var(--ink); border-color: var(--ink-2); background: transparent; }

/* ---------- form fields ---------- */
.field { display: grid; gap: 6px; align-content: start; }
.field__label { font: 500 14px/1.3 var(--font-body); color: var(--ink); }
.field__opt { font-weight: 400; color: var(--ink-2); }
.field__hint { font-size: 13px; line-height: 1.4; color: var(--ink-2); }
.field__error { font-size: 13px; line-height: 1.4; color: var(--redline-text); }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--sheet);
  color: var(--ink);
  border: 1px solid var(--field-edge);
  border-radius: var(--r-ctl);
  font: 400 16px/1.3 var(--font-body);
  transition: border-color var(--t-ui) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--placeholder); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-2); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--redline-text); }
.input--mono, .textarea--mono { font: 400 14px/1.4 var(--font-mono); font-stretch: 87.5%; letter-spacing: 0; }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23F2EEE6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 1.75 6 6.25l4.5-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.4; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--ink); flex: none; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(520px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--ink);
  color: var(--sheet);
  border-radius: var(--r-ctl);
  font: 400 14px/1.4 var(--font-body);
  animation: toast-in 200ms var(--ease) both;
}
.toast.is-leaving { animation: toast-out 160ms var(--ease) both; }
.toast__mark { width: 16px; height: 16px; flex: none; }
.toast__text { flex: 1; min-width: 0; }
.toast__link { color: var(--sheet); font-weight: 500; text-underline-offset: 3px; white-space: nowrap; }
.toast__close {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-ctl);
  background: transparent; color: var(--sheet);
}
.toast__close:hover { background: rgb(27 28 31 / 0.14); }
.toast :focus-visible { outline-color: var(--sheet); }
.toast__close svg { width: 14px; height: 14px; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(4px); } }

/* ---------- the redline path ----------
   An SVG <path pathLength="1"> drawn by dash offset. Hidden until it, or an
   ancestor, has .is-drawn. --draw / --draw-delay tune the pencil. */
.redline-path {
  fill: none;
  stroke: var(--redline);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 2;
  stroke-dashoffset: 1;
  opacity: 0;
  transition:
    stroke-dashoffset 220ms var(--ease),
    opacity 0s linear 220ms;
}
.is-drawn .redline-path,
.redline-path.is-drawn {
  stroke-dashoffset: 0;
  opacity: 1;
  transition:
    stroke-dashoffset var(--draw, 320ms) var(--ease) var(--draw-delay, 0ms),
    opacity 0s linear var(--draw-delay, 0ms);
}

/* ---------- diagrams (funding tree, timing histogram, exhibits) ---------- */
.dg { width: 100%; height: auto; overflow: visible; }
.dg-line { fill: none; stroke: var(--ink-2); stroke-width: 1.2; stroke-linecap: round; }
.dg-line--thin { stroke-width: 1; opacity: 0.7; }
.dg-node { fill: var(--gold); }
.dg-leaf { fill: var(--pyrite); }
.dg-box { fill: var(--sheet); stroke: var(--ink-2); stroke-width: 1.4; }
.dg-red { fill: none; stroke: var(--redline); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dg-axis { fill: none; stroke: var(--ink); stroke-width: 1; }
.dg-bar { fill: var(--ink-2); opacity: 0.55; }
.dg-bar--hot { fill: var(--redline); opacity: 1; }
.dg-text {
  font: 500 12.5px/1 var(--font-mono);
  font-stretch: 87.5%;
  fill: var(--ink-2);
  letter-spacing: 0.02em;
}
.dg-text--ink { fill: var(--ink); font-size: 13px; }
.dg-text--red { fill: var(--redline-text); font-size: 13.5px; }
.dg-text--small { font-size: 12px; }

/* ---------- motion preference: show final states ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}
