/* ============================================================================
   Family Lost in Tokyo — site.css
   Tokens, typography, and the responsive tier ladder (SDD §10.1, §17).
   ONE place for every value (REQ-212).

   No external fonts and no inline styles: the CSP is style-src 'self',
   font-src 'self'. The serif stack is resolved locally and degrades to
   Times — which is also the longevity position (SDD §11).

   THE TIER LADDER
   Layout has *intent* at each width; it does not merely reflow. Breakpoints
   are in em so they follow the reader's own font size, not a device list.

     hand    < 40em   Phone. One column. The header splits in two: brand and
                      theme control on a bar, navigation on a scrolling rail
                      beneath it — never three wrapped rows. Paired controls
                      go full width and stack.
     lap    >= 40em   Large phone / tablet. The header returns to a single
                      row. Paired controls sit side by side. Grids go 2-up.
     desk   >= 64em   The measure is reached. Vertical rhythm opens up.
     room   >= 90em   Nothing grows. The column stays at --measure and the
                      margins simply get quieter; full-bleed figures stop at
                      90rem so they stay photographs rather than wallpaper.

   Type and space are fluid clamps across 20rem–90rem, so the tiers change
   *arrangement* and the scale handles *size*. That division is the whole
   design: a line of this book holds roughly the same number of characters
   on a phone as it does on a desk.
   ============================================================================ */

:root {
  /* --- colour: ink on paper ------------------------------------------- */
  --bg: #faf8f4; --ink: #1c1a17; --muted: #6b665e; --accent: #8a4b2d;
  --rule: #e4dfd6; --card: #ffffff;

  /* --- measure and gutters -------------------------------------------- */
  --measure: 72ch;            /* the reading column. Never exceeded.      */
  --measure-narrow: 45ch;
  --shell: calc(var(--measure) + 8rem);   /* header/footer furniture      */
  --gutter: clamp(1rem, 4vw, 2rem);       /* page edge → content          */

  /* --- fluid space: 320px → 1440px ------------------------------------ */
  --space-1: clamp(0.4rem,  0.34rem + 0.30vw, 0.55rem);
  --space-2: clamp(0.7rem,  0.55rem + 0.75vw, 1rem);
  --space-3: clamp(1.1rem,  0.78rem + 1.60vw, 1.75rem);
  --space-4: clamp(1.75rem, 1.16rem + 2.95vw, 3rem);

  /* --- fluid type: one ladder, no per-breakpoint patches -------------- */
  --step--1: clamp(0.80rem, 0.77rem + 0.15vw, 0.88rem);   /* meta, ui     */
  --step-0:  clamp(1.05rem, 1.00rem + 0.25vw, 1.1875rem); /* body         */
  --step-1:  clamp(1.12rem, 1.05rem + 0.35vw, 1.35rem);   /* h3, prose h2 */
  --step-2:  clamp(1.28rem, 1.15rem + 0.65vw, 1.65rem);   /* h2           */
  --step-3:  clamp(1.55rem, 1.30rem + 1.25vw, 2.25rem);   /* h1           */
  --step-4:  clamp(2.00rem, 1.48rem + 2.60vw, 3.25rem);   /* hero         */

  --radius: 6px;
  --tap: 44px;                /* minimum touch target (REQ-146)           */
  --font-body: Charter, 'Iowan Old Style', 'Times New Roman', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --font-ui: system-ui, sans-serif;
}
[data-theme="dark"] {
  --bg: #17150f; --ink: #e8e4da; --muted: #9d968a; --accent: #d99a6c;
  --rule: #33302a; --card: #201d18;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

/* ---------------------------------------------------------------- base -- */
* { box-sizing: border-box; }
html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;   /* iOS Safari must not inflate landscape text */
  scroll-padding-top: 3rem;         /* clears the sticky progress rule on anchors */
}
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); font-size: var(--step-0); line-height: 1.65;
  overflow-x: clip;                 /* lets figures break full-bleed without a
                                       horizontal scrollbar. clip, not hidden:
                                       hidden would kill the sticky progress. */
}
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
:target { scroll-margin-top: 4rem; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: var(--gutter); top: var(--space-1); background: var(--card); padding: var(--space-1); z-index: 10; }

