/* Jameson · narrated essays
   A long read with a narrator: the header over a contour terrain, the contents beside the text, the essay set for
   reading, and the player and voice settings that essay.js adds. Colors and type come from site.css. */

:root {
  --now-bg: rgb(var(--glow) / 0.15);
  --word-bg: rgb(var(--glow) / 0.42);
  --scrim: rgba(3, 5, 4, 0.55);
  --measure: 40em;
}
:root[data-theme="light"] { --now-bg: rgb(214 160 60 / 0.2); --word-bg: rgb(214 160 60 / 0.42); --scrim: rgba(20, 30, 25, 0.35); }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) { --now-bg: rgb(214 160 60 / 0.2); --word-bg: rgb(214 160 60 / 0.42); --scrim: rgba(20, 30, 25, 0.35); } }

.essay-page main { padding-bottom: calc(var(--dock-space, 0px) + 24px); }
.essay-page .foot { padding-bottom: calc(var(--dock-space, 0px) + 28px); }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn.sm { min-height: 36px; padding: 6px 14px; font-size: 0.92rem; }
.btn.ghost { border-color: transparent; background: transparent; }

/* ───── header ───── */
.e-head { position: relative; isolation: isolate; overflow: hidden; padding: calc(var(--nav-h) + env(safe-area-inset-top, 0px) + clamp(40px, 8vw, 96px)) 0 clamp(36px, 6vw, 64px); }
.e-terrain { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.e-terrain canvas { width: 100%; height: 100%; }
.e-terrain::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, var(--bg) 18%, rgb(var(--shade) / 0.55) 60%, transparent), linear-gradient(0deg, var(--bg), transparent 45%); }
.e-head-in { max-width: var(--maxw); }
.e-title { max-width: 16em; margin: 18px 0 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(2.2rem, 1.3rem + 4vw, 4.2rem); line-height: 1.04; letter-spacing: 0.005em; text-wrap: balance; }
.e-sub { max-width: 30em; margin: 16px 0 0; font-size: clamp(1.15rem, 1rem + 0.7vw, 1.5rem); font-style: italic; font-weight: 300; line-height: 1.35; color: var(--ink-2); text-wrap: balance; }
.e-facts { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 24px 0 0; font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.e-facts b { font-weight: 500; color: var(--ink-2); }
.e-facts span + span::before { content: ""; display: inline-block; width: 5px; height: 5px; margin-right: 14px; border: 1px solid var(--hair-2); transform: translateY(-2px) rotate(45deg); }
.e-cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.e-note { max-width: 36em; margin: 18px 0 0; font-family: var(--font-ui); font-size: 0.95rem; color: var(--muted); }
.e-title.now, .e-sub.now { color: var(--gold-ink); }
/* the essay as a poster: below the introduction on a phone, beside it on a wider screen */
.e-poster { width: min(100%, 420px); margin: 32px 0 0; }
.e-poster a:has(img) { display: block; border-radius: 10px; overflow: hidden; border: 1px solid var(--hair-2); background: #1b1e22; box-shadow: 0 18px 50px -24px rgb(0 0 0 / 0.6); transition: border-color 0.2s, transform 0.3s; }
.e-poster img { display: block; width: 100%; height: auto; }
.e-poster figcaption { margin-top: 10px; font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--muted); }
.e-poster figcaption a { color: var(--ink-2); text-underline-offset: 3px; }
@media (hover: hover) { .e-poster a:has(img):hover { border-color: var(--gold); transform: translateY(-2px); } }
@media (min-width: 900px) {
  .e-head-in { display: grid; grid-template-columns: minmax(0, 1fr) clamp(240px, 27vw, 360px); column-gap: clamp(32px, 5vw, 72px); align-items: start; }
  .e-head-in > * { grid-column: 1; }
  .e-head-in > .e-poster { grid-column: 2; grid-row: 1 / span 6; width: 100%; margin: 0; align-self: center; }
}

/* ───── the contents beside the essay ───── */
.e-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; padding-top: clamp(8px, 2vw, 24px); }
@media (min-width: 1060px) { .e-body { grid-template-columns: 260px minmax(0, 1fr); gap: clamp(40px, 5vw, 72px); } }
.toc { align-self: start; border: 1px solid var(--hair); border-radius: var(--radius); background: var(--surface); }
.toc summary { padding: 14px 18px; cursor: pointer; font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-ink); }
.toc ol { margin: 0; padding: 4px 8px 12px; list-style: none; display: grid; gap: 2px; }
.toc a { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 2px 8px; padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--ink-2); font-family: var(--font-ui); font-size: 0.96rem; line-height: 1.3; }
.toc .toc-n { grid-column: 1; grid-row: 1; align-self: start; font-family: var(--font-mono); font-size: 0.8rem; line-height: 1.6; color: var(--muted); }
.toc .toc-n:empty::before { content: ""; display: inline-block; width: 5px; height: 5px; border: 1px solid var(--hair-2); transform: translateY(-2px) rotate(45deg); }
.toc .toc-t { grid-column: 2; grid-row: 1; }
.toc .toc-p { grid-column: 2; grid-row: 2; height: 2px; margin-top: 4px; border-radius: 2px; background: var(--hair); overflow: hidden; }
.toc .toc-p i { display: block; width: 0; height: 100%; background: var(--gold); transition: width 0.4s ease; }
.toc a[aria-current="true"] { background: var(--surface-2); color: var(--ink); }
.toc a[aria-current="true"] .toc-n { color: var(--gold-ink); }
@media (hover: hover) { .toc a:hover { color: var(--ink); background: var(--surface-2); } }
@media (min-width: 1060px) {
  .toc { position: sticky; top: calc(var(--nav-h) + 20px); max-height: calc(100vh - var(--nav-h) - 40px - var(--dock-space, 0px)); overflow: auto; border: none; background: transparent; }
  .toc summary { padding: 0 10px 10px; pointer-events: none; list-style: none; }
  .toc summary::-webkit-details-marker { display: none; }
  .toc ol { padding: 0; }
}

