/* Immersive (immersive.js): a chapter played like a video, full screen, over the reader. Always dark, whatever the
   reading theme: the pictures are the page. Tall screens are a Short; wide ones show the whole picture beside a map. */
body.immersive-on .topbar, body.immersive-on .sidebar { display: none; }
body.immersive-on .layout { height: 100%; }
body.immersive-on .main { padding: 0; overflow: hidden; }

.im-stage {
  --im-ink: #f4efe6;
  --im-soft: rgba(244, 239, 230, .72);
  --im-glass: rgba(16, 14, 12, .58);
  --im-line: rgba(244, 239, 230, .18);
  --im-accent: #e7b877;
  /* The map's own colours, as the dark theme draws them. */
  --bg: #1b1916; --surface: #23201c; --border: #36312b; --text: #e9e3d9; --text-soft: #cfc6b8; --muted: #b0a698;
  --accent: #e7b877; --map-water: #1d2a30; --map-land: #2b2721; --map-coast: #4a4136; --map-ink: #a99f90;
  position: fixed; inset: 0; z-index: 100; overflow: hidden; outline: none;
  height: 100dvh; background: #0d0c0b; color: var(--im-ink);
  font-family: Inter, system-ui, sans-serif; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.im-stage .cm-tint { filter: brightness(.62) saturate(.85); }

/* Pictures: each new one fades in over the last; the blurred copy behind fills the screen around a whole picture. */
.im-backdrop, .im-pictures { position: absolute; inset: 0; }
.im-backdrop img {
  position: absolute; inset: -6%; width: 112%; height: 112%; object-fit: cover;
  filter: blur(38px) brightness(.42) saturate(1.15); opacity: 0; transition: opacity 1.1s ease;
}
.im-pic { position: absolute; left: 0; top: 0; max-width: none; opacity: 0; transition: opacity 1.1s ease; will-change: transform; }
.im-backdrop img.in, .im-pic.in { opacity: 1; }
.im-stage:not(.im-tall) .im-pic { border-radius: 4px; box-shadow: 0 24px 80px rgba(0, 0, 0, .55); }
.im-unpainted .im-pictures { background: radial-gradient(ellipse at 50% 35%, #2a241d 0%, #0d0c0b 70%); }

/* Shade under the subtitles and the bar, so white text reads on any picture. */
.im-shade {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0,0,0,.55) 0, rgba(0,0,0,0) 18%, rgba(0,0,0,0) 55%, rgba(0,0,0,.7) 100%);
}

/* Taps: back, pause, next. Under the controls. */
.im-tap { position: absolute; inset: 0; display: grid; grid-template-columns: 28% 1fr 32%; z-index: 2; }

/* Top: progress per picture, then the chapter, the picture's title and the controls. */
.im-top { position: absolute; left: 0; right: 0; top: 0; z-index: 4; padding: max(10px, env(safe-area-inset-top)) 14px 0; transition: opacity .4s; }
/* The bar is also a scrubber: a tall invisible hit area around it, thicker while it's touched. */
.im-scrub { position: relative; margin: -10px 0 0; padding: 10px 0 8px; cursor: pointer; touch-action: none; outline: none; }
.im-progress { display: flex; gap: 4px; height: 3px; transition: height .15s; }
.im-scrub:hover .im-progress, .im-scrubbing .im-progress, .im-scrub:focus-visible .im-progress { height: 6px; }
.im-scrub-label {
  position: absolute; top: 22px; transform: translateX(-50%); padding: 4px 9px; border-radius: 8px;
  background: var(--im-glass); font-size: 12.5px; font-weight: 600; white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity .15s; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.im-scrubbing .im-scrub-label { opacity: 1; }
/* While scrubbing the bar stays, though the rest of the controls may fade. */
.im-stage.im-playing:not(.im-awake) .im-scrub .im-progress { opacity: .75; }
.im-seg { flex: 1 1 0; min-width: 6px; background: var(--im-line); border-radius: 2px; overflow: hidden; }
.im-seg i { display: block; height: 100%; background: var(--im-ink); transform: scaleX(0); transform-origin: left; }
.im-head { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.im-title {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25;
  text-shadow: 0 1px 6px rgba(0,0,0,.6); border: 0; padding: 2px 4px; margin-left: -4px; border-radius: 8px;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.im-title:hover { background: rgba(255,255,255,.07); }
.im-title:focus-visible { outline: 2px solid var(--im-accent); }
.im-ref-row { display: flex; align-items: center; gap: 5px; }
.im-caret { font-size: 11px; color: var(--im-soft); }
.im-ref { font-weight: 600; font-size: 15px; }
.im-caption { font-size: 13px; color: var(--im-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.im-close, .im-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 36px; height: 36px;
  padding: 0 10px; border: 1px solid var(--im-line); border-radius: 18px; background: var(--im-glass);
  color: var(--im-ink); font: 600 13px/1 Inter, system-ui, sans-serif; text-decoration: none; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.im-close { padding: 0; width: 36px; font-size: 15px; }
.im-btn[aria-pressed="false"].im-map-btn { color: var(--im-soft); }
.im-close:hover, .im-btn:hover { border-color: var(--im-soft); }
.im-close:focus-visible, .im-btn:focus-visible, .im-go:focus-visible { outline: 2px solid var(--im-accent); outline-offset: 2px; }

/* Controls fade while playing and come back on a touch or a move. */
.im-stage.im-playing:not(.im-awake) .im-head { opacity: 0; pointer-events: none; }
.im-head { transition: opacity .4s; }

/* The chapter's title card, before its first line. */
.im-card {
  position: absolute; left: 0; right: 0; top: 38%; z-index: 3; text-align: center; pointer-events: none;
  opacity: 0; transform: translateY(8px); transition: opacity .7s, transform .7s;
  font-family: Literata, Georgia, serif; text-shadow: 0 2px 18px rgba(0,0,0,.7);
}
.im-titling .im-card { opacity: 1; transform: none; }
.im-card-book { font-size: clamp(34px, 6vw, 64px); font-weight: 500; letter-spacing: .01em; }
.im-card-ch { margin-top: 6px; font: 600 13px/1 Inter, system-ui, sans-serif; letter-spacing: .22em; text-transform: uppercase; color: var(--im-soft); }

/* Subtitles. */
.im-sub {
  position: absolute; left: 50%; bottom: max(44px, calc(env(safe-area-inset-bottom) + 28px)); z-index: 3;
  transform: translateX(-50%); width: min(92%, 920px); text-align: center; pointer-events: none;
  font-family: Literata, Georgia, serif; font-size: clamp(21px, 2.1vw, 30px); line-height: 1.38; font-weight: 450;
  text-shadow: 0 1px 2px rgba(0,0,0,.9), 0 2px 18px rgba(0,0,0,.75); text-wrap: balance;
}
.im-sub.empty { opacity: 0; }
.im-verse {
  display: inline-block; margin-right: .45em; vertical-align: .45em; font: 600 12px/1 Inter, system-ui, sans-serif;
  color: var(--im-accent); letter-spacing: .04em;
}
.im-verse:empty { display: none; }
.im-line { transition: opacity .15s; }
.im-place { color: var(--im-accent); }

/* The map: beside the picture on a wide screen. */
.im-map {
  position: absolute; z-index: 3; display: flex; flex-direction: column;
  right: 20px; top: 92px; bottom: 150px; width: clamp(260px, 26vw, 420px);
  padding: 8px 10px 10px; border: 1px solid var(--im-line); border-radius: 14px; background: var(--im-glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: opacity .5s, transform .5s;
}
.im-map[hidden], .im-map-off .im-map { display: none; }
.im-map .cm-head { padding: 2px 2px 8px; font-size: 13px; }
.im-map .cm-now { color: var(--im-ink); font-weight: 600; }
.im-map .cm-map { flex: 1; min-height: 0; border: 0; border-radius: 9px; background: #171512; }
.im-map .cm-dot { pointer-events: none; }
/* On a wide screen with a map, the subtitles sit under the picture, clear of the map. */
.im-with-map:not(.im-tall) .im-sub { left: calc((100% - clamp(260px, 26vw, 420px) - 20px) / 2); width: min(80%, 820px); }
.im-with-map:not(.im-tall) .im-card { right: calc(clamp(260px, 26vw, 420px) + 20px); }

/* Start: sound or not (a tap is also what lets the browser play the recording). */
.im-start {
  position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; gap: 12px; padding: 0 20px max(120px, 18vh); background: rgba(0,0,0,.28);
}
.im-start[hidden] { display: none; }
.im-go {
  min-width: 250px; padding: 14px 22px; border: 0; border-radius: 28px; background: var(--im-ink); color: #15130f;
  font: 600 16px/1 Inter, system-ui, sans-serif; cursor: pointer; box-shadow: 0 6px 30px rgba(0,0,0,.4);
}
.im-go.quiet { background: var(--im-glass); color: var(--im-ink); border: 1px solid var(--im-line); backdrop-filter: blur(8px); }
.im-go[hidden] { display: none; }
.im-hint { margin: 6px 0 0; max-width: 420px; text-align: center; font-size: 12.5px; line-height: 1.5; color: var(--im-soft); }

/* Paused: a quiet mark in the middle. */
.im-paused {
  position: absolute; left: 50%; top: 50%; z-index: 3; width: 72px; height: 72px; margin: -36px 0 0 -36px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--im-glass);
  font-size: 26px; padding-left: 5px; pointer-events: none; opacity: 0; transition: opacity .25s;
}
.im-stage:not(.im-playing) .im-paused { opacity: 1; }
.im-stage:not(.im-playing):has(.im-start:not([hidden])) .im-paused,
.im-stage:not(.im-playing):has(.im-end:not([hidden])) .im-paused { opacity: 0; }
.im-end {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  font: 500 28px/1.3 Literata, Georgia, serif; background: rgba(0,0,0,.5);
}
.im-end[hidden] { display: none; }

/* Tall screens (a phone): a Short. The picture fills the screen and pans; the map is a small card that comes up when
   the verse names a place. Set by immersive.js (.im-tall) from the stage's own shape. */
.im-tall .im-map {
  top: auto; right: 12px; left: auto; bottom: calc(max(44px, env(safe-area-inset-bottom) + 28px) + 9.5em);
  width: min(46vw, 210px); height: min(46vw, 210px); padding: 6px; border-radius: 12px;
  opacity: 0; transform: translateY(8px) scale(.97); pointer-events: none;
}
.im-tall.im-has-places .im-map { opacity: 1; transform: none; }
.im-tall .im-map .cm-head { padding: 0 2px 5px; font-size: 11.5px; }
.im-tall .im-sub { width: calc(100% - 32px); font-size: clamp(20px, 5.6vw, 25px); line-height: 1.36; }
.im-tall .im-card { top: 30%; }
.im-tall .im-shade {
  background: linear-gradient(to bottom, rgba(0,0,0,.5) 0, rgba(0,0,0,0) 16%, rgba(0,0,0,0) 48%, rgba(0,0,0,.78) 100%);
}

@media (prefers-reduced-motion: reduce) {
  .im-pic, .im-backdrop img, .im-card { transition: none; }
}

/* The way in, in the chapter page's bar (app.js), styled as the bar's Map button. */
.stream-immersive {
  flex: none; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-soft); font: 500 13px Inter, system-ui, sans-serif; text-decoration: none;
}
.stream-immersive:hover { border-color: var(--accent); color: var(--accent); }
/* The terrain as the dark stage wants it: quieter than the reader's map. */
.im-map .cm-terrain { filter: brightness(.72) saturate(.9); }
.im-with-map:not(.im-tall) .im-start { padding-right: calc(clamp(260px, 26vw, 420px) + 40px); }

/* The chapter's text: every verse, the one up now marked; tap one to go there. A panel on the left of a wide
   screen, a sheet over the lower part of a tall one. */
.im-text {
  position: absolute; z-index: 5; display: flex; flex-direction: column;
  left: 20px; top: 92px; bottom: 40px; width: clamp(300px, 30vw, 440px);
  border: 1px solid var(--im-line); border-radius: 14px; background: rgba(16, 14, 12, .82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); user-select: text; -webkit-user-select: text;
}
.im-text[hidden] { display: none; }
.im-text-head { display: flex; align-items: center; padding: 10px 10px 6px 16px; font-weight: 600; font-size: 14px; }
.im-text-ref { flex: 1; }
.im-text-close { border: 0; background: none; color: var(--im-soft); font-size: 16px; cursor: pointer; padding: 4px 8px; }
.im-verses { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; overscroll-behavior: contain; }
.im-v {
  display: block; width: 100%; padding: 7px 8px; border: 0; border-radius: 8px; background: none; text-align: left;
  color: var(--im-soft); font: 400 15.5px/1.5 Literata, Georgia, serif; cursor: pointer;
}
.im-v:hover { background: rgba(255,255,255,.06); color: var(--im-ink); }
.im-v.now { background: rgba(231, 184, 119, .14); color: var(--im-ink); }
.im-v-num { display: inline-block; min-width: 1.6em; margin-right: 4px; font: 600 11.5px/1 Inter, system-ui, sans-serif; color: var(--im-accent); vertical-align: .2em; }
.im-btn.im-text-btn[aria-pressed="true"] { border-color: var(--im-accent); color: var(--im-accent); }
.im-tall .im-text { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 62%; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
.im-tall.im-text-open .im-sub, .im-tall.im-text-open .im-map { opacity: 0; }
/* Over the controls row, so the verse being scrubbed to is never under a button. */
.im-scrub { z-index: 2; }
.im-scrub-label { z-index: 6; }
/* With the text open on a wide screen, the marked verse there is the subtitle. */
.im-text-open:not(.im-tall) .im-sub { opacity: 0; }

/* The chapter picker, from the title: a book, then its chapters. Placed like the text panel. */
.im-chapters {
  position: absolute; z-index: 5; display: flex; flex-direction: column;
  left: 20px; top: 92px; max-height: calc(100% - 132px); width: clamp(300px, 30vw, 440px);
  border: 1px solid var(--im-line); border-radius: 14px; background: rgba(16, 14, 12, .88);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.im-chapters[hidden] { display: none; }
.im-book {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--im-line); border-radius: 9px;
  background: rgba(255,255,255,.06); color: var(--im-ink); font: 600 15px Inter, system-ui, sans-serif;
}
.im-book option { color: #15130f; }
.im-chapters .im-text-head { gap: 8px; padding: 10px 8px 8px 12px; }
.im-chapters-close { border: 0; background: none; color: var(--im-soft); font-size: 16px; cursor: pointer; padding: 4px 8px; }
.im-ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; padding: 4px 12px 14px; overflow-y: auto; overscroll-behavior: contain; }
.im-ch {
  height: 40px; border: 1px solid var(--im-line); border-radius: 9px; background: none; color: var(--im-ink);
  font: 500 14px Inter, system-ui, sans-serif; cursor: pointer;
}
.im-ch:hover { border-color: var(--im-soft); }
.im-ch.now { background: var(--im-ink); color: #15130f; border-color: var(--im-ink); }
.im-tall .im-chapters { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 70%; border-radius: 16px 16px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
.im-tall.im-chapters-open .im-sub, .im-tall.im-chapters-open .im-map { opacity: 0; }
/* The start screen dims the picture but leaves the top bar (✕, the chapter picker) usable: only its buttons take clicks. */
.im-start { pointer-events: none; }
.im-start > * { pointer-events: auto; }
/* The panels open over everything, the start screen included. */
.im-chapters, .im-text { z-index: 7; }
/* A phone's map, pinned with the Map button: up the whole time, not only for verses that name a place. */
.im-tall.im-map-pinned .im-map { opacity: 1; transform: none; }
.im-tall .im-map-btn[aria-pressed="true"] { border-color: var(--im-accent); color: var(--im-accent); }
.im-tall .im-map-btn[aria-pressed="false"] { color: var(--im-ink); }

/* ---- The launch pages (#/immersive, #/immersive/<book>): in the reader's own theme, pictures first. */
.iml { max-width: 1180px; margin: 0 auto; padding-bottom: 40px; }
.iml-intro h1 { margin: 0; font: 500 34px/1.2 Literata, Georgia, serif; }
.iml-intro p { margin: 8px 0 0; max-width: 620px; color: var(--text-soft); font-size: 15.5px; line-height: 1.55; }
.iml-crumbs { margin-bottom: 10px; font-size: 13.5px; color: var(--muted); }
.iml-crumbs a { color: var(--accent); text-decoration: none; }
.iml-pic { position: relative; display: block; overflow: hidden; background: var(--surface); }
.iml-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .5s, transform .6s; }
.iml-pic img.in { opacity: 1; }
.iml-play {
  position: absolute; z-index: 1; display: flex; align-items: center; justify-content: center; width: 54px; height: 54px;
  border-radius: 50%; background: rgba(16, 14, 12, .55); color: #f4efe6; font-size: 20px; padding-left: 4px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* Continue: one wide card. */
.iml-hero {
  position: relative; display: block; margin: 22px 0 34px; border-radius: 16px; overflow: hidden; color: #f4efe6;
  text-decoration: none; aspect-ratio: 21 / 9; max-height: 420px; width: 100%; background: #1b1916;
}
.iml-hero .iml-pic { position: absolute; inset: 0; }
.iml-hero::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0) 60%); }
.iml-hero-text { position: absolute; left: 24px; bottom: 20px; right: 90px; z-index: 1; display: flex; flex-direction: column; gap: 4px; text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.iml-kicker { font: 600 12px/1 Inter, system-ui, sans-serif; letter-spacing: .16em; text-transform: uppercase; color: #e7b877; }
.iml-hero-ref { font: 500 32px/1.15 Literata, Georgia, serif; }
.iml-hero .iml-caption { font-size: 14.5px; color: rgba(244, 239, 230, .8); }
.iml-hero .iml-play { right: 22px; bottom: 22px; width: 62px; height: 62px; font-size: 22px; }
.iml-hero:hover .iml-pic img, .iml-book:hover .iml-pic img, .iml-chapter:hover .iml-pic img { transform: scale(1.03); }

/* Books: picture cards by section. */
.iml-group h2 { margin: 26px 0 12px; font: 600 13px/1 Inter, system-ui, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.iml-books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.iml-book { display: flex; flex-direction: column; color: var(--text); text-decoration: none; }
.iml-book .iml-pic { aspect-ratio: 3 / 2; border-radius: 10px; }
.iml-name { margin-top: 7px; font-weight: 600; font-size: 14.5px; }
.iml-count { font-size: 12.5px; color: var(--muted); }

/* A book's chapters. */
.iml-chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; margin-top: 18px; }
.iml-chapter { display: flex; flex-direction: column; color: var(--text); text-decoration: none; }
.iml-chapter .iml-pic { aspect-ratio: 3 / 2; border-radius: 10px; }
.iml-chapter .iml-play { left: 50%; top: 50%; margin: -24px 0 0 -24px; width: 48px; height: 48px; font-size: 17px; opacity: 0; transition: opacity .2s; }
.iml-chapter:hover .iml-play, .iml-chapter:focus-visible .iml-play { opacity: 1; }
.iml-chapter.last .iml-pic { outline: 2px solid var(--accent); outline-offset: 2px; }
.iml-ch { margin-top: 8px; font-weight: 600; font-size: 14.5px; }
.iml-ch em { font-style: normal; font-weight: 500; color: var(--accent); }
.iml-chapter .iml-caption { font-size: 13px; color: var(--text-soft); line-height: 1.4; }

@media (max-width: 640px) {
  .iml-intro h1 { font-size: 28px; }
  .iml-hero { aspect-ratio: 4 / 3; margin: 16px -4px 26px; }
  .iml-hero-ref { font-size: 26px; }
  .iml-books { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .iml-chapters { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .iml-chapter .iml-play { opacity: 1; width: 40px; height: 40px; margin: -20px 0 0 -20px; font-size: 14px; }
}
/* A control the chapter has no use for (Map without places, 🔊 without a recording) is gone, not just inert. */
.im-btn[hidden] { display: none; }

/* Chapters without pictures (lists of names, some of the letters). */
.iml-words { display: none; }
.iml-textonly .iml-pic { background: linear-gradient(160deg, var(--surface), var(--bg)); border: 1px solid var(--border); }
.iml-textonly .iml-words {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 14px 16px;
  font: italic 400 14px/1.45 Literata, Georgia, serif; color: var(--text-soft); overflow: hidden;
}
.iml-words-label { font: 600 10.5px/1 Inter, system-ui, sans-serif; font-style: normal; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.iml-textonly.iml-chapter .iml-play { display: none; }
/* In the player, with no picture the words are the screen: in the middle, larger. */
.im-unpainted .im-sub { bottom: auto; top: 50%; transform: translate(-50%, -50%); font-size: clamp(24px, 2.6vw, 36px); line-height: 1.45; }
.im-tall.im-unpainted .im-sub { font-size: clamp(23px, 6.4vw, 28px); }