/* The one centring idiom, used by header, main and footer alike. */
main {
  width: min(100% - var(--gutter) * 2, var(--measure));
  margin-inline: auto;
  padding-block: var(--space-2);
}

.meta { color: var(--muted); font-family: var(--font-ui); font-size: var(--step--1); }
.era { font-variant-caps: all-small-caps; letter-spacing: .04em; }

/* -------------------------------------------------------------- header --
   hand: two rows — [brand | theme] over a nav rail that scrolls sideways
   with a masked edge to show there is more. lap and up: a single row.
   The header is deliberately NOT sticky: on a phone a sticky bar costs
   ~12% of the reading viewport, and the chapter progress rule already
   provides the "where am I" signal. -------------------------------------- */
.site-head { border-bottom: 1px solid var(--rule); }
.site-head nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "brand toggle" "menu menu";
  align-items: center;
  gap: var(--space-1) var(--space-2);
  width: min(100% - var(--gutter) * 2, var(--shell));
  margin-inline: auto;
  padding-block: var(--space-1);
  font-family: var(--font-ui); font-size: .95rem;
}
.brand { grid-area: brand; font-size: 1.05rem; }
.theme-toggle {
  grid-area: toggle;
  background: none; border: 1px solid var(--rule); border-radius: var(--radius);
  color: var(--ink); min-width: var(--tap); min-height: var(--tap); cursor: pointer;
}
.site-head ul {
  grid-area: menu;
  display: flex; gap: var(--space-2); list-style: none; margin: 0; padding: 0;
  /* the rail: bleeds to the page edge, snaps, hides its scrollbar */
  overflow-x: auto;
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  /* Fade the trailing edge only. A leading fade would dim the first item at
     rest, which reads as a rendering fault rather than as "there is more". */
  mask-image: linear-gradient(90deg, #000 0,
              #000 calc(100% - var(--gutter) * 1.5), transparent 100%);
}
.site-head ul::-webkit-scrollbar { display: none; }
.site-head li { flex: none; scroll-snap-align: start; }
.site-head a {
  color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: 2.75rem; padding-inline: .35rem;
  border-bottom: 2px solid transparent;
}
.site-head a[aria-current="page"] { border-bottom-color: var(--accent); }
@media (hover: hover) {
  .site-head a:hover { border-bottom-color: var(--rule); }
}

@media (min-width: 40em) {          /* lap: one row, rail becomes a plain list */
  .site-head nav {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "brand menu toggle";
    padding-block: var(--space-2);
  }
  .site-head ul {
    overflow-x: visible; mask-image: none;
    margin-inline: 0; padding-inline: 0;
    flex-wrap: wrap; justify-content: flex-end;
  }
}

/* ---------------------------------------------------------------- home -- */
.hero { text-align: center; padding: var(--space-4) 0 var(--space-3); }
.hero h1 { font-size: var(--step-4); margin: 0 0 var(--space-2); }
.premise { font-size: var(--step-1); max-width: 34ch; margin: 0 auto var(--space-3); text-wrap: balance; }
.cta { display: flex; flex-direction: column; gap: var(--space-1); margin: 0; }
.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 1.2rem;
  border: 1px solid var(--accent); border-radius: var(--radius);
  text-decoration: none; font-family: var(--font-ui);
  background: none; color: var(--accent); cursor: pointer;
}
.button.primary { background: var(--accent); color: var(--bg); }
@media (min-width: 40em) {
  .cta { flex-direction: row; justify-content: center; gap: var(--space-2); }
  .button { padding: 0 1.6rem; }
}
/* landscape phone: the hero must not consume the whole screen */
@media (max-height: 30em) and (orientation: landscape) {
  .hero { padding-block: var(--space-2); }
}

.story-promo { border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-2) var(--space-3); background: var(--card); }
.card { border-top: 1px solid var(--rule); padding-top: var(--space-2); }

