/* =====================================================================
   Our World — UI stylesheet
   Pastel, chunky, playful. Thick chocolate outlines, rounded everything.
   ===================================================================== */

:root {
  --cream: #fff6e5;
  --cream-2: #fff0d2;
  --pink: #ffb7c5;
  --pink-2: #ff8fa8;
  --mint: #b8f1d0;
  --mint-2: #7fd8a8;
  --sky: #bfe6ff;
  --sky-2: #8fd0ff;
  --sun: #ffd166;
  --choc: #5a3a22;
  --ink: #3b2314;
  --text: #3b2314;
  --muted: #8a6b55;
  --plum: #7b3f61;
  --radius: 18px;
  --outline: 3px solid var(--choc);
  --shadow-chunk: 0 6px 0 var(--choc);
  --shadow-soft: 0 12px 32px rgba(59, 35, 20, .28);
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --font: 'Fredoka', 'Nunito', 'Quicksand', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --hand: 'Caveat', 'Bradley Hand', 'Segoe Print', 'Comic Sans MS', cursive;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  background: #bfe6ff;
}
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.3;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#game {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #bfe6ff;
  overflow: hidden;
}
#game canvas { display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
img { -webkit-user-drag: none; user-select: none; }
[hidden] { display: none !important; }
.scroll { touch-action: pan-y; -webkit-overflow-scrolling: touch; }

/* ---------- shared bits ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 999px;
  padding: 5px 16px 5px 8px;
  box-shadow: 0 5px 0 var(--choc);
  font-weight: 600;
  font-size: 22px;
  line-height: 1;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 26px;
  border: var(--outline);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  font-weight: 700;
  font-size: 18px;
  box-shadow: 0 5px 0 var(--choc);
  transition: transform .08s ease, box-shadow .08s ease, background .2s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--choc); }
.btn-primary { background: var(--pink); }
.btn-small { min-height: 40px; padding: 6px 16px; font-size: 15px; box-shadow: 0 3px 0 var(--choc); }
.btn-danger { background: #ffd5d5; }
.link {
  background: none;
  border: 0;
  padding: 10px 8px;
  min-height: 44px;
  color: var(--choc);
  font-weight: 600;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.key {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  background: #fff;
  border: 2px solid var(--choc);
  border-bottom-width: 4px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  color: var(--ink);
}

/* ---------- vignette ---------- */
#vignette {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, transparent 32%, var(--vig-color, #000) 100%);
  transition: opacity .9s ease;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  transition: opacity .7s ease;
}
#hud.hud-hidden, #prompt.hud-hidden, #companion-bubble.hud-hidden { opacity: 0 !important; }
/* invisible HUD must not be clickable/tappable (Empty Life); the P / M shortcuts still work */
#hud.hud-hidden, #hud.hud-hidden *, #companion-bubble.hud-hidden, #companion-bubble.hud-hidden * { pointer-events: none !important; }
.hud-left {
  position: absolute;
  left: calc(12px + var(--sal));
  top: calc(12px + var(--sat));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.hud-right {
  position: absolute;
  right: calc(12px + var(--sar));
  top: calc(12px + var(--sat));
}
#bliss { pointer-events: none; }
.bliss-icon { width: 36px; height: 36px; flex: none; }
.bliss-num { display: inline-flex; align-items: baseline; gap: 4px; padding-top: 2px; }
.bliss-sep { font-size: .75em; color: var(--muted); }
#bliss-total { font-size: .85em; color: var(--muted); }
.golden-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
  padding: 2px 9px 2px 7px;
  background: var(--sun);
  border: 2px solid var(--choc);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
#bliss.pop .bliss-icon { animation: pop .55s cubic-bezier(.2, 1.7, .4, 1); }
#bliss.pop #bliss-count { display: inline-block; animation: numpop .45s cubic-bezier(.2, 1.7, .4, 1); }
#golden.pop { animation: pop .55s cubic-bezier(.2, 1.7, .4, 1); }
.hud-buttons { display: flex; gap: 8px; }
.hud-btn {
  position: relative;
  width: 52px;
  height: 52px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--cream);
  border: var(--outline);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--choc);
  pointer-events: auto;
  transition: transform .08s, box-shadow .08s;
}
.hud-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--choc); }
.hud-btn svg { width: 34px; height: 34px; }
.hud-btn.wiggle { animation: wiggle .8s ease; }
.hud-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  background: var(--pink-2);
  border: 2px solid var(--choc);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
