/* The Hearthside Theatre.
   A dark room, one warm light, and the cast standing in it. Everything here exists to
   keep attention on the picture and on WHO is talking — the one thing this app knows
   that a storybook app has no way to know. */
:root {
  --ember: #ff9d4d;
  --ember-deep: #d2521a;
  --room: #120e14;
  --room-2: #1b1520;
  --ink: #f4e9dd;
  --dim: #a3927f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--room);
  color: var(--ink);
  font: 16px/1.5 ui-rounded, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

/* the fire behind everything: it breathes, slowly, and brightens while a voice speaks */
#hearth { position: fixed; inset: 0; pointer-events: none; }
#hearth .glow {
  position: absolute; left: 50%; bottom: -30vh; transform: translateX(-50%);
  width: 120vmax; height: 90vh;
  background: radial-gradient(ellipse at center,
    rgba(255, 157, 77, .30), rgba(210, 82, 26, .12) 42%, transparent 70%);
  filter: blur(6px);
  animation: breathe 7s ease-in-out infinite;
}
body.speaking #hearth .glow { animation-duration: 3.5s; }
@keyframes breathe {
  0%, 100% { opacity: .72; transform: translateX(-50%) scale(1); }
  50%      { opacity: 1;   transform: translateX(-50%) scale(1.05); }
}

#stage {
  position: relative; z-index: 1;
  height: 100svh;
  display: grid; grid-template-rows: 1fr auto auto;
  padding: max(12px, env(safe-area-inset-top)) 12px
           max(12px, env(safe-area-inset-bottom));
  gap: 10px;
}

#scene { margin: 0; position: relative; display: grid; place-items: center; min-height: 0; }
#page-image {
  max-width: min(100%, 78vh); max-height: 100%;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .65), 0 0 0 1px rgba(255, 157, 77, .18);
  opacity: 0; transform: scale(.985);
  transition: opacity .7s ease, transform .7s ease;
}
#page-image.shown { opacity: 1; transform: scale(1); }

/* the spoken line, not the whole page: you hear one line at a time, you read one line */
#line {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  max-width: min(92%, 60ch); margin: 0; padding: 10px 16px;
  background: rgba(18, 14, 20, .82); backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 157, 77, .22); border-radius: 14px;
  text-align: center; font-size: clamp(15px, 2.4vh, 20px);
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); }
                  to   { opacity: 1; transform: translate(-50%, 0); } }

/* ---- the cast ---- */
#cast { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.lantern {
  --lit: 0;
  display: grid; justify-items: center; gap: 4px;
  padding: 8px 12px 10px; min-width: 74px;
  border-radius: 14px; border: 1px solid rgba(255, 157, 77, calc(.12 + var(--lit) * .5));
  background: linear-gradient(180deg,
    rgba(255, 157, 77, calc(var(--lit) * .18)), rgba(27, 21, 32, .85));
  transform: translateY(calc(var(--lit) * -6px)) scale(calc(1 + var(--lit) * .04));
  transition: transform .25s ease, border-color .25s ease, background .25s ease;
}
.lantern .face {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 17px;
  color: #2a1a10;
  background: radial-gradient(circle at 35% 30%, #ffd9a8, var(--ember));
  filter: saturate(calc(.35 + var(--lit) * .65)) brightness(calc(.62 + var(--lit) * .38));
  box-shadow: 0 0 calc(var(--lit) * 26px) rgba(255, 157, 77, calc(var(--lit) * .85));
  transition: filter .25s ease, box-shadow .25s ease;
}
.lantern .who { font-size: 12px; color: var(--dim); white-space: nowrap; }
.lantern[data-narrator="1"] .face {
  background: radial-gradient(circle at 40% 30%, #fff0d6, #ffb066);
}

#controls { display: flex; align-items: center; gap: 12px; }
#controls button {
  width: 46px; height: 46px; flex: none; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(255, 157, 77, .35); background: rgba(255, 157, 77, .1);
  color: var(--ink); font-size: 17px;
}
#controls button:hover { background: rgba(255, 157, 77, .2); }
#progress { flex: 1; height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .1); }
#progress-fill { height: 100%; width: 0; border-radius: 3px;
  background: linear-gradient(90deg, var(--ember-deep), var(--ember)); }
.muted { color: var(--dim); font-size: 13px; }
#page-no { min-width: 54px; text-align: right; }

#curtain {
  position: fixed; inset: 0; z-index: 2; margin: 0;
  display: grid; place-content: center; gap: 6px; text-align: center;
  background: var(--room); transition: opacity .6s ease;
}
#curtain[hidden] { display: none; }
#curtain-title { font-size: 20px; }

@media (max-width: 520px) {
  .lantern { min-width: 62px; padding: 6px 8px 8px; }
  .lantern .face { width: 34px; height: 34px; font-size: 15px; }
}

/* the playbill, when the theatre is opened without a story in mind */
#bill { display: grid; gap: 8px; margin-top: 16px; min-width: min(88vw, 380px); }
.bill-row {
  display: grid; gap: 2px; padding: 12px 16px; border-radius: 12px;
  text-decoration: none; color: var(--ink);
  background: rgba(27, 21, 32, .9); border: 1px solid rgba(255, 157, 77, .18);
  transition: border-color .2s ease, transform .2s ease;
}
.bill-row:hover { border-color: rgba(255, 157, 77, .55); transform: translateY(-2px); }
