/* Sacred Gita — visual system ported from Gate of Noor's study-desk layout (tokens and
   component rules kept structurally identical) with the accent palette swapped to
   sacredgita.com's warm orange/gold/cream. Light study-desk look: white panels, cream
   ruled paper. No dark theme, no audio anywhere. Mobile-first.
   Variable names are kept from the Gate of Noor port (--teal, --rose, etc.) to
   minimise the diff against the rest of this file — their VALUES are Sacred Gita's
   palette: --teal is now the warm primary orange, not teal. */

:root {
  --ink: #3E2723;
  --muted: #795548;
  --line: #D7CCC8;
  --paper: #FFF8E7;
  --paper-deep: #FFF0D0;
  --panel: #ffffff;
  /* Deep sapphire: the arrival page backdrop behind and around the welcome painting.
     Carlos, Oct 12 2026: the whole painting is shown uncropped, so the page needs a
     deliberate dark field for the letterbox space instead of the cream study-desk paper. */
  --sapphire: #0B1E39;
  --teal: #E8712C;
  --teal-soft: #FBE0C8;
  --gold: #D4A017;
  --rose: #B23A2E;
  --shadow: 0 18px 45px rgba(62, 39, 35, .14);

  /* The reserved live-preview pane's own footprint, in one place, so the pane's own geometry and
     the sidebar's reservation can never drift apart (JOB-20261015317). --preview-visible-height
     is written by app.js from the REAL visual viewport, with 100dvh as the CSS fallback: a mobile
     browser's chrome makes the visible viewport shorter than the layout viewport `vh` reports, and
     a reservation measured from the wrong one is exactly what put the pane over the sidebar's goal
     text on the real iPad Chrome draft. --preview-bottom-gap is the strip of the layout viewport a
     bottom browser bar (or a keyboard) really covers, so the pane is never anchored behind it. */
  --preview-pane-height: 252px;
  --preview-pane-inset: 18px;   /* the pane's own gap from the visible viewport edge */
  --preview-pane-clear: 18px;   /* clearance kept between the sidebar's foot and the pane's top */
  --preview-pane-top: 18px;     /* .app's padding / the sticky sidebar's own top offset */
  --preview-bottom-gap: 0px;

  /* THE SYSTEM SAFE AREA THE PINNED RESERVATION MUST CLEAR (JOB-20261015333).
     The narrow layout pins the preview strip to the top of the viewport and reads the passage in the
     clipped view directly below it. A pinned (`position: sticky; top: 0`) element is positioned
     against the SCROLLPORT, so it does not inherit the native shell's own body padding (native.css
     reserves that for everything in flow) — which is exactly why the real iPhone capture
     (RUN38684812490, 03-resumed-without-scribbles.png, 440x956 css, dpr 3) shows the strip's own top
     border on the capture's row 0 with "LIVE PREVIEW" sharing rows with 9:41 and the status icons,
     while the same app's in-flow cards start below them. --native-safe-* is the native shell's own
     channel, published by native.css for `html.is-native-app` (the Capacitor SystemBars plugin's
     --safe-area-inset-*, falling back to env(), and 0px when neither exists); the plain env() below
     it is the browser's own channel, which a hosted page with viewport-fit=cover also reports. max()
     of the two is the union of both honest measurements of one physical inset, and it errs larger —
     the only safe direction for a reservation whose failure mode is being painted under the system
     bars. Both are 0px on a desktop browser and in the headless suites, and the pinned geometry is
     built from these two numbers in one place (app.js reads them back through a probe element, so
     CSS and the scroll arithmetic cannot drift). */
  --preview-safe-top: max(env(safe-area-inset-top, 0px), var(--native-safe-top, 0px));
  --preview-safe-right: max(env(safe-area-inset-right, 0px), var(--native-safe-right, 0px));
  --preview-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--native-safe-bottom, 0px));
  --preview-safe-left: max(env(safe-area-inset-left, 0px), var(--native-safe-left, 0px));
}

* { box-sizing: border-box; }
/* overflow-x on html/body MUST be clip, never hidden: a non-visible overflow-x computes
   overflow-y to auto, which makes html/body scroll containers. The sidebar then has a
   scrollport that never scrolls (body is as tall as its content), so the sticky sidebar
   simply scrolls away with the page and takes the sidebar word-help card with it —
   exactly where it must NOT be. clip trims the horizontal overflow without creating a
   scroll container, so the document keeps scrolling and the sticky sidebar sticks. */
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: clip; }
html { scroll-behavior: smooth; }

/* THE TWO-FINGER PAN MUST NOT ANIMATE THE SCROLL.
   Root steering, Oct 15 2026: the writer's two-finger gesture scrolls with window.scrollBy,
   while the rule above turns every one of those calls into a smooth animation. A real scrub
   outruns the animation, so the paper keeps sliding after the fingers have lifted and a
   re-contact that lands immediately is written onto a page that is still moving underneath it
   (measured in checks/pointer-checks.cjs section L: a 180 px two-finger drag left the document
   9 px short at the lift and drifted the rest of the way afterwards). While the gesture owns the
   scroll the document is scrolled instantly instead; ordinary page scrolling is untouched,
   because this class only exists for as long as two fingers are down. */
html.panning { scroll-behavior: auto; }

/* NO TEXT SELECTION ANYWHERE IN THE APP CHROME.
   Carlos, Oct 3 2026: "while u write the text turns green like u tried to select the
   entire line ... press and slide selects text usually with the pen as ure already
   trying to write by press and slide, it fucks things up in this app."
   Nothing in this UI is meant to be selectable — the guide is painted on the canvas and
   every label is chrome. But the DOM labels (.translation-chip, hints, nav) were still
   selectable, so a pen press-and-slide started iPadOS's native selection: the run of
   text highlights in the system/tint colour (green on his iPad) and the selection drag
   competes with the stroke being written. touch-action:none + preventDefault() on
   pointerdown do not suppress that; only user-select/-webkit-touch-callout do.
   Text fields opt back in below, so signing in and searching still behave normally. */
/* Every element, not just html/body: user-select is not inherited, so a label left on
   the default ("auto") is still selectable and the selection gesture can start on it —
   which is why a body-only rule would have looked like it worked and then failed on the
   verse labels. Carlos, Oct 3 2026: "anywhere where i write with the stylus, the ipad
   thinks im trying to select the text and it tries thus to select the entire page like
   when u select to do copy paste, it happens in the video multiple times". */
