/* The site's look on the Finance 100 tools served at /tools/<name>/.
   worker/tools.js links this file after each tool's own css/style.css. That
   stylesheet is built on CSS variables, so the :root block does most of the
   work: it swaps them for the site's tokens (src/styles/tokens.css;
   test/tools.test.js keeps the two in step). The rest redraws the shared parts
   the way the site draws them: display headings, mono labels, square corners,
   1px rules. The fonts are declared in the page head (src/fonts.js). */

:root {
  color-scheme: dark;
  --accent: #d3d8dc !important; /* over each tool's own category colour, set inline on <html> */
  --bg: #07090b;
  --card: #0d1114;
  --soft: #141a1e;
  --fg: #e6ece4;
  --muted: #95a1a6;
  --line: #262f35;
  --line-strong: #3a454d;
  --on-accent: #03140a;
  /* Results a tool marks good, bad or warn keep a hue, because some tools mark
     them by colour alone. Pale, so they sit in the palette. */
  --good: #93cfa5;
  --bad: #e39a96;
  --warn: #dcc07e;
  --radius: 0;
  --shadow: none;
  --font: 'Atkinson Hyperlegible Next', 'Segoe UI', ui-sans-serif, system-ui, sans-serif;
  --display: 'Big Shoulders Display', 'Bahnschrift SemiCondensed', 'Avenir Next Condensed', ui-sans-serif, sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'Cascadia Mono', 'SF Mono', Menlo, Consolas, monospace;
  --label: 500 12px/1.35 var(--mono); /* the site's small labels: mono, uppercase, tracked */
  --tracking: 0.06em;
}

/* Moving between the site and a tool cross-fades. The opt-in (@view-transition) is inline in
   the page head, added by worker/tools.js: here it would arrive too late on a first visit. */

html { scroll-padding-top: 88px; }
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
/* The site's floor grid, still: the tools have no 3D behind them. */
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--line) 55%, transparent) 1px, transparent 1px);
  background-size: 96px 96px;
  background-position: -1px -1px;
  -webkit-mask-image: linear-gradient(to bottom, #000, rgb(0 0 0 / 0.25) 70%, transparent);
  mask-image: linear-gradient(to bottom, #000, rgb(0 0 0 / 0.25) 70%, transparent);
}
::selection { background: var(--accent); color: var(--on-accent); }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ------------------------------------------------------------------ header */
.top { position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--bg) 86%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.top .wrap { gap: 16px; height: 64px; }
/* The site's logo, added by worker/tools.js: the way home. */
.site-home { display: inline-flex; align-items: center; gap: 12px; flex: none; min-height: 44px; padding-right: 16px; border-right: 1px solid var(--line); font: 600 13px/1 var(--mono); letter-spacing: var(--tracking); text-transform: uppercase; text-decoration: none; white-space: nowrap; }
.site-home img { flex: none; width: 28px; height: 28px; }
.site-home ~ .brand::before { display: none; } /* the logo stands in for the tool's own square mark */
.brand::before { border-radius: 0; }
.brand, .top .gh { display: inline-flex; align-items: center; flex: none; min-height: 44px; font: 500 13px/1 var(--mono); letter-spacing: var(--tracking); text-transform: uppercase; white-space: nowrap; color: var(--muted); transition: color 0.18s; }
.brand:hover, .top .gh:hover { color: var(--fg); }
.tag { min-width: 0; padding: 5px 10px; overflow: hidden; border-radius: 0; font: var(--label); letter-spacing: var(--tracking); text-transform: uppercase; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) { .top .gh { display: none; } } /* the footer has the same link */
@media (max-width: 560px) {
  .top .wrap { gap: 12px; }
  .site-home { min-width: 44px; padding-right: 12px; } /* the logo alone is still a 44px target */
  .site-home span { display: none; }
}

/* -------------------------------------------------------------------- page */
.hero { padding: 56px 0 18px; }
.hero::before { width: 56px; height: 1px; margin-bottom: 22px; border-radius: 0; }
.hero h1 { margin-bottom: 16px; font-weight: 760; font-size: clamp(40px, 6.4vw, 76px); line-height: 0.92; letter-spacing: 0.004em; text-transform: uppercase; text-wrap: balance; }
.lead { font-size: 18px; line-height: 1.55; }
.card { padding: 22px; background: color-mix(in srgb, var(--card) 90%, transparent); }
.card h2 { margin-bottom: 16px; font-weight: 760; font-size: 26px; line-height: 1; letter-spacing: 0.004em; text-transform: uppercase; }
.card h3 { margin: 20px 0 10px; font: var(--label); letter-spacing: var(--tracking); }
/* Crop marks at two corners of the results, as on the site's figures. */
#results { position: relative; }
#results::before, #results::after { content: ''; position: absolute; width: 14px; height: 14px; pointer-events: none; border: 0 solid var(--accent); }
#results::before { top: -6px; left: -6px; border-top-width: 1px; border-left-width: 1px; }
#results::after { right: -6px; bottom: -6px; border-right-width: 1px; border-bottom-width: 1px; }
.how { font-size: 15px; }
.how code { border-radius: 0; }
.foot { margin-top: 56px; padding: 24px 0 40px; font: 500 12px/1.9 var(--mono); letter-spacing: var(--tracking); text-transform: uppercase; }
.foot a { text-decoration-color: var(--line-strong); transition: color 0.18s; }
.foot a:hover { color: var(--fg); }

/* More tools of the same category, added by worker/tools.js above the footer. */
.more { margin-top: 44px; }
.more h2 { margin: 0 0 12px; color: var(--muted); font: var(--label); letter-spacing: var(--tracking); text-transform: uppercase; }
.more ul { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.more a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); font-size: 14px; text-decoration: none; transition: border-color 0.18s; }
.more a:hover { border-color: var(--accent); }

