/*
  Arthur's Codex — the front door (home page and navigation).
  Reuses the design-system tokens, self-hosted fonts and light, book-like
  character of the reader (codex/styles.css). Presentation only; it reads the
  derived nav-index and links into the reader. "Theme" is the reader-facing name
  for the internal Wing taxonomy (issue #20).
*/

@font-face {
  font-family: "Young Serif";
  src: url("./fonts/YoungSerif-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Mulish";
  src: url("./fonts/Mulish-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 1000;
  font-display: swap;
}
@font-face {
  font-family: "Mulish";
  src: url("./fonts/Mulish-Italic-Variable.ttf") format("truetype");
  font-style: italic;
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  --ink: #2b2620;
  --ink-soft: #6a6154;
  --cream: #fbf6ea;
  --manual: #f5f0e5;
  --card: #fefcf6;
  --hairline: #e4dac4;
  --thread: #f4b41a;
  --honey: #ae730f;

  /* Page-colour bases (entry covers) */
  --teal: #74c2b4; --sky: #92c7e8; --sage: #adc79a; --coral: #f0705a;
  --pink: #f1a7b4; --mustard: #edb23e; --periwinkle: #aeb4e6; --peach: #f4b78e;
  --mint: #a0d4b9; --lilac: #cbb0de; --brown: #6e4a22; --ultramarine: #33509e;
  --plum: #6e4a86; --forest: #4e7b3c; --ember: #b23a2c;

  /* Theme (Wing) dots */
  --deep-time: #b87814; --life: #5e7b3c; --cosmos: #33509e;
  --gallery: #e0603f; --story: #2e7a72; --library: #6e4a86;

  --display: "Young Serif", Georgia, "Times New Roman", serif;
  --body: "Mulish", system-ui, -apple-system, "Segoe UI", sans-serif;

  --s3: 0.75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem; --s7: 3rem;
  --r-md: 16px; --r-lg: 22px; --r-pill: 999px;
  --frame: 1180px;
  --shadow: 0 12px 34px -16px rgba(43, 38, 32, 0.4);
  --shadow-sm: 0 5px 16px -9px rgba(43, 38, 32, 0.5);
  --focus: 3px solid var(--cosmos);
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: light; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-inline-size: min(20rem, 100%);
  background: var(--manual);
  color: var(--ink);
  font-family: var(--body);
  font-size: clamp(1rem, 0.96rem + 0.22vw, 1.15rem);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
}

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

.wrap { max-inline-size: var(--frame); margin-inline: auto; padding-inline: clamp(var(--s5), 5vw, var(--s6)); }

button { font-family: inherit; }
a { color: var(--honey); }

.visually-hidden {
  position: absolute !important;
  inline-size: 1px; block-size: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-block-start: var(--s4);
  inset-inline-start: var(--s4);
  z-index: 100;
  background: var(--thread);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--r-pill);
  padding: 0.6rem 1.1rem;
  font-weight: 800;
  text-decoration: none;
  transform: translateY(-250%);
  transition: transform 0.15s ease;
}
.skip-link:focus { transform: translateY(0); }

:where(a, button):focus-visible { outline: var(--focus); outline-offset: 3px; border-radius: 6px; }

/* ---- header ---- */
.site-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--manual) 92%, transparent);
  backdrop-filter: blur(8px);
  border-block-end: 1px solid var(--hairline);
}
.site-header__bar {
  display: flex;
  align-items: center;
  gap: var(--s4) var(--s5);
  padding-block: 0.75rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 1.3rem;
  color: var(--ink);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.brand__mark { inline-size: 13px; block-size: 24px; border-radius: 4px; background: var(--thread); box-shadow: inset 0 0 0 1px rgba(43, 38, 32, 0.1); }

.site-nav { display: inline-flex; gap: 2px; padding: 3px; background: #efe7d5; border: 1px solid var(--hairline); border-radius: var(--r-pill); }
.site-nav__link {
  display: inline-flex;
  align-items: center;
  min-block-size: 2.25rem;
  padding: 0.4rem 0.9rem;
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 0.82rem;
  text-decoration: none;
  white-space: nowrap;
}
.site-nav__link[aria-current="page"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

.site-search { position: relative; margin-inline-start: auto; display: flex; align-items: center; }
.site-search__icon { position: absolute; inset-inline-start: 0.7rem; color: var(--ink-soft); font-size: 1rem; pointer-events: none; }
.site-search input {
  font-family: var(--body);
  font-size: 0.92rem;
  min-block-size: 2.5rem;
  inline-size: min(14rem, 42vw);
  padding-block: 0.45rem;
  padding-inline: 2rem 0.9rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
}
.site-search input::placeholder { color: var(--ink-soft); }

/* Theme dot classes (set --theme-dot; descendants inherit it). Class-driven so
   the strict style-src 'self' CSP needs no inline style attributes. */
.theme-deep-time { --theme-dot: var(--deep-time); }
.theme-life { --theme-dot: var(--life); }
.theme-cosmos { --theme-dot: var(--cosmos); }
.theme-gallery { --theme-dot: var(--gallery); }
.theme-story { --theme-dot: var(--story); }
.theme-library { --theme-dot: var(--library); }

.band {
  block-size: 7px;
  background: linear-gradient(
    90deg,
    var(--deep-time) 0 16.667%, var(--life) 0 33.333%, var(--cosmos) 0 50%,
    var(--gallery) 0 66.667%, var(--story) 0 83.333%, var(--library) 0 100%
  );
}

/* ---- intro ---- */
main { display: block; padding-block-end: var(--s7); }
.intro { padding-block: var(--s7) var(--s5); }
.kicker { margin: 0 0 0.6rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.8rem; color: var(--honey); }
.intro h1 { margin: 0 0 0.6rem; font-family: var(--display); font-weight: 400; font-size: clamp(2rem, 1.4rem + 3vw, 2.9rem); line-height: 1.07; max-inline-size: 20ch; }
.intro p.lede { margin: 0; font-size: clamp(1.05rem, 1rem + 0.5vw, 1.25rem); max-inline-size: 62ch; color: var(--ink); }
.intro p.lede em { font-style: italic; }

/* ---- Theme grid (home) ---- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); gap: var(--s5); margin-block-start: var(--s6); }

.theme-card {
  display: block;
  color: inherit;
  text-decoration: none;
  text-align: start;
  inline-size: 100%;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  padding: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
a.theme-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.theme-card__strip { block-size: 10px; background: var(--theme-dot, var(--hairline)); }
/* Dot in a gutter, everything else (title, blurb, tag) in one aligned column,
   matching the Theme detail head. */
.theme-card__inner { display: grid; grid-template-columns: auto 1fr; column-gap: 11px; padding: var(--s5); }
.theme-card__body { min-inline-size: 0; }
.theme-dot { inline-size: 26px; block-size: 26px; margin-block-start: 0.15rem; border-radius: 50%; flex: 0 0 auto; background: var(--theme-dot, var(--hairline)); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55); }
.theme-card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 1.5rem; }
.theme-card p { margin: 0.75rem 0 0; font-size: 0.95rem; color: var(--ink-soft); }
.theme-card__soon { margin-block-start: 0.9rem; display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); border: 1px dashed var(--hairline); border-radius: var(--r-pill); padding: 0.25rem 0.7rem; }
.theme-card.is-empty { opacity: 0.72; }

