/*
 * Topo — Dyhedral design system, v0.2
 * One file: tokens, base, type, layout, components.
 * Drawn from climbing guidebooks, survey maps and aeronautical charts:
 * cool granite paper, spruce ink, one lichen signal colour, hairline rules,
 * tight headlines, mono labels, gently rounded corners.
 *
 * Fonts (Google Fonts):
 *   Instrument Sans (variable: wght 400-700) — display and text, one family
 *   Spline Sans Mono                         — labels, grades, code
 * <link href="https://fonts.googleapis.com/css2?family=Instrument+Sans:wght@400..700&family=Spline+Sans+Mono:wght@400;500;600&display=swap" rel="stylesheet">
 *
 * Contents: 1 tokens  2 base  3 type  4 layout  5 components
 */

/* ============ 1. tokens ============ */
:root {
  /* colour: raw palette. Components use the roles below, not these. */
  --granite-0: #f2f5f3;
  --granite-1: #e5eae7;
  --granite-2: #cdd5d1;
  --granite-3: #9aa6a1;
  --granite-4: #56625d;
  --spruce-0:  #0e2620;
  --spruce-1:  #173b31;
  --spruce-2:  #24584a;
  --lichen:    #9fc21c;
  --lichen-ink:#3f5a08;
  --tide:      #24607f;
  --buoy:      #c93a1f;

  /* colour: roles */
  --bg: var(--granite-0);
  --bg-alt: var(--granite-1);
  --surface: #fafcfb;
  --text: var(--spruce-0);
  --text-2: var(--granite-4);
  --text-3: #6f7b76;
  --rule: var(--granite-2);
  --rule-strong: var(--spruce-0);
  --signal: var(--lichen);          /* fills and marks only */
  --signal-text: var(--lichen-ink); /* lichen when it must be read as text */
  --on-signal: var(--spruce-0);
  --link: var(--tide);
  --danger: var(--buoy);
  --ok: var(--spruce-2);
  --inverse-bg: var(--spruce-0);
  --inverse-text: #e9f0ec;
  --inverse-text-2: #9fb3ab;
  --inverse-rule: #2a4a40;

  /* type */
  --font-display: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --display-weight: 700;
  --size-0: 12px;                          /* label */
  --size-1: 14px;                          /* small, code */
  --size-2: 16px;                          /* body small, buttons */
  --size-3: 18px;                          /* body */
  --size-4: 22px;                          /* h3, lede */
  --size-5: clamp(24px, 2.6vw, 30px);      /* statement */
  --size-6: clamp(32px, 4.2vw, 50px);      /* h2 */
  --size-7: clamp(42px, 6.4vw, 84px);      /* h1 */
  --leading-tight: 1.02;
  --leading-snug: 1.25;
  --leading-body: 1.55;
  --track-display: -0.04em;
  --track-heading: -0.02em;
  --track-label: 0.12em;

  /* space: 4px base */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px;
  --s-6: 32px; --s-7: 48px; --s-8: 72px; --s-9: 112px;

  /* shape */
  --radius-sm: 4px;    /* tags, marks, inputs' inner bits */
  --radius: 8px;       /* buttons, inputs */
  --radius-lg: 14px;   /* panels, terminal, figures. Never pills. */
  --hair: 1px;
  --heavy: 3px;

  /* layout */
  --measure: 62ch;
  --page: 1180px;
  --gutter: var(--s-5);

  /* motion */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --fast: 140ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1714; --bg-alt: #0f201b; --surface: #112520;
    --text: #e9f0ec; --text-2: #a3b4ad; --text-3: #7d8f88;
    --rule: #254138; --rule-strong: #e9f0ec;
    --signal-text: var(--lichen); --link: #86c5e2; --danger: #ff8068; --ok: #7fcdb4;
    --inverse-bg: #e9f0ec; --inverse-text: var(--spruce-0);
    --inverse-text-2: #4d5c56; --inverse-rule: #c3cec9;
  }
}
:root[data-theme="dark"] {
  --bg: #0a1714; --bg-alt: #0f201b; --surface: #112520;
  --text: #e9f0ec; --text-2: #a3b4ad; --text-3: #7d8f88;
  --rule: #254138; --rule-strong: #e9f0ec;
  --signal-text: var(--lichen); --link: #86c5e2; --danger: #ff8068; --ok: #7fcdb4;
  --inverse-bg: #e9f0ec; --inverse-text: var(--spruce-0);
  --inverse-text-2: #4d5c56; --inverse-rule: #c3cec9;
}