/* --------------------------------------------------------------- prose -- */
.prose p { margin: 0 0 .9em; text-wrap: pretty; }
.prose blockquote { margin: var(--space-3) 0; padding-left: var(--space-2); border-left: 3px solid var(--rule); font-style: italic; }
.scene-break { border: none; text-align: center; margin: var(--space-3) 0; }
.scene-break::after { content: "⁂"; color: var(--muted); }
.smallcaps { font-variant-caps: small-caps; letter-spacing: .03em; }
dfn { font-style: normal; border-bottom: 1px dotted var(--accent); }
.gloss-link { text-decoration: none; font-size: .8em; vertical-align: super; }
.gloss { font-family: var(--font-ui); font-size: var(--step--1); color: var(--muted); border-left: 2px solid var(--rule);
  padding-left: var(--space-1); margin: .4em 0 1em; }

.prose h2 { font-size: var(--step-1); margin: var(--space-4) 0 var(--space-1); }
.prose h3 { font-size: var(--step-1); margin: var(--space-3) 0 var(--space-1); }
.prose h4 { font-size: 1rem; margin: var(--space-3) 0 var(--space-1); font-variant-caps: all-small-caps; letter-spacing: .05em; }
.prose-list { margin: 0 0 .9em; padding-left: 1.4em; }
.prose-list li { margin: .25em 0; }
.fnref a { text-decoration: none; padding: 0 .15em; }
.footnotes { margin-top: var(--space-4); border-top: 1px solid var(--rule); font-size: .92rem; }
.footnotes h2 { font-size: 1rem; font-variant-caps: all-small-caps; letter-spacing: .06em; color: var(--muted); }
.footnotes li { margin: .4em 0; }

/* hand only: at a ~34ch measure an unbroken proper noun opens a river.
   Above 40em the measure is wide enough that hyphens cost more than they buy. */
@media (max-width: 39.99em) {
  .prose { hyphens: auto; }
}

/* ------------------------------------------------------------- figures -- */
.fig { margin: var(--space-3) 0; }
.fig img { width: 100%; height: auto; border-radius: 2px; }
.fig figcaption { font-family: var(--font-ui); font-size: var(--step--1); color: var(--muted); margin-top: var(--space-1); }
/* Break out of the measure to the page edge — but stop at 90rem, so on a
   wide desk the photograph stays a photograph instead of becoming wallpaper.
   One rule, no media query: below 90rem `min()` picks 50vw and this is the
   ordinary full-bleed breakout; above it, the half-width is pinned at 45rem
   and the figure centres itself on the page. */
.fig.full {
  width: min(100vw, 90rem);
  margin-inline: calc(50% - min(50vw, 45rem));
}
.fig.full img { border-radius: 0; }
.fig.full figcaption { width: min(100% - var(--gutter) * 2, var(--measure)); margin-inline: auto; }
@media (min-width: 90em) { .fig.full img { border-radius: 2px; } }

/* ------------------------------------------------------------- chapter -- */
.chapter-head { margin: var(--space-3) 0; }
.kicker { font-family: var(--font-ui); font-variant-caps: all-small-caps; letter-spacing: .06em; color: var(--muted); margin-bottom: var(--space-1); }
.subtitle { font-size: var(--step-1); color: var(--muted); margin-top: 0; }
.progress { position: sticky; top: 0; height: 3px; background: var(--rule); z-index: 5; }
.progress .bar { height: 100%; width: 0; background: var(--accent); }

.share { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-family: var(--font-ui); font-size: var(--step--1); }
.share a, .share button { min-height: var(--tap); display: inline-flex; align-items: center; }
.share button { background: none; border: 1px solid var(--rule); border-radius: var(--radius); color: var(--accent); padding: 0 .8rem; cursor: pointer; font: inherit; }

/* hand: prev and next stack, each on its own full-width line — side by side
   at this width gives two 6-word links colliding in the middle. */
.prevnext span[data-chain] {
  display: grid; grid-template-columns: 1fr; gap: var(--space-1);
  margin: var(--space-3) 0; font-family: var(--font-ui); font-size: var(--step--1);
}
.prevnext a { display: block; padding-block: .5rem; }
.prevnext span[data-chain][hidden] { display: none; }
@media (min-width: 40em) {
  .prevnext span[data-chain] { grid-template-columns: 1fr 1fr; gap: var(--space-2); }
  .prevnext a[rel="next"] { text-align: right; }
}
[hidden] { display: none !important; }
.keystone-nudge { border-top: 1px solid var(--rule); padding-top: var(--space-2); font-family: var(--font-ui); font-size: .95rem; }

