/* reader.css - every selector is .lb- namespaced. No global resets.
   Page rules (.lb-pagebox / .lb-col / .lb-t / .lb-foot) mirror the Phase 1 acceptance test
   (ligure-book-tools/qa/visual_diff.py). Keep the two in step. */

.lb-app {
  --lb-midnight: #0c1a2a;
  --lb-gold: #c4a265;
  --lb-cream: #faf8f4;
  --lb-ink: #231f20;
  --lb-bar-h: 56px;
  --lb-safe-t: env(safe-area-inset-top, 0px);
  --lb-safe-b: env(safe-area-inset-bottom, 0px);
  --lb-safe-l: env(safe-area-inset-left, 0px);
  --lb-safe-r: env(safe-area-inset-right, 0px);
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  margin: 0;
  color: var(--lb-midnight);
  font: 400 16px/1.4 'LB Footer', system-ui, sans-serif;
  background: radial-gradient(120% 90% at 50% 35%, #f3eee5 0%, #e6dfd2 55%, #cfc6b6 100%);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.lb-app *,
.lb-app *::before,
.lb-app *::after {
  box-sizing: border-box;
}
.lb-sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- stage and book ---------- */

.lb-stage {
  position: absolute;
  left: var(--lb-safe-l);
  right: var(--lb-safe-r);
  top: calc(var(--lb-safe-t) + var(--lb-bar-h));
  bottom: calc(var(--lb-safe-b) + var(--lb-bar-h));
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none; /* gestures are handled in app.js / zoom.js */
}
.lb-zoom {
  position: relative;
  transform-origin: 0 0;
}
.lb-flip,
.lb-fade {
  position: relative;
  filter: drop-shadow(0 18px 28px rgba(40, 30, 15, 0.28)) drop-shadow(0 3px 6px rgba(40, 30, 15, 0.18));
}
/* gutter shading in spread mode */
.lb-app[data-mode='spread'] .lb-side-L:not(.lb-cover) .lb-pagebox::after,
.lb-app[data-mode='spread'] .lb-side-R:not(.lb-cover) .lb-pagebox::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6%;
  pointer-events: none;
  z-index: 3;
}
.lb-app[data-mode='spread'] .lb-side-L .lb-pagebox::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.03) 35%, transparent);
}
.lb-app[data-mode='spread'] .lb-side-R .lb-pagebox::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.03) 35%, transparent);
}
.lb-fade .lb-page {
  position: absolute;
  top: 0;
}
.lb-page[hidden] {
  display: none !important;
}
.lb-fadein {
  animation: lb-fade 160ms ease-out;
}
@keyframes lb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- one page (same rules as the acceptance test) ---------- */