#btn-companion img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 12%;
  background: var(--sky);
  border: 2px solid var(--choc);
  transition: filter .3s, opacity .3s;
}
#btn-companion .zz {
  display: none;
  position: absolute;
  right: 2px;
  top: 0;
  font-family: var(--hand);
  font-weight: 700;
  font-size: 17px;
  color: var(--plum);
  transform: rotate(10deg);
}
#btn-companion.off img { filter: grayscale(1); opacity: .5; }
#btn-companion.off .zz { display: block; }
#btn-mute .muted-x { display: none; }
#btn-mute.is-muted .wave { display: none; }
#btn-mute.is-muted .muted-x { display: block; }
#minimap-wrap {
  position: relative;
  width: 128px;
  height: 128px;
  border: var(--outline);
  border-radius: 30px;
  overflow: hidden;
  background: #79c7ee;
  box-shadow: 0 4px 0 var(--choc);
  pointer-events: none;
}
#minimap { display: block; width: 100%; height: 100%; }
.compass {
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 0 var(--choc), 0 0 4px rgba(59, 35, 20, .5);
}

/* ---------- prompt pill (desktop) ---------- */
#prompt {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--sab));
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 10px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--choc);
  font-weight: 600;
  font-size: 19px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 16px) scale(.9);
  transition: opacity .18s ease, transform .22s cubic-bezier(.2, 1.4, .4, 1);
}
#prompt.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
body.touch #prompt { display: none; }
body.modal-open #prompt { opacity: 0; }

