@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,600;1,400&family=Open+Sans:wght@400;700&display=swap');

:root {
  --bg:      #0e0c0a;
  --ink:     #cfc6ba;
  --ink-dim: #6b6358;
  --accent:  #c4622a;
  --title:   #ede8e0;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'EB Garamond', Georgia, serif;
  /* Lock the page edge-to-edge: no scroll, no rubber-band gutters. */
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

/* The fixed-viewport book. Pages stack inside it; only one shows at a time.
   Use dynamic viewport height so mobile browser chrome can't leave a gutter. */
.reader {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

.page {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

/* Per-page background, with a scrim so text stays legible over any scene. */
.page-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.55;
}
.page-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(14,12,10,0.5), rgba(14,12,10,0.82));
}

/* The only thing that scrolls — within a single page, so nothing else reflows. */
.page-scroll {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: clamp(2.5rem, 7vh, 4.5rem) clamp(1.25rem, 6vw, 3rem)
           calc(4.75rem + env(safe-area-inset-bottom, 0px));
}

.page-inner {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

/* Speaker portrait + name, inline at each speaker change (decoded before the
   page flips in, so it never resizes mid-read). */
.speaker-block {
  text-align: center;
  margin: 0.25rem 0 1.1rem;
}
.portrait {
  display: inline-block;
  max-height: 30vh;
  max-width: 72%;
  border-radius: 3px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
.reader-title {
  text-align: center;
  margin: 1rem 0 2.4rem;
}
.reader-title h1 {
  font-family: 'EB Garamond', Georgia, serif;
  font-weight: 600;
  font-size: clamp(2rem, 8vw, 2.8rem);
  line-height: 1.1;
  color: var(--title);
}
.reader-subtitle {
  margin-top: 0.5rem;
  font-family: 'Open Sans', sans-serif;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-dim);
}

.speaker-name {
  margin-top: 0.55rem;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.page p {
  font-size: 1.15rem;
  line-height: 1.85;
  color: var(--ink);
  margin: 0 0 1.1rem;
}

.story-img {
  display: block;
  margin: 0.5rem auto 1rem;
  max-width: 100%;
  border-radius: 3px;
}

.whisper { font-style: italic; color: var(--ink-dim); text-align: center; }

/* Choices — the page-turn triggers. Comfortable, full-width tap targets. */
.page-choices {
  margin-top: 1.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  align-items: stretch;
  transition: opacity 0.4s;
}
.page-choices.pending { opacity: 0; pointer-events: none; }   /* hidden until typing finishes */

.choice-btn {
  font-family: 'EB Garamond', Georgia, serif;
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.4;
  color: var(--accent);
  background: rgba(196,98,42,0.06);
  border: 1px solid rgba(196,98,42,0.4);
  border-radius: 6px;
  padding: 0.85rem 1.3rem;
  min-height: 3rem;            /* ~48px tap target */
  width: 100%;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.05s;
}
.choice-btn:hover:not(:disabled) { background: rgba(196,98,42,0.16); border-color: var(--accent); }
.choice-btn:active:not(:disabled) { transform: scale(0.985); }
.choice-btn:disabled { cursor: default; opacity: 0.35; }
.choice-btn.chosen { color: var(--title); border-color: var(--accent); background: rgba(196,98,42,0.14); opacity: 1; }
.choice-btn.chosen::before { content: '› '; color: var(--accent); }

.restart-btn {
  font-style: normal;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.8rem;
}

/* Top + bottom chrome */
.ink-credit {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 46;
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(207,198,186,0.3);
  padding: 0.55rem;
  pointer-events: none;
}
.ink-credit a { color: inherit; text-decoration: none; pointer-events: auto; }

.reader-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem max(0.6rem, env(safe-area-inset-left))
           calc(0.4rem + env(safe-area-inset-bottom, 0px))
           max(0.6rem, env(safe-area-inset-right));
  /* Solid bar so scrolling text ends in a clean edge, with a short fade above. */
  background: var(--bg);
  border-top: 1px solid rgba(207,198,186,0.08);
}
.reader-nav::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: -1.75rem;
  height: 1.75rem;
  background: linear-gradient(rgba(14,12,10,0), var(--bg));
  pointer-events: none;
}
.nav-btn {
  flex: 0 0 auto;
  min-width: 5.5rem;
  min-height: 2.9rem;          /* ~46px tap target */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  font-family: 'Open Sans', sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.nav-btn:not(:disabled):hover { background: rgba(207,198,186,0.06); border-color: rgba(207,198,186,0.18); }
.nav-btn:not(:disabled):active { background: rgba(207,198,186,0.12); }
.nav-btn:disabled { color: var(--ink-dim); opacity: 0.3; cursor: default; }
.page-count {
  flex: 1 1 auto;
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
}

/* Page reveal + curtain page-turn */
.page-enter { animation: page-fade 600ms ease; }
@keyframes page-fade { from { opacity: 0; } to { opacity: 1; } }

@keyframes flip-fwd {
  from { transform: perspective(1400px) rotateY(0deg);    }
  to   { transform: perspective(1400px) rotateY(-180deg); }
}
@keyframes flip-bwd {
  from { transform: perspective(1400px) rotateY(0deg);   }
  to   { transform: perspective(1400px) rotateY(180deg); }
}

@media (prefers-reduced-motion: reduce) {
  .page-enter { animation: none; }
}