/* ───── the essay ───── */
.essay { max-width: var(--measure); font-size: clamp(1.08rem, 1rem + 0.32vw, 1.22rem); line-height: 1.78; color: var(--ink-2); outline: none; }
.part { padding-top: clamp(28px, 4vw, 44px); scroll-margin-top: calc(var(--nav-h) + 16px); }
.part:first-child { padding-top: 0; }
.part + .part { border-top: 1px solid var(--hair); margin-top: clamp(28px, 4vw, 44px); }
/* the part's number and its "Listen from here" share a line; the heading has the full width under them */
.part-h { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 16px; margin: 0 0 18px; }
.part-n { grid-column: 1; grid-row: 1; margin: 0; font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-ink); }
.part-h h2 { grid-column: 1 / -1; grid-row: 2; margin: 0; font-family: var(--font-display); font-weight: 600; font-size: clamp(1.4rem, 1.1rem + 1.1vw, 1.95rem); line-height: 1.18; letter-spacing: 0.01em; color: var(--ink); text-wrap: balance; }
.part-h h2.now { color: var(--gold-ink); }
.part-h .listen { grid-column: 2; grid-row: 1; justify-self: end; margin-right: -14px; gap: 8px; color: var(--muted); font-family: var(--font-ui); white-space: nowrap; }
.part-h .listen svg { width: 17px; height: 17px; }
.part-h .listen.on { color: var(--gold-ink); }
@media (hover: hover) { .part-h .listen:hover { color: var(--gold-ink); } }
.essay p { position: relative; margin: 0 0 1.05em; text-wrap: pretty; }
.essay .pull {
  margin: 1.6em 0; padding: 4px 0 4px 22px; border-left: 2px solid var(--gold);
  font-size: 1.2em; font-style: italic; line-height: 1.5; color: var(--ink);
}
.essay .coda { margin-top: 1.4em; font-size: 1.1em; color: var(--ink); }
.notes p { padding-left: 34px; font-size: 0.96em; font-style: italic; color: var(--ink-2); counter-increment: note; }
.notes { counter-reset: note; }
.notes p::after { content: counter(note); position: absolute; left: 0; top: 0.35em; display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--hair-2); border-radius: 50%; font-family: var(--font-mono); font-size: 0.7rem; font-style: normal; line-height: 1; color: var(--gold-ink); }

/* sentence and word being read */
.s { border-radius: 3px; transition: background-color 0.25s, box-shadow 0.25s; }
.s.now { background-color: var(--now-bg); box-shadow: 0 0 0 2px var(--now-bg); color: var(--ink); }
::highlight(essay-word) { background-color: var(--word-bg); color: inherit; }
body.narrating .s, body.narrating .part-h h2 { cursor: pointer; }
.part.reading .part-n { color: var(--gold); }

