/* PLAYBOOK - chrome over a painted world */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #060610;
  font-family: Georgia, "Times New Roman", serif;
  color: #f4efe2;
}

#sea {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: pointer;
}

.hidden { display: none !important; }

.ui-layer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
  pointer-events: none;
  padding: 20px;
}
.ui-layer > * { pointer-events: auto; }

@keyframes rise {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: none; }
}

/* library */
#library-head { margin-bottom: 28px; animation: rise 1.2s ease-out; }
#brand {
  font-size: clamp(40px, 8vw, 92px);
  letter-spacing: 0.22em;
  font-weight: bold;
  margin-left: 0.22em;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.6), 0 0 60px rgba(255, 230, 180, 0.2);
}
#brand-tag {
  font-style: italic;
  color: rgba(244, 239, 226, 0.72);
  font-size: clamp(12px, 1.7vw, 18px);
  margin-top: 8px;
}

#book-shelf {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1000px;
}
.book-card {
  width: 240px;
  background: none;
  border: none;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  animation: rise 1s ease-out backwards;
  transition: transform 0.22s ease;
}
.book-card:nth-child(2) { animation-delay: 0.12s; }
.book-card:hover, .book-card:focus { transform: translateY(-10px); outline: none; }
.book-card canvas {
  width: 240px;
  height: 336px;
  border-radius: 4px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  display: block;
}
.book-card:hover canvas { box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6), 0 0 36px rgba(255, 220, 150, 0.22); }
.book-meta { margin-top: 12px; }
.book-title { font-size: 20px; letter-spacing: 0.14em; color: #ffe3a0; }
.book-author { font-size: 12px; color: rgba(244, 239, 226, 0.6); margin-top: 3px; }
.book-blurb { font-size: 12.5px; font-style: italic; color: rgba(244, 239, 226, 0.7); margin-top: 8px; line-height: 1.5; }

#library-foot {
  margin-top: 34px;
  font-size: 12px;
  color: rgba(244, 239, 226, 0.4);
}
#library-foot a, .back-link { color: rgba(255, 217, 138, 0.6); text-decoration: none; }
#library-foot a:hover { color: #ffd98a; }

/* soul select */
.back-link {
  position: absolute;
  top: 22px; left: 24px;
  background: none; border: none; cursor: pointer;
  font-family: inherit; font-size: 14px;
  letter-spacing: 0.08em;
}
.back-link:hover { color: #ffd98a; }
#select-book {
  font-size: clamp(12px, 1.6vw, 16px);
  letter-spacing: 0.1em;
  color: rgba(244, 239, 226, 0.6);
  margin-bottom: 8px;
}
#select-title {
  font-size: clamp(18px, 3vw, 30px);
  letter-spacing: 0.5em;
  margin-bottom: 28px;
  margin-left: 0.5em;
  color: #ffd98a;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}
#soul-cards {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1100px;
}
.soul-card {
  width: 215px;
  background: rgba(8, 12, 22, 0.82);
  border: 1px solid rgba(255, 217, 138, 0.25);
  border-radius: 6px;
  padding: 16px 14px 18px;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  backdrop-filter: blur(2px);
  animation: rise 0.7s ease-out backwards;
}
.soul-card:nth-child(2) { animation-delay: 0.08s; }
.soul-card:nth-child(3) { animation-delay: 0.16s; }
.soul-card:nth-child(4) { animation-delay: 0.24s; }
.soul-card:hover, .soul-card:focus {
  transform: translateY(-6px);
  border-color: #ffd98a;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  outline: none;
}
.soul-card canvas { width: 120px; height: 120px; border-radius: 50%; display: block; margin: 0 auto 12px; }
.soul-name { font-size: 20px; letter-spacing: 0.2em; color: #ffe3a0; margin-bottom: 7px; }
.soul-line { font-size: 13px; font-style: italic; color: rgba(244, 239, 226, 0.75); line-height: 1.5; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
/* the top of the HUD: the chapter, then the voyage rail, stacked in the
   clear between the pause and sound controls */
#hud-top {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}
#chapter-label {
  max-width: calc(100vw - 168px); /* a long title folds before it reaches a control */
  padding-left: 0.45em; /* balances the tracking after the last letter */
  font-size: clamp(11px, 1.5vw, 15px);
  line-height: 1.5;
  letter-spacing: 0.45em;
  text-align: center;
  text-wrap: balance;
  color: rgba(244, 239, 226, 0.82);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}
#compass {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 100px;
  height: 100px;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

/* caption + choices */
#caption-wrap {
  position: fixed;
  left: 50%;
  bottom: 5.5vh;
  transform: translateX(-50%);
  width: min(860px, 92vw);
  z-index: 9;
  text-align: center;
  pointer-events: none;
}
/* The standing block: a set of sentences that stays while the picture plays.
   Upright, because it is the book's own prose and it stays to be read. */