.lb-page {
  overflow: hidden;
  background: var(--lb-bg, #fff);
}
.lb-pagebox {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  container-type: inline-size;
  background: var(--lb-bg, #fff);
  font-family: 'LB Spectral', Georgia, serif;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  text-rendering: geometricPrecision;
}
.lb-plate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.lb-plate:not([src]) {
  visibility: hidden;
}
/* until the plate arrives, show its average colour (no layout shift: the page box is fixed) */
.lb-pagebox:has(.lb-plate:not([src])) {
  background: var(--lb-tint, var(--lb-bg, #fff));
}
.lb-text {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.lb-col {
  position: absolute;
  display: flow-root;
}
.lb-t {
  margin: 0;
  padding: 0;
  hyphens: manual;
  overflow-wrap: normal;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.lb-t b {
  font-weight: 500;
}
/* translated text flows freely and hyphenates (brief s8) */
.lb-t.lb-tr {
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.lb-foot {
  position: absolute;
  z-index: 2;
  font-family: 'LB Footer', sans-serif;
  font-weight: 400;
  white-space: nowrap;
}

/* ---------- bars and controls ---------- */

.lb-bar {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: calc(8px + var(--lb-safe-l));
  padding-right: calc(8px + var(--lb-safe-r));
  z-index: 20;
  transition: opacity 240ms ease;
}
.lb-top {
  top: 0;
  height: calc(var(--lb-bar-h) + var(--lb-safe-t));
  padding-top: var(--lb-safe-t);
}
.lb-bottom {
  bottom: 0;
  height: calc(var(--lb-bar-h) + var(--lb-safe-b));
  padding-bottom: var(--lb-safe-b);
}
/* quiet controls: they fade when idle, but are never hover-only (any tap or key brings them back) */
.lb-app[data-idle='1'] .lb-bar:not(:focus-within):not(:hover) {
  opacity: 0.2;
}
.lb-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0 8px;
  font: 400 15px/1.2 'LB Spectral', Georgia, serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.lb-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  margin: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  color: var(--lb-midnight);
  font: inherit;
  font-size: 14px;
  letter-spacing: 0.04em;
  cursor: pointer;
  flex: 0 0 auto;
}
.lb-btn:hover { background: rgba(12, 26, 42, 0.07); }
.lb-btn:active { background: rgba(12, 26, 42, 0.12); }
.lb-btn[disabled] {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}
.lb-btn[aria-pressed='true'],
.lb-btn[aria-expanded='true'] {
  background: var(--lb-midnight);
  color: var(--lb-cream);
}
.lb-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}
.lb-app :focus-visible {
  outline: 2px solid var(--lb-gold);
  outline-offset: 2px;
}
.lb-btn-label { white-space: nowrap; }
.lb-progress {
  flex: 1 1 auto;
  min-width: 60px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}
.lb-range {
  flex: 1 1 auto;
  min-width: 40px;
  height: 44px;
  margin: 0;
  background: transparent;
  accent-color: var(--lb-gold);
  cursor: pointer;
}
.lb-count {
  flex: 0 0 auto;
  font-size: 13px;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: rgba(12, 26, 42, 0.75);
}
.lb-badge {
  flex: 0 0 auto;
  padding: 3px 8px;
  border: 1px solid var(--lb-gold);
  border-radius: 10px;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #7a6131;
  white-space: nowrap;
}
.lb-badge[hidden] { display: none; }
@media (max-width: 700px) {
  .lb-btn-label { display: none; }
  .lb-hide-narrow { display: none !important; }
  .lb-title { font-size: 13px; letter-spacing: 0.08em; margin: 0 2px; }
}
@media (max-width: 380px) {
  .lb-count { display: none; }
}

/* edge tap zones (click/tap the page edges to turn) */
.lb-edge {
  position: absolute;
  top: calc(var(--lb-safe-t) + var(--lb-bar-h));
  bottom: calc(var(--lb-safe-b) + var(--lb-bar-h));
  width: max(44px, 8%);
  z-index: 10;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.lb-edge:hover { background: linear-gradient(to var(--lb-edge-dir, right), rgba(12, 26, 42, 0.05), transparent); }
.lb-edge-prev { left: var(--lb-safe-l); --lb-edge-dir: right; }
.lb-edge-next { right: var(--lb-safe-r); --lb-edge-dir: left; }
.lb-edge[disabled] { display: none; }
.lb-app[data-zoomed='1'] .lb-edge { display: none; }

/* ---------- panels (contents, language) ---------- */

.lb-panel {
  position: absolute;
  z-index: 40;
  top: calc(var(--lb-safe-t) + var(--lb-bar-h) + 4px);
  max-height: calc(100% - var(--lb-safe-t) - var(--lb-safe-b) - 2 * var(--lb-bar-h) - 8px);
  width: min(360px, calc(100% - 16px));
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px;
  border-radius: 12px;
  background: var(--lb-cream);
  color: var(--lb-midnight);
  box-shadow: 0 16px 40px rgba(12, 26, 42, 0.22), 0 2px 6px rgba(12, 26, 42, 0.12);
}
.lb-panel[hidden] { display: none; }
.lb-panel-left { left: calc(8px + var(--lb-safe-l)); }
.lb-panel-right { right: calc(8px + var(--lb-safe-r)); }
.lb-panel h2 {
  margin: 6px 10px 8px;
  font: 400 12px/1.2 'LB Footer', sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #7a6131;
}
.lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.lb-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: 400 15px/1.25 'LB Spectral', Georgia, serif;
  text-align: left;
  cursor: pointer;
}
.lb-item:hover { background: rgba(196, 162, 101, 0.16); }
.lb-item[aria-current='true'] { background: rgba(196, 162, 101, 0.3); }
.lb-item-n {
  margin-left: auto;
  font: 400 12px/1 'LB Footer', sans-serif;
  color: rgba(12, 26, 42, 0.55);
  font-variant-numeric: tabular-nums;
}
.lb-goto {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  margin-top: 6px;
  border-top: 1px solid rgba(12, 26, 42, 0.1);
}
.lb-goto label { font-size: 14px; }
.lb-goto input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid rgba(12, 26, 42, 0.25);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: 16px; /* 16px or more: no iOS focus zoom */
  user-select: text;
  -webkit-user-select: text;
}
.lb-goto .lb-btn {
  background: var(--lb-midnight);
  color: var(--lb-cream);
}
.lb-scrim {
  position: absolute;
  inset: 0;
  z-index: 30;
}
.lb-scrim[hidden] { display: none; }

/* ---------- hint toast ---------- */

.lb-hint {
  position: absolute;
  z-index: 25;
  left: 50%;
  bottom: calc(var(--lb-safe-b) + var(--lb-bar-h) + 10px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 4px 4px 4px 16px;
  border-radius: 26px;
  background: var(--lb-midnight);
  color: var(--lb-cream);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(12, 26, 42, 0.3);
}
.lb-hint[hidden] { display: none; }
.lb-hint .lb-btn { color: var(--lb-cream); }
.lb-hint .lb-hint-go {
  color: var(--lb-midnight);
  background: var(--lb-gold);
}

/* ---------- reading view ---------- */

.lb-reading {
  position: absolute;
  z-index: 15;
  left: 0;
  right: 0;
  top: calc(var(--lb-safe-t) + var(--lb-bar-h));
  bottom: calc(var(--lb-safe-b) + var(--lb-bar-h));
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  background: var(--lb-cream);
  touch-action: pan-y;
  user-select: text;
  -webkit-user-select: text;
}
.lb-reading[hidden] { display: none; }
.lb-app[data-view='reading'] .lb-stage,
.lb-app[data-view='reading'] .lb-edge {
  visibility: hidden;
}
.lb-article {
  --lb-rv-size: 19px;
  max-width: 34em;
  margin: 0 auto;
  padding: 28px 20px 32px;
  font: 300 var(--lb-rv-size)/1.6 'LB Spectral', Georgia, serif;
  color: var(--lb-ink);
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.lb-article h2 {
  margin: 0;
  font-weight: 400;
  font-size: 1.3em;
  line-height: 1.25;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  hyphens: manual;
}
.lb-article h2 + .lb-rv-rule {
  width: 2.4em;
  height: 1px;
  margin: 0.9em 0 1.2em;
  background: #58595b;
}
.lb-article p { margin: 0 0 1em; }
.lb-article .lb-rv-quote,
.lb-article .lb-rv-strong,
.lb-article b { font-weight: 500; }
.lb-article .lb-rv-li {
  margin: 0 0 0.35em;
  padding-left: 1.1em;
  text-indent: -1.1em;
}
.lb-article .lb-rv-li::before { content: '\2013\00a0\00a0'; }
.lb-article .lb-rv-small {
  font-size: 0.8em;
  margin: 0 0 0.3em;
}
.lb-article .lb-rv-sec + .lb-rv-sec { margin-top: 2.2em; }
.lb-rv-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  max-width: 34em;
  margin: 0 auto;
  padding: 0 12px 24px;
}
.lb-rv-nav .lb-btn { border: 1px solid rgba(12, 26, 42, 0.18); }
.lb-rv-tools { display: none; }
.lb-app[data-view='reading'] .lb-rv-tools { display: inline-flex; }
.lb-app[data-view='reading'] .lb-book-tools { display: none; }

/* ---------- narration (Phase 4) ---------- */

/* everything audio is hidden until the language has a manifest ("audio later") */
.lb-app:not([data-audio='1']) .lb-audio-only { display: none !important; }
.lb-audio {
  bottom: calc(var(--lb-safe-b) + var(--lb-bar-h));
  height: var(--lb-bar-h);
  background: rgba(250, 248, 244, 0.92);
  border-top: 1px solid rgba(12, 26, 42, 0.1);
  border-bottom: 1px solid rgba(12, 26, 42, 0.1);
}
.lb-app:not([data-audio-open='1']) .lb-audio { display: none; }
/* the open bar takes its own row: the book, edges and Reading view end above it */
.lb-app[data-audio='1'][data-audio-open='1'] .lb-stage,
.lb-app[data-audio='1'][data-audio-open='1'] .lb-edge,
.lb-app[data-audio='1'][data-audio-open='1'] .lb-reading {
  bottom: calc(var(--lb-safe-b) + 2 * var(--lb-bar-h));
}
.lb-app[data-audio='1'][data-audio-open='1'] .lb-hint {
  bottom: calc(var(--lb-safe-b) + 2 * var(--lb-bar-h) + 10px);
}
.lb-a-play {
  background: var(--lb-midnight);
  color: var(--lb-cream);
}
.lb-a-play:hover { background: #1c2e44; }
.lb-audio[data-playing='1'] .lb-i-play,
.lb-audio:not([data-playing='1']) .lb-i-pause { display: none; }
.lb-a-play svg { fill: currentColor; }
.lb-a-play .lb-i-pause { fill: none; stroke-width: 2.4; }
.lb-a-speed {
  min-width: 52px;
  font-variant-numeric: tabular-nums;
}
.lb-panel-audio {
  top: auto;
  right: calc(8px + var(--lb-safe-r));
  bottom: calc(var(--lb-safe-b) + 2 * var(--lb-bar-h) + 4px);
}
@media (max-width: 480px) {
  .lb-a-time { display: none; }
  .lb-audio { gap: 0; }
  .lb-a-speed { min-width: 44px; padding: 0 4px; }
}

/* ---------- loading / error ---------- */

.lb-status {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  font: 400 14px/1.4 'LB Footer', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(12, 26, 42, 0.6);
  pointer-events: none;
}
.lb-status[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .lb-bar { transition: none; }
}
