:root {
  --gold: #ffd166;
  --pink: #ff6fa5;
  --ink: #fff7ee;
  --glass: rgba(24, 12, 48, .55);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #120a22; color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; top: 0; left: 0; right: 0; padding: max(12px, env(safe-area-inset-top)) 16px 0;
  text-align: center; pointer-events: none; }
#title { margin: 0; font-family: 'Pacifico', cursive; font-weight: 400; font-size: clamp(1.5rem, 5vw, 2.6rem);
  color: var(--gold); text-shadow: 0 2px 18px rgba(255, 150, 80, .6), 0 0 2px #000; }
#tagline { margin: 2px 0 10px; font-size: clamp(.8rem, 2.4vw, 1rem); opacity: .85; text-shadow: 0 1px 6px #000; }
#progress { display: inline-block; padding: 8px 16px 10px; background: var(--glass); border-radius: 18px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, .12); }
#dots { display: flex; gap: 10px; justify-content: center; margin-bottom: 7px; }
.dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800;
  border: 2px solid rgba(255, 255, 255, .35); color: rgba(255, 255, 255, .7); transition: all .4s; }
.dot.done { background: var(--c, var(--pink)); border-color: #fff; color: #fff; box-shadow: 0 0 12px var(--c, var(--pink)); transform: scale(1.1); }
.dot.final { border-color: var(--gold); }
.dot.final.ready { background: var(--gold); color: #5a3a00; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 20px 6px rgba(255, 209, 102, .8); } 0%, 100% { box-shadow: 0 0 6px rgba(255, 209, 102, .5); } }
#bar { height: 6px; width: min(260px, 70vw); border-radius: 6px; background: rgba(255, 255, 255, .15); overflow: hidden; margin: 0 auto; }
#barFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--gold)); transition: width .6s ease; }
#progressText { margin: 6px 0 0; font-size: .8rem; font-weight: 600; }

#hint { position: fixed; bottom: max(14px, env(safe-area-inset-bottom)); left: 0; right: 0; margin: 0; text-align: center;
  font-size: .85rem; opacity: .75; text-shadow: 0 1px 6px #000; pointer-events: none; transition: opacity 1s; }

/* ---------- Toast ---------- */
#toast { position: fixed; left: 50%; bottom: 14%; transform: translate(-50%, 20px); opacity: 0; max-width: 88vw;
  padding: 12px 20px; border-radius: 16px; background: rgba(30, 14, 60, .92); border: 1px solid var(--gold);
  font-weight: 700; text-align: center; transition: all .35s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Message card ---------- */
#modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at center, rgba(40, 15, 70, .55), rgba(5, 2, 15, .85)); animation: fade .35s both; }
#card { width: min(460px, 100%); max-height: 92vh; overflow: auto; text-align: center; padding: 18px 20px 22px;
  border-radius: 24px; background: linear-gradient(160deg, #fff7ee, #ffe3ef); color: #3b2250;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6), 0 0 0 4px var(--accent, var(--gold)); animation: pop .55s cubic-bezier(.2, 1.4, .4, 1) both; }
#cardPhoto { width: 100%; max-height: 42vh; object-fit: cover; border-radius: 16px; margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25); }
#cardTitle { margin: 0 0 8px; font-family: 'Pacifico', cursive; font-weight: 400; font-size: 1.6rem; color: var(--accent-dark, #b3205c); }
#cardMessage { margin: 0 0 16px; line-height: 1.55; font-size: 1.05rem; white-space: pre-line; }
#cardClose { font: inherit; font-weight: 800; border: 0; padding: 11px 32px; border-radius: 999px; cursor: pointer;
  color: #fff; background: linear-gradient(135deg, #ff6fa5, #ff9f1c); box-shadow: 0 6px 16px rgba(255, 111, 165, .5); }
#cardClose:active { transform: scale(.96); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.6) translateY(40px); } }

/* ---------- Loader ---------- */
#loader { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; background: #120a22; transition: opacity .6s; text-align: center; padding: 20px; }
#loader.done { opacity: 0; pointer-events: none; }
#loader code { color: var(--gold); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .15); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .dot { width: 24px; height: 24px; }
  #card { padding: 14px 16px 18px; }
}

/* ---------- Music controls ---------- */
#music { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 15;
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px; background: var(--glass);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,.15); }
#music button { width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; font-size: 18px; color: #fff;
  background: rgba(255,255,255,.12); display: grid; place-items: center; }
#music button:hover { background: rgba(255,255,255,.22); }
#musicBtn.on { background: linear-gradient(135deg, #ff6fa5, #ff9f1c); animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: scale(1.1); } }
#musicVol { width: 90px; accent-color: var(--gold); }
@media (max-width: 520px) { #musicVol { width: 70px; } #hint { bottom: 70px; } }

/* ---------- Grand finale ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 40; pointer-events: none; }
#finale { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: 16px; overflow: auto;
  background: radial-gradient(circle at 50% 40%, rgba(90, 30, 110, .55), rgba(8, 3, 22, .88)); animation: fade .6s both; }
#finaleCard { width: min(560px, 100%); text-align: center; padding: 26px 22px 22px; border-radius: 28px; margin: auto;
  background: linear-gradient(160deg, rgba(255, 247, 238, .97), rgba(255, 224, 238, .97)); color: #3b2250;
  box-shadow: 0 0 0 4px var(--gold), 0 0 60px 10px rgba(255, 190, 90, .55), 0 24px 70px rgba(0, 0, 0, .6);
  animation: pop .9s cubic-bezier(.2, 1.4, .4, 1) both; }
#finaleTitle { margin: 0; font-family: 'Pacifico', cursive; font-size: clamp(1.4rem, 5vw, 2rem); color: #d4488a; }
#finaleName { margin: 0 0 12px; font-family: 'Pacifico', cursive; font-weight: 400; font-size: clamp(2.6rem, 11vw, 4.6rem); line-height: 1.1;
  background: linear-gradient(90deg, #ff4d8d, #ff9f1c, #b5179e); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 3s ease-in-out infinite alternate; }
@keyframes shimmer { to { filter: brightness(1.12) saturate(1.2); } }
#finaleMsg { margin: 0 0 16px; line-height: 1.6; font-size: 1.08rem; white-space: pre-line; }
#finaleVideoWrap { margin: 0 0 16px; border-radius: 16px; overflow: hidden; background: #000; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); }
#finaleVideo { display: block; width: 100%; max-height: 46vh; }
.finale-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.finale-buttons button { font: inherit; font-weight: 800; border: 0; padding: 11px 24px; border-radius: 999px; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, #ff6fa5, #ff9f1c); box-shadow: 0 6px 16px rgba(255, 111, 165, .5); }
.finale-buttons button#finaleClose { background: #7a5a98; box-shadow: none; }
#musicTitle { max-width: 130px; font-size: .78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#musicTitle:empty { display: none; }
@media (max-width: 520px) { #musicTitle { display: none; } }

/* ---------- Letters room ---------- */
#fade { position: fixed; inset: 0; z-index: 45; background: #000; opacity: 0; pointer-events: none; }
#backBtn { position: fixed; left: max(12px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 15;
  font: inherit; font-weight: 800; font-size: .85rem; color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; padding: 11px 16px;
  cursor: pointer; background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#backBtn:hover { background: rgba(255,255,255,.18); }
@media (max-width: 520px) { #backBtn { padding: 10px 12px; font-size: .78rem; } }