.cap-block {
  font-size: clamp(16px, 2.3vw, 24px);
  line-height: 1.5;
  color: #f4efe2;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 24px rgba(0, 0, 0, 0.8);
}
#caption { min-height: 1.6em; }
.cap-s {
  text-wrap: balance;
  transition: transform 0.58s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.cap-s + .cap-s { margin-top: 0.4em; }
.cap-s + .cap-s.cap-next { margin-top: 0.95em; }
/* each word inks in on its beat; the engine's scene clock sets .on */
.cap-w {
  display: inline-block;
  opacity: 0;
  transform: translateY(0.3em);
  transition: opacity 0.45s ease-out, transform 0.58s cubic-bezier(0.2, 0.9, 0.25, 1);
}
.cap-w.on { opacity: 1; transform: none; }
/* a full set lifting away as the next one begins */
.cap-ghost {
  position: fixed;
  z-index: 9;
  pointer-events: none;
  transition: opacity 0.58s ease-in, transform 0.58s ease-in;
}
.cap-ghost.leaving { opacity: 0; transform: translateY(-18px); }
@media (prefers-reduced-motion: reduce) {
  .cap-s { transition: none; }
  .cap-w { transform: none; transition: opacity 0.2s linear; }
}
#choice-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
  pointer-events: auto;
}
.choice-btn {
  font-family: inherit;
  font-size: clamp(13px, 1.7vw, 17px);
  padding: 10px 22px;
  color: #ffe9bb;
  background: rgba(8, 12, 22, 0.8);
  border: 1px solid rgba(255, 217, 138, 0.45);
  border-radius: 24px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  opacity: 0;
  visibility: hidden; /* laid out with the scene, shown when the last sentence lands */
}
#choice-row.open .choice-btn { visibility: visible; animation: rise 0.5s ease-out forwards; }
#choice-row.spent .choice-btn { pointer-events: none; }
#choice-row.spent .choice-btn:not(.chosen) { visibility: hidden; }
#choice-row.spent .choice-btn.chosen { background: rgba(30, 36, 50, 0.9); border-color: #ffd98a; }
.choice-btn:nth-child(2) { animation-delay: 0.12s; }
.choice-btn:nth-child(3) { animation-delay: 0.24s; }
.choice-btn:hover { transform: translateY(-2px); background: rgba(30, 36, 50, 0.9); border-color: #ffd98a; }
#tap-hint {
  margin-top: 16px;
  height: 18px;
  color: rgba(255, 217, 138, 0.8);
  animation: pulse 1.6s ease-in-out infinite;
}
/* drawn, not typed: iOS swaps the triangle character for an emoji */
#tap-hint::before {
  content: "";
  display: inline-block;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
}
#tap-hint.waiting { visibility: hidden; }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ending */
#ending-title {
  font-size: clamp(26px, 5vw, 54px);
  letter-spacing: 0.3em;
  margin-bottom: 22px;
  margin-left: 0.3em;
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.7);
  animation: rise 1.6s ease-out;
}
#ending-title.alt { color: #aef2c0; }
#ending-title.end { color: #f4efe2; }
#ending-line {
  max-width: 640px;
  padding: 0 20px;
  font-style: italic;
  font-size: clamp(14px, 2vw, 20px);
  line-height: 1.7;
  color: rgba(244, 239, 226, 0.9);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  margin-bottom: 36px;
  animation: rise 1.6s 0.3s ease-out backwards;
}

.vbtn {
  font-family: inherit;
  font-size: clamp(14px, 1.8vw, 19px);
  letter-spacing: 0.3em;
  padding: 13px 38px 13px calc(38px + 0.3em);
  color: #0a1016;
  background: linear-gradient(180deg, #ffe3a0, #e8b45a);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: transform 0.15s ease;
}
.vbtn:hover { transform: translateY(-2px) scale(1.02); }

#sound-toggle {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 20;
  font-size: 13px;
  letter-spacing: 0.15em;
  color: rgba(244, 239, 226, 0.5);
  cursor: pointer;
  user-select: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
#sound-toggle.on { color: #ffd98a; }

@media (max-width: 640px) {
  .book-card, .book-card canvas { width: 180px; }
  .book-card canvas { height: 252px; }
  .soul-card { width: 46%; min-width: 150px; }
  .soul-card canvas { width: 84px; height: 84px; }
  #compass { width: 74px; height: 74px; }
  #caption-wrap { bottom: 3.5vh; }
}

/* ===================================================================
 * The special pass: continue, sign your name, rail, pause, the edition
 * =================================================================== */

/* continue an unfinished voyage */
#continue-row { margin: -6px 0 24px; }
#continue-btn {
  display: inline-flex; flex-direction: column; gap: 3px;
  padding: 12px 28px; border-radius: 10px; cursor: pointer;
  font-family: inherit; color: #0b1016;
  background: linear-gradient(180deg, #ffe3a0, #e7b457);
  border: none; box-shadow: 0 10px 28px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.5);
  animation: rise .8s ease-out;
}
#continue-btn:hover { transform: translateY(-2px); }
.cont-k { font-size: 14px; letter-spacing: .14em; text-transform: uppercase; font-weight: bold; }
.cont-v { font-size: 13px; font-style: italic; opacity: .78; }

