:root {
  --bg-2: #120926;
  --ink: #fff8ee;
  --ink-dim: #d9cdf3;
  --outline: #1b0f2e;
  --paper: #fff8ec;
  --pink: #ff5fa2;
  --pink-dark: #b4386f;
  --yellow: #ffd23f;
  --teal: #3ee0c5;
  --violet: #7b61ff;
  --panel: #2a1a4a;
  --font: "Pixelify Sans", ui-monospace, "Segoe UI", system-ui, sans-serif;
  /* chunky pixel border + drop shadow, no blur */
  --px-shadow: 0 0 0 3px var(--outline), 6px 6px 0 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  /* morning sky behind the 3D scene */
  background: linear-gradient(to bottom, #7fb8f0 0%, #b7dafc 45%, #ffe2c4 75%, #ffd1a8 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#scene, #scene canvas { position: fixed; inset: 0; }
#scene canvas { touch-action: none; }
.labels { position: fixed !important; inset: 0; pointer-events: none; }

.hidden { opacity: 0 !important; pointer-events: none !important; transform: translate(-50%, 12px) !important; }

/* ---------- loader ---------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  background: var(--bg-2);
  transition: opacity 0.6s steps(6);
}
#loader.gone { opacity: 0; pointer-events: none; }
.loader-emoji { font-size: 56px; animation: hop 0.9s steps(4) infinite; }
#loader p { font-size: 20px; color: var(--ink-dim); margin: 10px 0 14px; }
.loader-track { width: 220px; height: 14px; background: #241542; box-shadow: 0 0 0 3px var(--outline); }
.loader-track i {
  display: block;
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(90deg, var(--teal) 0 10px, #2bb39c 10px 12px);
  transition: width 0.25s steps(5);
}

/* ---------- speech bubble ---------- */
.bubble {
  position: fixed;
  left: 50%;
  top: max(22px, env(safe-area-inset-top));
  transform: translate(-50%, 0);
  width: min(580px, calc(100vw - 40px));
  padding: 12px 18px 14px;
  background: var(--paper);
  color: #2a1640;
  border-radius: 4px;
  box-shadow: var(--px-shadow);
  transition: opacity 0.25s steps(3), transform 0.25s steps(3);
  z-index: 10;
}
.bubble .who {
  display: inline-block;
  background: var(--pink);
  color: white;
  font-weight: 700;
  font-size: 15px;
  padding: 1px 10px 2px;
  margin-bottom: 6px;
  box-shadow: 0 0 0 2px var(--outline);
}
.bubble .who[hidden] { display: none; }
.bubble .text { margin: 0; font-size: clamp(19px, 2.6vw, 24px); font-weight: 600; line-height: 1.3; }
.bubble.hint {
  top: auto;
  bottom: max(34px, env(safe-area-inset-bottom));
  width: auto;
  max-width: calc(100vw - 40px);
  cursor: pointer;
  animation: nudge 1.2s steps(2) infinite;
}
.bubble.sign .who { background: #8a5a3a; }
.bubble:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 6px; }

/* ---------- caption ---------- */
.caption {
  position: fixed;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  transform: translate(-50%, 0);
  z-index: 10;
  width: min(1100px, calc(100vw - 32px));
  text-align: center;
  line-height: 1.15;
  font-weight: 700;
  font-size: clamp(30px, 6.5vw, 72px);
  color: var(--yellow);
  text-shadow: 4px 4px 0 var(--pink-dark), 8px 8px 0 rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s steps(3);
}
.caption span { display: inline-block; animation: pop-letter 0.4s steps(4) both, bounce 1.2s steps(2) infinite; }

/* ---------- action panel ---------- */
.panel {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 0);
  width: min(620px, calc(100vw - 40px));
  padding: 14px 16px 12px;
  text-align: center;
  background: var(--panel);
  box-shadow: var(--px-shadow);
  z-index: 10;
  transition: opacity 0.25s steps(3), transform 0.25s steps(3);
}
.panel .prompt { margin: 0 0 12px; font-size: 21px; font-weight: 700; }
.panel .help { margin: -6px 0 10px; font-size: 16px; color: var(--ink-dim); }
.panel .row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.panel .status { margin: 10px 0 0; min-height: 1.3em; color: var(--ink-dim); font-size: 16px; }
.panel.compact { width: min(440px, calc(100vw - 40px)); padding: 10px 14px; }
.panel.compact .prompt { font-size: 19px; margin-bottom: 8px; }
.panel.slim { width: auto; max-width: calc(100vw - 40px); padding: 8px 10px; background: rgba(42, 26, 74, 0.85); }
.panel.slim .row { gap: 10px; flex-wrap: nowrap; }
.panel.slim .btn { font-size: 15px; padding: 7px 12px 8px; }
.meter { height: 14px; margin-top: 14px; background: #1a0f33; box-shadow: 0 0 0 3px var(--outline); }
.meter i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, var(--yellow) 0 10px, var(--pink) 10px 20px); }
.meter.hidden { transform: none !important; height: 0; margin: 0; box-shadow: none; }

