/* =========================================================
   SUNDAY COMICS — base styles and components
   Requires tokens.css loaded first.
   Signature motifs:
     · Sunny halftone paper instead of a white wall
     · Bangers headlines, Geist body copy, Kalam speech
     · 3px ink outlines + hard offset shadows on anything you can touch
     · Colour bands (cobalt, red, emerald, plum) for big sections
     · Mono tabular figures and the accounting double rule (=)
       for totals: a nod to the day job
   ========================================================= */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
img, svg, video, canvas { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
[hidden] { display: none !important; }

/* ---------- Page ---------- */
body {
  background: var(--halftone), var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
  overflow-x: hidden;
}
::selection { background: var(--selection-bg); color: var(--selection-fg); }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------- Typography ---------- */
h1, h2, h3, .display {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  line-height: var(--lh-tight);
  letter-spacing: var(--display-tracking);
  text-wrap: balance;
}
h1, .h1 { font-size: var(--fs-hero); }
h2, .h2 { font-size: var(--fs-2xl); }
h3, .h3 { font-size: var(--fs-xl); line-height: 1.05; }
h4, .h4 { font-family: var(--font-body); font-size: var(--fs-lg); font-weight: 600; line-height: var(--lh-snug); letter-spacing: -0.01em; }
h1 small, h2 small { display: block; font-family: var(--font-body); font-size: var(--fs-lg); font-weight: 500; letter-spacing: 0; line-height: 1.35; margin-top: var(--s-4); color: var(--text-soft); }
/* Comic "pop" headline: ink outline + hard shadow */
.pop { color: var(--panel); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); }
.pop--blue { color: var(--accent); } .pop--red { color: var(--spark); } .pop--sun { color: var(--sun-400); }
p { max-width: var(--measure); text-wrap: pretty; }
.lede { font-size: var(--fs-lg); line-height: 1.5; color: var(--text-soft); max-width: 48ch; }
small, .small { font-size: var(--fs-sm); }
.muted { color: var(--text-muted); }
.soft { color: var(--text-soft); }

.ink { color: var(--accent-text); }
.spark { color: var(--spark); }
.dot { color: var(--spark); }

/* Eyebrow = a comic caption box */
.eyebrow {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 500;
  text-transform: uppercase; letter-spacing: var(--tracking-label);
  color: var(--ink); background: var(--panel);
  border: 2px solid var(--ink); box-shadow: var(--comic-shadow-sm);
  padding: .3rem .65rem; rotate: -1.5deg;
}
.eyebrow b { color: var(--panel); background: var(--spark); font-weight: 500; padding: 0 .35rem; margin-left: -.25rem; }

.num, .figure, td.num, time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: -0.01em;
}
.total { border-bottom: 3px double currentColor; padding-bottom: 1px; }
mark, .hl { background: var(--sun-400); color: var(--ink); padding: 0 0.2em; }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.9em; }
code { background: var(--panel-2); padding: 0.1em 0.35em; border: 1px solid var(--rule); }

/* ---------- Links ---------- */
a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  transition: color var(--dur-fast) var(--ease-out), text-decoration-color var(--dur-fast);
}
a:hover { color: var(--link-hover); text-decoration-color: currentColor; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: var(--max-w); margin-inline: auto; padding-inline: var(--gutter); }
.section { padding-block: var(--s-9); border-top: var(--comic-line) solid var(--ink); }
.section--deep, .section--blue, .section--red, .section--green, .section--plum {
  color: #fff; --text: #fff; --text-soft: rgba(255,255,255,.86); --text-muted: rgba(255,255,255,.7);
  --rule: rgba(255,255,255,.25); --link: #fff; --link-hover: var(--sun-400); --accent-text: var(--sun-400);
  --paper-dot: rgba(0,0,0,.14);
  background: var(--halftone), var(--_band, var(--cobalt-500));
}
.section--deep, .section--blue { --_band: var(--cobalt-500); }
.section--red   { --_band: var(--red-500); }
.section--green { --_band: var(--emerald-800); }
.section--plum  { --_band: var(--plum-600); }
.section--sunken { background: var(--halftone), var(--bg-sunken); }
.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-6); }
.grid { display: grid; gap: var(--s-5); grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.split { display: grid; gap: var(--s-6); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 56rem) { .split { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); } }