/* ---------- companion bubble ---------- */
#companion-bubble {
  position: fixed;
  left: calc(14px + var(--sal));
  bottom: calc(14px + var(--sab));
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  transition: opacity .6s;
}
.companion-face {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: var(--outline);
  object-fit: cover;
  object-position: 50% 10%;
  background: var(--sky);
  box-shadow: 0 3px 0 var(--choc);
  animation: floaty 3.2s ease-in-out infinite;
  transition: opacity .3s, filter .3s;
}
#companion-bubble.off .companion-face { opacity: 0; }
.bubble {
  position: relative;
  margin-left: 22px;
  max-width: min(280px, 62vw);
  padding: 9px 14px;
  background: #fff;
  border: var(--outline);
  border-radius: 18px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.25;
  box-shadow: 0 4px 0 var(--choc);
  opacity: 0;
  transform: scale(.5) translateY(12px);
  transform-origin: 12% 110%;
  transition: opacity .2s ease, transform .3s cubic-bezier(.2, 1.5, .4, 1);
}
.bubble::before, .bubble::after {
  content: '';
  position: absolute;
  left: 8px;
  bottom: -14px;
  border-style: solid;
  border-width: 14px 12px 0 0;
  border-color: var(--choc) transparent transparent transparent;
}
.bubble::after { bottom: -9px; left: 11px; border-width: 10px 8px 0 0; border-color: #fff transparent transparent transparent; }
#companion-bubble.say .bubble { opacity: 1; transform: none; }
body.touch #companion-bubble { bottom: calc(196px + var(--sab)); }
body.modal-open #companion-bubble { opacity: 0; }
body.touch #companion-bubble .companion-face { width: 48px; height: 48px; }

/* ---------- hint ---------- */
#hint {
  position: fixed;
  left: 50%;
  top: 62%;
  z-index: 12;
  max-width: 90vw;
  padding: 9px 18px;
  background: rgba(59, 35, 20, .78);
  color: #fff;
  border-radius: 999px;
  font-weight: 500;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 6px);
  transition: opacity .3s, transform .3s;
}
#hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- zone banner ---------- */
#banner {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(17% + var(--sat));
  z-index: 14;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  pointer-events: none;
}
.banner-card {
  position: relative;
  max-width: min(92vw, 760px);
  padding: 16px 44px 18px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 30px;
  box-shadow: 0 7px 0 var(--choc), var(--shadow-soft);
  text-align: center;
  opacity: 0;
}
#banner.show .banner-card { animation: bannerIn .65s cubic-bezier(.2, 1.4, .4, 1) forwards; }
#banner.hide .banner-card { animation: bannerOut .5s ease forwards; }
.banner-title {
  font-size: clamp(30px, 6.2vw, 60px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: .5px;
  color: var(--ink);
}
.banner-title span { display: inline-block; opacity: 0; white-space: pre; }
#banner.show .banner-title span { animation: letterPop .55s cubic-bezier(.2, 1.7, .4, 1) forwards; animation-delay: calc(var(--i) * 42ms + .18s); }
.banner-sub {
  margin-top: 4px;
  font-family: var(--hand);
  font-size: clamp(20px, 3.4vw, 32px);
  font-weight: 600;
  color: var(--plum);
  opacity: 0;
}
#banner.show .banner-sub { animation: fadeUp .6s ease forwards; animation-delay: .5s; }
/* the text fades out WITH the card (dropping .show would otherwise snap it back to opacity 0: an empty card) */
#banner.hide .banner-title span, #banner.hide .banner-sub { opacity: 1; }
.banner-deco {
  position: absolute;
  top: 50%;
  width: 26px;
  height: 26px;
  margin-top: -13px;
  background: var(--pink);
  clip-path: polygon(50% 100%, 0 45%, 6% 20%, 25% 5%, 50% 20%, 75% 5%, 94% 20%, 100% 45%);
}
.banner-deco-l { left: 12px; transform: rotate(-14deg); }
.banner-deco-r { right: 12px; transform: rotate(14deg); background: var(--mint-2); }

/* ---------- toasts ---------- */
#toasts {
  position: fixed;
  left: 50%;
  top: calc(12px + var(--sat));
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(92vw, 540px);
  transform: translateX(-50%);
  pointer-events: none;
  transition: top .3s ease;
}
/* while a zone banner shows, toasts stack under its card instead of covering the title (ui.zoneBanner sets both) */
body.banner-on #toasts { top: var(--banner-bottom, calc(17% + 140px + var(--sat))); }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 8px 18px 8px 10px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--choc);
  font-weight: 600;
  font-size: 17px;
  animation: toastIn .55s cubic-bezier(.2, 1.5, .4, 1);
}
.toast.out { animation: toastOut .4s ease forwards; }
.toast-icon { width: 30px; height: 30px; flex: none; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.toast-icon svg { width: 30px; height: 30px; }
.toast-text { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) {
  #toasts { top: calc(154px + var(--sat)); }
  body.banner-on #toasts { top: var(--banner-bottom, calc(27% + 118px + var(--sat))); }
  #banner { top: calc(27% + var(--sat)); }
  body.touch #companion-bubble { bottom: calc(214px + var(--sab)); }
  body.touch .bubble { max-width: 58vw; }
  #hint { top: 50%; }
}

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; z-index: 12; display: none; pointer-events: none; }
body.touch #touch { display: block; }
body.modal-open #touch { visibility: hidden; }
#look-zone {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 50%;
  pointer-events: auto;
  touch-action: none;
}
#joy-base {
  position: absolute;
  left: 0;
  top: 0;
  width: 124px;
  height: 124px;
  margin: -62px 0 0 -62px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .22);
  border: 3px solid rgba(255, 255, 255, .8);
  box-shadow: inset 0 0 0 5px rgba(90, 58, 34, .12), 0 4px 18px rgba(0, 0, 0, .18);
  pointer-events: none;
  display: none;
}
#joy-base::before {
  content: '';
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .55);
}
#joy-knob {
  position: absolute;
  left: 0;
  top: 0;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: var(--cream);
  border: var(--outline);
  box-shadow: 0 4px 0 var(--choc);
  pointer-events: none;
  display: none;
}
#joy-knob::after {
  content: '';
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--pink);
  border: 2px solid var(--choc);
}
#joy-base.active, #joy-base.show, #joy-base.visible, #joy-base.on, #joy-base.shown,
#joy-knob.active, #joy-knob.show, #joy-knob.visible, #joy-knob.on, #joy-knob.shown { display: block; }
.touch-buttons {
  position: absolute;
  right: calc(16px + var(--sar));
  bottom: calc(20px + var(--sab));
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
.tbtn {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  border-radius: 50%;
  border: var(--outline);
  background: var(--cream);
  box-shadow: 0 5px 0 var(--choc);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .6px;
  color: var(--ink);
  touch-action: none;
  transition: transform .06s, box-shadow .06s, background .25s;
}
.tbtn:active, .tbtn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--choc); }
.tbtn-label { line-height: 1; margin-top: -2px; }
.tbtn-label.long { font-size: 11px; letter-spacing: 0; }
#interact-wrap { position: relative; display: flex; flex-direction: column; align-items: center; margin-bottom: 44px; }
#btn-interact { width: 86px; height: 86px; background: var(--mint); }
#btn-interact svg { width: 36px; height: 36px; }
#btn-interact.active { background: var(--sun); animation: pulse 1.3s ease-in-out infinite; }
#btn-jump { width: 70px; height: 70px; background: var(--sky); }
#btn-jump svg { width: 30px; height: 30px; }
#interact-label {
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 10px;
  width: max-content;
  max-width: min(calc(100vw - 130px - var(--sal) - var(--sar)), 340px);
  padding: 5px 13px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 16px;
  box-shadow: 0 3px 0 var(--choc);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.15;
  text-align: right;
  white-space: normal;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .25s cubic-bezier(.2, 1.4, .4, 1);
}
#interact-wrap.active #interact-label { opacity: 1; transform: none; }

