.intro-awakening {
  --wake-duration: 4.8s;
  position: absolute;
  z-index: 8;
  inset: 0;
  container-type: size;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: clamp(8px, 2vw, 28px);
  pointer-events: none;
}

.intro-shot {
  position: absolute;
  inset: 0;
  overflow: hidden;
  visibility: hidden;
  background: #241409;
}

.intro-awakening.is-playing .intro-shot { visibility: visible; animation: wake-dismiss var(--wake-duration) both; }

.intro-camera {
  position: absolute;
  top: 50%;
  left: 50%;
  width: max(100cqw, calc(100cqh * 2048 / 1153));
  aspect-ratio: 2048 / 1153;
  transform: translate(-50%, -50%);
  transform-origin: 50% 64%;
}

.intro-awakening.is-playing .intro-camera { animation: wake-camera var(--wake-duration) cubic-bezier(.26, .46, .45, .94) both; }
.intro-pov { position: absolute; inset: 0; width: 100%; height: 100%; }
.intro-pov-prince { position: absolute; left: 59%; bottom: 22%; height: 35%; width: auto; transform: translateX(-50%); }
.intro-pov-shadow {
  position: absolute;
  left: 59%;
  bottom: 21.2%;
  width: 10%;
  height: 3%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, #482e17a6 0%, #482e173d 44%, #482e1700 72%);
}

@property --wake-eye-opening {
  syntax: '<percentage>';
  inherits: false;
  initial-value: 1%;
}

.intro-awakening::after {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 65% var(--wake-eye-opening) at 50% 52%, #180f0900 26%, #180f09b8 70%, #100905 100%);
  content: '';
}

.intro-awakening.is-playing::after { animation: wake-blink var(--wake-duration) ease-in-out both; }
.is-waking > :is(.stage-dock, .stage-progress, .explore-overlay, .interact, .feedback) { visibility: hidden; }
.cardboard-game:has(.intro-dialogue[open]) :is(.stage-dock, .stage-progress, .region-arrival, .explore-overlay, .interact, .feedback) { visibility: hidden; }
#stage[data-disc-installation] :is(.stage-progress, .region-arrival) { visibility: hidden; }

@keyframes wake-camera {
  0%, 8% { transform: translate(-50%, -71%) rotate(-7deg) scale(1.52); filter: blur(14px) brightness(.54) saturate(.72); }
  24% { transform: translate(-48%, -67%) rotate(3.6deg) scale(1.41); filter: blur(9px) brightness(.69) saturate(.8); }
  37% { transform: translate(-54%, -60%) rotate(-3.3deg) scale(1.26); filter: blur(5px) brightness(.83) saturate(.9); }
  56% { transform: translate(-53%, -53%) rotate(1.1deg) scale(1.17); filter: blur(1.5px) brightness(.96); }
  77%, 100% { transform: translate(-54%, -50%) rotate(0) scale(1.12); filter: none; }
}

@keyframes wake-blink {
  0%, 5% { --wake-eye-opening: 1%; opacity: 1; }
  16% { --wake-eye-opening: 24%; opacity: .88; }
  23% { --wake-eye-opening: 8%; opacity: 1; }
  36% { --wake-eye-opening: 40%; opacity: .73; }
  43% { --wake-eye-opening: 13%; opacity: .94; }
  61% { --wake-eye-opening: 72%; opacity: .51; }
  84%, 100% { --wake-eye-opening: 100%; opacity: 0; }
}

@keyframes wake-dismiss { 0%, 87% { opacity: 1; } 100% { opacity: 0; } }