/* ============ 2. base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font-sans); font-size: var(--size-3); line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img, svg, video { max-width: 100%; }
::selection { background: var(--signal); color: var(--on-signal); }
:focus-visible { outline: var(--heavy) solid var(--signal-text); outline-offset: 3px; border-radius: 2px; }

/* links: ink text, tide underline that thickens on hover */
a {
  color: inherit; text-decoration: underline; text-decoration-color: var(--link);
  text-decoration-thickness: 1.5px; text-underline-offset: 4px;
  transition: text-decoration-thickness var(--fast) var(--ease);
}
a:hover { text-decoration-thickness: 3px; }

/* ============ 3. type ============ */
.t-display, h1, h2, h3, h4 {
  font-family: var(--font-display); font-weight: var(--display-weight);
  letter-spacing: var(--track-display); line-height: var(--leading-tight);
  margin: 0; text-wrap: balance;
}
h1, .t-h1 { font-size: var(--size-7); }
h2, .t-h2 { font-size: var(--size-6); letter-spacing: -0.035em; line-height: 1.06; }
h3, .t-h3 { font-size: var(--size-4); font-weight: 650; letter-spacing: var(--track-heading); line-height: 1.18; }
h4, .t-h4 { font-size: var(--size-3); font-weight: 650; letter-spacing: -0.01em; line-height: 1.3; }
p { margin: 0; text-wrap: pretty; }
.t-statement { font-family: var(--font-display); font-size: var(--size-5); font-weight: 600; letter-spacing: -0.025em; line-height: 1.2; max-width: 28ch; }
.t-lede { font-size: var(--size-4); line-height: 1.4; color: var(--text-2); max-width: 34em; }
.t-body { max-width: var(--measure); }
.t-small { font-size: var(--size-2); }
.t-muted { color: var(--text-2); }
.t-num { font-variant-numeric: tabular-nums; }

/* label: the guidebook caption. Mono, uppercase, tracked. */
.t-label {
  font-family: var(--font-mono); font-size: var(--size-0); font-weight: 500;
  letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-2);
}
/* highlighter: the only place lichen sits behind running text. Once per screen. */
.t-mark {
  background: var(--signal); color: var(--on-signal); padding: 0 0.14em;
  border-radius: var(--radius-sm); box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
code, kbd, .t-code {
  font-family: var(--font-mono); font-size: 0.86em; background: var(--bg-alt);
  border: var(--hair) solid var(--rule); border-radius: var(--radius-sm); padding: 0.1em 0.35em;
}
blockquote, .t-quote {
  margin: 0; padding-left: var(--s-5); border-left: var(--heavy) solid var(--signal);
  font-family: var(--font-display); font-size: var(--size-4); font-weight: 500;
  letter-spacing: -0.015em; line-height: 1.35; max-width: 30em;
}
.t-quote cite, blockquote cite { display: block; margin-top: var(--s-3); font-style: normal; }
.t-list { margin: 0; padding: 0; list-style: none; }
.t-list > li { position: relative; padding: var(--s-2) 0 var(--s-2) var(--s-5); border-top: var(--hair) solid var(--rule); }
.t-list > li::before { content: ""; position: absolute; left: 2px; top: 1.05em; width: 8px; height: 8px; border-radius: 2px; background: var(--signal); border: var(--hair) solid var(--text); }

/* ============ 4. layout ============ */
.t-page { max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter); }
.t-section { padding: var(--s-8) 0; }
.t-stack > * + * { margin-top: var(--s-4); }
.t-stack--lg > * + * { margin-top: var(--s-6); }
.t-row { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: center; }
.t-split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-7); align-items: center; }
.t-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s-6); }
.t-rule { border: 0; border-top: var(--hair) solid var(--rule); margin: 0; }
.t-rule--heavy { border-top: var(--heavy) solid var(--rule-strong); }
@media (max-width: 820px) {
  .t-split { grid-template-columns: minmax(0, 1fr); gap: var(--s-6); }
  .t-section { padding: var(--s-7) 0; }
}