/* a paragraph's own play button, in the margin */
.pplay {
  position: absolute; left: -48px; top: 0.3em;
  width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 1px solid var(--hair-2);
  display: grid; place-items: center; background: var(--bg); color: var(--muted); cursor: pointer;
  opacity: 0; transition: opacity 0.2s, color 0.2s, border-color 0.2s;
}
.pplay svg { width: 13px; height: 13px; margin-left: 2px; }
.essay p:hover > .pplay, .pplay:focus-visible { opacity: 1; }
@media (hover: hover) { .pplay:hover { color: var(--gold-ink); border-color: var(--gold); } }
@media (max-width: 1059px), (hover: none) { .pplay { display: none; } }

/* a personal note after the essay, set apart from it */
.e-stand { margin-top: clamp(40px, 6vw, 64px); padding: clamp(20px, 3vw, 28px) clamp(20px, 3vw, 30px); border: 1px solid var(--hair); border-left: 3px solid var(--gold); border-radius: var(--radius); background: var(--surface); }
.e-stand h2 { margin: 0 0 12px; font-family: var(--font-mono); font-size: 0.74rem; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold-ink); }
.e-stand p { margin: 0; color: var(--ink-2); }
.e-stand p + p { margin-top: 0.9em; }
.e-end { display: flex; flex-wrap: wrap; gap: 12px; margin-top: clamp(36px, 5vw, 56px); padding-top: 24px; border-top: 1px solid var(--hair); }
.e-back { font-family: var(--font-ui); }

/* ───── the player ───── */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--surface);
  background: color-mix(in oklab, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(16px) saturate(1.2); backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--hair-2);
  transform: translateY(110%); visibility: hidden;
  transition: transform 0.3s ease, visibility 0s linear 0.3s;
}
.dock.on { transform: none; visibility: visible; transition: transform 0.3s ease, visibility 0s; }
@media (prefers-reduced-motion: reduce) { .dock, .dock.on { transition: none; } }
.dock-prog { position: absolute; left: 0; right: 0; top: -9px; height: 18px; cursor: pointer; }
.dock-prog::before { content: ""; position: absolute; left: 0; right: 0; top: 8px; height: 3px; background: var(--hair); }
.dock-prog i { position: absolute; left: 0; top: 8px; height: 3px; width: 0; background: linear-gradient(90deg, var(--gold), var(--moss)); transition: width 0.3s ease; }
.dock-in { max-width: var(--maxw); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "info ctl x"; align-items: center; gap: 8px 14px; }
.dock-info { grid-area: info; min-width: 0; }
.dock-label { margin: 0; font-family: var(--font-ui); font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dock-sub { margin: 0; font-family: var(--font-ui); font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.dock-ctl { grid-area: ctl; display: flex; align-items: center; gap: 4px; }
.dock-x { grid-area: x; display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.dock .icon-btn svg { width: 20px; height: 20px; }
.play-btn {
  width: 50px; height: 50px; margin: 0 4px; padding: 0; border-radius: 50%; border: none; cursor: pointer;
  display: grid; place-items: center; background: var(--gold); color: var(--on-gold);
}
.play-btn svg { width: 24px; height: 24px; }
.play-btn.loading svg { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.pill-btn {
  min-height: 34px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--hair-2);
  background: transparent; color: var(--ink-2); cursor: pointer;
  font-family: var(--font-ui); font-size: 13.5px; font-weight: 600; font-variant-numeric: tabular-nums;
}
@media (hover: hover) { .pill-btn:hover { border-color: var(--gold); color: var(--gold-ink); } }
.backpill {
  position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; border: 1px solid var(--hair-2);
  background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap;
  font-family: var(--font-ui); font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  display: inline-flex; align-items: center; gap: 8px;
}
.backpill svg { width: 16px; height: 16px; color: var(--gold-ink); }

/* ───── voice and reading settings ───── */
.drawer { position: fixed; inset: 0; z-index: 55; }
.drawer-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; } }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--hair-2); box-shadow: -30px 0 80px -30px rgba(0, 0, 0, 0.6);
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); padding-right: env(safe-area-inset-right, 0px);
  animation: slidein 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0.4; } }
