/* ==========================================================
   Shared styles for the pages under the home page
   (/audit and its case study).
   Tokens, type, header and rail are copied from the
   home page's inline styles so every page reads as one site:
   cream for the work, navy for the numbers, yellow to close.
   ========================================================== */

/* ---------- tokens ---------- */
:root {
  --bg: #f5f4ef;
  --surface: #ebe9e1;
  --rule: #d9d6cb;
  --ink: #0f2346;
  --muted: #4b5570;
  --accent: #f3cc57;
  --accent-ink: #0f2346;
  --dark: #0f2346;
  --dark-surface: #172f58;
  --dark-ink: #f5f4ef;
  --dark-muted: #b4bcd2;
  --gain: #1d6b47;
  --loss: #a83a2f;
  --warn: #8a5a00;

  --font-display: 'DM Serif Display', Georgia, 'Times New Roman', serif;
  --font-text: 'Albert Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --step-small: 0.9rem;
  --step-body: clamp(1.0625rem, 1rem + 0.25vw, 1.15rem);
  --step-lead: clamp(1.25rem, 1.1rem + 0.6vw, 1.55rem);
  --step-head: clamp(2.1rem, 1.3rem + 2.4vw, 3.4rem);
  --step-title: clamp(2.8rem, 6.4vw, 6.5rem);

  --pad: clamp(1.25rem, 4vw, 2.5rem);
  --rail: 13.5rem;
  --gutter: clamp(2.5rem, 4vw, 4.5rem);
  --measure: 38rem;
  --out: 0px;
  --section: clamp(4.5rem, 8vw, 7rem);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --t-press: 140ms;
  --t-hover: 180ms;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-text); font-size: var(--step-body); line-height: 1.58; font-kerning: normal; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden; }