/* ---------- dialogue ---------- */
#dialogue {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 calc(12px + var(--sar)) calc(18px + var(--sab)) calc(12px + var(--sal));
  pointer-events: auto;
  opacity: 0;
  transition: opacity .22s ease;
}
#dialogue.open { opacity: 1; }
.dlg-card {
  position: relative;
  width: min(100%, 780px);
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 18px;
  padding: 18px 26px 22px 18px;
  min-height: 132px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 26px;
  box-shadow: 0 7px 0 var(--choc), var(--shadow-soft);
  transform: translateY(40px) scale(.96);
  transition: transform .32s cubic-bezier(.2, 1.4, .4, 1);
}
#dialogue.open .dlg-card { transform: none; }
.dlg-card.no-portrait { grid-template-columns: 1fr; padding-left: 26px; }
.dlg-card.no-portrait .dlg-portrait { display: none; }
.dlg-portrait {
  width: 116px;
  height: 128px;
  margin-top: -52px;
  align-self: start;
  border-radius: 22px;
  background: linear-gradient(160deg, var(--sky) 0%, var(--mint) 100%);
  border: var(--outline);
  box-shadow: 0 4px 0 var(--choc);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.dlg-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 0%;
  display: block;
  filter: drop-shadow(1.5px 0 0 #fff) drop-shadow(-1.5px 0 0 #fff) drop-shadow(0 1.5px 0 #fff) drop-shadow(0 -1.5px 0 #fff);
  transform-origin: 50% 100%;
}
.dlg-portrait img.in { animation: portraitIn .45s cubic-bezier(.2, 1.6, .4, 1); }
.dlg-right { display: flex; flex-direction: column; min-width: 0; }
.dlg-name {
  align-self: flex-start;
  margin-top: -34px;
  padding: 5px 16px;
  background: var(--pink);
  border: var(--outline);
  border-radius: 999px;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 3px 0 var(--choc);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dlg-name.alt { background: var(--mint); }
.dlg-name.empty { visibility: hidden; }
.dlg-text {
  white-space: pre-wrap;
  margin-top: 10px;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.35;
  min-height: 2.7em;
  padding-right: 18px;
  overflow-wrap: anywhere;
}
.dlg-cue {
  position: absolute;
  right: 18px;
  bottom: 10px;
  font-size: 24px;
  line-height: 1;
  color: var(--choc);
  opacity: 0;
}
.dlg-card.done .dlg-cue { opacity: 1; animation: blink 1s steps(2, start) infinite; }
@media (max-width: 640px) {
  .dlg-card { grid-template-columns: 84px 1fr; gap: 12px; padding: 14px 18px 18px 12px; min-height: 110px; }
  .dlg-portrait { width: 84px; height: 96px; margin-top: -40px; border-radius: 18px; }
  .dlg-name { margin-top: -30px; font-size: 15px; padding: 4px 12px; }
  .dlg-text { font-size: 18px; margin-top: 8px; padding-right: 10px; }
}

/* ---------- modals (passport, vault) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(10px + var(--sat)) calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal));
  pointer-events: auto;
  opacity: 0;
  transition: opacity .25s ease;
}
.modal.open { opacity: 1; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(59, 35, 20, .55); }
.modal-close {
  position: absolute;
  top: calc(12px + var(--sat));
  right: calc(12px + var(--sar));
  z-index: 3;
  width: 50px;
  height: 50px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: var(--outline);
  background: var(--cream);
  box-shadow: 0 4px 0 var(--choc);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}
.modal-close:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--choc); }
.modal-body {
  position: relative;
  width: min(100%, 860px);
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 30px 8px 16px;
  scrollbar-width: thin;
  transform: scale(.92) translateY(24px);
  transition: transform .4s cubic-bezier(.2, 1.4, .4, 1);
}
.modal.open .modal-body { transform: none; }

/* passport booklet */
.passport-book {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  max-width: 740px;
  margin: 0 auto;
  padding: 14px;
  background: #6b2d4e;
  background-image: radial-gradient(circle at 12% 18%, rgba(255, 255, 255, .08), transparent 40%);
  border: var(--outline);
  border-radius: 22px;
  box-shadow: var(--shadow-soft), inset 0 0 0 2px rgba(255, 209, 102, .35);
}
.passport-book.shake { animation: shake .45s ease; }
.pp-page {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 384px;
  padding: 16px 16px 14px;
  background-color: #fffaf0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(123, 63, 97, .06) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(123, 63, 97, .05) 0 2px, transparent 3px),
    repeating-linear-gradient(0deg, rgba(90, 58, 34, .035) 0 1px, transparent 1px 9px);
  background-size: 120px 120px, 160px 160px, auto;
}
.pp-left { border-radius: 14px 3px 3px 14px; box-shadow: inset -14px 0 22px -16px rgba(0, 0, 0, .45); }
.pp-right { border-radius: 3px 14px 14px 3px; box-shadow: inset 14px 0 22px -16px rgba(0, 0, 0, .45); }
.pp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(123, 63, 97, .25);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--plum);
}
.pp-emblem { font-size: 16px; }
.pp-photo {
  width: 124px;
  height: 154px;
  margin: 0 auto 14px;
  border: 3px solid var(--choc);
  border-radius: 8px;
  background: #d9c7a8;
  box-shadow: 0 3px 0 var(--choc);
  overflow: hidden;
  transform: rotate(-1.5deg);
}
.pp-photo img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; filter: sepia(.22) contrast(1.05); display: block; }
.pp-fields { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; }
.pp-fields dt { align-self: end; font-size: 9.5px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--plum); padding-bottom: 3px; }
.pp-fields dd { margin: 0; font-family: var(--hand); font-size: 21px; font-weight: 600; line-height: 1.05; color: var(--ink); overflow-wrap: anywhere; }
.pp-mrz {
  margin-top: auto;
  padding-top: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 10px;
  letter-spacing: 1.2px;
  line-height: 1.5;
  color: #8a6b55;
  word-break: break-all;
}
.pp-stamps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pp-slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 2px dashed rgba(123, 63, 97, .35);
  border-radius: 14px;
  display: grid;
  place-items: center;
  overflow: visible;
}
.pp-slot-label { font-family: var(--hand); font-size: 19px; font-weight: 600; color: rgba(123, 63, 97, .5); text-align: center; padding: 6px; }
.pp-slot.stamped { border-color: transparent; }
.pp-slot.stamped .pp-slot-label { display: none; }
.pp-stamp {
  position: absolute;
  inset: 3%;
  transform: rotate(var(--rot, -6deg));
  mix-blend-mode: multiply;
  opacity: .92;
}
.pp-stamp svg { width: 100%; height: 100%; display: block; }
.pp-stamp.slam { animation: slam .6s cubic-bezier(.25, 1.3, .4, 1) forwards; }
.pp-footer { margin-top: auto; padding-top: 12px; font-family: var(--hand); font-size: 18px; color: var(--plum); text-align: center; }
.pp-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 740px; margin: 14px auto 0; }
.pp-extra section { background: var(--cream); border: var(--outline); border-radius: 18px; padding: 10px 14px; box-shadow: 0 4px 0 var(--choc); min-width: 0; }
.pp-extra h3 { margin: 0 0 8px; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--plum); }
.pp-extra ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pp-extra li { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; background: #fff; border: 2px solid var(--choc); border-radius: 999px; font-size: 14px; font-weight: 600; max-width: 100%; }
.pp-extra li .star { color: #e3a008; }
.pp-extra li.empty { border-style: dashed; color: var(--muted); font-weight: 500; background: transparent; }
.pp-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px 20px; margin-top: 12px; }
.pp-actions .link { color: var(--cream); }
@media (max-width: 600px) {
  .passport-book { grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  .pp-page { min-height: 0; }
  .pp-left { border-radius: 14px 14px 3px 3px; box-shadow: inset 0 -14px 22px -16px rgba(0, 0, 0, .45); }
  .pp-right { border-radius: 3px 3px 14px 14px; box-shadow: inset 0 14px 22px -16px rgba(0, 0, 0, .45); }
  .pp-photo { width: 104px; height: 128px; }
  .pp-extra { grid-template-columns: 1fr; }
  .modal-body { padding-top: 56px; }
}

/* stamp ghost flying to the HUD button */
.stamp-ghost {
  position: fixed;
  left: 0;
  top: 0;
  width: 150px;
  height: 150px;
  z-index: 16;
  pointer-events: none;
  mix-blend-mode: multiply;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .25));
}
.stamp-ghost svg { width: 100%; height: 100%; }

