/* ============================================================================
 * layout.css — screens, HUD, dialogue, choices, rhythm, chapter grid, endings
 * Mobile-first / vertical. The app is a centered phone-width frame so it looks
 * right shared from Instagram and still framed nicely on desktop.
 * ========================================================================= */

#app {
  position: relative;
  width: 100%;
  max-width: var(--frame-max);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg-0);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.8);
  transition: background-color 1.6s var(--ease);
}

/* ---- screens ---- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transition: opacity 0.6s var(--ease);
}
.screen--active { display: flex; opacity: 1; }

/* ---- title screen ---- */
#screen-title, #screen-ending {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8vh 24px;
}
.title-name {
  font-size: clamp(2.4rem, 11vw, 3.6rem);
  letter-spacing: 0.12em;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 24px var(--glow), 0 0 4px var(--accent);
}
.title-sub {
  margin-top: 14px;
  font-size: 0.85rem;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  opacity: 0.7;
  color: var(--accent);
}
.title-buttons {
  margin-top: 44px;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(320px, 80vw);
}
.title-hint {
  margin-top: 36px;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  opacity: 0.4;
}

/* ---- buttons ---- */
.btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: all 0.25s var(--ease);
}
.btn:hover, .btn:active {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--glow);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.btn--primary {
  border-color: var(--accent);
  box-shadow: 0 0 18px var(--glow);
}
.btn--ghost { border-color: transparent; opacity: 0.6; font-size: 0.75rem; }
.btn--small { padding: 7px 10px; font-size: 0.65rem; letter-spacing: 0.12em; }

/* ---- chapter select ---- */
.select-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 18px 10px;
}
.select-head h2 { font-size: 1rem; letter-spacing: 0.3em; color: var(--accent); }
.chapter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 18px 24px;
  overflow-y: auto;
}
.chapter-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  background: color-mix(in srgb, var(--bg-1) 80%, transparent);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 16px 14px;
  min-height: 110px;
  transition: all 0.25s var(--ease);
}
.chapter-card:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--glow);
}
.chapter-card--locked { opacity: 0.35; cursor: not-allowed; }
.chapter-card__no { font-size: 0.65rem; letter-spacing: 0.2em; color: var(--accent); }
.chapter-card__title { font-size: 0.95rem; line-height: 1.2; }
.chapter-card__status { margin-top: auto; font-size: 0.65rem; opacity: 0.7; letter-spacing: 0.1em; }

/* ---- game screen ---- */
.bg {
  position: absolute;
  inset: 0;
  background-size: cover;          /* overridden per-chapter by engine (cover/contain) */
  background-position: center;
  background-repeat: no-repeat;    /* keep a "contain" image from tiling */
  opacity: 0;
  transform: scale(1.06);
  transition: opacity 1.1s var(--ease), transform 8s linear;
  /* the grade tints the art so it warms with the meter */
  filter: saturate(calc(0.6 + var(--awaken) * 0.6))
          hue-rotate(calc(var(--awaken) * 8deg));
}
.bg--in { opacity: 0.9; transform: scale(1); }

/* HUD: meter + controls */
.hud {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px 8px;
}
.meter {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--text) 12%, transparent);
  overflow: visible;
}
.meter__fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-soft), var(--accent));
  box-shadow: 0 0 12px var(--glow);
  transition: width 0.7s var(--ease);
}
.meter__label {
  position: absolute;
  top: 10px;
  left: 0;
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  opacity: 0.7;
  color: var(--accent);
}
.hud__controls { display: flex; align-items: center; gap: 8px; }
.vol { width: 64px; accent-color: var(--accent); }

/* portrait */
.portrait {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 38%;
  width: 62%;
  max-width: 300px;
  aspect-ratio: 2 / 3;
  transform: translate(-50%, 30px);
  background-size: contain;
  background-position: bottom center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
  filter: drop-shadow(0 0 24px color-mix(in srgb, var(--glow) 40%, transparent));
}
.portrait--in { opacity: 1; transform: translate(-50%, 0); }

/* stage: where dialogue/choices/rhythm live (lower third, letterboxed feel) */
.stage {
  position: absolute;
  z-index: 4;
  inset: auto 0 0 0;
  min-height: 42%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 20px 18px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--bg-0) 92%, transparent) 38%);
}
/* panel slides bake their own text into the art — drop the readability gradient */
.stage.stage--panel { background: none; }

/* title / quote card overlay — engine typography over textless card art */
.card-overlay {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12% 28px;
  gap: 14px;
}
.card-overlay.card--visible { display: flex; }
.card-kicker {
  font-size: 0.85rem;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 12px var(--glow), 0 2px 6px #000;
}
.card-title {
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.05;
  color: var(--text);
  text-shadow: 0 0 26px var(--glow), 0 2px 10px #000;
}
.card-quote {
  max-width: 18em;
  font-size: clamp(1.5rem, 6.5vw, 2.1rem);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  text-shadow: 0 0 22px var(--glow), 0 2px 10px #000;
}

/* subtle "tap to continue" hint shown over baked-text panels */
.panel-hint {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  text-align: center;
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-shadow: 0 0 8px var(--bg-0), 0 0 12px var(--bg-0);
  opacity: 0;
  pointer-events: none;
}
.panel-hint.hint--visible { opacity: 0.75; animation: blink 1.6s infinite; }

/* dialogue box */
.dialogue {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
  pointer-events: none;
}
.dialogue--visible { opacity: 1; transform: translateY(0); }
.dialogue__speaker {
  font-size: 0.8rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 10px var(--glow);
  margin-bottom: 8px;
}
.dialogue__text {
  font-size: 1.05rem;
  line-height: 1.55;
  min-height: 4.6em;
  border-left: 2px solid var(--accent);
  padding-left: 14px;
}
.dialogue__hint {
  display: block;
  margin-top: 14px;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  opacity: 0;
  color: var(--accent);
  text-align: right;
}
.dialogue__hint.hint--visible { opacity: 0.7; animation: blink 1.4s infinite; }

/* choices */
.choices {
  display: none;
  flex-direction: column;
  gap: 12px;
}
.choices.choices--visible { display: flex; }
.choices__prompt {
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 6px;
  opacity: 0.9;
}
.choices__list { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  background: color-mix(in srgb, var(--bg-1) 70%, transparent);
  border: 1px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 16px 16px;
  text-align: left;
  font-size: 0.95rem;
  line-height: 1.4;
  transition: all 0.2s var(--ease);
}
.choice-btn:hover, .choice-btn:active {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--glow);
  transform: translateX(4px);
}

/* rhythm mini-mechanic */
.rhythm {
  display: none;
  flex-direction: column;
  gap: 12px;
  height: 100%;
}
.rhythm.rhythm--visible { display: flex; }
.rhythm__prompt { font-size: 0.95rem; line-height: 1.45; color: var(--accent); }
.rhythm__area {
  position: relative;
  flex: 1;
  min-height: 240px;
  border: 1px dashed color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  overflow: hidden;
}
.rhythm__progress {
  text-align: center;
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  color: var(--accent);
  opacity: 0.85;
}

/* ---- ending ---- */
.ending-block { max-width: 360px; }
.ending-title {
  font-size: clamp(1.8rem, 9vw, 2.6rem);
  letter-spacing: 0.12em;
  color: var(--text);
  text-shadow: 0 0 24px var(--glow);
  margin-bottom: 20px;
}
.ending-text { font-size: 1rem; line-height: 1.6; opacity: 0.9; }
.ending-meter {
  margin: 24px 0 28px;
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  color: var(--accent);
}