/* Sunburst rays behind a hero */
.rays { position: relative; isolation: isolate; overflow: clip; }
.rays::before {
  content: ""; position: absolute; inset: -40% -20%; z-index: -1; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at var(--rx, 70%) var(--ry, 55%), rgba(255,201,60,.55) 0 6deg, transparent 6deg 15deg);
  -webkit-mask: radial-gradient(closest-side at var(--rx, 70%) var(--ry, 55%), #000 30%, transparent 100%);
          mask: radial-gradient(closest-side at var(--rx, 70%) var(--ry, 55%), #000 30%, transparent 100%);
}

.ledger { background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(2rem - 1px), var(--rule) calc(2rem - 1px), var(--rule) 2rem); }
.rule { height: 0; border: 0; border-top: 2px solid var(--ink); }
.rule--double { border-top: 4px double var(--ink); }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--panel);
  border-bottom: var(--comic-line) solid var(--ink);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 4rem; gap: var(--s-4); }
.brand {
  font-family: var(--sfx-font); font-size: 1.7rem; letter-spacing: .04em; line-height: 1;
  color: var(--panel); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; text-shadow: 3px 3px 0 var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; gap: .35rem;
}
.brand:hover { color: var(--sun-400); }
.brand .dot { color: var(--spark); }
.nav { display: flex; gap: clamp(.25rem, 1.2vw, .9rem); list-style: none; padding: 0; align-items: center; }
.nav a {
  font-family: var(--sfx-font); font-size: 1.15rem; letter-spacing: .05em; line-height: 1;
  color: var(--ink); text-decoration: none; padding: .45rem .6rem .35rem; border: 2px solid transparent;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast), box-shadow var(--dur-fast);
}
.nav a:hover { background: var(--sun-400); border-color: var(--ink); box-shadow: var(--comic-shadow-sm); transform: translate(-1px, -1px) rotate(-2deg); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--ink); color: var(--sun-400); border-color: var(--ink); }
@media (max-width: 30rem) { .nav a { font-size: 1rem; padding: .4rem .4rem .3rem; } .brand { font-size: 1.4rem; } }