/* ---- Theme detail ---- */
.back {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 0;
  color: var(--honey);
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  margin-block: var(--s6) var(--s4);
  text-decoration: none;
}
.theme-head { display: flex; align-items: flex-start; gap: 16px; border-block-end: 1px solid var(--hairline); padding-block-end: var(--s5); }
.theme-head__dot { inline-size: 40px; block-size: 40px; border-radius: 50%; flex: 0 0 auto; margin-block-start: 6px; background: var(--theme-dot, var(--hairline)); box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.5); }
.theme-head h1 { margin: 0 0 0.25rem; font-family: var(--display); font-weight: 400; font-size: clamp(1.8rem, 1.3rem + 2.4vw, 2.5rem); }
.theme-head p { margin: 0; color: var(--ink-soft); max-inline-size: 60ch; }

.letter-group { grid-column: 1 / -1; margin-block: var(--s4) 0.2rem; font-family: var(--display); font-size: 1rem; color: var(--honey); border-block-end: 1px solid var(--hairline); padding-block-end: 4px; }

.entry-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 12px; margin-block-start: var(--s5); }
.entry-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-inline-start: 5px solid var(--cover, var(--hairline));
  border-radius: 12px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.entry-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.entry-card__title { font-family: var(--display); font-weight: 400; font-size: 1.1rem; line-height: 1.15; }