*, *::before, *::after {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
input[type="text"], input[type="email"], input[type="search"], input[type="tel"],
input[type="url"], input[type="number"], input[type="password"], textarea,
[contenteditable="true"] {
  -webkit-user-select: text;
  -moz-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
body {
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(212, 160, 23, .16), transparent 30%),
    linear-gradient(135deg, #f6f1e6 0%, #FDF3E2 50%, #fffaf0 100%);
}
img, canvas { max-width: 100%; }
button, select, input { font: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

*:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ══════════════════════════════════════════════
   APP SHELL — sidebar + main workspace
═══════════════════════════════════════════════ */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.sidebar, .workspace, .bottom-panel, .journey-panel, .sheet {
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(62, 39, 35, .1);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.sidebar {
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-self: start;
}
/* Below 920px the sidebar stacks UNDER the workspace, so it travels with the page like
   any other block and only needs to become a scroll container on a short viewport (laptop
   lid half-open, a landscape phone, etc). Below 760px tall it scrolls as a whole so the
   controls further down are still reachable without the page growing past the viewport. */
@media (max-height: 759.98px) {
  .sidebar {
    /* 36px = .app's 18px padding, top + bottom. Measured from the VISIBLE viewport height rather
       than `100vh`: on a real mobile browser `vh` is the layout (largest) viewport, so a column
       sized from it reaches below what the reader can see and its foot controls cannot be
       scrolled into view (JOB-20261015317). dvh is the CSS fallback; app.js publishes the
       measured visual-viewport height when the engine has one. */
    max-height: calc(var(--preview-visible-height, 100dvh) - var(--preview-pane-top) * 2);
    overflow-y: auto;
  }
}

/* Where the sidebar IS the left column (>= 920.01px wide, which is every iPad in both
   orientations) it has to stay on screen while you write. Writing happens far down the
   page — the paper starts around y=840 with the page ~3200px tall — so a sidebar that
   scrolls away takes the word-help card with it, and word help you cannot see is worth
   nothing. Pinning the column and letting it scroll internally keeps the help card
   beside the pen at every scroll position. The panel is at the TOP of the sidebar, so it
   is visible the moment the column pins. */
@media (min-width: 920.01px) {
  .sidebar {
    position: sticky;
    top: var(--preview-pane-top);
    /* The visible height, for the same reason as the short-viewport rule above. The wide-screen
       override further down subtracts the reserved preview pane's own footprint as well. */
    max-height: calc(var(--preview-visible-height, 100dvh) - var(--preview-pane-top) * 2);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

.brand { display: flex; align-items: center; gap: 12px; }
.mark {
  width: 46px; height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: #f8dc80;
  font-family: 'Noto Serif Devanagari', serif;
  font-size: 26px;
  font-weight: 800;
  flex-shrink: 0;
}
h1 { font-size: 1.35rem; line-height: 1.12; }
.subtitle { color: var(--muted); font-size: .92rem; line-height: 1.45; margin-top: 4px; }

.group { display: grid; gap: 10px; }
.group-title {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #6c675b;
  font-weight: 800;
}

/* ── Today verse list ── */
.verse-list { display: grid; gap: 8px; max-height: 34vh; overflow-y: auto; }
.verse-btn, .tool-btn, .chip {
  min-height: 44px;
  border: 1px solid rgba(232, 113, 44, .16);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}
.verse-btn {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  display: grid;
  gap: 4px;
}
.verse-btn[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); }
.verse-name { font-weight: 800; font-size: .96rem; }
.verse-meta { color: var(--muted); font-size: .82rem; }

/* ── generic outline button (also used standalone: Change chapter, sheet close, etc) ── */
.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  font-weight: 750;
  width: 100%;
}
.tool-btn:hover { border-color: var(--teal); }
.tool-btn.primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.tool-btn.primary:hover { background: #C9561A; }
.tool-btn.warn { color: var(--rose); border-color: rgba(178, 58, 46, .28); }
.tool-btn.warn:hover { background: rgba(178, 58, 46, .06); }
.tool-btn:disabled { opacity: .55; cursor: not-allowed; }
.field-btn { margin-top: 12px; }

.link-btn {
  display: block;
  width: 100%;
  min-height: 40px;
  background: none;
  border: none;
  color: var(--teal);
  font-weight: 700;
  font-size: .88rem;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
  padding: 2px 0;
}

/* ── Journey / Account / About — three small pills right under the brand block, always
   visible without scrolling (see the .sidebar media query above) ── */
.sidebar-pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sidebar-pills-4 { grid-template-columns: repeat(4, 1fr); }
.pill-btn {
  min-height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(232, 113, 44, .18);
  background: #fff;
  color: var(--teal);
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0 6px;
  /* .pill-btn is also used on the <a> Museum link — same look as the <button> pills. */
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  text-align: center;
}
.pill-btn:hover { border-color: var(--teal); background: var(--teal-soft); }

/* ── controls (ink / stroke / guide / writing mode) ── */
.controls { display: grid; gap: 12px; }
.control-row { display: grid; gap: 6px; }
label { font-size: .88rem; font-weight: 750; color: #6B4A3A; }
select, input[type="range"] { width: 100%; }
select {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid rgba(232, 113, 44, .18);
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}
input[type="range"] { accent-color: var(--teal); }

.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chips.chips-2 { grid-template-columns: repeat(2, 1fr); }
.level-exhausted { display: grid; gap: 8px; margin-top: 4px; }
.chip { display: grid; place-items: center; padding: 8px; font-weight: 700; }
.chip[aria-pressed="true"] { background: var(--teal); color: #fff; border-color: var(--teal); }

.progress, .goal-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 8px;
  background: #FDF6EA;
  border: 1px solid rgba(232, 113, 44, .12);
}
.meter { height: 10px; border-radius: 999px; background: #F0E0C8; overflow: hidden; }
.meter span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width .25s ease;
}

/* ── one-year goal panel (sidebar, replaces the old Routine box) ── */
.goal-line { font-size: .88rem; color: var(--ink); line-height: 1.4; }
.goal-meter span { background: linear-gradient(90deg, var(--gold), var(--teal)); } /* gold -> orange, whole-Gita progress */
.goal-status { font-size: .84rem; font-weight: 750; margin-top: 2px !important; }
.goal-status.on-track { color: #4C7A3D; } /* calm earthy green */
.goal-status.behind { color: var(--rose); }

/* Same four lines, reused atop the Journey screen for members. */
.journey-goal-lines { display: grid; gap: 4px; margin-bottom: 4px; font-size: .88rem; color: var(--ink); }
.journey-goal-status { font-weight: 750; margin-top: 2px; }
.journey-goal-status.on-track { color: #4C7A3D; }
.journey-goal-status.behind { color: var(--rose); }

/* ══════════════════════════════════════════════
   MAIN WORKSPACE
═══════════════════════════════════════════════ */
.main {
  min-width: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 18px;
}

.workspace {
  position: relative;
  border-radius: 8px;
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar h2 { font-size: 1.05rem; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.actions .tool-btn { width: auto; padding: 0 14px; min-height: 44px; }

.zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(232, 113, 44, .16);
  border-radius: 8px;
  overflow: hidden;
}
.zoom-group .zoom-btn {
  width: 40px;
  min-width: 40px;
  min-height: 44px;
  border: none;
  border-radius: 0;
  font-size: 1.1rem;
}
/* The visible name of the group, added because the owner read the bare plus/minus as the
   painting zoom. The buttons keep their IDs and their existing range/scale behaviour. */
.zoom-label {
  padding: 0 6px 0 8px;
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--muted);
  white-space: nowrap;
}
.zoom-value {
  min-width: 46px;
  text-align: center;
  font-size: .82rem;
  font-weight: 700;
  color: var(--muted);
}

/* ── the writing paper ── */
/* ── art plate + paper: always stacked, painting first, full width, at every size —
   no side column, no sticky. A painting on every verse, directly above the paper it
   belongs to. ── */
.paper-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}
.paper-row.no-plate .art-plate-frame { display: none; }

/* Paintings are NOT all one shape, though Sacred Gita's own collection runs mostly
   wide (roughly 1.85:1 landscape). The frame hugs each painting's OWN real aspect
   ratio (app.js sets --plate-aspect from the loaded image's naturalWidth/naturalHeight)
   so object-fit: contain below fills it edge to edge with no crop AND no letterboxed
   cream bands. 1.85 is only the fallback before an image has loaded once. Full width,
   no max-height cap — the frame's height is simply width / aspect, so the whole
   painting shows with nothing to letterbox against. */
.art-plate-frame {
  position: relative;
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper-deep);
  cursor: pointer;
  aspect-ratio: var(--plate-aspect, 1.85);
}
.art-plate-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain; /* the WHOLE painting, never cropped */
  object-position: center;
  opacity: 0;
  transition: opacity 400ms ease;
}
.art-plate-img.active { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .art-plate-img { transition: none; }
}

.page {
  position: relative;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 48px, rgba(212, 160, 23, .22) 49px, transparent 50px),
    repeating-linear-gradient(0deg, transparent 0 66px, rgba(150, 110, 40, .19) 67px, transparent 68px),
    var(--paper);
  border: 1px solid var(--line);
  min-height: 38vh;
  /* No max-height, no inner scroll, at any size. app.js's positionTranslationChip grows
     #page's own min-height to fit the guide + glosses + translation chip (see that
     function's comment) — on a long verse (2:255 is ~3.8x a viewport tall) that just
     makes a tall paper, and the ONE document scrollbar carries the reader through it,
     the art plate included, instead of a scrollbar nested inside the paper card. */
  overflow: visible;
}
@media (min-width: 700px) {
  .page { min-height: 45vh; }
}

/* ── The writing viewport and its reserved scroll view (JOB-20261015322, JOB-20261015323) ─────
   On a WIDE screen these are plain blocks: the document is the only scroll root and nothing about
   the reviewed layout changes. On a NARROW screen the media query further down makes the viewport a
   normal-flow wrapper whose reserved preview strip is sticky to the visible top edge, with the
   passage read inside .paper-clip — the clipped view directly below the strip — and .paper-scroll
   the view app.js offsets from the document scroll. The space the pinned strip takes out of the flow
   is given back with .writing-scroll-space, which app.js sizes from the passage's own reach and keeps
   in step with the clip; it is display:none here so the wide layout never sees it. */
.writing-viewport { display: block; min-width: 0; }
.paper-clip { display: block; min-width: 0; }
.paper-scroll { display: block; min-width: 0; }
.writing-scroll-space { display: none; }

.trace-text { position: absolute; inset: 0; pointer-events: none; }
.translation-chip {
  position: absolute;
  left: 16px;
  right: 16px;
  transform: none;
  max-width: none;
  width: auto;
  direction: ltr;
  text-align: center;
  color: rgba(62, 39, 35, .62);
  font-size: .98rem;
  line-height: 1.5;
  background: rgba(255, 255, 255, .8);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(62, 39, 35, .08);
}

#writerCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.rise-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  pointer-events: none;
  font-family: 'Noto Serif Devanagari', serif;
  font-size: clamp(1.5rem, 5vw, 2.6rem);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(212, 160, 23, .35);
  opacity: 0;
  background: rgba(255, 248, 231, .65);
}
.rise-overlay.rising { animation: riseFade 2.2s ease forwards; }
@keyframes riseFade {
  0%   { opacity: 0; transform: translateY(18px) scale(0.97); }
  16%  { opacity: 1; transform: translateY(0) scale(1); }
  72%  { opacity: 0.85; transform: translateY(-22px) scale(1.01); }
  100% { opacity: 0; transform: translateY(-70px) scale(1.02); }
}
@media (prefers-reduced-motion: reduce) {
  .rise-overlay.rising { animation: riseFadeReduced 0.6s ease forwards; }
}
@keyframes riseFadeReduced {
  0% { opacity: 0; }
  40% { opacity: 1; }
  100% { opacity: 0; }
}

/* ── art interlude — a painting between verses, illuminated-manuscript style ── */
/* ── the painting moment is a SCREEN, not part of the tall sheet ────────────────
   JOB-20261016407 targeted repair, reviewed against the frozen live baseline: the interlude was
   absolutely positioned inside the paper, so on a short phone — or on any sheet that is several
   viewports tall — the painting and its Continue control landed far below the fold and the reader
   had to hunt the sheet for them. It is now pinned to the visible viewport and laid out as stage +
   control, with its own scroll only for a window too short to hold both; the painting keeps
   object-fit: contain, so nothing is ever cropped. Nothing else about the moment changed. */
.art-interlude {
  position: fixed;
  inset: 0;
  /* Above the fixed writing footer (z-index 380): the interlude owns the whole
     screen, so its Continue control must never sit under Prev/Next. */
  z-index: 420;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 16px;
  padding: 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  opacity: 0;
  transition: opacity 600ms ease;
  pointer-events: none;
}
.art-interlude.visible { opacity: 1; pointer-events: all; }
/* Sacred Gita's paintings run wide (roughly 1.85:1 landscape) rather than Gate of
   Noor's portrait plates — app.js sets --art-aspect from the loaded image's own
   naturalWidth/naturalHeight (same pattern as .art-plate-frame's --plate-aspect
   below), so a landscape painting gets a landscape frame instead of a tall portrait
   box with a strip of image and a lot of empty cream underneath it. 1.85 is only the
   fallback before an image has loaded once; max-width widened to match. */
.art-frame {
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: var(--art-aspect, 1.85);
  /* The frame is the interlude grid's stage row: it may shrink to that row, and it may never push
     the Continue control out of the window (JOB-20261016407). */
  min-height: 0;
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper-deep);
  padding: 0;
  cursor: pointer;
}
.art-image { width: 100%; height: 100%; object-fit: contain; display: block; }
.art-continue { width: auto; padding: 0 24px; }
@media (prefers-reduced-motion: reduce) {
  .art-interlude { transition: none; }
}

/* ── stats row ── */
/* Relative so the footer's buttons stay above the absolutely-positioned writing canvas.
   The canvas can extend past .page's bottom (see positionTranslationChip in app.js), and
   an unpositioned footer loses the hit test there — which swallowed taps on "Mark verse
   done" on a phone. Belt and braces next to the .page height fix. */
.completion-footer { position: relative; z-index: 2; display: flex; justify-content: flex-end; }
.completion-footer .tool-btn { width: auto; min-height: 48px; padding: 0 24px; }
@media (max-width: 699px) { .completion-footer .tool-btn { width: 100%; } }
.bottom-panel {
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.stat { padding: 12px; border-radius: 8px; background: rgba(255, 255, 255, .74); border: 1px solid rgba(232, 113, 44, .1); }
.stat strong { display: block; font-size: 1.35rem; margin-bottom: 2px; }
.stat span { color: var(--muted); font-size: .86rem; }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; padding: 10px; }
  .sidebar { order: 2; }
  .journey-screen { order: 2; }
  .workspace { min-height: 66vh; }
  .bottom-panel { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .actions { justify-content: stretch; }
  .actions .tool-btn { flex: 1 1 100px; }
}

/* ══════════════════════════════════════════════
   JOURNEY SCREEN
═══════════════════════════════════════════════ */
.journey-screen { min-width: 0; grid-column: 1 / -1; }
.journey-panel {
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.journey-header { display: flex; align-items: center; gap: 12px; }
.journey-header .tool-btn { width: auto; padding: 0 14px; }
.journey-title { font-size: 1.2rem; font-weight: 800; }

.journey-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  font-size: .88rem;
  color: var(--muted);
}
.journey-day { font-weight: 800; font-size: 1.05rem; color: var(--ink); flex-basis: 100%; }
.journey-streak { color: var(--teal); font-weight: 700; }

.journey-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
}
.journey-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 44px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(62, 39, 35, .12);
  background-color: var(--paper-deep);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 8px;
  color: var(--ink);
  text-align: left;
  transition: border-color .2s, box-shadow .2s;
}
.journey-tile:hover { border-color: var(--teal); }
.journey-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 248, 231, var(--tile-overlay, .88));
  transition: background .3s;
}
.journey-tile.is-complete { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212, 160, 23, .35); }
.journey-tile-num, .journey-tile-name, .journey-tile-pct { position: relative; z-index: 1; }
.journey-tile-num { font-weight: 800; font-size: .72rem; color: var(--teal); }
.journey-tile-name { display: block; font-size: .7rem; font-weight: 700; line-height: 1.2; margin-top: 2px; }
.journey-tile-pct { display: block; font-size: .62rem; color: var(--muted); margin-top: 2px; }

