:root {
  --accent: #bd96ff;
  --bg: #0a0716;
  --panel: rgba(14, 16, 32, 0.5);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text: #f3f0ff;
  --muted: rgba(243, 240, 255, 0.62);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Fredoka', system-ui, sans-serif;
  transition: background 1.2s ease;
}

#scene,
#scene canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

button {
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  border: 2px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  transition: border-color 0.2s, background 0.2s,
    transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1);
}
button:hover { border-color: var(--accent); background: rgba(255, 255, 255, 0.11); }
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.5; cursor: progress; }

/* ---------- Start screen ---------- */
#start {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(70% 70% at 50% 35%, rgba(0,0,0,0.12), rgba(0,0,0,0.74));
  backdrop-filter: blur(2px);
  z-index: 30;
}
#start[hidden] { display: none; }
.start-card {
  width: min(580px, 100%);
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 28px;
  padding: 30px 34px 28px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
}
.ball {
  font-size: 56px;
  display: inline-block;
  filter: drop-shadow(0 0 18px var(--accent));
  animation: wobble 3.6s ease-in-out infinite;
}
@keyframes wobble {
  0%, 100% { transform: rotate(-13deg); }
  50% { transform: rotate(13deg); }
}
.start-card h1 {
  margin: 4px 0 8px;
  font-size: 60px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
  background: linear-gradient(90deg, #ff5db1, #ffd24d, #5be0ff, #b07bff, #ff5db1);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: partyhue 9s linear infinite;
}
@keyframes partyhue { to { background-position: 300% 0; } }
.tagline { margin: 0 auto 24px; max-width: 44ch; color: var(--muted); line-height: 1.5; font-size: 16px; }

.start-buttons { display: grid; gap: 13px; margin-bottom: 16px; }
.start-buttons button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 16px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 18px;
}
.start-buttons button:hover { transform: translateY(-3px) scale(1.015); }
.start-buttons button small { font-weight: 400; font-size: 13px; color: var(--muted); }
.start-buttons .primary {
  background: var(--accent); /* fallback */
  background: linear-gradient(120deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ff8adf));
  color: #160a22;
  border-color: transparent;
}
.start-buttons .primary small { color: rgba(22, 10, 34, 0.72); }
.start-buttons .primary:hover { filter: brightness(1.06); }

.hint { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin: 8px 0 0; }
.hint em { color: var(--text); font-style: normal; font-weight: 600; }
.warn {
  margin-top: 16px;
  padding: 11px 13px;
  font-size: 13px;
  border-radius: 14px;
  background: rgba(255, 196, 0, 0.13);
  border: 2px solid rgba(255, 196, 0, 0.32);
  color: #ffe39a;
}
.warn code { background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 6px; }
.busy { cursor: progress; }

/* ---------- Brand wordmark (top-right, neon disco) ---------- */
#brand {
  position: fixed;
  top: 18px;
  right: 30px;
  z-index: 22;
  font-family: 'Monoton', cursive;
  font-size: clamp(30px, 4.6vw, 50px);
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow:
    0 0 6px color-mix(in srgb, var(--accent) 80%, #fff),
    0 0 14px var(--accent),
    0 0 30px var(--accent),
    0 0 56px color-mix(in srgb, var(--accent) 60%, transparent);
  animation: neonflicker 5s infinite;
  pointer-events: none;
  user-select: none;
}
@keyframes neonflicker {
  0%, 19%, 23%, 54%, 58%, 100% { opacity: 1; }
  21%, 56% { opacity: 0.62; }
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 18px;
  left: 18px;
  width: 240px;
  padding: 16px 18px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 22px;
  backdrop-filter: blur(13px);
  z-index: 20;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.4);
}
#hud[hidden] { display: none; }
.hud-kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.hud-mood #mood-name {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
  text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: color 1s ease;
}
.hud-mood #mood-blurb { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

.meter { margin-bottom: 10px; }
.meter label {
  display: block;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.bar { height: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.09); overflow: hidden; }
.bar span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: var(--accent); /* fallback */
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #fff));
  transition: width 0.12s linear;
}

.hud-beat { display: flex; align-items: center; gap: 9px; margin-top: 13px; font-size: 14px; color: var(--muted); }
.hud-beat strong { color: var(--text); font-size: 18px; }
#beat-dot {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
}
#beat-dot.hit { animation: beatflash 0.42s ease-out; }
@keyframes beatflash {
  0% { opacity: 1; transform: scale(1.9); box-shadow: 0 0 18px var(--accent); }
  100% { opacity: 0.35; transform: scale(1); box-shadow: none; }
}

.hud-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px solid var(--panel-border);
  font-size: 12.5px;
  color: var(--muted);
}
.hud-foot button { padding: 6px 13px; font-size: 12.5px; border-radius: 12px; }

/* ---------- Journey ribbon ---------- */
#journey {
  position: fixed;
  top: 26px;
  left: 50%;
  transform: translate(-50%, -14px);
  padding: 10px 20px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  font-size: 15px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#journey[hidden] { display: none; }
#journey.show { opacity: 1; transform: translate(-50%, 0); }
#journey .plane { margin-right: 5px; }
#journey strong { font-weight: 700; color: var(--accent); }

/* ---------- Photo card ---------- */
#photo-card {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(860px, 92vw);
  aspect-ratio: 3 / 2;
  max-height: 82vh;
  transform: translate(-50%, -50%) scale(0.9) rotate(-2.5deg);
  border-radius: 26px;
  overflow: hidden;
  z-index: 25;
  opacity: 0;
  transition: opacity 0.6s ease, transform 0.7s cubic-bezier(0.34, 1.4, 0.5, 1);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.65), 0 0 0 2px var(--panel-border);
  background: #000;
}
#photo-card[hidden] { display: none; }
#photo-card.show { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }

#photo-fallback {
  position: absolute;
  inset: 0;
  background: var(--card-grad, linear-gradient(135deg, #444, #111));
}
#photo-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.8s ease, transform 9s ease-out;
  transform: scale(1.04);
}
#photo-img.loaded { opacity: 1; transform: scale(1.13); } /* slow Ken-Burns drift */

.photo-caption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 48px 24px 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.84), rgba(0, 0, 0, 0));
}
.photo-where h2 { margin: 0; font-size: 33px; font-weight: 700; letter-spacing: -0.5px; }
.photo-where p { margin: 2px 0 0; color: var(--muted); font-size: 15.5px; }
.photo-mood {
  margin: 0;
  flex-shrink: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: #160a22;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 55%, transparent);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 18px);
  max-width: min(520px, 90vw);
  padding: 13px 19px;
  border-radius: 16px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  backdrop-filter: blur(10px);
  font-size: 14.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 90, 110, 0.55); background: rgba(60, 12, 20, 0.72); }

@media (max-width: 560px) {
  #hud { width: calc(100% - 36px); }
  .photo-where h2 { font-size: 25px; }
  .start-card h1 { font-size: 46px; }
  #brand { display: none; } /* avoid clashing with the full-width HUD */
}