.intro-skip {
  padding: 7px 15px;
  border: 0;
  background: var(--cardboard-label) center / 100% 100% no-repeat;
  color: var(--cardboard-ink);
  font: 800 .87rem/1.25 'Trebuchet MS', 'Segoe UI', sans-serif;
  filter: drop-shadow(1px 2px #3d241f64);
}

.intro-skip { position: relative; z-index: 1; pointer-events: auto; }

.stage-progress {
  position: absolute;
  z-index: 3;
  inset: calc(var(--stage-rail-height) + 3px) var(--stage-rail-gutter) auto auto;
  display: flex;
  gap: .6em;
  align-items: baseline;
  padding: 7px 12px;
  margin: 0;
  background: var(--cardboard-label) center / 100% 100% no-repeat;
  color: var(--cardboard-ink);
  font: 700 clamp(.71rem, 1vw, .87rem)/1.17 'Trebuchet MS', 'Segoe UI', sans-serif;
  filter: drop-shadow(1px 2px #3d241f64);
  pointer-events: none;
}

.stage-progress strong { color: #853f29; }
.stage-progress button {
  display: grid;
  gap: 3px;
  padding: .12em .25em;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  text-align: start;
  cursor: pointer;
  pointer-events: auto;
}
.stage-progress button:focus-visible { outline: 2px solid #733e28; outline-offset: 2px; }
.progress-numbers { display: flex; align-items: center; gap: .5em; }
.progress-numbers span { margin-left: auto; }
.profile-dock-icon { width: 1.45em; height: 1.45em; object-fit: contain; flex: none; }
.stage-progress progress { width: 100%; height: 5px; accent-color: #79402c; }
.stage-progress small { font-size: .72em; font-weight: 600; }

.stage-progress output {
  position: absolute;
  inset: 100% 0 auto auto;
  min-width: max-content;
  padding: 5px 12px;
  background: var(--cardboard-stamp) center / 100% 100% no-repeat;
  color: #fff0c0;
}

.stage-progress output:empty { opacity: 0; }

.intro-dialogue {
  --dialogue-ink: #722c24;
  --dialogue-cream: #fff0ce;
  --dialogue-font: 'Trebuchet MS', 'Segoe UI', sans-serif;
  position: fixed;
  inset: 0 0 auto;
  width: var(--frame-width);
  height: var(--stage-height);
  max-width: none;
  max-height: none;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: var(--dialogue-ink);
  color-scheme: light;
  container: npc-dialogue / size;
}

.intro-dialogue::backdrop { background: transparent; }

.intro-dialogue-layout {
  position: absolute;
  inset: auto 2.6% max(6px, 2.1cqh);
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(0, 1fr);
  align-items: end;
  gap: 3.7cqw;
}

.intro-captions {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: min(15.3cqw, 32cqh);
  margin-bottom: 3.1cqh;
  padding: clamp(12px, 1.32cqw, 22px) clamp(13px, 4.35cqw, 68px) clamp(15px, 3.1cqw, 46px);
  filter: drop-shadow(2px 4px 2px #3924128a);
}
.intro-captions::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url('assets/cardboard/dialogue-green.webp') center / 100% 100% no-repeat;
  filter: brightness(1.19);
}
.intro-captions:has(p:empty) { visibility: hidden; }

.intro-captions p {
  margin: 0;
  color: var(--dialogue-cream);
  overflow-wrap: anywhere;
  text-wrap: balance;
  font: 700 clamp(.88rem, 2.53cqw, 2.36rem)/1.24 var(--dialogue-font);
  letter-spacing: .013em;
}

.intro-captions .intro-line-speaker {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 .23em -.2em;
  padding: .19em .66em .25em;
  background: var(--cardboard-label) center / 100% 100% no-repeat;
  color: var(--dialogue-ink);
  font: 850 clamp(.82rem, 2.4cqw, 2.38rem)/1.13 var(--dialogue-font);
}
.intro-captions .is-hero .intro-line-speaker { color: #2f5140; }

.intro-response {
  position: relative;
  isolation: isolate;
  min-width: 0;
  padding: clamp(26px, 3.53cqw, 54px) clamp(11px, 2.35cqw, 37px) clamp(10px, 1.74cqw, 28px);
  filter: drop-shadow(2px 4px 2px #3b241085);
  animation: dialogue-enter .18s ease-out both;
}
.intro-response::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: url('assets/cardboard/dialogue-paper.webp') center / 100% 100% no-repeat;
  filter: saturate(.87) brightness(1.02);
}

.intro-dismiss {
  position: absolute;
  z-index: 1;
  top: clamp(4px, 1.4cqw, 23px);
  right: clamp(5px, .86cqw, 15px);
  display: grid;
  place-items: center;
  width: clamp(36px, 2.55cqw, 42px);
  height: clamp(36px, 2.55cqw, 42px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.intro-dismiss img {
  display: block;
  width: clamp(14px, 1.82cqw, 28px);
  height: auto;
}

.intro-film-controls { display: flex; flex-wrap: wrap; gap: 5px 8px; }
.intro-film-controls button {
  padding: 5px 10px;
  border: 1px solid #a66947a3;
  border-radius: 2px;
  color: var(--dialogue-ink);
  background: #f7d9a489;
  font: 800 clamp(.77rem, 1.36cqw, 1.12rem)/1.2 var(--dialogue-font);
  cursor: pointer;
}
.intro-film-controls button:last-child { color: var(--dialogue-cream); background: #315543; border-color: #315543; }
.intro-film-controls button:hover { box-shadow: inset 0 0 0 1px currentColor; }

.intro-dialogue-sheet {
  display: flex;
  flex-direction: column;
  max-height: min(22.6cqh, 15.7cqw);
  overflow: hidden;
}
.intro-dialogue-sheet:has(.intro-transcript[open]) {
  max-height: min(42cqh, 27cqw);
  overflow: auto;
}
.intro-dialogue-sheet:has(.intro-transcript[open]) .intro-replies { flex-shrink: 0; }
.intro-dialogue :is(.intro-dialogue-sheet, .intro-film-controls)[hidden] { display: none; }
.intro-dialogue-sheet, .intro-replies {
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #ad734e7d transparent;
}
.intro-replies:hover { scrollbar-color: #a36943 transparent; }

@keyframes dialogue-enter { from { opacity: 0; } to { opacity: 1; } }

.intro-transcript {
  margin: 0;
  padding: .34em .85em 0;
  color: #7a3b28;
  font: 700 clamp(.78rem, 1.65cqw, 1.57rem)/1.2 var(--dialogue-font);
}
.intro-transcript summary { width: fit-content; list-style: none; cursor: pointer; }
.intro-transcript summary::-webkit-details-marker { display: none; }
.intro-transcript summary:hover { text-decoration: underline; }
.intro-lines { margin-block: 8px; }

.intro-order:not([hidden]) {
  display: flex;
  gap: 8px;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 8px;
  padding: 4px 11px 5px 6px;
  background: var(--cardboard-label) center / 100% 100% no-repeat;
  color: var(--dialogue-ink);
}
.intro-order img { width: 31px; height: 31px; object-fit: contain; }
.intro-order :is(small, strong) { display: block; line-height: 1.12; }
.intro-order small { font-size: .62rem; font-weight: 800; letter-spacing: .04em; }
.intro-order strong { font-size: clamp(.76rem, 1.55vw, 1rem); }
.intro-lines p { margin: 5px 0; font-size: clamp(.84rem, 1.45cqw, 1.18rem); line-height: 1.35; }
.intro-lines .intro-line-speaker { color: #853f29; font-weight: 800; }
.intro-lines .intro-line-speaker::after { content: ' ·'; }
.intro-lines .is-hero .intro-line-speaker { color: #30584e; }

.intro-replies {
  display: grid;
  grid-auto-rows: max-content;
  gap: clamp(3px, .39cqw, 6px);
  min-height: 0;
  overflow: auto;
  padding: 2px 2px 4px;
}
.intro-replies button {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .36em;
  border: 0;
  border-radius: .26em .4em .27em .36em;
  background: none;
  color: var(--dialogue-ink);
  padding: .20em .59em .30em .82em;
  text-align: start;
  overflow-wrap: anywhere;
  font: 850 clamp(.88rem, 2.02cqw, 2rem)/1.25 var(--dialogue-font);
  cursor: pointer;
}
.intro-replies button::after {
  content: '';
  position: absolute;
  inset: auto .19em 0;
  height: max(1px, .145cqw);
  border-radius: 1px;
  background: #b75c43bd;
  pointer-events: none;
}
.intro-replies button img {
  width: clamp(17px, 1.04em, 31px);
  height: clamp(17px, 1.04em, 31px);
  object-fit: contain;
}
.intro-replies button:hover, .intro-replies button:focus-visible,
.intro-replies:not(:has(button:is(:hover, :focus-visible))) button:nth-child(1 of :not([hidden])) { background: #e58c55ee; }
:is(.intro-replies button, .intro-dismiss, .intro-film-controls button, .intro-transcript summary, .intro-skip, .intro-pages button):focus-visible {
  outline: 2px solid #843e31;
  outline-offset: 1px;
}

.intro-pages, .intro-transcript-mobile { display: none; }
.intro-replies button[hidden] { display: none; }

@container npc-dialogue (max-width: 560px) or (max-height: 440px) {
  .intro-dialogue-layout {
    grid-template-columns: minmax(0, 1.48fr) minmax(0, 1fr);
    gap: 3cqw;
    inset-inline: max(2.6%, env(safe-area-inset-left)) max(2.6%, env(safe-area-inset-right));
    bottom: max(6px, 2.1cqh, env(safe-area-inset-bottom));
  }
  .intro-captions {
    min-height: 0;
    margin-bottom: 1cqh;
    padding: 10px clamp(13px, 2.5cqw, 25px) 15px;
  }
  .intro-captions p { font-size: clamp(.86rem, 2.05cqw, 1.14rem); }
  .intro-captions .intro-line-speaker { font-size: clamp(.86rem, 1.9cqw, 1.08rem); }
  .intro-response { padding: 30px clamp(12px, 1.58cqw, 19px) 10px; }
  .intro-dismiss { top: 0; right: 5px; }
  .intro-dialogue-sheet, .intro-dialogue-sheet:has(.intro-transcript[open]) {
    --intro-compact: 1;
    max-height: none;
    overflow: visible;
  }
  .intro-order:not([hidden]) { margin-bottom: 3px; }
  .intro-order img { width: 25px; height: 25px; }
  .intro-replies {
    --intro-replies-height: 47cqh;
    max-height: var(--intro-replies-height);
    overflow: hidden;
    gap: 3px;
  }
  .intro-dialogue-sheet:has(.intro-order:not([hidden])) .intro-replies { max-height: calc(var(--intro-replies-height) - 36px); }
  .intro-replies button { min-height: 34px; font-size: clamp(.85rem, 1.72cqw, 1.02rem); }
  .intro-replies button img { width: 17px; height: 17px; }
  .intro-transcript { padding: 0 4px; font-size: clamp(.8rem, 1.65cqw, 1rem); }
  .intro-transcript summary { display: flex; min-height: 30px; align-items: center; }
  .intro-dialogue-sheet:has(.intro-transcript[open]) :is(.intro-order, .intro-replies, .intro-reply-pages),
  .intro-transcript .intro-lines:not(.intro-transcript-mobile) { display: none; }
  .intro-transcript-mobile { display: block; margin-block: 4px 6px; }
  .intro-transcript-mobile p { font-size: clamp(.83rem, 1.68cqw, 1rem); overflow-wrap: anywhere; }
  .intro-pages:not([hidden]) { display: flex; gap: 5px; align-items: center; justify-content: center; }
  .intro-pages button {
    width: 40px;
    min-height: 30px;
    border: 1px solid #a66947a3;
    border-radius: 3px;
    background: #f7d9a489;
    color: var(--dialogue-ink);
    font: 800 1.1rem/1 var(--dialogue-font);
    cursor: pointer;
  }
  .intro-pages button[aria-disabled='true'] { opacity: .42; cursor: default; }
  .intro-pages output { min-width: 3ch; text-align: center; font: 700 .8rem/1.2 var(--dialogue-font); }
}

@container npc-dialogue (max-width: 560px) {
  .intro-dialogue-layout { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .intro-captions { margin: 0; }
  .intro-replies { --intro-replies-height: 37cqh; }
  .intro-dialogue[data-disc-installation] .intro-replies { --intro-replies-height: 23cqh; }
}

.intro-mobile-footer { display: none; }

html[data-mobile-game] .intro-dialogue-layout {
  inset: max(6px, env(safe-area-inset-top)) max(2.2cqw, env(safe-area-inset-right))
    max(6px, env(safe-area-inset-bottom)) max(2.2cqw, env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
  grid-template-rows: minmax(0, 1fr) auto;
  column-gap: clamp(12px, 3cqw, 34px);
  row-gap: 7px;
}

html[data-mobile-game] .intro-captions {
  grid-area: 1 / 1;
  min-height: 0;
  margin: 0;
  max-width: 95%;
  padding: 11px clamp(11px, 2.35cqw, 24px) 15px;
}

html[data-mobile-game] .intro-captions p {
  font-size: clamp(.875rem, 2.1cqw, 1.24rem);
  text-wrap: wrap;
}

html[data-mobile-game] .intro-captions .intro-line-speaker {
  font-size: clamp(.875rem, 1.9cqw, 1.12rem);
}

html[data-mobile-game] .intro-response {
  grid-area: 1 / 2;
  padding: clamp(9px, 1.65cqh, 17px) clamp(10px, 1.7cqw, 20px);
  filter: none;
  animation: none;
}

html[data-mobile-game] .intro-response::before {
  filter: drop-shadow(2px 4px 2px #3b24107d);
}

html[data-mobile-game] .intro-dismiss {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border: 1px solid #865534;
  border-radius: 50%;
  background: var(--cardboard-label) center / 100% 100% no-repeat, #f5dbad;
  box-shadow: 1px 2px 3px #45271066;
}

html[data-mobile-game] .intro-dismiss img { width: 22px; }

html[data-mobile-game] .intro-film-controls { justify-content: flex-end; }
html[data-mobile-game] .intro-film-controls button {
  min-height: 44px;
  font-size: clamp(.8125rem, 1.7cqw, 1.02rem);
}

html[data-mobile-game] .intro-dialogue-sheet {
  max-height: none;
  overflow: visible;
}

html[data-mobile-game] .intro-transcript { display: none; }

html[data-mobile-game] .intro-order:not([hidden]) { margin-bottom: 4px; }
html[data-mobile-game] .intro-order img { width: 24px; height: 24px; }

html[data-mobile-game] .intro-replies {
  --intro-replies-height: min(60cqh, calc(100cqh - 109px));
  max-height: var(--intro-replies-height);
  overflow: hidden;
  gap: 4px;
}

html[data-mobile-game] .intro-dialogue-sheet:has(.intro-order:not([hidden])) .intro-replies {
  max-height: calc(var(--intro-replies-height) - 37px);
}

html[data-mobile-game] .intro-replies button {
  min-height: clamp(44px, 17.7cqh, 74px);
  padding: 5px clamp(7px, 1.3cqw, 14px);
  border: 1px solid #a46a3a91;
  border-radius: 6px;
  background: #fff0cc6e;
  color: #502915;
  font-size: clamp(.875rem, 2.2cqw, 1.26rem);
  line-height: 1.15;
}

html[data-mobile-game] .intro-replies button::after { display: none; }

html[data-mobile-game] .intro-replies button:not(:focus-visible) { background: #fff0cc6e; }
html[data-mobile-game] .intro-replies button:active,
html[data-mobile-game] .intro-replies button:focus-visible { background: #eab376; }
html[data-mobile-game] .intro-replies button img {
  width: clamp(20px, 3.25cqw, 30px);
  height: clamp(20px, 3.25cqw, 30px);
}

html[data-mobile-game] .intro-reply-place {
  display: block;
  margin-top: 2px;
  color: #6e472e;
  font-size: .83em;
  font-weight: 650;
}

html[data-mobile-game] .intro-mobile-footer:not([hidden]) {
  grid-area: 2 / 1 / 3 / -1;
  display: flex;
  justify-content: space-between;
  padding: 0 clamp(5px, 1.2cqw, 12px);
  border: 1px solid #966540;
  border-radius: 10px;
  background: #264535 url('assets/cardboard/cloth-grain.webp') center / 220px auto repeat;
  background-blend-mode: multiply;
  box-shadow: 1px 2px 4px #45271066;
}

html[data-mobile-game] .intro-mobile-footer button:not([hidden]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 3px clamp(8px, 1.6cqw, 18px);
  border: none;
  background: transparent;
  color: var(--dialogue-cream);
  font: 800 clamp(.9rem, 2.12cqw, 1.26rem)/1.14 var(--dialogue-font);
}

html[data-mobile-game] .intro-mobile-footer button:active { background: #f5dcad29; }
html[data-mobile-game] .intro-mobile-footer button.intro-trail:not([hidden]) { margin-inline-start: auto; }
html[data-mobile-game] .intro-trail img { width: 29px; height: 29px; object-fit: contain; }

@container npc-dialogue (min-height: 321px) {
  html[data-mobile-game] .intro-response:has(.intro-replies button:nth-child(3 of :not([hidden]))):not(:has(.intro-order:not([hidden]))) {
    padding-block: clamp(14px, 6.3cqh, 27px);
  }
}

@container npc-dialogue (max-height: 320px) {
  html[data-mobile-game] .intro-captions {
    max-width: 100%;
    padding-block: 7px 10px;
  }
  html[data-mobile-game] .intro-captions p { font-size: clamp(.875rem, 1.7cqw, 1rem); }
  html[data-mobile-game] .intro-response { margin-inline-end: 32px; }
  html[data-mobile-game] .intro-replies button {
    min-height: 44px;
    font-size: clamp(.875rem, 1.85cqw, 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro-awakening::after { display: none; }
  .intro-awakening.is-playing :is(.intro-shot, .intro-camera), .intro-response { animation: none; }
}