/* ══════════════════════════════════════════════
   SHEETS — chapter picker / about / membership / account
═══════════════════════════════════════════════ */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(62, 39, 35, .35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
/* The welcome stays behind an unfinished sign-in (closing it must not leave a
   blank reader), so this one sheet must sit above the welcome's layer. */
#signInSheetOverlay { z-index: 520; }
.sheet {
  background: var(--panel);
  color: var(--ink);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 700px) {
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: 8px; max-height: 70vh; }
}
.sheet-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid rgba(62, 39, 35, .08); }
.sheet-header .tool-btn { width: 40px; min-height: 40px; padding: 0; flex-shrink: 0; }
.sheet-title { font-size: 1.1rem; font-weight: 800; flex: 1; }
.sheet-search {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid rgba(232, 113, 44, .18);
  font-size: max(1rem, 16px); /* Preserve larger user text without iOS focus zoom. */
  color: var(--ink);
  background: #fff;
}
.sheet-body { padding: 16px 20px 22px; font-size: .92rem; line-height: 1.65; color: var(--ink); overflow-y: auto; }
.sheet-body p { margin: 0 0 14px; }
.sheet-attribution { font-size: .78rem; color: var(--muted); }

.chapter-list { overflow-y: auto; padding: 4px 10px 16px; }
.chapter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}
.chapter-row:hover { background: var(--teal-soft); }
.chapter-row-num {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: .8rem;
  flex-shrink: 0;
}
.chapter-row-names { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chapter-row-en { font-weight: 800; font-size: .95rem; }
.chapter-row-meaning { font-size: .78rem; color: var(--muted); }
.chapter-row-sa { font-family: 'Noto Serif Devanagari', serif; font-size: 1.05rem; color: var(--ink); flex-shrink: 0; }

/* ── sign-in / account forms ── */
.field-label { display: block; font-size: .8rem; color: var(--muted); margin: 14px 0 6px; }
.field-input { display: block; width: 100%; margin-bottom: 0; }
.signin-pane { margin-top: 10px; padding-top: 14px; border-top: 1px solid rgba(62, 39, 35, .08); }
.google-btn-container { margin: 10px 0; min-height: 40px; display: flex; justify-content: center; }
.code-entry-row { margin-top: 4px; }
.form-error { color: var(--rose); font-size: .82rem; margin-top: 10px !important; }
.form-status { color: var(--teal); font-size: .82rem; margin-top: 10px !important; }
.account-email { font-weight: 800; font-size: 1.02rem; margin-bottom: 2px !important; }
.account-status { color: var(--muted); font-size: .88rem; }

/* ══════════════════════════════════════════════
   WORD TOOLTIP — hover only (pen/mouse, never a press, never touch — see
   canvas-writer.js's pointermove handler). Two lines: pronunciation, then the
   English meaning. pointer-events: none so it can never itself intercept the
   press that's meant for the paper underneath it.
═══════════════════════════════════════════════ */
.word-tooltip {
  box-sizing: border-box;
  overflow: auto;
  position: fixed;
  z-index: 300;
  background: rgba(255, 248, 231, .76);
  border: 1px solid rgba(121, 85, 72, .16);
  border-radius: 8px;
  padding: 7px 12px;
  box-shadow: 0 4px 16px rgba(62, 39, 35, .08);
  max-width: 220px;
  text-align: center;
  pointer-events: none;
}
/* Dark lettering stays readable over the translucent paper-coloured card. */
.word-tooltip-tl { font-style: italic; font-weight: 700; font-size: .88rem; color: #8C4219; }
.word-tooltip-en { font-size: .8rem; color: #3E2723; margin-top: 2px; }
.word-tooltip-sa { font-family: 'Noto Serif Devanagari', serif; font-size: 1.25rem; color: #3E2723; line-height: 1.35; }
.word-tooltip-row { margin-top: 3px; }
.word-tooltip-label { display: block; font-size: .62rem; letter-spacing: .06em; text-transform: uppercase; color: #795548; }
.word-tooltip-hi { font-family: 'Noto Sans Devanagari', sans-serif; font-size: .92rem; color: #3E2723; }
.word-tooltip-hi-tl { font-style: italic; font-size: .8rem; color: #8C4219; }
.word-tooltip-letters { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 8px; margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(121, 85, 72, .18); }
.word-tooltip-letter { display: inline-flex; flex-direction: column; align-items: center; min-width: 26px; }
.word-tooltip-letter .l-sa { font-family: 'Noto Serif Devanagari', serif; font-size: 1.05rem; color: #3E2723; line-height: 1.2; }
.word-tooltip-letter .l-tl { font-size: .68rem; color: #8C4219; font-style: italic; }
.word-tooltip-letter .l-parts { font-size: .6rem; color: #795548; }
.word-tooltip.rich { max-width: 320px; text-align: center; }
.word-tooltip * { pointer-events: none; }
.word-tooltip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* The help card no longer floats under the pen. It renders here, in the sidebar. */
.word-help-panel { gap: 8px; }
.word-help-idle { margin: 0; font-size: .82rem; line-height: 1.45; color: var(--muted); }
.word-help-panel.has-help .word-help-idle { display: none; }
.word-help-panel .word-tooltip {
  position: static;
  z-index: auto;
  width: 100%;
  max-width: none;
  max-height: 42vh;
  background: rgba(255, 255, 255, .6);
  box-shadow: none;
}
/* Narrow screens stack the sidebar below the workspace, so a docked card would be
   off-screen. Float it at the bottom instead, and only while a word is active. */
@media (max-width: 920px) {
  .word-help-panel.has-help {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 320;
    margin: 0;
    padding: 10px 14px;
    background: rgba(255, 248, 231, .96);
    border: 1px solid rgba(121, 85, 72, .16);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(62, 39, 35, .14);
  }
  .word-help-panel.has-help .group-title { display: none; }
  .word-help-panel.has-help .word-tooltip { max-height: 32vh; }
}
.check-row { display: flex; align-items: center; gap: 8px; font-size: .86rem; color: var(--ink); cursor: pointer; }
.check-row input { accent-color: var(--teal); width: 16px; height: 16px; margin: 0; }
.control-label { font-size: .8rem; font-weight: 600; color: var(--muted); }


/* ══════════════════════════════════════════════
   ART PLATE VIEWER (JOB-20261025579) — the whole painting at the largest fit of the display.
   The surround is deliberately dark: it is the letterbox, not a pale page around a
   near-page-sized image. Zoomed content keeps its real layout size inside .lightbox-stage's
   ordinary scroll container, so every edge stays reachable by touch/wheel/scrollbar/keys.
═══════════════════════════════════════════════ */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  background: #12100c;
  color: #f4efe0;
  cursor: default;
}
.lightbox-overlay:fullscreen {
  width: 100%;
  height: 100%;
}
.lightbox-toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
  background: #1b1712;
  border-bottom: 1px solid rgba(244, 239, 224, .14);
}
.lightbox-btn {
  width: auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  background: rgba(244, 239, 224, .1);
  border-color: rgba(244, 239, 224, .28);
  color: #f4efe0;
  font-size: .86rem;
}
.lightbox-btn:hover:not(:disabled) {
  background: rgba(244, 239, 224, .2);
  border-color: var(--gold);
}
.lightbox-btn:focus-visible { outline-color: var(--gold); }
.lightbox-btn:disabled { opacity: .4; }
.lightbox-btn[aria-pressed="true"] {
  background: rgba(212, 160, 23, .28);
  border-color: var(--gold);
}
.lightbox-zoom-value {
  min-width: 3.2em;
  text-align: center;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
  color: rgba(244, 239, 224, .8);
}
.lightbox-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding:
    calc(12px + env(safe-area-inset-top, 0px))
    calc(12px + env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px))
    calc(12px + env(safe-area-inset-left, 0px));
  background: #12100c;
  touch-action: pan-x pan-y;
}
.lightbox-stage:focus-visible { outline: 2px solid var(--gold); outline-offset: -4px; }
.lightbox-image {
  display: block;
  max-width: none;
  max-height: none;
  height: auto;
  border-radius: 4px;
  opacity: 0;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 120ms ease;
}
.lightbox-image.is-ready { opacity: 1; }
.lightbox-stage.can-pan .lightbox-image { cursor: grab; }
.lightbox-stage.is-panning .lightbox-image { cursor: grabbing; }
/* The spoken state lives outside the visual layout: the visible zoom percentage and the
   control labels already carry the same information. */
.lightbox-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
@media (prefers-reduced-motion: reduce) {
  .lightbox-image { transition: none; }
}

/* ══════════════════════════════════════════════
   WELCOME — the COMPLETE painting is shown, never cropped or zoomed. The overlay is a
   two-row grid: row 1 is the painting, centred, sized with `contain` so its own aspect
   ratio is preserved; row 2 is the existing title/Begin panel. Because the panel is a
   real grid row below the painting, the two boxes cannot intersect at any width.

   This replaces the earlier arrival layout (`.welcome-bg { position:absolute; inset:0;
   object-fit:cover }` with the panel absolutely positioned over the painting's lower
   third). That version cropped the 1918x820 original on phones: cover on a 390x844
   portrait viewport scales the painting to 1918x844 and shows only its middle ~39% of
   width, and the panel sat on top of the visible remainder. Carlos, Oct 12 2026: no
   cropping or zoom on the arrival page, one of ten paintings chosen per arrival.
═══════════════════════════════════════════════ */
.welcome-overlay {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  position: fixed;
  inset: 0;
  z-index: 500;
  overflow: hidden;
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: minmax(0, 1fr) auto; /* [1] painting stage, [2] title/Begin panel */
  background: var(--sapphire); /* dark sapphire behind and around the painting */
}
.welcome-bg {
  /* Grid row 1. width/height stay auto with BOTH max constraints, so the used box is the
     painting's own aspect ratio at the largest size that fits the row: the canvas is
     fully visible, the element's bounds ARE the painting's bounds (no letterbox inside
     the box), and there is no transform/scale. `contain` is kept explicit as a second
     guarantee that nothing is ever cropped. */
  place-self: center;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}
.welcome-card {
  /* Grid row 2 — the existing panel, in normal flow below the painting. */
  display: flex;
  justify-content: center;
  padding: 18px 20px calc(22px + env(safe-area-inset-bottom, 0px));
}
.welcome-content {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 26px 28px 30px;
  text-align: center;
}
.welcome-title {
  font-family: 'Noto Serif Devanagari', serif;
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  color: var(--teal);
  margin: 0 0 4px;
}
.welcome-title-en { font-size: 1.3rem; font-weight: 800; margin: 0 0 14px; }
.welcome-line { color: var(--muted); font-size: .95rem; line-height: 1.55; margin: 0 0 22px; }
.welcome-content .tool-btn { min-height: 48px; }

/* Phone: the panel runs edge to edge along the bottom instead of floating as a
   centred card with side margins. The painting keeps the whole row above it. */
@media (max-width: 700px) {
  .welcome-card { padding: 0; }
  .welcome-content {
    max-width: none;
    border-radius: 14px 14px 0 0;
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  }
}

/* Landscape phones / short windows: the panel is the fixed part, so tighten it rather
   than let it squeeze the painting row down to nothing. */
@media (max-height: 480px) {
  .welcome-card { padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .welcome-content { padding: 16px 20px 18px; }
  .welcome-title { font-size: 1.5rem; }
  .welcome-title-en { font-size: 1rem; margin-bottom: 8px; }
  .welcome-line { font-size: .85rem; margin-bottom: 12px; }
}

/* ══════════════════════════════════════════════
   SOUNDS — music playlist + ambience loops, sidebar panel (see js/sounds.js). Built
   entirely by JS into #soundsPanel; empty and invisible until playlist.json has
   content, so there is nothing here to hide/show by hand. Reuses .group /
   .group-title / .tool-btn / the global range-input styling above.
═══════════════════════════════════════════════ */
.sounds-subtitle { margin-top: -4px !important; }
.sound-music-row { display: flex; gap: 8px; }
.sound-music-row .sound-toggle { flex: 1; }
.sound-next-btn { flex: 0 0 auto; width: auto; padding: 0 14px; }
.sound-track-title {
  color: var(--muted);
  font-size: .82rem;
  margin-top: -4px !important;
  min-height: 1.2em; /* stable height whether or not a title is showing yet */
}
.sound-ambience-list { display: grid; gap: 8px; }
.sound-ambience-row { display: flex; align-items: center; gap: 10px; }
.sound-ambience-row .sound-toggle { flex: 0 0 auto; width: auto; padding: 0 12px; }
.sound-ambience-row input[type="range"] { flex: 1; }
.sound-icon { display: inline-flex; color: inherit; }
.tool-btn.sound-toggle[aria-pressed="true"] {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal);
}

/* ══════════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .journey-tile, .tool-btn, .meter span { transition: none; }
}

/* Compact, accessible shared painting reactions. */
.art-reactions { display:flex; align-items:center; justify-content:center; gap:8px; flex-wrap:wrap; padding:8px 12px; }
.art-reactions[hidden] { display:none; }
.art-reaction { display:inline-flex; align-items:center; justify-content:center; gap:8px; min-height:44px; min-width:64px; padding:8px 12px; border:1px solid var(--line); border-radius:16px; background:var(--paper); color:var(--ink); font:inherit; cursor:pointer; }
.art-reaction[aria-pressed="true"] { color:var(--teal); border-color:var(--teal); background:var(--paper-deep); }
.art-reaction:focus-visible { outline:2px solid var(--teal); outline-offset:3px; }
.art-reaction:disabled { cursor:wait; opacity:.6; }
.reaction-count { font-variant-numeric:tabular-nums; }
.reaction-status { flex-basis:100%; text-align:center; font-size:12px; color:var(--muted); }

/* ── Finger writing loupe (JOB-20261012397) ──────────────────────────────────────
   The small magnified view of the writing surface shown while a touch stroke is being
   drawn. js/finger-loupe.js paints the real crop and the exact point's crosshair.
   pointer-events:none makes it a view, never an input: it can never capture, block or
   move a stroke.

   Owner steering, October 15 (JOB-20261015313 continuation): the magnifier no longer
   floats beside the hand. The owner found that box — almost on top of the writing —
   distracting and confusing, so the crop now lives in a RESERVED pane that is a real,
   labelled part of the page: the sidebar's own column on a wide screen, and a reserved
   strip on the viewport edge on a narrow one. The pane keeps its size whether or not a
   contact is being followed, so the writing can never move because a preview appeared,
   and its plain label and border keep it visually distinct from ink. The rule just below
   is the floating fallback, kept for any host that hands over no pane. */
.finger-loupe {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 360;
  pointer-events: none;
  overflow: hidden;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, .32);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  background: var(--paper, #ffffff);
}
.finger-loupe[hidden] { display: none; }
.finger-loupe-surface { display: block; width: 100%; height: 100%; }

/* The reserved preview pane. A view, never an input: pointer-events:none on the whole pane,
   so a strip that a narrow screen docks over the paper still lets every tap and every stroke
   through to the paper underneath. It is fixed to the viewport so it is always beside the
   writing, and it lives outside the sidebar cards on purpose — they carry backdrop-filter,
   which would otherwise turn position:fixed into card-relative placement. */
.preview-pane {
  position: fixed;
  z-index: 340;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(194, 24, 91, .34);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 6px 18px rgba(62, 39, 35, .16);
  pointer-events: none;
}
.preview-pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.preview-pane-head .group-title { margin: 0; }
.preview-pane-state { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
/* Square, always: the crop is a square of real paper and the helper paints it at the frame's
   own size, so the frame's aspect ratio is what keeps the magnification honest. */
.preview-pane-frame {
  position: relative;
  width: 144px;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(62, 39, 35, .34);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper, #ffffff);
}
.preview-pane .finger-loupe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}
.preview-pane-note { margin: 0; color: var(--muted); font-size: .8rem; }

/* Wide screens: the sidebar is the left column and stays on screen while you write, so the
   pane is docked at the foot of that column. The writing rectangle is a different grid
   column, so the pane can never cover the paper, the toolbar or the active glyph, whatever
   the zoom. The column reserves the pane's whole footprint — its own gap from the visible
   viewport edge, whatever strip of the layout viewport a bottom browser bar really covers, the
   pane's height and a clearance — so no control of the column can ever be stranded underneath
   it, and the reservation is measured from the VISIBLE viewport (JOB-20261015317), which is what
   the real iPad Chrome draft got wrong: the pane sat over the goal text because the column had
   been sized from `100vh`, the layout viewport, which is taller than what the reader can see. */
@media (min-width: 920.01px) {
  .preview-pane {
    left: 36px;
    bottom: calc(var(--preview-bottom-gap) + var(--preview-pane-inset));
    width: 266px;
    height: var(--preview-pane-height);
    z-index: 6;
  }
  /* The crop frame takes whatever height the pane has left and stays square, so the pane's
     reserved height is the only thing that decides its size. align-self keeps the column flex
     from stretching it to the pane's width, which is what keeps the aspect ratio square. */
  .preview-pane-frame { width: auto; flex: 1 1 auto; min-height: 0; align-self: center; }
  /* The sticky column's foot stops exactly where the pane's reserved footprint begins, so the pane
     docks in clear space and can never sit over one of the column's controls. app.js publishes the
     measured visible height; `100dvh` is the CSS fallback for the first paint and for an engine
     without visualViewport. */
  .sidebar {
    max-height: calc(
      var(--preview-visible-height, 100dvh)
      - var(--preview-pane-top)
      - var(--preview-pane-inset)
      - var(--preview-bottom-gap)
      - var(--preview-pane-height)
      - var(--preview-pane-clear)
    );
  }
}

/* Narrow and tablet layouts: the sidebar stacks under the writing area, so the pane becomes a
   compact strip reserved at the top of the writing viewport, AFTER the painting and directly
   ABOVE the passage (app.js moves it there — see setupPreviewPane — because a fixed or absolutely
   positioned descendant of that card would resolve against the card's own backdrop-filter box).
   The writing viewport is given the VISIBLE viewport's own height and is pinned, so the strip is
   on screen for the whole passage; the passage itself lives in the clipped view below the strip
   (.paper-scroll), which app.js offsets from the document scroll, so the strip can never paint
   over a writing row and the strip never scrolls away while the passage is read
   (JOB-20261015322). Because the strip is a passive view (pointer-events: none) it can never take
   a stroke; the artwork stays in the flow ABOVE the strip and keeps its own full width and height,
   and the space the pinned viewport reserves is given back to the document by app.js
   (#writingScrollSpace), so every row stays reachable. */
@media (max-width: 920px) {
  /* A normal-flow wrapper: the document keeps its own length and stays the only scroll root; the
     children are what pin. */
  .writing-viewport {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
  }
  /* The reserved preview strip is the one thing pinned, and it is pinned BELOW the system safe area:
     `top: var(--preview-safe-top)` is the status bar / cutout / Dynamic Island inset the OS really
     reports (app.css :root, native channel first). Pinning it at 0 is what the real iPhone capture
     showed painted over 9:41 (JOB-20261015333). It is sticky, not fixed, so it stays a reserved item
     of the passage's own column: while any of the paper below it is still visible and
     input-receiving it is on screen, and it leaves only once the last slice of paper has closed
     (JOB-20261015323). */
  .preview-pane {
    position: sticky;
    top: var(--preview-safe-top, 0px);
    z-index: 2;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
  }
  /* The clipped view the passage is read in, pinned directly below the strip. Its top is the safe
     inset the strip itself starts at, PLUS the strip's own measured footprint and the row gap (app.js
     publishes --preview-strip-offset), so the strip can never paint over a writing row and the paper
     can never start under the status bar; its height is exactly the part of the visible viewport that
     is still below the strip and above the bottom safe inset (app.js publishes --preview-paper-window
     from the same two numbers); app.js closes that height with the document scroll as the reader
     leaves the passage — so no paper stays writable once the strip has left — and drives the view's
     own offset from the document scroll. */
  .paper-clip {
    position: sticky;
    top: calc(var(--preview-safe-top, 0px) + var(--preview-strip-offset, 118px));
    z-index: 0;
    flex: 0 0 auto;
    min-height: 0;
    height: var(--preview-paper-window, 100dvh);
    overflow: hidden;
    overscroll-behavior: contain;
  }
  .paper-scroll {
    height: var(--preview-paper-window, 100dvh);
    overflow: hidden;
    overscroll-behavior: contain;
  }
  .writing-scroll-space { display: block; min-width: 0; }
  /* Before app.js has placed the pane it is still a grid child of .app, exactly as the reviewed
     revision had it: first row, above everything, clear of the writing area. The child selector
     means this can never reorder the pane once it lives inside the writing viewport. */
  .app > .preview-pane { order: -1; }
  .preview-pane-head { flex-direction: column; align-items: flex-start; gap: 2px; }
  /* Reserve the state column's width. The last-trace label ("Final point (finger)")
     is longer than "No contact"; without this, the whole strip reflows and the
     crop frame shifts sideways at the moment of lift. A fixed reserved width keeps
     the frame still; only the text inside this column changes. */
  .preview-pane-head { flex: 0 0 150px; width: 150px; min-width: 0; }
  .preview-pane-state { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .preview-pane-frame { width: 84px; flex: 0 0 auto; }
  .preview-pane-note { display: none; }
  /* The app's own controls always paint over the passive preview. */
  .topbar { position: relative; z-index: 360; }
}

/* ══════════════════════════════════════════════
   JOB 582 — measured bottom navigation, scroll rail, adoption and account state
═══════════════════════════════════════════════ */

/* The welcome cover's fine print under each route. */
.welcome-fine { margin: 6px 0 16px; color: var(--muted); font-size: .82rem; line-height: 1.4; }

/* The writing footer is a real reserved row: its measured height is published as
   --writing-footer-h by app.js and subtracted from the narrow paper window and the
   rail's travel, so no writing row is ever hidden under it. It stays pinned to the
   visible bottom while the reader is inside the sheet, and it wraps every control
   inside the screen on a phone instead of letting the last one hang off the edge. */
.completion-footer {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 0;
  z-index: 380;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 calc(8px + var(--preview-safe-bottom, 0px));
  border-top: 1px solid var(--line);
  background: rgba(255, 248, 231, .97);
  backdrop-filter: blur(6px);
}
@media (min-width: 920.01px) {
  /* The writing column's own left edge: 18px app padding + 320px sidebar + 18px gap. */
  .completion-footer { left: calc(18px + 320px + 18px); right: 18px; }
}
/* The passage footer is fixed to the viewport bottom here, so the rail never reaches it and
   needs no inset of its own (JOB-20261026598). */
/* The footer is fixed, so the flow must reserve its measured height once at the end
   of the writing screen: the statistics panel is never hidden underneath it. */
#writeScreen { padding-bottom: calc(var(--writing-footer-h, 0px) + 12px); }
.writing-nav-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.writing-nav-controls .tool-btn {
  width: auto;
  flex: 0 1 auto;
  min-height: 48px;
  min-width: 0;
  padding: 0 16px;
  white-space: nowrap;
}
.nav-status {
  margin: 0;
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.4;
  min-width: 0;
}
.nav-status:empty { display: none; }

@media (max-width: 699px) {
  .writing-nav-controls { justify-content: stretch; gap: 6px; }
  .writing-nav-controls .tool-btn {
    flex: 1 1 calc(50% - 6px);
    padding: 0 8px;
    font-size: .92rem;
  }
  /* The primary action gets its own full-width line so it is never the button that
     has to squeeze onto a third row beside Change chapter. */
  .writing-nav-controls .tool-btn.primary { flex-basis: 100%; order: -1; }
}

/* ── the deliberate way to move the sheet: the scroll rail beside the paper (JOB-20261026598) ─────
   Owner request, October 26: the writing sites had no deliberate scroll control - a wheel, a
   two-finger pan or the browser's scrollbar were the only ways to reach the top actions or the
   controls under the passage. The screenshot puts the rail in the vertical gap BETWEEN the left
   settings sidebar and the writing sheet, never at the far left of the window, with a handle that
   is easy to grab and clear up/down controls.

   js/writing-scroll-rail.js owns the behaviour (drag, hold-to-step, keyboard, ink guard) and writes
   the rail's own top/left/height from the REAL sidebar and writing-column boxes, so this block is
   only shape, colour and the gutter the rail reserves. Because the rail is a fixed, out-of-flow box
   it can never push or cover a writing row: on a wide screen the app's own column gap grows by the
   rail's width and the rail sits centred in the gap; on a narrow screen, where the sidebar drops
   below the sheet, the writing column keeps a reserved strip of exactly that width instead.

   Colours come from this app's own palette (--paper, --paper-deep, --line, --ink, --gold,
   --teal-soft); nothing here introduces a new colour. */
:root {
  --writing-rail-w: 56px;
  /* JOB-20261026624: the rail's own stacking layer. The rail only has to outrank the writing
     content it stands beside, and positioned writing content tops out at z-index 6. Every
     foreground surface in this app family is 200 or above (.sheet-overlay 200, .word-tooltip and
     .art-interlude 300, .lightbox-overlay 400, .welcome-overlay 500), so 150 keeps the rail over
     the paper and under any open overlay, in paint order and in hit-test order alike. */
  --writing-rail-layer: 150;
}

.writing-scroll-rail {
  position: fixed;
  z-index: var(--writing-rail-layer, 150);
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  box-sizing: border-box;
  width: var(--writing-rail-w, 56px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 2px 12px rgba(var(--ink-rgb, 0, 0, 0), .18);
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.writing-scroll-rail[data-visible="true"] { display: flex; }

/* Clear up/down controls: a full 44px target each, the app's own raised-paper tone, the app's ink
   for the glyph. Content-sized arrows only - the rail is 56px wide, so a label would not fit and
   the accessible name lives in aria-label. */
.writing-scroll-rail-step {
  flex: 0 0 auto;
  width: 100%;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(var(--ink-rgb, 0, 0, 0), .12);
  border-radius: 9px;
  background: var(--paper-deep);
  color: var(--ink);
  font-size: .82rem;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
}
.writing-scroll-rail-step:hover { background: var(--teal-soft); }
.writing-scroll-rail-step:active { background: var(--line); }

/* The track is the real drag target: it spans the rail's whole content column (44px on the shipped
   56px rail), so every pointer that lands on it inside this box is a real 44px-plus hit area even
   though the painted thumb is the same width. */
.writing-scroll-rail-track {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 56px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-deep);
  touch-action: none;
  cursor: pointer;
}

/* The handle: a full-width slug in the title's own ink colour, never shorter than 44px, with three
   quiet grip lines so it reads as something to hold rather than as a painted tick. Ink - not the
   gold accent - is the one token every title guarantees to be legible on its own paper, so the
   handle clears 3:1 against the track; the gold ring is the palette's own accent. */
.writing-scroll-rail-thumb {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  min-height: 44px;
  box-sizing: border-box;
  border: 1px solid rgba(var(--ink-rgb, 0, 0, 0), .34);
  border-radius: 999px;
  background-color: var(--ink);
  background-image: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, .62) 0 2px,
    rgba(255, 255, 255, 0) 2px 6px
  );
  background-size: 14px 14px;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28), 0 0 0 1px var(--gold), 0 1px 4px rgba(var(--ink-rgb, 0, 0, 0), .3);
  cursor: grab;
  touch-action: none;
}
.writing-scroll-rail-thumb:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
body[data-rail-dragging="true"] .writing-scroll-rail-thumb { cursor: grabbing; }

/* While a writing contact is down the rail refuses input (js/writing-scroll-rail.js): show that it
   is deliberately inert instead of looking like a rail that has stopped working. */
.writing-scroll-rail[data-ink="active"] { opacity: .6; }
.writing-scroll-rail[data-ink="active"] .writing-scroll-rail-thumb { background-color: var(--muted); }

/* WIDE: the rail lives in the app's own internal gutter, between the sidebar and the writing
   column. The gutter grows by exactly the rail's width and the rail centres itself in it, so no
   page margin is spent and nothing is covered. The class is set from the MEASURED placement (the
   module sees whether the sidebar really is beside the sheet), so a title that changes its own
   breakpoints or collapses on height never leaves the rail sitting in an unreserved space. */
body.writing-rail-active.writing-rail-wide .app {
  column-gap: calc(18px + var(--writing-rail-w, 56px));
}

/* NARROW: the sidebar is not beside the sheet, so the writing column keeps the rail's own strip on
   its left. The rail, the top actions, the preview strip, the paper and the passage controls all
   start inside the padded column, which is what keeps them clear of the rail at 390px and at every
   writing zoom. No horizontal overflow: the strip is padding, not a fixed width. */
body.writing-rail-active.writing-rail-narrow .workspace,
body.writing-rail-active.writing-rail-narrow .bottom-panel {
  padding-left: calc(var(--writing-rail-w, 56px) + 26px);
}



/* Explicit guest adoption — shown only after the reader has signed in. */
.adoption-panel {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: var(--teal-soft);
}
.adoption-panel[hidden] { display: none; }
.adoption-panel p { margin: 0; font-size: .9rem; line-height: 1.45; }
.adoption-panel .tool-btn { width: 100%; }

/* Text-size controls stay their own group and show the real disabled ends (80/220). */
.zoom-group .tool-btn:disabled { opacity: .45; cursor: not-allowed; }

/* The owner's writing preview uses the full pane and shows a wider area of the paper. */
@media (min-width: 920.01px) {
  :root { --preview-pane-height: 320px; }
  .preview-pane-frame { width: 100%; flex: 0 0 auto; }
  .preview-pane-note { display: none; }
}
@media (max-width: 920px) {
  .preview-pane { box-sizing: border-box; min-width: 0; max-width: 100%; }
  .preview-pane-head { flex: 0 1 110px; width: 110px; min-width: 75px; }
  .preview-pane-frame { width: min(155px, calc(100% - 90px)); min-width: 0; max-width: 155px; flex: 1 1 155px; }
}
.word-tooltip { max-height: min(45vh, 300px); overflow: auto; }

.single-word-controls { display:flex; flex-wrap:wrap; align-items:center; justify-content:center; gap:10px; margin:12px 0; }
.single-word-controls[hidden] { display:none; }
.single-word-controls [data-word-status] { font-weight:700; }

.word-help-details { max-height: 42vh; overflow: auto; padding: 10px; background: #fff9eb; border: 1px solid rgba(121,85,72,.2); border-radius: 8px; color: #3e2723; font-size: 1rem; }
.word-help-details .word-tooltip-sa { font-size: 1.5rem; }
.word-help-details .word-tooltip-en, .word-help-details .word-tooltip-hi, .word-help-details .word-tooltip-hi-tl { font-size: 1.1rem; }
.word-help-parts-heading { font-weight: 700; margin-top: 12px; }
.word-help-part { display: flex; flex-direction: column; gap: 2px; padding-top: 7px; }
