:root {
  --bg: #ffffff;
  --ink: #333333;
  --brown: #7a5a2e;
  --muted: #767676;
  --paper: rgba(255, 255, 255, 0.88);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Source Sans 3', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}
#stage canvas { display: block; touch-action: none; }

.brand {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  pointer-events: none;
  transition: opacity 0.4s ease;
}
.brand h1 {
  margin: 0;
  font-family: 'Merriweather', Georgia, serif;
  font-weight: 900;
  font-size: clamp(22px, 3.2vw, 36px);
  letter-spacing: -0.01em;
  color: var(--brown);
}
body.focused .brand { opacity: 0; }

.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: 'Merriweather', Georgia, serif;
  font-style: italic;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.loader.hidden { opacity: 0; }

.hint {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  margin: 0;
  max-width: calc(100vw - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.hint.visible { opacity: 1; transform: translate(-50%, 0); }

.back {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 600 15px 'Source Sans 3', system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.back.visible { opacity: 1; pointer-events: auto; transform: none; transition-delay: 0.25s; }
.back:focus-visible { outline: 2px solid var(--brown); outline-offset: 2px; }

/* Video scenes: replay button in the middle of the box, sound button in its corner
   (positions are set from JS) */
.replay,
.sound {
  position: fixed;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font: 600 16px 'Source Sans 3', system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.92);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.replay { padding: 12px 20px 12px 16px; }
.sound { padding: 8px 14px 8px 10px; font-size: 14px; transform: none; }
.replay svg,
.sound svg { width: 22px; height: 22px; fill: currentColor; }
.replay.visible { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.sound.visible { opacity: 1; pointer-events: auto; }
.replay:hover,
.sound:hover { background: #fff; }
.replay:focus-visible,
.sound:focus-visible { outline: 2px solid var(--brown); outline-offset: 2px; }
.focused-zoomed .replay,
.focused-zoomed .sound { opacity: 0; pointer-events: none; }

/* Caption: placed directly below the open box (top/width are set from JS) */
.caption {
  position: fixed;
  margin: 0;
  left: 50%;
  top: 70%;
  width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, 10px);
  padding: 10px 16px 12px;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.08);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.caption.visible { opacity: 1; transform: translate(-50%, 0); transition-delay: 0.3s; }
.caption.visible.zoomed { opacity: 0; transition-delay: 0s; }

.kicker {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.quote {
  margin: 6px 0 0;
  font-family: 'Merriweather', Georgia, serif;
  font-style: italic;
  font-size: clamp(18px, 2.2vw, 26px);
  line-height: 1.3;
  color: var(--brown);
}

/* Narrative text (instead of a quote): plain reading text */
.caption.narrative .quote {
  font-style: normal;
  font-size: clamp(16px, 1.7vw, 20px);
  line-height: 1.45;
  color: var(--ink);
}

}

.version {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  transition: opacity 0.4s ease;
}
.version:hover { color: var(--ink); text-decoration: underline; }
body.focused .version { opacity: 0; pointer-events: none; }

/* Donation dialog after the daily limit */
.donate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.donate[hidden] { display: none; }
.donate.visible { opacity: 1; }
.donate-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 12px 20px 20px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.14);
  transform: translateY(8px);
  transition: transform 0.3s ease;
}
.donate.visible .donate-card { transform: none; }

/* Illustration (3:2, white background) with an HTML speech bubble */
.donate-figure { position: relative; aspect-ratio: 3 / 2; }
.donate-figure img { display: block; width: 100%; height: 100%; object-fit: contain; }
.donate-bubble-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.16));
}
.donate-tail { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.donate-tail polygon { fill: #fff; }
.donate-bubble {
  position: absolute;
  margin: 0;
  padding: 10px 14px;
  border-radius: 18px;
  background: #fff;
  color: #2f2b28;
  font: 600 clamp(13px, 2.6vw, 16px) / 1.35 'Source Sans 3', system-ui, sans-serif;
  text-align: center;
}
.donate-text { margin: 8px 0 0; line-height: 1.5; text-align: center; }

/* Ad boxes: the caption holds only the call to action */
.caption-cta { display: none; }
.caption.ad { padding: 10px; background: transparent; box-shadow: none; }
.caption.ad .caption-cta { display: inline-block; }
.caption.ad .quote { display: none; }
.caption.ad.visible .caption-cta { pointer-events: auto; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); }
.caption-cta:hover { filter: brightness(1.08); }

/* Ad offer window */
.adinfo-card { width: min(520px, 100%); padding: 24px 24px 20px; line-height: 1.5; }
.adinfo h2 {
  margin: 0 0 8px;
  font: 900 clamp(21px, 3vw, 26px) / 1.2 'Merriweather', Georgia, serif;
  color: var(--brown);
}
.adinfo h3 { margin: 18px 0 6px; font-size: 15px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.adinfo-lead { margin: 0 0 14px; }
.adinfo-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.adinfo-options li { padding: 10px 14px; border-radius: 12px; background: #f6f6f6; border-left: 4px solid #d8342a; }
.adinfo-options strong { display: block; }
.adinfo-steps { margin: 0; padding-left: 22px; }
.adinfo-steps li { margin: 3px 0; }
.adinfo-note { margin: 14px 0 0; color: var(--muted); font-size: 15px; }
.donate-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.btn {
  padding: 10px 18px;
  border: 1px solid #dcdcdc;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: 600 15px 'Source Sans 3', system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
}
.btn-primary { background: var(--brown); border-color: var(--brown); color: #fff; }
.btn:focus-visible { outline: 2px solid var(--brown); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .hint, .back, .caption { transition: none; }
}