@keyframes sheetup { from { transform: translateY(40px); opacity: 0.4; } }
@media (prefers-reduced-motion: reduce) { .drawer-panel, .drawer-scrim { animation: none; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 14px 12px 22px; border-bottom: 1px solid var(--hair); }
.drawer-head h2 { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; letter-spacing: 0.03em; }
.drawer-body { overflow: auto; overscroll-behavior: contain; padding: 18px 22px 28px; display: grid; gap: 20px; align-content: start; }
.drawer-body hr { width: 100%; margin: 0; border: none; border-top: 1px solid var(--hair); }
.flabel { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 0 0 8px; font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); }
.flabel output { font-size: 14px; letter-spacing: 0; text-transform: none; color: var(--ink); font-variant-numeric: tabular-nums; }
.note { margin: 0; font-family: var(--font-ui); font-size: 14px; line-height: 1.45; color: var(--muted); }
.note b { color: var(--ink-2); font-weight: 600; }
.note.warn { color: var(--gold-ink); }
.drawer input[type="range"] { width: 100%; accent-color: var(--gold); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--surface-2); }
.seg button { min-height: 36px; padding: 6px 10px; border: none; border-radius: 999px; background: transparent; cursor: pointer; font-family: var(--font-ui); font-size: 14px; font-weight: 500; color: var(--ink-2); }
.seg button[aria-checked="true"] { background: var(--gold); color: var(--on-gold); font-weight: 600; }
.vhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.vhead .flabel { margin: 0; }
.mini { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-ui); font-size: 14px; color: var(--ink-2); cursor: pointer; }
.mini input { width: 17px; height: 17px; margin: 0; accent-color: var(--gold); }
.vlist { display: grid; gap: 4px; margin-top: 10px; max-height: min(46vh, 420px); overflow: auto; padding-right: 2px; }
.vgroup { margin: 8px 0 2px; font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-ink); }
.vopt {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 10px;
  padding: 9px 12px; border: 1px solid var(--hair); border-radius: 10px; cursor: pointer; font-family: var(--font-ui);
}
.vopt[aria-selected="true"] { border-color: var(--gold); background: var(--surface-2); }
.vopt .vn { font-size: 14.5px; font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }
.vopt .vl { grid-column: 1; font-size: 13px; color: var(--muted); }
.vopt .vb { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.vopt .badge { padding: 0 7px; border-radius: 999px; border: 1px solid var(--hair-2); font-size: 11.5px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-2); }
.vopt .badge.g { border-color: transparent; background: var(--moss); color: var(--bg); }
.vopt .vp { grid-row: 1 / span 2; grid-column: 2; width: 34px; height: 34px; }
.vopt .vp svg { width: 14px; height: 14px; }
@media (hover: hover) { .vopt:hover { border-color: var(--hair-2); } }
.sw-list { display: grid; gap: 2px; }
.sw {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 12px;
  width: 100%; padding: 10px 2px; border: none; border-bottom: 1px solid var(--hair); background: transparent; cursor: pointer; text-align: left;
  font-family: var(--font-ui); font-size: 15px; color: var(--ink);
}
.sw small { grid-column: 1; font-size: 13px; color: var(--muted); }
.sw i { grid-column: 2; grid-row: 1 / span 2; position: relative; width: 40px; height: 24px; border-radius: 999px; background: var(--hair-2); transition: background-color 0.2s; }
.sw i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.sw[aria-checked="true"] i { background: var(--gold); }
.sw[aria-checked="true"] i::after { transform: translateX(16px); background: var(--on-gold); }
.help summary { cursor: pointer; font-family: var(--font-ui); font-size: 14px; font-weight: 600; color: var(--ink-2); }
.keys { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; margin: 14px 0 0; font-family: var(--font-ui); font-size: 14px; color: var(--ink-2); }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--hair-2); border-bottom-width: 2px; border-radius: 6px; font-family: var(--font-mono); font-size: 0.82em; text-align: center; color: var(--ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock-space, 0px) + 18px + env(safe-area-inset-bottom, 0px)); z-index: 80;
  transform: translateX(-50%); max-width: min(520px, calc(100% - 32px));
  padding: 10px 16px; border-radius: 12px; border: 1px solid var(--hair-2); background: var(--surface); color: var(--ink);
  font-family: var(--font-ui); font-size: 14.5px; line-height: 1.4; box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.7);
}

/* ───── narrow screens ───── */
@media (max-width: 760px) {
  .dock-in { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "info x" "ctl ctl"; }
  .dock-ctl { justify-content: center; }
  .dock-x .pill-btn { display: none; }
  .drawer-panel { top: auto; left: 0; width: 100%; max-height: 88vh; border-left: none; border-top: 1px solid var(--hair-2); border-radius: 16px 16px 0 0; padding-left: env(safe-area-inset-left, 0px); animation-name: sheetup; }
  .essay .pull { padding-left: 16px; }
}