h1, h2, h3, p, figure, ul, ol, dl, dd, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, video, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.skip { position: absolute; left: var(--pad); top: 1rem; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); background: var(--accent); color: var(--accent-ink); padding: .6rem 1rem; z-index: 50; text-decoration: none; }
.skip:focus { width: auto; height: auto; clip-path: none; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 400; text-wrap: balance; hyphens: none; letter-spacing: -0.01em; }
h2 { font-size: var(--step-head); line-height: 1.02; }
h3 { font-size: var(--step-lead); line-height: 1.2; }
p { max-width: 64ch; text-wrap: pretty; }
.lead { font-size: var(--step-lead); line-height: 1.38; max-width: 36ch; }
.small { font-size: var(--step-small); line-height: 1.45; }
.muted { color: var(--muted); }
.hl { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: .5em; text-underline-offset: -.32em; text-decoration-skip-ink: none; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
code, .mono { font-family: var(--font-mono); font-size: .86em; }
.num { font-variant-numeric: tabular-nums; }

.link { text-decoration: underline; text-underline-offset: 0.18em; text-decoration-thickness: 0.07em; transition: text-decoration-color var(--t-hover) ease; }
@media (hover: hover) and (pointer: fine) { .link:hover { text-decoration-color: var(--accent); } }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 3rem; padding: 0 1.4rem; background: var(--ink); color: var(--bg); text-decoration: none; white-space: nowrap; font-weight: 500; transition: transform var(--t-press) var(--ease-out), background-color var(--t-hover) ease; }
@media (hover: hover) and (pointer: fine) { .button:hover { background: #1b3158; } .button.accent:hover { background: #f7d873; } .button.ghost:hover { background: var(--ink); color: var(--bg); } }
.button:active { transform: scale(0.97); }
.button.accent { background: var(--accent); color: var(--accent-ink); }
.button.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.6rem; }

/* ---------- header: same as the home page, with the name always shown ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--bg); display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .4rem 1.5rem; padding: 1rem var(--pad); }
.top .wordmark { font-family: var(--font-display); font-size: var(--step-lead); text-decoration: none; letter-spacing: -0.01em; }
.top .wordmark::before { content: ''; display: inline-block; width: .42em; height: .42em; background: var(--accent); margin-right: .5em; vertical-align: .08em; }
.top ul { display: flex; flex-wrap: wrap; gap: .3rem 1.4rem; }
.top a { text-decoration: none; padding: .2rem 0; display: inline-block; }
.top ul a { color: var(--muted); text-decoration: underline; text-decoration-color: transparent; text-decoration-thickness: 0.16em; text-underline-offset: 0.3em; transition: color var(--t-hover) ease, text-decoration-color var(--t-hover) ease; }
.top ul a:hover, .top ul a[aria-current="page"] { color: var(--ink); }
.top ul a[aria-current="page"] { text-decoration-color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .top ul a:hover { text-decoration-color: var(--accent); } }

/* ---------- the frame: one writing column with a rail on the left ---------- */
.frame { max-width: calc(var(--measure) + var(--out) + 2 * var(--pad)); margin-inline: auto; padding-inline: calc(var(--pad) + var(--out)) var(--pad); }
.out { margin-left: calc(-1 * var(--out)); }
.hang { display: grid; gap: .35rem; }
.flow > * + * { margin-top: 1.4rem; }
.flow-tight > * + * { margin-top: .9rem; }
.section { padding-top: var(--section); }

main h2::before { content: ''; display: block; width: 2.75rem; height: .3rem; background: var(--accent); margin-bottom: 1.1rem; }
.section > h2 + * { margin-top: 2rem; }

/* ---------- first screen ---------- */
.hero { padding-top: clamp(3rem, 9vh, 6rem); }
.hero h1 { font-size: var(--step-title); line-height: 0.95; letter-spacing: -0.02em; margin-left: calc(-1 * var(--out) - 0.04em); }
.hero .mark { width: 3.5rem; height: .4rem; background: var(--accent); margin-top: clamp(1.5rem, 3vw, 2.25rem); }
.hero-row { margin-top: clamp(1.75rem, 3.5vw, 2.75rem); align-items: start; }
.hero-row > :first-child { color: var(--muted); }
.hero-row .flow > * + * { margin-top: 1.6rem; }

/* big figures, as in the home page's chart stats */
.stats { display: flex; flex-wrap: wrap; gap: 1.25rem 2.75rem; }
.stats strong { display: block; font-family: var(--font-display); font-weight: 400; font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.4rem); line-height: 1.05; font-variant-numeric: tabular-nums; }
.stats span { font-size: var(--step-small); color: var(--muted); }

/* label in the rail, writing beside it (used for principles, accounts, timelines) */
.plan { display: grid; gap: 1.6rem; }
.plan dt { color: var(--muted); }
.plan dd { font-weight: 500; }
.plan dd p { font-weight: 400; margin-top: .25rem; color: var(--muted); }

.entry + .entry { margin-top: 2.75rem; }
.entry .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.entry h3 { font-family: var(--font-text); font-weight: 600; font-size: var(--step-lead); letter-spacing: 0; line-height: 1.25; }
.entry .body > * + * { margin-top: .75rem; }

.ticks li { padding-left: 1.4rem; position: relative; }
.ticks li + li { margin-top: .55rem; }
.ticks li::before { content: ''; position: absolute; left: 0; top: .52em; width: .55em; height: .55em; background: var(--accent); }

/* a pull line with the card's yellow bar */
.closer { font-family: var(--font-display); font-size: var(--step-lead); line-height: 1.3; padding-left: 1.1rem; border-left: .3rem solid var(--accent); max-width: 30ch; }

/* plates: tinted panels for diagrams and tables */
.plate { background: var(--surface); padding: clamp(1rem, 3vw, 2rem); }

/* data flow diagram */
.flowchart { display: flex; flex-wrap: wrap; align-items: stretch; gap: .5rem; }
.flowchart .node { flex: 1 1 8rem; background: var(--bg); padding: .8rem 1rem; }
.flowchart .node b { display: block; font-weight: 600; }
.flowchart .node span { display: block; font-size: var(--step-small); color: var(--muted); line-height: 1.4; margin-top: .2rem; }
.flowchart .arrow { align-self: center; color: var(--muted); }

/* tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table caption { text-align: left; font-family: var(--font-display); font-size: var(--step-lead); padding-bottom: .75rem; }
.table th { text-align: left; font-weight: 500; font-size: var(--step-small); color: var(--muted); padding: .6rem .75rem; border-bottom: 2px solid var(--ink); white-space: nowrap; }
.table td { padding: .75rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 0; }
.table th:last-child, .table td:last-child { padding-right: 0; }
.table .r { text-align: right; }

/* code */
.code { background: var(--dark); color: var(--dark-ink); }
.code-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .65rem 1.25rem; background: var(--dark-surface); font-family: var(--font-mono); font-size: .78rem; color: var(--dark-muted); }
.code pre { padding: 1.25rem; overflow-x: auto; font-family: var(--font-mono); font-size: .82rem; line-height: 1.8; }
.code .cm { color: #8e9abb; font-style: italic; } .code .kw { color: var(--accent); } .code .fn { color: #9cc3f0; } .code .st { color: #f2dfa6; } .code .nm { color: #f0b48c; }

/* ---------- act two: navy ---------- */
.night { background: var(--dark); color: var(--dark-ink); margin-top: var(--section); padding-block: var(--section); }
.night ::selection { background: var(--accent); color: var(--ink); }
.night .muted, .night .plan dt, .night .plan dd p, .night .entry .when, .night .stats span { color: var(--dark-muted); }
.night .plate { background: var(--dark-surface); }
.night .code { background: #0a1834; }
.night .table th { color: var(--dark-muted); border-bottom-color: var(--dark-ink); }
.night .table td { border-bottom-color: rgba(245, 244, 239, .14); }
.night .flowchart .node { background: var(--dark); }
.night .flowchart .node span, .night .flowchart .arrow { color: var(--dark-muted); }
.night + .section, .night + .yellow { margin-top: 0; }

/* ---------- act three: yellow ---------- */
.yellow { background: var(--accent); color: var(--accent-ink); margin-top: var(--section); padding-block: clamp(4rem, 8vw, 6.5rem); }
.yellow h2::before { background: var(--ink); }
.yellow h2 + * { margin-top: 1.4rem; }
.yellow .actions { margin-top: 2rem; }
.yellow .to-top { margin-top: 1.5rem; font-weight: 500; }
/* nothing sits in the rail here, so the whole block lines up with the heading (as on the home page) */
.yellow .frame > :not(.out) { margin-left: calc(-1 * var(--out)); }
.yellow ::selection { background: var(--ink); color: var(--accent); }
.yellow :focus-visible { outline-color: var(--ink); }
@media (hover: hover) and (pointer: fine) { .yellow .button.ghost:hover { background: var(--ink); color: var(--accent); } }

/* ---------- desktop: open the rail ---------- */
@media (min-width: 960px) {
  :root { --out: calc(var(--rail) + var(--gutter)); }
  .hang { grid-template-columns: var(--rail) minmax(0, 1fr); column-gap: var(--gutter); margin-left: calc(-1 * var(--out)); }
  .hang > :first-child { padding-top: .15em; }
  .plan .hang > dt { padding-top: 0; }
  .entry .when { padding-top: .35em !important; }
}

/* ---------- motion: the same entrance as the home page ---------- */
@media (prefers-reduced-motion: no-preference) {
  .hero h1, .hero .mark, .hero-row { animation: rise 900ms var(--ease-expo) both; }
  .hero .mark { animation-delay: 60ms; }
  .hero-row { animation-delay: 140ms; }
}
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0ms !important; animation: none !important; }
}

/* ---------- phone ---------- */
@media (max-width: 640px) {
  .top { position: static; }
  .hero h1 { font-size: clamp(2.6rem, 12vw, 3.8rem); }
}