.entry-card__pill { display: inline-flex; align-items: center; gap: 7px; font-size: 0.75rem; font-weight: 700; color: var(--ink-soft); }
.entry-card__pill i { inline-size: 9px; block-size: 9px; border-radius: 50%; background: var(--theme-dot, var(--hairline)); flex: 0 0 auto; }
.entry-card__badge { align-self: flex-start; margin-block-start: 0.15rem; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--honey); border: 1px solid var(--honey); border-radius: var(--r-pill); padding: 0.1rem 0.55rem; }

/* A draft in review mode carries the parent's decision beneath it, linking out
   to the local approval gate. */
.entry-slot { display: flex; flex-direction: column; gap: 0.4rem; }
.approve-link { align-self: start; padding: 0.15rem 0.1rem; font-size: 0.78rem; font-weight: 800; color: var(--honey); text-decoration: none; }
.approve-link:hover { text-decoration: underline; }

/* Entry cover colours */
.cover-teal { --cover: var(--teal); } .cover-sky { --cover: var(--sky); }
.cover-sage { --cover: var(--sage); } .cover-coral { --cover: var(--coral); }
.cover-pink { --cover: var(--pink); } .cover-mustard { --cover: var(--mustard); }
.cover-periwinkle { --cover: var(--periwinkle); } .cover-peach { --cover: var(--peach); }
.cover-mint { --cover: var(--mint); } .cover-lilac { --cover: var(--lilac); }
.cover-brown { --cover: var(--brown); } .cover-ultramarine { --cover: var(--ultramarine); }
.cover-plum { --cover: var(--plum); } .cover-forest { --cover: var(--forest); }
.cover-ember { --cover: var(--ember); }

/* ---- review mode ---- */
.review-banner {
  display: flex;
  align-items: center;
  gap: var(--s4);
  flex-wrap: wrap;
  background: var(--plum);
  color: var(--cream);
  padding: 0.6rem clamp(var(--s5), 5vw, var(--s6));
}
.review-banner[hidden] { display: none; }
.review-banner strong { font-weight: 800; }
.review-banner a { color: var(--cream); font-weight: 800; }
.review-banner .wrap { display: contents; }

.empty-note { color: var(--ink-soft); padding-block: var(--s6); }

/* ---- footer ---- */
.foot { border-block-start: 1px solid var(--hairline); margin-block-start: var(--s6); padding-block: var(--s6) var(--s7); color: var(--ink-soft); font-size: 0.9rem; }
.foot strong { color: var(--ink); }

.intro--tight { padding-block-end: 0; }
.review-banner__inner { display: flex; align-items: center; gap: 0.5rem var(--s4); flex-wrap: wrap; }
.search-results { margin-block-start: var(--s5); }

/* ---- Timeline lens ---- */
/* One row per era; periods wrap within their band, so there is no horizontal
   scroll (and no scrollbar) at any width. */