/* vault */
#vault { z-index: 45; }
.vault-backdrop { background: radial-gradient(ellipse at center, rgba(123, 63, 97, .78) 0%, rgba(44, 20, 34, .94) 100%); }
.hearts-rain { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.hearts-rain .fh {
  position: absolute;
  top: -12vh;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  animation: fall var(--d) linear var(--delay) infinite;
  opacity: .92;
}
.hearts-rain .fh i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--c);
  clip-path: polygon(50% 100%, 0 45%, 6% 20%, 25% 5%, 50% 20%, 75% 5%, 94% 20%, 100% 45%);
  animation: sway var(--sd) ease-in-out infinite alternate;
}
.vault-wrap { padding-top: 48px; }
.letter {
  position: relative;
  max-width: 640px;
  margin: 18px auto 0;
  padding: 36px 34px 30px;
  background-color: #fff9ec;
  background-image: repeating-linear-gradient(rgba(90, 58, 34, .14) 0 1px, transparent 1px 34px);
  background-position: 0 112px;
  border: var(--outline);
  border-radius: 6px;
  box-shadow: var(--shadow-soft);
  transform: rotate(-1deg);
}
.letter.no-title { background-position: 0 68px; }
.tape {
  position: absolute;
  top: -15px;
  left: 50%;
  width: 130px;
  height: 32px;
  background: rgba(255, 214, 102, .78);
  border: 2px dashed rgba(90, 58, 34, .3);
  transform: translateX(-50%) rotate(2deg);
}
#vault-title { margin: 0 0 10px; font-size: 30px; font-weight: 700; color: var(--plum); line-height: 34px; }
.letter-body {
  min-height: 102px;
  font-family: var(--hand);
  font-size: 27px;
  line-height: 34px;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.letter-body .caret { display: inline-block; width: 2px; height: .9em; margin-left: 1px; background: var(--choc); vertical-align: -.12em; animation: blink 1s steps(2, start) infinite; }
.letter.done .caret { display: none; }
.photo-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; max-width: 760px; margin: 28px auto 0; }
.polaroid {
  width: 150px;
  margin: 0;
  padding: 8px 8px 10px;
  background: #fff;
  border: 2px solid var(--choc);
  box-shadow: var(--shadow-soft);
  transform: rotate(var(--r, 0deg));
  animation: polaroidIn .6s cubic-bezier(.2, 1.4, .4, 1) both;
  animation-delay: var(--delay, 0s);
}
.polaroid img { display: block; width: 100%; height: 128px; object-fit: cover; object-position: 50% 15%; background: var(--sky); }
.polaroid figcaption { margin-top: 6px; font-family: var(--hand); font-size: 18px; font-weight: 600; text-align: center; color: var(--ink); min-height: 1.2em; }
.vault-actions { display: flex; justify-content: center; margin-top: 22px; }
@media (max-width: 600px) {
  .letter { padding: 30px 20px 22px; }
  .letter-body { font-size: 24px; line-height: 34px; }
  .polaroid { width: 128px; }
  .polaroid img { height: 108px; }
}

