/*
 * The edition — the one place this site's type, colour and motion are decided.
 *
 * The look is a printed monograph: white paper, near-black ink, one deep green.
 * Titles, labels and the navigation are EB Garamond, with true small caps and
 * old-style figures; IM Fell English italic is kept for the occasional
 * flourish; and everything read at length is Source Sans 3. Corners are
 * square, fills are replaced by hairline rules, and images sit as plates.
 *
 * How it reaches every page:
 *
 *   - The captured pages ship a minified Tailwind bundle (assets/css/site.css)
 *     that defines --ploy-* custom properties. That file is generated output
 *     and is not edited by hand; this sheet loads after it and overrides the
 *     tokens. Tailwind's utilities live in @layer, and nothing here does, so
 *     these rules win regardless of specificity.
 *   - The pages this repo generates (case studies, blog) read the --tf-*
 *     tokens below from their own stylesheets.
 *   - /zipsplit/ is a tool with its own light/dark tokens in
 *     styles/tokens.css. The --ploy-* overrides are scoped to :root.light so
 *     they cannot reach it; it picks up the typefaces through its own tokens.
 *
 * The fonts are all SIL Open Font License (licences sit beside them in
 * assets/fonts/). They replace the SangBleu trial cuts the captured site
 * shipped, which were never licensed for production.
 *
 * Motion is CSS only, short, and off entirely under prefers-reduced-motion.
 * Scroll reveals use a view() timeline inside @supports, so a browser without
 * it simply shows the page at rest — nothing is ever left hidden waiting for
 * a script.
 */

/* --- Typefaces ------------------------------------------------------------ */