/* ---------- Buttons ---------- */
.btn {
  --_bg: var(--panel); --_fg: var(--ink);
  display: inline-flex; align-items: center; gap: 0.6em;
  min-height: 2.875rem; padding: 0 1.2rem;
  font-family: var(--font-body); font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0.01em;
  background: var(--_bg); color: var(--_fg);
  border: var(--comic-line) solid var(--ink); box-shadow: 4px 4px 0 var(--ink);
  text-decoration: none; white-space: nowrap;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out), background-color 120ms;
}
.btn:hover { color: var(--_fg); transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn .arrow { transition: transform var(--dur) var(--ease-out); }
.btn:hover .arrow { transform: translateX(4px); }
.btn--primary { --_bg: var(--accent); --_fg: #fff; }
.btn--red { --_bg: var(--spark); --_fg: #fff; }
.btn--sun { --_bg: var(--sun-400); }
.btn--quiet { border-color: transparent; box-shadow: none; padding-inline: 0; min-height: auto; --_bg: transparent; }
.btn--quiet:hover { box-shadow: none; transform: none; color: var(--accent-text); }

/* ---------- Tags ---------- */
.tag {
  display: inline-flex; align-items: center; height: 1.6rem; padding: 0 0.55rem;
  font-family: var(--font-mono); font-size: var(--fs-xs); letter-spacing: 0.03em;
  color: var(--ink); background: var(--panel-2); border: 2px solid var(--ink);
}
.tag--plum { color: #fff; background: var(--plum-600); }
.tag--emerald { color: #fff; background: var(--emerald-500); }

/* ---------- Cards (comic panels) ---------- */
.card {
  position: relative; display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-5); background: var(--surface); color: var(--ink);
  border: var(--comic-line) solid var(--ink); box-shadow: var(--comic-shadow);
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
a.card { color: inherit; text-decoration: none; }
a.card:hover { transform: translate(-2px, -2px) rotate(-.4deg); box-shadow: 8px 8px 0 var(--ink); }
.card__index { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); }
.card__title { font-family: var(--font-display); letter-spacing: .02em; font-size: var(--fs-xl); line-height: 1; }

/* ---------- Stats ---------- */
.stat { display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-3) var(--s-4); background: var(--panel); border: var(--comic-line) solid var(--ink); box-shadow: var(--comic-shadow-sm); color: var(--ink); }
.stat__value { font-family: var(--font-display); font-size: var(--fs-2xl); line-height: 1; letter-spacing: .02em; color: var(--accent); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; }
.stat__label { font-size: var(--fs-sm); color: var(--text-soft); }

/* ---------- Ledger table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); background: var(--panel); }
.table th { text-align: left; font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 500; text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-muted); padding: var(--s-3) var(--s-2); border-bottom: 2px solid var(--ink); }
.table td { padding: var(--s-3) var(--s-2); border-bottom: 1px solid var(--rule); }
.table .num { text-align: right; }
.table tfoot td { border-bottom: 4px double var(--ink); font-weight: 600; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field label { font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-muted); }
.input, .textarea {
  width: 100%; padding: .55rem .75rem; background: var(--panel);
  border: 2px solid var(--ink); border-radius: 0;
  font-size: var(--fs-base); color: var(--ink);
  transition: box-shadow var(--dur-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .textarea:focus { outline: none; box-shadow: var(--comic-shadow-sm); }
.textarea { min-height: 7rem; resize: vertical; }

/* ---------- Footer ---------- */
.site-footer {
  padding-block: var(--s-7); font-size: var(--fs-sm);
  background: var(--ink); color: rgba(255,255,255,.75); border-top: var(--comic-line) solid var(--ink);
  --link: var(--sun-400); --link-hover: #fff;
}
.site-footer .dot { color: var(--sun-400); }

/* ---------- Motion utilities ---------- */
.reveal { opacity: 0; transform: translateY(18px); transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out); }
.reveal.is-visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .reveal { opacity: 1; transform: none; } }

/* ---------- Accessibility ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s-4); top: -3rem; background: var(--ink); color: var(--sun-400); padding: var(--s-2) var(--s-4); z-index: 100; }
.skip-link:focus { top: var(--s-4); }

/* ---------- Page transition: comic colour wipe (assets/js/transition.js) ---------- */
.wipe { position: fixed; inset: 0; z-index: 9000; pointer-events: none; background: var(--c);
  background-image: radial-gradient(circle, rgba(0,0,0,.14) 1.3px, transparent 1.8px); background-size: 12px 12px;
  clip-path: circle(0 at var(--x) var(--y)); transition: clip-path 620ms cubic-bezier(.7,0,.3,1); }
.wipe.is-on { clip-path: circle(150vmax at var(--x) var(--y)); pointer-events: auto; }
.wipe.is-on.is-out { clip-path: circle(0 at 50% 50%); transition-duration: 560ms; }
.wipe.is-instant { transition: none !important; }
.wipe span { position: absolute; left: 50%; top: 50%; translate: -50% -50%; font-family: var(--sfx-font); font-size: clamp(3rem, 10vw, 7rem); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 6px 6px 0 var(--ink); white-space: nowrap; opacity: 0; transition: opacity 200ms 300ms; }
.wipe.is-on span { opacity: 1; }

/* ---------- DEV reset button (testing only; remove before launch) ---------- */
.dev-reset { position: fixed; left: 0; top: 50%; z-index: 9500; translate: 0 -50%; writing-mode: vertical-rl; rotate: 180deg;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .12em; padding: .7rem .3rem; background: var(--ink); color: var(--sun-400);
  border: 2px solid var(--sun-400); border-left: 0; opacity: .55; transition: opacity 150ms; }
.dev-reset:hover { opacity: 1; }