/* --------------------------------------------------- table of contents -- */
.toc { list-style: none; padding: 0; margin: 0; }
.toc li { border-top: 1px solid var(--rule); padding: var(--space-2) 0; }
.toc li > a { display: inline-block; padding-block: .2rem; }
.toc li.seen > a::after { content: " ✓"; color: var(--muted); }
.toc li.forthcoming { color: var(--muted); }
.toc p { margin: .3em 0 0; font-size: .95rem; }

/* hand: two equal halves, so the pair reads as one switch rather than two
   stray buttons. lap and up: intrinsic width, left aligned. */
.path-switch { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); font-family: var(--font-ui); margin: var(--space-2) 0; }
.path-switch a {
  text-decoration: none; padding: .4rem .8rem; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--rule); border-radius: var(--radius); color: var(--ink);
}
.path-switch a[aria-selected="true"] { border-color: var(--accent); color: var(--accent); }
@media (min-width: 40em) {
  .path-switch { display: flex; gap: var(--space-2); }
}

/* ----------------------------------------------------------- subscribe -- */
.subscribe { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card);
  padding: var(--space-2) var(--space-3); margin: var(--space-3) 0; font-family: var(--font-ui); }
.subscribe form { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: end; }
.subscribe label { flex: 1 0 100%; font-size: var(--step--1); }
.subscribe input[type=email] {
  flex: 1 1 14rem; min-width: 0;      /* min-width:0 is what keeps 320px safe */
  min-height: var(--tap); padding: 0 .6rem;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--bg); color: var(--ink); font: inherit;
}
.subscribe form .button { flex: 0 0 auto; }
@media (max-width: 39.99em) { .subscribe form .button { flex: 1 0 100%; } }
.subscribe .err { color: #b3261e; font-weight: 600; }
.subscribe .confirm { font-weight: 600; }
.hp { position: absolute; left: -9999px; }

/* -------------------------------------------------------------- family -- */
.tree, .tree ul { list-style: none; padding-left: var(--space-2); border-left: 1px solid var(--rule); }
.tree a { display: inline-block; padding-block: .35rem; }
/* min(100%, 18rem) is the whole trick: below 18rem of available width the
   track collapses to the container instead of overflowing it. */
.cast { list-style: none; padding: 0; display: grid; gap: var(--space-2);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); }
.cast-card { border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--space-2); background: var(--card); }
.cast-card:target { border-color: var(--accent); }
.glossary dt { font-weight: 700; margin-top: var(--space-2); }
.glossary dd { margin-left: 0; padding-left: var(--space-2); border-left: 1px solid var(--rule); }

/* ------------------------------------------------------- map and audio -- */
.place-list { list-style: none; padding: 0; }
.place-list > li { border-top: 1px solid var(--rule); padding: var(--space-2) 0; }
.place-list ul { padding-left: var(--space-2); }
/* svh, not vh: on iOS Safari vh is the *expanded* viewport, so a 60vh map
   is taller than the screen until the address bar retracts. */
#map-canvas { height: clamp(18rem, 60svh, 34rem); border-radius: var(--radius); background: var(--rule); }
.audio-list { padding-left: 1.2em; }
.audio-list audio { width: 100%; margin-block: var(--space-1); }

/* -------------------------------------------------------------- footer -- */
.site-foot { border-top: 1px solid var(--rule); margin-top: var(--space-4); padding: var(--space-3) var(--gutter);
  text-align: center; font-family: var(--font-ui); font-size: var(--step--1); color: var(--muted); }
.site-foot p { margin: 0 0 var(--space-1); line-height: 2.2; }
.site-foot a { padding: .5rem .15rem; }

.empty-state { color: var(--muted); }

@media print {
  .site-head, .site-foot, .progress, .subscribe, .prevnext, .share, .keystone-nudge, .theme-toggle { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { width: auto; }
  .prose p { orphans: 2; widows: 2; }
  .fig.full { width: auto; margin-inline: 0; }
  img { break-inside: avoid; }
}