@font-face {
  font-family: "EB Garamond";
  src: url(fonts/ebgaramond-roman-latin.woff2) format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-024F, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20B9, U+20BD, U+2116, U+2122,
    U+2190-2197, U+2212, U+2215, U+2248, U+2260, U+2264, U+2265, U+FB00-FB04;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/ebgaramond-italic-latin.woff2) format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-024F, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+20B9, U+20BD, U+2116, U+2122,
    U+2190-2197, U+2212, U+2215, U+2248, U+2260, U+2264, U+2265, U+FB00-FB04;
}
/* The notes feed is partly Russian; without these it would fall back to a
   system face mid-page. */
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/ebgaramond-roman-cyrillic.woff2) format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0400-045F, U+0490, U+0491;
}
@font-face {
  font-family: "EB Garamond";
  src: url(fonts/ebgaramond-italic-cyrillic.woff2) format("woff2");
  font-weight: 400 800;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0400-045F, U+0490, U+0491;
}
@font-face {
  font-family: "Source Sans 3";
  src: url(fonts/sourcesans3-roman-latin.woff2) format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-024F, U+2000-206F, U+20AC, U+2122, U+2190-2197, U+2212;
}
@font-face {
  font-family: "Source Sans 3";
  src: url(fonts/sourcesans3-roman-cyrillic.woff2) format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0400-045F, U+0490, U+0491;
}
@font-face {
  font-family: "Source Sans 3";
  src: url(fonts/sourcesans3-italic-latin.woff2) format("woff2");
  font-weight: 400 600;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0000-024F, U+2000-206F, U+20AC, U+2122, U+2190-2197, U+2212;
}
@font-face {
  font-family: "Source Sans 3";
  src: url(fonts/sourcesans3-italic-cyrillic.woff2) format("woff2");
  font-weight: 400 600;
  font-style: italic;
  font-display: swap;
  unicode-range: U+0400-045F, U+0490, U+0491;
}
@font-face {
  font-family: "IM Fell English";
  src: url(fonts/imfellenglish-italic-latin.woff2) format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

/* --- Tokens --------------------------------------------------------------- */

:root {
  --tf-paper: #ffffff;
  --tf-ink: #1f2428;
  --tf-slate: #5a636a;
  --tf-mute: #8a9298;
  --tf-rule: #c4cacf;
  --tf-hair: #dde1e4;
  --tf-wash: #f3f4f5;
  --tf-accent: #2b6a55;

  --tf-serif: "EB Garamond", Garamond, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --tf-sans: "Source Sans 3", "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  /* What is read at length is set in the grotesque; titles, labels and the
     navigation are in the serif. */
  --tf-body: var(--tf-sans);
  --tf-fell: "IM Fell English", "EB Garamond", Garamond, Georgia, serif;

  /* One easing and three durations, so every movement on the site is related. */
  --tf-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --tf-quick: 0.16s;
  --tf-slow: 0.32s;
  --tf-grand: 0.9s;
}

:root.light {
  --ploy-neutral-primary: var(--tf-paper);
  --ploy-background-primary: var(--tf-paper);
  --ploy-background-secondary: var(--tf-paper);
  --ploy-text-primary: var(--tf-ink);
  --ploy-text-secondary: var(--tf-slate);
  --ploy-neutral-inverse: var(--tf-ink);
  --ploy-border-primary: var(--tf-rule);
  --ploy-input-border: var(--tf-rule);
  --ploy-input-background: var(--tf-paper);
  --ploy-button-primary-background: var(--tf-ink);
  --ploy-button-primary-border: var(--tf-ink);
  --ploy-button-primary-text: var(--tf-paper);
  --ploy-accent-primary: var(--tf-accent);
  --ploy-accent-primary-950: var(--tf-accent);
  /* The shared nav reads --background and --border as fallbacks. */
  --background: var(--tf-paper);
  --border: var(--tf-hair);

  --font-heading: var(--tf-serif);
  --font-body: var(--tf-body);
  --font-eyebrow: var(--tf-serif);
  --font-button: var(--tf-serif);
  --font-heading-weight: 500;
}

/* --- Page ----------------------------------------------------------------- */

:root.light body {
  background: var(--tf-paper);
  color: var(--tf-ink);
  font-family: var(--tf-body);
  font-feature-settings: "kern", "liga";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root.light ::selection {
  background: color-mix(in srgb, var(--tf-accent) 22%, var(--tf-paper));
}
:root.light strong,
:root.light b {
  font-weight: 600;
}

/* --- Captured pages: Tailwind utilities, re-read as a book ---------------- */

/* The capture carries inline font-family on its root wrapper and on every
   card title (the trial faces this sheet retires). Inline styles outrank any
   selector, so this is the one place !important is the right tool. */
:root.light [style*="Sangbleu"] {
  font-family: var(--tf-body) !important;
}
:root.light :is(h1, h2, h3, h4, strong)[style*="Sangbleu"] {
  font-family: var(--tf-serif) !important;
}
/* <html> and <body> on the captured pages carry an inline system-font stack. */
:root.light,
:root.light body {
  font-family: var(--tf-body) !important;
}

/* Headings. The captured h1 wraps its text in a <strong class="font-heading">. */
:root.light [class~="font-heading"],
:root.light h1,
:root.light h2,
:root.light h3 {
  font-family: var(--tf-serif);
  font-feature-settings: "kern", "liga", "onum", "pnum";
  font-weight: 500;
  letter-spacing: -0.008em;
  text-wrap: balance;
}
:root.light h1 [class~="font-heading"],
:root.light h1[class~="font-heading"] {
  font-size: clamp(2.5rem, 1.4rem + 4.4vw, 4.4rem);
  line-height: 1.04;
  font-weight: 500;
}
:root.light h2[class~="font-heading"] {
  font-size: clamp(2rem, 1.5rem + 1.9vw, 2.9rem);
  line-height: 1.08;
}
:root.light h3 {
  font-size: 1.5rem;
  line-height: 1.2;
}
:root.light [class~="font-semibold"],
:root.light [class~="font-bold"] {
  font-weight: 500;
}

/* Body sizes, nudged up a step from the capture for Source Sans at this measure. */
:root.light [class~="text-xl"] { font-size: 1.25rem; line-height: 1.5; }
:root.light [class~="text-lg"] { font-size: 1.125rem; line-height: 1.6; }
:root.light [class~="text-base"] { font-size: 1.0625rem; }
:root.light [class~="text-xs"] { font-size: 0.9rem; }

/* Greys that were tints of black become the ink's own greys. */
:root.light [class~="text-black"] { color: var(--tf-ink); }
:root.light [class*="text-[rgba(0,0,0,0.5)]"],
:root.light [class*="text-[rgba(0,0,0,0.6)]"] { color: var(--tf-slate); }
:root.light [class*="text-ploy-accent"] { color: var(--tf-accent); }
:root.light [class*="border-[rgba(0,0,0"] { border-color: var(--tf-rule); }

/* Labels set in capitals become true small caps, letterspaced. */
:root.light [class~="uppercase"] {
  font-family: var(--tf-serif);
  text-transform: none;
  font-variant-caps: all-small-caps;
  font-feature-settings: "kern", "smcp", "c2sc", "lnum";
  letter-spacing: 0.13em;
  font-weight: 400;
  font-size: 1.05rem;
  line-height: 1.35;
}

/* Section headings carry a roman numeral, as chapters do. */
/* Reset on body, not per island: a page is several islands and the count has
   to run through all of them. */
:root.light body { counter-reset: tf-chapter; }
:root.light .section h2[class~="font-heading"]::before {
  counter-increment: tf-chapter;
  content: counter(tf-chapter, upper-roman);
  display: block;
  margin-bottom: 0.9rem;
  font-size: 1.1rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  font-feature-settings: "kern", "lnum";
  color: var(--tf-accent);
}

/* Buttons: ruled rectangles in small caps. */
:root.light a[class*="rounded-full"],
:root.light button[class*="rounded-full"] {
  border-radius: 0;
  font-family: var(--tf-serif);
  font-variant-caps: all-small-caps;
  font-feature-settings: "kern", "smcp", "c2sc", "lnum";
  letter-spacing: 0.16em;
  font-weight: 500;
  font-size: 1.05rem;
  line-height: 1.2;
  padding: 0.8rem 1.6rem 0.9rem;
  border: 1px solid var(--tf-ink);
  opacity: 1;
  transition: background-color var(--tf-slow) var(--tf-ease), color var(--tf-slow) var(--tf-ease),
    border-color var(--tf-slow) var(--tf-ease);
}
:root.light a[class*="rounded-full"][class*="bg-ploy-neutral-inverse"],
:root.light button[class*="rounded-full"][class*="bg-ploy-neutral-inverse"] {
  background: var(--tf-ink);
  color: var(--tf-paper);
}
:root.light a[class*="rounded-full"][class*="bg-ploy-neutral-inverse"]:hover,
:root.light button[class*="rounded-full"][class*="bg-ploy-neutral-inverse"]:hover {
  background: var(--tf-accent);
  border-color: var(--tf-accent);
  opacity: 1;
}
:root.light a[class*="rounded-full"]:not([class*="bg-ploy-neutral-inverse"]):hover,
:root.light button[class*="rounded-full"]:not([class*="bg-ploy-neutral-inverse"]):hover {
  background: var(--tf-ink);
  color: var(--tf-paper);
}

/* Cards lose their fill and corners and gain a rule above, like ledger rows. */
:root.light [class~="card"] {
  background: transparent;
  border-radius: 0;
  border-top: 1px solid var(--tf-rule);
  box-shadow: none;
  transition: border-color var(--tf-slow) var(--tf-ease);
}
:root.light a:hover > [class~="card"],
:root.light a[class~="card"]:hover {
  border-top-color: var(--tf-ink);
  background: transparent;
}
:root.light [class~="card"][class~="p-9"] {
  padding: 2rem 0 1.75rem;
}
:root.light a[class~="card"] [class~="p-6"] {
  padding: 1.1rem 0 0.5rem;
}
/* The timeline rows were padded for a card; as rows they want to sit closer. */
:root.light .card-info [class~="mb-16"] {
  margin-bottom: 0.35rem;
}
:root.light .card-info [class~="header"] {
  font-family: var(--tf-serif);
  font-size: 1.6rem;
}

/* Images are plates: square, with a hairline. Logos stay round. */
:root.light [class*="rounded-2xl"],
:root.light [class*="rounded-xl"],
:root.light [class*="rounded-lg"],
:root.light [class*="rounded-md"],
:root.light img[class*="rounded-["]:not(.logo) {
  border-radius: 0;
}
:root.light a[class~="card"] [class*="aspect-"] {
  border: 1px solid var(--tf-hair);
  background: var(--tf-wash);
}
:root.light a[class~="card"] img {
  transition-duration: var(--tf-grand);
  transition-timing-function: var(--tf-ease);
}
:root.light .logo {
  box-shadow: 0 0 0 1px var(--tf-hair);
}
/* The portrait prints in monochrome and takes its colour back under the
   cursor — the one indulgence on the page. */
:root.light img.image-3 {
  filter: grayscale(1) contrast(1.04);
  transition: filter var(--tf-grand) var(--tf-ease);
}
:root.light img.image-3:hover {
  filter: none;
}

/* The row of profile links under the timeline. */
:root.light a.link {
  font-family: var(--tf-serif);
  font-variant-caps: all-small-caps;
  font-feature-settings: "kern", "smcp", "c2sc";
  letter-spacing: 0.12em;
  font-size: 1.08rem;
  color: var(--tf-slate);
  text-decoration: none;
  transition: color var(--tf-quick) var(--tf-ease);
}
:root.light a.link:hover {
  color: var(--tf-accent);
}

/* Form fields: a rule to write on, and the grotesque for what is typed. */
:root.light input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
:root.light textarea,
:root.light select {
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid var(--tf-rule);
  background: transparent;
  box-shadow: none;
  font-family: var(--tf-sans);
  font-size: 1rem;
  transition: border-color var(--tf-quick) var(--tf-ease);
}
:root.light input:focus,
:root.light textarea:focus,
:root.light select:focus {
  outline: none;
  border-bottom-color: var(--tf-ink);
}

/* --- Tool pages (/zipsplit/) ---------------------------------------------- */

/* These run on styles/tokens.css and keep their own light and dark modes. The
   tool's interface stays in the grotesque; only its headings and label join
   the book. */
:root:not(.light) h1,
:root:not(.light) h2,
:root:not(.light) h3 {
  font-family: var(--tf-serif);
  font-weight: 500;
  letter-spacing: -0.008em;
  text-wrap: balance;
}
:root:not(.light) h1 { font-size: clamp(2.4rem, 1.6rem + 3vw, 3.4rem); line-height: 1.06; }
:root:not(.light) h2 { font-size: 1.8rem; }
:root:not(.light) h3 { font-size: 1.4rem; }
:root:not(.light) .eyebrow {
  font-family: var(--tf-serif);
  text-transform: none;
  font-variant-caps: all-small-caps;
  font-feature-settings: "kern", "smcp", "c2sc";
  letter-spacing: 0.16em;
  font-size: 1.05rem;
  font-weight: 500;
}

/* --- Motion --------------------------------------------------------------- */

@view-transition {
  navigation: auto;
}
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.36s;
  animation-timing-function: var(--tf-ease);
}

@keyframes tf-rise {
  from { opacity: 0; transform: translateY(0.75rem); }
  to { opacity: 1; transform: none; }
}
@keyframes tf-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes tf-rule {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (prefers-reduced-motion: no-preference) {
  /* The opening of each page arrives in order: label, title, then the rest. */
  :root.light astro-island > div > div:first-child > div:first-child > *,
  :root.light .cs-wrap > .cs-eyebrow,
  :root.light .cs-wrap > h1,
  :root.light .cs-wrap > .cs-period,
  :root.light .cs-wrap > .cs-lede,
  :root.light .cs-wrap > .cs-tags,
  :root.light .cs-wrap > .cs-metrics,
  :root.light .blog-main > .blog-eyebrow,
  :root.light .blog-main > h1,
  :root.light .blog-main > .blog-lede,
  :root.light .blog-main > .blog-tags,
  :root.light .blog-main > .blog-original-note {
    animation: tf-rise var(--tf-grand) var(--tf-ease) both;
  }
  :root.light astro-island > div > div:first-child > div:first-child > :nth-child(2),
  :root.light .cs-wrap > h1,
  :root.light .blog-main > h1 { animation-delay: 0.08s; }
  :root.light .cs-wrap > .cs-period,
  :root.light .cs-wrap > .cs-lede,
  :root.light .blog-main > .blog-lede,
  :root.light .blog-main > .blog-tags { animation-delay: 0.18s; }
  :root.light .cs-wrap > .cs-tags,
  :root.light .cs-wrap > .cs-metrics,
  :root.light .blog-main > .blog-original-note { animation-delay: 0.28s; }

  /* The rule under the navigation draws itself outward from the centre. */
  .site-nav::after {
    animation: tf-rule 1.1s var(--tf-ease) 0.1s both;
  }

  /* Plates and rows settle into place as they come onto the page. Tied to
     scroll position, so anything already in view at load is simply there. */
  @supports (animation-timeline: view()) {
    :root.light [class~="card"],
    :root.light .section h2,
    :root.light .cs-hero,
    :root.light .cs-body figure,
    :root.light .cs-entry,
    :root.light .cs-gallery li,
    :root.light .cs-chronology dl > div,
    :root.light .blog-post-list > li,
    :root.light .blog-note,
    :root.light .blog-post-body figure {
      animation: tf-rise linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 55%;
    }
  }
}