/* ---------- start screen ---------- */
#start {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  background: linear-gradient(180deg, #8fd0ff 0%, #bfe6ff 48%, #fff6e5 100%);
  overflow: hidden auto;
  touch-action: pan-y;
  transition: opacity .75s ease, visibility .75s;
}
#start.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.float-shapes { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.shape {
  position: absolute;
  left: var(--x);
  bottom: -14vh;
  width: var(--s);
  height: var(--s);
  opacity: .85;
  animation: floatUp var(--d) linear var(--delay) infinite;
  will-change: transform;
}
.shape.heart { background: var(--c); clip-path: polygon(50% 100%, 0 45%, 6% 20%, 25% 5%, 50% 20%, 75% 5%, 94% 20%, 100% 45%); }
.shape.tri { background: var(--c); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.shape.gem { background: var(--c); clip-path: polygon(50% 0, 100% 40%, 80% 100%, 20% 100%, 0 40%); }
.shape.ball {
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 60%, #fff6e5 0 9%, transparent 10%),
    radial-gradient(circle at 66% 34%, #fff6e5 0 8%, transparent 9%),
    radial-gradient(circle at 62% 74%, #fff6e5 0 7%, transparent 8%),
    radial-gradient(circle at 36% 30%, #8a5a3a, #5a3a22 62%);
  box-shadow: inset -3px -4px 0 rgba(0, 0, 0, .18);
}
.shape.cloud { height: calc(var(--s) * .55); background: #fff; border-radius: 999px; opacity: .9; }
.shape.cloud::before, .shape.cloud::after {
  content: '';
  position: absolute;
  bottom: 30%;
  background: #fff;
  border-radius: 50%;
}
.shape.cloud::before { left: 18%; width: 45%; height: 110%; }
.shape.cloud::after { left: 48%; width: 38%; height: 85%; }
.start-card {
  position: relative;
  width: 100%;
  max-width: 680px;
  text-align: center;
}
.title-top {
  margin: 0 0 2px;
  font-family: var(--hand);
  font-size: clamp(30px, 6.5vw, 48px);
  font-weight: 700;
  color: var(--choc);
  transform: rotate(-3deg);
}
.title-main {
  margin: 0;
  font-size: clamp(56px, 14vw, 118px);
  font-weight: 700;
  line-height: .95;
  letter-spacing: 1px;
  color: #fff;
  -webkit-text-stroke: 3px var(--choc);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--choc), 0 12px 24px rgba(59, 35, 20, .25);
}
.title-main span { display: inline-block; white-space: pre; animation: bounceLetter 2.6s ease-in-out infinite; animation-delay: calc(var(--i) * 95ms); }
.title-main span:nth-child(5n+1) { color: var(--pink); }
.title-main span:nth-child(5n+2) { color: var(--mint); }
.title-main span:nth-child(5n+3) { color: var(--sun); }
.title-main span:nth-child(5n+4) { color: var(--sky); }
.title-main span:nth-child(5n+5) { color: #fff; }
.subtitle { margin: 14px 0 22px; font-size: clamp(16px, 3vw, 22px); font-weight: 500; color: var(--choc); }
.loading { width: min(100%, 380px); max-height: 120px; margin: 0 auto 16px; overflow: hidden; transition: opacity .45s ease, max-height .5s ease .1s, margin .5s ease .1s; }
.loading.done { opacity: 0; max-height: 0; margin-bottom: 0; }
.loading-bar { height: 24px; border: var(--outline); border-radius: 999px; background: #fff; overflow: hidden; box-shadow: 0 4px 0 var(--choc); }
.loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: repeating-linear-gradient(135deg, var(--pink) 0 14px, var(--pink-2) 14px 28px);
  background-size: 40px 40px;
  animation: stripes 1s linear infinite;
  transition: width .35s ease;
}
.loading-label { margin-top: 8px; min-height: 1.3em; font-size: 15px; font-weight: 600; color: var(--choc); }
.loading-quip { min-height: 1.25em; font-family: var(--hand); font-size: 19px; color: var(--muted); }
.btn-start {
  min-height: 66px;
  padding: 16px 44px;
  border: var(--outline);
  border-radius: 999px;
  background: var(--pink);
  color: var(--ink);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: .5px;
  box-shadow: 0 8px 0 var(--choc), 0 14px 30px rgba(59, 35, 20, .25);
  transition: transform .1s, box-shadow .1s, background .3s, color .3s;
  animation: breathe 2.2s ease-in-out infinite;
}
.btn-start:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--choc); }
.btn-start:disabled { background: #efe4cf; color: var(--muted); animation: none; cursor: default; box-shadow: 0 6px 0 var(--choc); }
.controls-card {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 22px;
  margin: 24px auto 0;
  padding: 12px 20px;
  background: rgba(255, 255, 255, .72);
  border: var(--outline);
  border-radius: 20px;
  box-shadow: 0 4px 0 var(--choc);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
}
.ctrl { display: inline-flex; align-items: center; gap: 8px; }
.ctrl .keys { display: inline-flex; gap: 3px; }
.ctrl svg { width: 34px; height: 34px; flex: none; }
.start-footer { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 16px; margin-top: 14px; font-size: 14px; color: var(--muted); }
.confirm {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 14px;
  background: #fff;
  border: var(--outline);
  border-radius: 16px;
  font-weight: 600;
  box-shadow: 0 4px 0 var(--choc);
}
.start-error {
  display: none;
  margin: 12px auto 0;
  max-width: 520px;
  padding: 8px 12px;
  background: #fff;
  border: 2px solid #b3261e;
  border-radius: 12px;
  color: #b3261e;
  font-weight: 600;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.start-error.show { display: block; }
@media (max-height: 560px) {
  #start { justify-content: flex-start; }
  .title-top { font-size: 26px; }
  .title-main { font-size: clamp(44px, 9vw, 64px); text-shadow: 0 4px 0 var(--choc); }
  .subtitle { margin: 6px 0 12px; font-size: 15px; }
  .loading { margin-bottom: 10px; }
  .loading-quip { display: none; }
  .btn-start { min-height: 54px; padding: 10px 30px; font-size: 22px; }
  .controls-card { margin-top: 14px; padding: 8px 14px; font-size: 13px; gap: 8px 16px; }
  .ctrl svg { width: 28px; height: 28px; }
  .start-footer { margin-top: 8px; }
}
@media (max-height: 480px) {
  #minimap-wrap { width: 92px; height: 92px; border-radius: 22px; }
  .pill { font-size: 18px; padding: 4px 12px 4px 6px; }
  .bliss-icon { width: 28px; height: 28px; }
  .hud-btn { width: 46px; height: 46px; border-radius: 14px; }
  .hud-btn svg { width: 30px; height: 30px; }
  #btn-companion img { width: 34px; height: 34px; }
  .dlg-card { min-height: 100px; padding-top: 12px; padding-bottom: 14px; }
  .dlg-portrait { width: 84px; height: 92px; margin-top: -36px; }
  .dlg-text { font-size: 18px; min-height: 2.2em; }
  #banner { top: calc(8% + var(--sat)); }
  /* landscape phone: the banner sits high, so toasts move to the free bottom-centre lane (joystick left, TALK/JUMP right) */
  body.touch #toasts { top: auto; bottom: calc(14px + var(--sab)); flex-direction: column-reverse; max-width: min(60vw, 460px); gap: 6px; }
  body.touch .toast { font-size: 14px; padding: 5px 12px 5px 8px; gap: 8px; }
  body.touch .toast-icon, body.touch .toast-icon svg { width: 22px; height: 22px; font-size: 17px; }
  .banner-card { padding: 10px 40px 12px; }
  .banner-title { font-size: 34px; }
  .banner-sub { font-size: 20px; }
  .modal-body { padding-top: 10px; }
  .modal-close { width: 44px; height: 44px; }
  #interact-wrap { margin-bottom: 20px; }
  body.touch #companion-bubble { bottom: calc(96px + var(--sab)); left: calc(150px + var(--sal)); }
  #btn-interact { width: 72px; height: 72px; }
  #btn-jump { width: 64px; height: 64px; }
}

/* ---------- fatal panels ---------- */
.fatal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #8fd0ff, #fff6e5);
}
html.no-webgl #nowebgl, .fatal.show, .fatal-noscript { display: flex; }
.fatal-card {
  max-width: 460px;
  padding: 24px 28px;
  background: var(--cream);
  border: var(--outline);
  border-radius: 24px;
  box-shadow: var(--shadow-chunk);
  text-align: center;
}
.fatal-card h2 { margin: 0 0 8px; font-size: 26px; }
.fatal-card p { margin: 0; font-size: 16px; font-weight: 500; }

/* ---------- keyframes ---------- */
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.45) rotate(-10deg); } 100% { transform: scale(1); } }
@keyframes numpop { 0% { transform: scale(1); } 40% { transform: scale(1.5); color: var(--pink-2); } 100% { transform: scale(1); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(-14deg) scale(1.1); } 30% { transform: rotate(12deg) scale(1.12); } 45% { transform: rotate(-9deg) scale(1.08); } 60% { transform: rotate(6deg); } 75% { transform: rotate(-3deg); } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }
@keyframes bannerIn { 0% { opacity: 0; transform: translateY(-26px) scale(.8); } 100% { opacity: 1; transform: none; } }
@keyframes bannerOut { 0% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-18px) scale(.95); } }
@keyframes letterPop { 0% { opacity: 0; transform: translateY(18px) scale(.4) rotate(-8deg); } 100% { opacity: 1; transform: none; } }
@keyframes fadeUp { 0% { opacity: 0; transform: translateY(8px); } 100% { opacity: 1; transform: none; } }
@keyframes toastIn { 0% { opacity: 0; transform: translateY(-24px) scale(.8); } 100% { opacity: 1; transform: none; } }
@keyframes toastOut { 0% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-14px) scale(.9); } }
@keyframes blink { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes portraitIn { 0% { transform: translateY(30px) scale(.6); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes slam { 0% { transform: rotate(var(--rot, -6deg)) scale(2.8); opacity: 0; } 55% { transform: rotate(var(--rot, -6deg)) scale(.92); opacity: .95; } 75% { transform: rotate(var(--rot, -6deg)) scale(1.05); } 100% { transform: rotate(var(--rot, -6deg)) scale(1); opacity: .92; } }
@keyframes shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-5px, 2px) rotate(-.6deg); } 40% { transform: translate(5px, -2px) rotate(.6deg); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(3px, -1px); } }
@keyframes fall { 0% { transform: translateY(0) rotate(0); } 100% { transform: translateY(125vh) rotate(300deg); } }
@keyframes sway { 0% { transform: translateX(-18px); } 100% { transform: translateX(18px); } }
@keyframes floatUp { 0% { transform: translateY(0) rotate(0); } 100% { transform: translateY(-125vh) rotate(var(--spin, 180deg)); } }
@keyframes bounceLetter { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-7px) rotate(2deg); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }
@keyframes stripes { 0% { background-position: 0 0; } 100% { background-position: 40px 0; } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes polaroidIn { 0% { opacity: 0; transform: translateY(30px) rotate(var(--r, 0deg)) scale(.7); } 100% { opacity: 1; transform: rotate(var(--r, 0deg)); } }

@media (prefers-reduced-motion: reduce) {
  .shape, .hearts-rain .fh, .hearts-rain .fh i, .title-main span, .companion-face, .btn-start, #btn-interact.active, .loading-fill { animation: none !important; }
  .banner-title span { animation-duration: .01ms !important; animation-delay: 0s !important; }
  .polaroid { animation: none; opacity: 1; }
}