/* ============ 5. components ============ */

/* nav: wordmark left, links right, heavy rule under */
.t-nav { display: flex; justify-content: space-between; align-items: center; gap: var(--s-5); padding: var(--s-5) 0; border-bottom: var(--heavy) solid var(--rule-strong); }
.t-nav a { text-decoration: none; }
.t-nav a.t-label:hover { color: var(--text); }
.t-wordmark { display: inline-flex; align-items: center; gap: var(--s-3); color: var(--text); font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: var(--track-display); text-decoration: none; }
.t-wordmark svg { width: 24px; height: 24px; flex: none; }

/* buttons: plain ink, sentence case, an arrow that moves on hover. Never pills. */
.t-btn {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-sans); font-size: var(--size-2); font-weight: 600; letter-spacing: -0.01em; line-height: 1.2;
  text-decoration: none; padding: 13px 20px; border: var(--hair) solid var(--text);
  background: var(--text); color: var(--bg); cursor: pointer; border-radius: var(--radius);
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.t-btn::after { content: "\2192"; transition: transform var(--fast) var(--ease); }
.t-btn:hover { background: var(--signal); color: var(--on-signal); border-color: var(--on-signal); }
.t-btn:hover::after { transform: translateX(4px); }
.t-btn--quiet { background: transparent; color: var(--text); }
.t-btn--quiet:hover { background: var(--text); color: var(--bg); border-color: var(--text); }
.t-btn--plain::after { content: none; }
.t-btn[disabled], .t-btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

/* tag: a grade, a status, a version */
.t-tag {
  display: inline-block; font-family: var(--font-mono); font-size: var(--size-0); font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; line-height: 1.4;
  padding: 3px 8px; border: var(--hair) solid var(--rule-strong); border-radius: var(--radius-sm); color: var(--text);
}
.t-tag--signal { background: var(--signal); color: var(--on-signal); border-color: var(--signal); }
.t-tag--danger { border-color: var(--danger); color: var(--danger); }
.t-tag--quiet { border-color: var(--rule); color: var(--text-2); }

/* form fields */
.t-field { display: grid; gap: var(--s-2); max-width: 420px; }
.t-field > label { font-weight: 600; font-size: var(--size-2); }
.t-input, .t-field input, .t-field textarea, .t-field select {
  font: inherit; font-size: var(--size-2); color: var(--text); background: var(--surface);
  border: var(--hair) solid var(--granite-3); border-radius: var(--radius); padding: 11px 13px; width: 100%;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.t-field input::placeholder, .t-field textarea::placeholder { color: var(--text-3); }
.t-field input:hover, .t-field textarea:hover, .t-field select:hover { border-color: var(--text); }
.t-field input:focus, .t-field textarea:focus, .t-field select:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px var(--signal); }
.t-help { font-size: var(--size-1); color: var(--text-2); }
.t-field--error input, .t-field--error textarea { border-color: var(--danger); }
.t-field--error .t-help { color: var(--danger); }

/* note: an aside with a signal bar. For caveats and status, not decoration. */
.t-note { border-left: var(--heavy) solid var(--signal); background: var(--bg-alt); padding: var(--s-4) var(--s-5); border-radius: 0 var(--radius) var(--radius) 0; max-width: var(--measure); font-size: var(--size-2); }
.t-note--danger { border-left-color: var(--danger); }