/* sign your name, co-author */
#sign-row {
  display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap;
  justify-content: center; margin: 0 0 24px; color: rgba(244,239,226,.72);
}
#sign-label { font-style: italic; font-size: 15px; letter-spacing: .03em; }
#reader-name {
  font-family: inherit; font-size: 17px; color: #fff; font-style: italic;
  background: rgba(255,255,255,.06);
  border: none; border-bottom: 1px solid rgba(255,217,138,.5);
  padding: 6px 12px; width: 240px; max-width: 70vw; text-align: center;
}
#reader-name:focus { outline: none; border-bottom-color: #ffd98a; background: rgba(255,255,255,.1); }
#reader-name::placeholder { color: rgba(244,239,226,.4); font-style: italic; }

/* HUD: pause + the voyage rail */
#pause-btn {
  position: absolute; top: 15px; left: 18px; z-index: 11;
  background: none; border: none; cursor: pointer; pointer-events: auto;
  color: rgba(244,239,226,.55); font-size: 13px; letter-spacing: 2px;
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
}
#pause-btn:hover { color: #ffd98a; }
#voyage-rail {
  display: flex; gap: 6px; align-items: center; justify-content: center;
  max-width: min(640px, 82vw); flex-wrap: wrap;
}
.rail-tick {
  width: 16px; height: 3px; border-radius: 2px;
  background: rgba(244,239,226,.2); transition: background .5s ease, width .5s ease;
}
.rail-tick.done { background: rgba(255,217,138,.68); }
.rail-tick.now { background: #ffd98a; width: 26px; box-shadow: 0 0 8px rgba(255,217,138,.55); }

/* pause menu */
#pause-card {
  display: flex; flex-direction: column; gap: 12px; width: min(320px, 86vw);
  background: rgba(10,13,22,.92); border: 1px solid rgba(255,217,138,.3);
  border-radius: 12px; padding: 28px 26px; backdrop-filter: blur(6px);
  animation: rise .3s ease-out;
}
#pause-title { font-size: 19px; letter-spacing: .4em; margin-left: .4em; color: #ffd98a; margin-bottom: 8px; }
.menu-btn {
  font-family: inherit; font-size: 16px; padding: 11px 16px; border-radius: 8px; cursor: pointer;
  color: #ffe9bb; background: rgba(255,217,138,.12); border: 1px solid rgba(255,217,138,.4);
}
.menu-btn:hover { background: rgba(255,217,138,.22); }
.menu-btn.ghost { background: none; border-color: rgba(244,239,226,.22); color: rgba(244,239,226,.7); }

/* the ending: the reveal, then the keepsake */
#ending-ui { justify-content: flex-start; overflow: hidden; }
#ending-scroll {
  width: 100%; max-width: 780px; margin: 0 auto;
  overflow-y: auto; max-height: 100%; padding: 6vh 4px 7vh;
  display: flex; flex-direction: column; align-items: center;
  -webkit-overflow-scrolling: touch;
}
#edition-wrap {
  width: min(440px, 86vw); margin: 22px auto 4px;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 24px 72px rgba(0,0,0,.6);
  animation: rise 1.2s .3s ease-out backwards;
}
#edition { width: 100%; height: auto; display: block; }
#ending-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 24px; }
.vbtn.ghost { background: none; border: 1px solid rgba(244,239,226,.3); color: #f4efe2; box-shadow: none; }
.vbtn.ghost:hover { background: rgba(255,255,255,.06); transform: translateY(-2px); }
#download-hint { margin-top: 14px; font-style: italic; font-size: 13px; color: rgba(174,242,192,.92); }

/* ===== installable app: install chip + safe-area insets ===== */
#install-btn {
  display: inline-block; margin-top: 10px;
  font-family: inherit; font-size: 12px; letter-spacing: .08em;
  color: #ffd98a; background: rgba(255,217,138,.1);
  border: 1px solid rgba(255,217,138,.4); border-radius: 20px;
  padding: 6px 16px; cursor: pointer;
}
#install-btn:hover { background: rgba(255,217,138,.2); }

/* clear notches / rounded corners when installed full-screen */
#sound-toggle { top: max(14px, env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); }
#pause-btn { top: max(15px, env(safe-area-inset-top, 0px)); left: max(18px, env(safe-area-inset-left, 0px)); }

/* Where the caption card can reach the corner (a window narrower than the
   card with a compass clear on each side), the compass moves up into the sky. */
@media (max-width: 1087px) {
  #compass { top: calc(84px + env(safe-area-inset-top, 0px)); bottom: auto; }
}

/* Native iPhone screens need room for the status bar and a scrollable shelf. */
@media (max-width: 640px) {
  html.native-app #library-ui,
  html.native-app #select-ui {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    padding-top: calc(env(safe-area-inset-top, 0px) + 52px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  }
  html.native-app #library-ui > *,
  html.native-app #select-ui > * { flex-shrink: 0; }
  html.native-app #select-ui .back-link {
    top: calc(env(safe-area-inset-top, 0px) + 16px);
  }
}