.timeline-eras { margin-block: var(--s5); }
.era-row { margin-block-end: var(--s6); }
.era-row:last-child { margin-block-end: 0; }
.era-row__label { margin: 0 0 var(--s3); font-weight: 800; font-size: 0.75rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--honey); }
.era-row__periods { display: flex; flex-wrap: wrap; align-items: start; gap: 0.75rem 0.25rem; }
.station {
  flex: 0 0 auto;
  inline-size: 6.75rem;
  display: grid;
  grid-template-rows: 3.25rem auto auto auto;
  justify-items: center;
  align-content: start;
  gap: 0.3rem;
  padding: 0.4rem 0.3rem;
  border-radius: 12px;
  border: 1px solid transparent;
  color: var(--ink);
  text-decoration: none;
}
.station:hover { background: var(--card); border-color: var(--hairline); }
.station__bar { align-self: end; inline-size: 8px; block-size: calc(6px + var(--bar, 0) * 0.42px); background: var(--dot, var(--hairline)); border-radius: 4px 4px 0 0; opacity: 0.85; }
.station__node { inline-size: 14px; block-size: 14px; border-radius: 50%; background: var(--dot, var(--hairline)); box-shadow: 0 0 0 3px var(--manual); }
.station__name { font-family: var(--display); font-size: 0.88rem; line-height: 1.1; }
.station__count { font-weight: 800; font-size: 0.75rem; min-inline-size: 1.5rem; text-align: center; padding: 0.05rem 0.5rem; border-radius: var(--r-pill); background: var(--cream); border: 1px solid var(--hairline); color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.station.is-empty { opacity: 0.5; }
.station.is-empty .station__count { background: transparent; }
.station.is-selected { background: var(--card); border-color: var(--hairline); box-shadow: var(--shadow-sm); }
.station.is-selected .station__node { box-shadow: 0 0 0 3px var(--thread); }
.station.is-selected .station__name { text-decoration: underline; text-decoration-color: var(--thread); text-decoration-thickness: 3px; text-underline-offset: 3px; }
.station.is-selected .station__count { background: var(--thread); border-color: var(--thread); color: var(--ink); }
.station:focus-visible { outline: var(--focus); outline-offset: 2px; }

.period-detail { margin-block-start: var(--s5); }
.period-head { display: flex; align-items: center; gap: 12px; border-block-end: 1px solid var(--hairline); padding-block-end: var(--s4); margin-block-end: var(--s5); }
.period-head__dot { inline-size: 28px; block-size: 28px; border-radius: 50%; background: var(--dot, var(--hairline)); flex: 0 0 auto; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.5); }
.period-head h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(1.4rem, 1.1rem + 1.4vw, 1.9rem); }
.period-head p { margin: 0; color: var(--ink-soft); font-size: 0.9rem; }
.cluster { margin-block-end: var(--s5); }
.cluster:last-child { margin-block-end: 0; }
.cluster__head { display: flex; align-items: center; gap: 8px; margin: 0 0 0.75rem; font-weight: 800; font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); }
.cluster__dot { inline-size: 12px; block-size: 12px; border-radius: 50%; flex: 0 0 auto; background: var(--theme-dot, var(--hairline)); }
.cluster__head--soon { color: var(--ink-soft); }
.meanwhile { display: block; margin-block-start: 0.5rem; padding: 0.5rem 0.7rem; background: #fcf4dc; border-inline-start: 4px solid var(--thread); border-start-start-radius: 0; border-start-end-radius: 9px; border-end-end-radius: 9px; border-end-start-radius: 0; font-size: 0.82rem; font-style: italic; line-height: 1.4; color: var(--ink); }
.soon-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 12px; }
.soon-item { background: var(--card); border: 1px dashed var(--hairline); border-radius: 12px; padding: 0.85rem 1rem; opacity: 0.75; }
.soon-item__title { font-family: var(--display); font-size: 1.05rem; }

/* ---- responsive ---- */
@media (max-width: 46rem) {
  .site-header__bar { gap: 0.6rem var(--s4); }
  .site-header__bar > * { max-inline-size: 100%; }
  .site-nav { order: 2; flex-wrap: wrap; justify-content: center; }
  .site-search { order: 3; inline-size: 100%; margin-inline-start: 0; }
  .site-search input { inline-size: 100%; }
}
/* Large text must never force the page to scroll sideways: let the nav pill
   wrap its links rather than push past the viewport. */
.site-nav { flex-wrap: wrap; max-inline-size: 100%; }

/* ---- forced colours ---- */
@media (forced-colors: active) {
  .theme-card, .entry-card, .theme-card__strip, .station, .soon-item, .period-head__dot { border: 1px solid CanvasText; }
  .theme-dot, .theme-head__dot, .entry-card__pill i, .station__node, .station__bar, .cluster__dot, .period-head__dot { forced-color-adjust: none; }
  .site-nav__link[aria-current="page"] { border: 1px solid CanvasText; }
}

/* ---- print ---- */
@media print {
  .site-header, .band, .back, .timeline-eras, .review-banner { display: none; }
  .theme-card, .entry-card, .soon-item { box-shadow: none; break-inside: avoid; }
  .cluster { break-inside: avoid; }
}
