/* ===== v13 (18 Nov 2026): the reading layer =====
   Sepia is the default: the navy frame, its motifs and the controls stay exactly as in Dark (data-reader="dark");
   only the page in the centre changes (data-paper="sepia"). Light keeps an ivory page on a slightly darker frame.
   Also: larger body text, captions and credits, a clearer Aa button, a marginal label for imagined examples and a
   short colour fade when the theme changes (none for readers who ask for reduced motion). */

/* ---------- the sepia page: plain and opaque, no texture; warmth from the colour, sharpness from the ink */
html[data-paper="sepia"] body.is-reading .unit {
  --bg:#ebe1cd; --surface:#f1e7d5; --raised:#e8dcc6; --line:#d3c4a8;
  --ink:#182b43; --ink-2:#4a5567; --accent:#1f5690; --accent-ink:#ffffff;
  --amber:#7d4a1c; --slate:#3a5f86; --mark:#ebcd8f; --wash:#e5d9c2;
  --shadow:0 10px 30px rgba(24,43,67,.16);
  color-scheme:light; color:var(--ink);
  box-shadow:0 0 0 1px #00000038, 0 28px 80px -34px #000000b3;
}
html[data-paper="sepia"] body.is-reading .unit > p::selection { background:#d9b56f8c; }
/* the chapter rail belongs to the page's markup but floats on the navy frame: it keeps the Dark palette */
html[data-paper="sepia"] body.is-reading .unit .chapter-rail {
  --bg:#101d30; --surface:#16263c; --raised:#21334b; --line:#3a4e69; --ink:#f4f0e8; --ink-2:#bac8da;
  --accent:#9ccaff; --accent-ink:#112945; --amber:#e6b985; --slate:#7fa8cc; --mark:#5d4a2b; --wash:#203955;
  color-scheme:dark; color:var(--ink);
}
@media (max-width:700px) {
  html[data-paper="sepia"] body.is-reading .unit { box-shadow:none; }
}

/* ---------- Light: an ivory page on a slightly darker frame */
html[data-reader="light"] body.is-reading { --bg:#ebe7de; }
html[data-reader="light"] body.is-reading .unit { --bg:#f1eee7; --surface:#f7f5f0; --raised:#edeae2; }
@media (prefers-color-scheme:light) {
  html:not([data-reader]) body.is-reading { --bg:#ebe7de; }
  html:not([data-reader]) body.is-reading .unit { --bg:#f1eee7; --surface:#f7f5f0; --raised:#edeae2; }
}

/* ---------- type: body 19 px on wide screens, 18 px on phones (at the default text size); the measure stays near
   68 characters a line, so the column is a little narrower than the figures */
html:not([data-face="sans"]) .unit > p:not(:first-of-type) { font-size:calc(1.1875rem * var(--fs)); line-height:1.7; max-width:58ch; }
html[data-face="sans"] .unit > p:not(:first-of-type) { font-size:calc(1.15rem * var(--fs)); line-height:1.74; max-width:56ch; }
@media (max-width:700px) {
  html:not([data-face="sans"]) .unit > p:not(:first-of-type) { font-size:calc(1.125rem * var(--fs)); line-height:1.68; }
  html[data-face="sans"] .unit > p:not(:first-of-type) { font-size:calc(1.07rem * var(--fs)); line-height:1.72; }
}
/* captions 13 px, credits and source notes 12 px */
.unit .fig figcaption, .unit .hero figcaption, .unit .pic figcaption, .unit > .hero figcaption { font-size:13px; line-height:1.5; }
.unit .fig-foot { font-size:12px; line-height:1.55; }
.unit .credit, .unit .hero .credit, .unit > .hero .credit { font-size:12px; line-height:1.55; }
.unit-meta { font-size:12px; }
@media (max-width:700px) {
  .unit .fig figcaption, .unit .hero figcaption, .unit .pic figcaption, .unit > .hero figcaption { font-size:13px; }
  .unit .credit, .unit .hero .credit, .unit > .hero .credit, .unit .fig-foot, .unit-meta { font-size:12px; }
}

/* ---------- the Aa button: a visible pill, so readers find the theme and the text size */
.bar #btn-type { width:auto; min-width:46px; height:34px; padding:0 12px; align-self:center; border:1px solid color-mix(in srgb, currentColor 40%, transparent); border-radius:999px; }
.bar #btn-type .aa { font:600 18px/1 var(--display); letter-spacing:.01em; }
.bar #btn-type:hover, .bar #btn-type[aria-expanded="true"] { border-color:currentColor; }
@media (max-width:700px) {
  .bar #btn-type { min-width:40px; height:32px; padding:0 9px; }
  .bar #btn-type .aa { font-size:16px; }
}

/* ---------- imagined examples: a small label in the margin, outside the text, so the drop cap and the flow are untouched */
.unit > p[data-imag] { position:relative; }
.unit > p[data-imag]::after {
  content:"Imagined example"; content:"Imagined example" / "";
  position:absolute; top:.5em; left:-33px; writing-mode:vertical-rl;
  font:600 9.5px/1 var(--sans); letter-spacing:.16em; text-transform:uppercase; white-space:nowrap;
  color:var(--amber); opacity:.88; pointer-events:none;
}
@media (max-width:700px) {
  .unit > p[data-imag]::after { left:-19px; font-size:8.5px; letter-spacing:.12em; }
}
@media print { .unit > p[data-imag]::after { display:none; } }

/* ---------- a short colour fade when the reader changes theme (added and removed by the settings sheet) */
html.theme-shift, html.theme-shift *, html.theme-shift *::before, html.theme-shift *::after {
  transition:background-color .45s ease, color .45s ease, border-color .45s ease, fill .45s ease, stroke .45s ease, box-shadow .45s ease !important;
}
@media (prefers-reduced-motion:reduce) {
  html.theme-shift, html.theme-shift *, html.theme-shift *::before, html.theme-shift *::after { transition:none !important; }
}

/* ===== v14 (18 Nov 2026): the thesis in one line on the closing spread of the cover page */
.closing-spread .closing-copy>p.closing-thesis { font:400 19px/1.45 var(--display); color:var(--ink); white-space:normal; text-wrap:pretty; margin:18px 0 0; max-width:540px; }
.closing-spread .closing-copy>p.closing-thesis + p.closing-lead { margin-top:12px; }
@media (max-width:700px) { .closing-spread .closing-copy>p.closing-thesis { font-size:17px; } }

/* The chapter opening sits flush with its photograph. The atlas and the reading sheet
   keep their own palettes; only the opening uses these inks. */
@font-face {
  font-family: "EB Garamond Chapter";
  src: url("fonts/eb-garamond-latin-500-italic.woff2") format("woff2");
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}

@media screen {
  .unit > .chapter-opening {
    --opening-gutter: 52px;
    --opening-offset: 43px;
    --opening-ink: #f9f2e4;
    --opening-gold: #efc58a;
    --opening-secondary: #cad6d7;
    --opening-edge: #829591;
    --opening-first: #0d2231;
    --opening-last: #223d47;
    position: relative;
    isolation: isolate;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    row-gap: 0;
    column-gap: 1rem;
    margin: calc(-1 * var(--opening-offset)) calc(-1 * var(--opening-gutter)) 0;
    padding: clamp(1.1rem, 2.6vw, 2rem) var(--opening-gutter) clamp(1.35rem, 2.9vw, 2rem);
    color: var(--opening-ink);
    background-color: var(--opening-first);
    background-image: linear-gradient(110deg, var(--opening-first) 8%, var(--opening-last) 100%);
    border-bottom: 1px solid #bea47b;
  }

  html[data-reader="dark"]:not([data-paper="sepia"]) .chapter-opening {
    --opening-first: #08151f;
    --opening-last: #162c37;
  }
  @media (prefers-color-scheme: dark) {
    html:not([data-reader]) .chapter-opening {
      --opening-first: #08151f;
      --opening-last: #162c37;
    }
  }

  .chapter-opening::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0;
    background: url("img/editorial-compass.svg") right -4.6rem top -4.1rem / clamp(14rem, 26vw, 23rem) auto no-repeat;
    opacity: .29;
    pointer-events: none;
  }
  .chapter-opening > .chapter-home {
    grid-column: 1 / -1;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    margin: 0 0 clamp(.65rem, 1.2vw, 1rem);
    color: var(--opening-secondary);
    font: 500 .8125rem/1.3 var(--sans);
  }
  .chapter-opening > .chapter-home:hover {
    color: var(--opening-ink);
    text-decoration: underline;
    text-underline-offset: .22em;
  }
  .unit > .chapter-opening > .kicker {
    display: flex;
    align-items: center;
    grid-column: 1 / -1;
    gap: .75rem;
    margin: 0;
    color: var(--opening-gold);
    font: 500 .75rem/1.4 var(--mono);
    letter-spacing: .14em;
  }
  .chapter-opening > .kicker::before {
    content: "";
    width: 1.7rem;
    border-top: 1px solid currentColor;
  }
  .unit > .chapter-opening > h1 {
    grid-column: 1 / -1;
    justify-self: start;
    min-width: 0;
    max-width: min(100%, 22ch);
    padding-inline-end: .06em;
    margin: .14em 0 .4em;
    color: var(--opening-ink);
    font: italic 500 clamp(2.65rem, 1.65rem + 3.6vw, 4.65rem)/1.02 "EB Garamond Chapter", "Newsreader", Georgia, serif;
    letter-spacing: -.022em;
    text-wrap: balance;
    overflow-wrap: anywhere;
  }
  .chapter-opening > h1.speaking {
    box-shadow: -14px 0 0 -11px var(--opening-gold);
  }
  .chapter-opening > .unit-meta {
    grid-column: 1;
    gap: .3rem .95rem;
    margin: 0;
    color: var(--opening-secondary);
    font: 400 .8125rem/1.5 var(--sans);
    letter-spacing: .015em;
  }
  .chapter-opening > .chapter-sharing {
    grid-column: 2;
    justify-content: end;
    margin: 0;
  }
  .chapter-opening .chapter-copy-link {
    min-height: 2.75rem;
    padding: .48rem .82rem;
    border: 1px solid var(--opening-edge);
    border-radius: 3px;
    color: var(--opening-ink);
    background: var(--opening-first);
    font: 500 .8125rem/1.3 var(--sans);
  }
  .chapter-opening .chapter-copy-link:hover {
    border-color: var(--opening-gold);
    background: #2b4651;
  }
  .chapter-opening .chapter-listen {
    min-height: 2.75rem;
    padding: .48rem .9rem;
    border: 1px solid var(--opening-gold);
    border-radius: 3px;
    color: var(--opening-gold);
    background: transparent;
    font: 600 .8125rem/1.3 var(--sans);
    letter-spacing: .01em;
    cursor: pointer;
  }
  .chapter-opening .chapter-listen:hover { background: rgba(239, 197, 138, .12); }
  .chapter-opening .chapter-listen[aria-pressed="true"] { color: var(--opening-first); background: var(--opening-gold); }
  .chapter-opening .chapter-listen[hidden] { display: none; }
  /* Glossary and Sources: the same plate, with no photograph under it */
  .unit > .chapter-opening.plain { margin-bottom: 2rem; }
  .chapter-opening .chapter-share-status {
    color: var(--opening-ink);
  }
  .chapter-opening .chapter-share-status:empty {
    display: none;
  }
  .chapter-opening :focus-visible {
    outline: 2px solid var(--opening-gold);
    outline-offset: 3px;
  }
  body.is-reading .unit > .chapter-opening + .hero {
    margin-top: 0;
  }

  @media (max-width: 700px) {
    .unit > .chapter-opening {
      --opening-gutter: 24px;
      --opening-offset: 28px;
      padding-block: .75rem 1.15rem;
    }
    .chapter-opening::before {
      background-position: right -4.2rem top -3.2rem;
      background-size: 14rem;
      opacity: .22;
    }
    .chapter-opening > .chapter-home { margin-bottom: .55rem; }
  }
  @media (max-width: 460px) {
    .unit > .chapter-opening {
      grid-template-columns: minmax(0, 1fr);
    }
    .chapter-opening > .chapter-sharing {
      grid-column: 1;
      justify-content: start;
      margin-top: .8rem;
    }
  }
  @media (forced-colors: active) {
    .chapter-opening::before { display: none; }
    .unit > .chapter-opening { border-block: 1px solid CanvasText; }
    .unit .chapter-opening h1.speaking { outline: 2px solid Highlight; }
  }
}

/* The original compass remains the still illustration. The interactive facsimile
   occupies the same rectangle and cannot take focus or intercept a link. */
.opening-compass { display: none; }

@media screen and (min-width: 1025px) and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) and (forced-colors: none) {
  html.fx .chapter-opening:has(> .opening-compass)::before { display: none; }
  html.fx .chapter-opening > .opening-compass {
    display: block;
    position: absolute;
    z-index: -1;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    opacity: .40;
    transition: opacity .45s ease;
  }
  html.fx .chapter-opening > .opening-compass.is-tracking { opacity: .60; }
  /* v16.6: three image layers (dial, bearing, rose) turned with transforms, so the browser's compositor moves them
     without repainting the drawing on every frame */
  .opening-compass .compass-face {
    position: absolute;
    top: -4.1rem;
    right: -4.6rem;
    width: clamp(14rem, 26vw, 23rem);
    height: clamp(14rem, 26vw, 23rem);
  }
  .opening-compass .compass-dial,
  .opening-compass .compass-bearing,
  .opening-compass .compass-needle {
    position: absolute;
    inset: 0;
    transform-origin: 50% 50%;
  }
  .opening-compass .compass-dial { background: url("img/compass-dial.svg") center / contain no-repeat; }
  .opening-compass .compass-needle { background: url("img/compass-rose.svg") center / contain no-repeat; }
  .opening-compass .compass-bearing {
    transform: rotate(var(--compass-angle, 0deg));  /* moved by a damped spring in editorial.js */
  }
  /* v16.6: the rose is always turning, slowly; the dial turns the other way, more slowly still.
     While the pointer is on the plate the rose stops turning and faces it; it carries on when the pointer leaves. */
  html.fx .opening-compass .compass-dial {
    animation: opening-compass-dial 300s linear infinite reverse;
    will-change: transform;
  }
  html.fx .opening-compass.is-tracking .compass-needle { animation-play-state: paused; }
  @keyframes opening-compass-drift { to { transform: rotate(360deg); } }
  @keyframes opening-compass-dial { to { transform: rotate(360deg); } }
  html.fx .opening-compass .compass-needle {
    animation: opening-compass-settle 2.6s both, opening-compass-drift 150s linear 2.6s infinite;
    will-change: transform;
  }
  @keyframes opening-compass-settle {
    0%   { transform: rotate(-32deg); animation-timing-function: ease-out; }
    61%  { transform: rotate(5deg);   animation-timing-function: ease-in-out; }
    84%  { transform: rotate(-1.5deg); animation-timing-function: ease-out; }
    100% { transform: rotate(0deg); }
  }
}