/* panel: a bordered, rounded box. No shadow. One per page at most. */
.t-panel { background: var(--surface); border: var(--hair) solid var(--rule); border-radius: var(--radius-lg); padding: var(--s-6); }

/* ledger: numbered rows under a heavy rule. Use instead of a card grid. */
.t-ledger { border-top: var(--heavy) solid var(--rule-strong); }
.t-ledger > * {
  display: grid; grid-template-columns: 5ch minmax(0, 1fr) minmax(0, 1.4fr); gap: var(--s-5);
  padding: var(--s-5) 0; border-bottom: var(--hair) solid var(--rule); align-items: baseline;
}
@media (max-width: 760px) {
  .t-ledger > * { grid-template-columns: 5ch minmax(0, 1fr); }
  .t-ledger > * > :nth-child(3) { grid-column: 2; }
}

/* table: rules only, mono header, tabular numbers */
.t-table { width: 100%; border-collapse: collapse; font-size: var(--size-2); font-variant-numeric: tabular-nums; }
.t-table th { font-family: var(--font-mono); font-size: var(--size-0); font-weight: 500; letter-spacing: var(--track-label); text-transform: uppercase; color: var(--text-2); text-align: left; padding: var(--s-3) var(--s-4) var(--s-3) 0; border-bottom: var(--heavy) solid var(--rule-strong); }
.t-table td { padding: var(--s-3) var(--s-4) var(--s-3) 0; border-bottom: var(--hair) solid var(--rule); vertical-align: top; }
.t-table .num { text-align: right; padding-right: 0; }
.t-table-wrap { overflow-x: auto; }

/* stat: one number and what it measures */
.t-stat { display: grid; gap: var(--s-1); }
.t-stat b { font-family: var(--font-display); font-size: var(--size-6); font-weight: 700; letter-spacing: var(--track-display); line-height: 1; font-variant-numeric: tabular-nums; }

/* figure */
.t-figure { margin: 0; }
.t-figure > :first-child { display: block; width: 100%; border: var(--hair) solid var(--rule); border-radius: var(--radius-lg); background: var(--surface); }
.t-figure figcaption { margin-top: var(--s-3); font-family: var(--font-mono); font-size: var(--size-0); letter-spacing: 0.06em; color: var(--text-2); }

/* inverse band: spruce block for the one section that should stop the eye */
.t-inverse { background: var(--inverse-bg); color: var(--inverse-text); }
.t-inverse .t-label, .t-inverse .t-muted, .t-inverse .t-lede { color: var(--inverse-text-2); }
.t-inverse .t-tag { border-color: var(--inverse-text); color: var(--inverse-text); }
.t-inverse .t-tag--signal { color: var(--on-signal); border-color: var(--signal); }
.t-inverse .t-btn { background: var(--signal); color: var(--on-signal); border-color: var(--signal); }
.t-inverse .t-btn:hover { background: var(--inverse-text); border-color: var(--inverse-text); color: var(--inverse-bg); }

/* terminal */
.t-term {
  font-family: var(--font-mono); font-size: var(--size-1); line-height: 1.8;
  background: #071310; color: #cfe0d8; border: var(--hair) solid #254138;
  border-radius: var(--radius-lg); padding: var(--s-5); overflow-x: auto;
}
.t-term .dim { color: #7d948a; } .t-term .ok { color: var(--lichen); }

/* contour field: faint topo lines. Decorative; at most one block per page. */
.t-contours {
  background-image: repeating-radial-gradient(ellipse 120% 90% at 82% 20%, transparent 0 34px, color-mix(in srgb, var(--rule) 55%, transparent) 34px 35px);
}

/* footer */
.t-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: var(--s-4); padding: var(--s-5) 0 var(--s-7); border-top: var(--heavy) solid var(--rule-strong); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