/* ------------------------------------------------------------------ fields */
.field > span { margin-bottom: 5px; font-size: 13.5px; }
.field small { font-size: 12.5px; }
input, select, textarea { min-height: 44px; padding: 9px 10px; border-color: var(--line-strong); border-radius: 0; transition: border-color 0.18s; }
input, select { font: 400 16px/1.3 var(--font); } /* the body font inside tables too; 16px, so a phone does not zoom the page when a field takes focus */
input[type=checkbox], input[type=radio], input[type=range] { accent-color: var(--accent); }

/* ----------------------------------------------------------------- buttons */
button, .btn { min-height: 40px; padding: 0 16px; border-radius: 0; color: var(--on-accent); font: 600 12px/1.2 var(--mono); letter-spacing: var(--tracking); text-transform: uppercase; transition: background-color 0.18s, border-color 0.18s, color 0.18s; }
button:enabled:hover, .btn:hover { background: var(--fg); border-color: var(--fg); }
button.ghost, .btn.ghost { border-color: var(--line-strong); color: var(--fg); }
:is(button.ghost:enabled, .btn.ghost):hover { background: transparent; border-color: var(--accent); color: var(--accent); }
button.small { min-height: 32px; padding: 0 10px; }
button.icon { min-height: 32px; padding: 0 9px; color: var(--muted); }
button.icon:enabled:hover { background: transparent; border-color: var(--line-strong); color: var(--fg); }
/* Segmented control. It wraps: the mono labels are wider than the tool's own. */
.seg { flex-wrap: wrap; max-width: 100%; border-color: var(--line-strong); border-radius: 0; }
.seg button { min-height: 38px; padding: 0 14px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:enabled:hover { background: transparent; color: var(--fg); }
.seg button[aria-pressed=true], .seg button[aria-pressed=true]:enabled:hover { background: var(--accent); color: var(--on-accent); }
/* Touch screens: the main buttons get the site's 44px target. The row buttons in tables stay small, beside 36px fields. */
@media (pointer: coarse) {
  button:not(.small, .icon), .btn { min-height: 44px; }
}

/* ----------------------------------------------------------------- results */
.kpi { display: flex; flex-direction: column; justify-content: space-between; gap: 8px; padding: 14px 16px; border-color: var(--line); border-radius: 0; }
.kpi .k { font: 500 12px/1.4 var(--mono); letter-spacing: 0.04em; }
.kpi .v { margin-top: 0; overflow: visible; font: 700 clamp(26px, 2.6vw, 32px)/1.05 var(--display); letter-spacing: 0.004em; white-space: normal; overflow-wrap: anywhere; } /* a long value wraps, where the tool's own style cut it short */
.note { border-left-width: 2px; border-radius: 0; }
.bar, .bar > i { border-radius: 0; }
.bar { height: 8px; }
.table-wrap { border-radius: 0; }
/* Tables: figures and headings in mono, names in the body font (mono names made tables scroll sideways). */
table { font: 400 13px/1.5 var(--font); }
th, td { padding: 8px 10px; }
td.n { font: 500 12px/1.5 var(--mono); }
/* Headings wrap: in mono capitals they are wider than the figures under them. */
th { font: 500 12px/1.4 var(--mono); letter-spacing: 0.04em; text-transform: uppercase; vertical-align: bottom; white-space: normal; }
/* A table of fields: its headings are field labels, so they stay in the body font like the labels above
   (mono capitals took the room the fields need), and a number field gives its side padding to the digits. */
table.edit th { font: 600 12.5px/1.4 var(--font); letter-spacing: 0; text-transform: none; }
table.edit input, table.edit select { min-height: 36px; font-size: 13px; }
table.edit input[type=number] { padding-inline: 5px; }
/* On a phone the theme takes no room from the tool: the tool's own card padding, tighter cells. */
@media (max-width: 560px) {
  .card { padding: 18px; }
  th, td { padding: 7px 6px; }
}
pre { font: 400 13px/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; } /* a long line of a plain-text summary wraps, where it pushed the page wider than a phone */
/* Charts: axes, labels and the first series follow the variables above. The
   other series colours are fixed in the tools' chart script, so they are toned
   down here to sit on a monotone page and stay told apart. */
.chart canvas, .tip span { filter: saturate(0.6); }
.tip { border-color: var(--line-strong); border-radius: 0; font: 500 12px/1.5 var(--mono); }

/* The invoice preview is a sheet of paper (invoice-generator): it keeps its own light look. */
.invoice { color-scheme: light; --fg: #111; --muted: #555; --line: #ddd; --soft: #f1f5f4; --bg: #fff; --card: #fff; border-radius: 0; }
.invoice table { font: inherit; font-size: 13.5px; }
.invoice td { font: inherit; }
.invoice th { font: inherit; font-weight: 700; letter-spacing: 0; text-transform: none; }

/* On paper: dark text on white. A chart is a picture drawn in the screen
   colours, so it keeps its dark plate and its labels stay readable. */
@media print {
  :root { color-scheme: light; --accent: #111 !important; --bg: #fff; --card: #fff; --soft: #f2f2f2; --fg: #111; --muted: #555; --line: #ccc; --line-strong: #999; --on-accent: #fff; --good: #1f7a4a; --bad: #b4262a; --warn: #a15c07; }
  body::before, #results::before, #results::after { display: none; }
  .chart { background: #0d1114; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