.btn {
  font-family: var(--font);
  font-size: 19px;
  font-weight: 700;
  border: 0;
  border-radius: 0;
  padding: 10px 20px 11px;
  cursor: pointer;
  color: white;
  box-shadow: 0 0 0 3px var(--outline), inset 0 -5px 0 rgba(0, 0, 0, 0.25), inset 0 3px 0 rgba(255, 255, 255, 0.25);
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 3px var(--outline), inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.btn.primary { background: var(--pink); }
.btn.ghost { background: #4a3480; }
.btn:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 5px; }

/* ---------- touch joystick ---------- */
.stick {
  position: fixed;
  z-index: 9;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  background: rgba(27, 15, 46, 0.35);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7);
  pointer-events: none;
}
.stick[hidden] { display: none; }
.stick i { position: absolute; left: 34px; top: 34px; width: 44px; height: 44px; background: var(--yellow); box-shadow: 0 0 0 3px var(--outline); }

/* ---------- name tags (never transition transform: CSS2DRenderer owns it) ---------- */
.nametag {
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  color: #2a1640;
  background: var(--yellow);
  padding: 0 8px 1px;
  box-shadow: 0 0 0 2px var(--outline);
  opacity: 0;
  transition: opacity 0.3s steps(3);
  white-space: nowrap;
}
.nametag.show { opacity: 1; }

/* ---------- final + fallback cards ---------- */
.final, .fallback {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  padding: 16px 20px max(22px, env(safe-area-inset-bottom));
  transition: opacity 0.6s steps(6);
}
.final { place-items: end center; padding-bottom: max(46px, calc(env(safe-area-inset-bottom) + 38px)); background: linear-gradient(to top, rgba(14, 7, 30, 0.7), transparent 55%); }
.final.hidden { transform: none !important; }
.fallback { place-items: center; background: var(--bg-2); z-index: 60; }
.fallback[hidden] { display: none; }
.card {
  position: relative;
  width: min(560px, 100%);
  text-align: center;
  padding: 30px 22px 18px;
  background: var(--paper);
  color: #2a1640;
  box-shadow: var(--px-shadow);
  animation: card-in 0.5s steps(5) both;
}
.final.hidden .card { animation: none; }
.card-emoji { position: absolute; left: 50%; top: -36px; margin-left: -28px; font-size: 52px; line-height: 1; animation: hop 1.2s steps(2) infinite; }
.card h1 { margin: 0 0 6px; font-size: clamp(26px, 5.5vw, 38px); line-height: 1.1; color: #c2185b; }
.card .msg { margin: 0 0 6px; font-size: 19px; line-height: 1.35; }
.card .names { margin: 0 0 6px; font-size: 16px; color: #6b5a86; }
.card .from { margin: 0 0 14px; font-size: 17px; font-weight: 700; color: var(--violet); }
.card .row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
/* small "built with ♥" line — slides up from the bottom once the final card is in */
.credit-tag {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 25;
  font-size: 14px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 220%);
  transition: transform 0.7s steps(7), opacity 0.7s steps(7);
}
.credit-tag.show { opacity: 1; transform: translate(-50%, 0); }
.credit-tag:empty { display: none; }

/* ---------- full-screen guard ---------- */
.fsguard {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--bg-2);
}
.fsguard[hidden] { display: none; }
.fsguard .msg b { background: var(--yellow); padding: 0 6px; box-shadow: 0 0 0 2px var(--outline); }

/* ---------- message viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 16px;
  background: rgba(7, 5, 13, 0.92);
  cursor: pointer;
}
.viewer[hidden] { display: none; }
.viewer img { max-width: min(100%, 1280px); max-height: calc(100vh - 80px); box-shadow: var(--px-shadow); }
.viewer p { margin: 0; color: var(--ink-dim); font-size: 16px; }

/* ---------- mute ---------- */
.mute {
  position: fixed;
  right: 18px;
  top: max(18px, env(safe-area-inset-top));
  z-index: 30;
  width: 44px;
  height: 44px;
  border: 0;
  background: #2a1a4a;
  box-shadow: 0 0 0 3px var(--outline);
  font-size: 20px;
  cursor: pointer;
}
.mute:focus-visible { outline: 3px dashed var(--yellow); outline-offset: 4px; }

@keyframes hop { 50% { transform: translateY(-8px); } }
@keyframes nudge { 50% { transform: translate(-50%, -6px); } }
@keyframes pop-letter { from { opacity: 0; transform: translateY(24px) scale(0.4); } }
@keyframes bounce { 50% { transform: translateY(-4px); } }
@keyframes card-in { from { opacity: 0; transform: translateY(40px); } }

@media (max-width: 600px) {
  .btn { font-size: 17px; padding: 9px 14px 10px; }
  .panel .prompt { font-size: 19px; }
  .bubble:not(.hint), .caption { top: max(74px, calc(env(safe-area-inset-top) + 60px)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
