:root {
  --bg-1: #2a1b5e;
  --bg-2: #5b2a86;
  --bg-3: #b8336a;
  --card: #ffffff;
  --ink: #24203a;
  --muted: #6f6a86;
  --line: #e7e3f3;
  --soft: #f4f1fd;
  --primary: #7c5cff;
  --primary-dark: #4d32c7;
  --danger: #e63946;
  --phase: #7c5cff;
  --radius: 24px;
  --display: "Fredoka", "Nunito", system-ui, sans-serif;
  --body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --card: #1d1830;
    --ink: #f3f0ff;
    --muted: #a9a3c4;
    --line: #342c52;
    --soft: #272043;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--body);
  color: var(--ink);
  /* Soft blobs over the gradient, all in the body background (no extra layer). */
  background:
    radial-gradient(circle at 15% 20%, rgb(255 255 255 / 0.1) 0 90px, transparent 91px),
    radial-gradient(circle at 85% 12%, rgb(255 209 102 / 0.16) 0 60px, transparent 61px),
    radial-gradient(circle at 80% 80%, rgb(24 185 138 / 0.14) 0 120px, transparent 121px),
    radial-gradient(circle at 10% 90%, rgb(255 92 154 / 0.16) 0 80px, transparent 81px),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* --- HUD */

.hud {
  position: sticky;
  top: 0;
  z-index: 5;
  max-width: 720px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  color: #fff;
  backdrop-filter: blur(10px);
}

.hud[hidden] { display: none; }

.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.chip {
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--phase) 70%, #000 0%);
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.25);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xp {
  font-family: var(--display);
  font-size: 1.05rem;
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.25);
}

.xp b { font-size: 1.2rem; }

.track {
  position: relative;
  height: 14px;
  margin-top: 10px;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.2);
  overflow: hidden;
}

.track-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffd166, #ff7a45, #ff5c9a);
  transition: width 0.5s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.track-marks i {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 3px;
  margin-left: -1px;
  border-radius: 2px;
  background: rgb(255 255 255 / 0.55);
}

.badges { display: flex; gap: 6px; margin-top: 8px; justify-content: center; }

.badge {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1rem;
  background: rgb(255 255 255 / 0.12);
  filter: grayscale(1);
  opacity: 0.55;
  transition: all 0.4s;
}

.badge.on {
  filter: none;
  opacity: 1;
  background: var(--phase);
  box-shadow: 0 0 0 3px rgb(255 255 255 / 0.85), 0 4px 12px rgb(0 0 0 / 0.3);
  animation: pop 0.5s;
}

.badges.big { margin: 6px 0; gap: 12px; flex-wrap: wrap; }
.badges.big .badge { width: 52px; height: 52px; font-size: 1.6rem; }

/* --- Stage and card */

.stage {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px max(32px, env(safe-area-inset-bottom));
}

.card {
  position: relative;
  margin-top: 8px;
  padding: 32px 24px 24px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 10px 0 color-mix(in srgb, var(--phase) 55%, #1a1033), 0 24px 60px rgb(0 0 0 / 0.35);
  text-align: center;
}

.card.enter { animation: enter 0.45s cubic-bezier(0.2, 1.3, 0.4, 1); }

@keyframes enter {
  from { opacity: 0; transform: translateY(30px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.card.start, .card.done { margin-top: max(5vh, 24px); }

h1, h2, h3 { font-family: var(--display); margin: 0; }

.logo {
  font-size: clamp(2.6rem, 10vw, 4rem);
  line-height: 0.95;
  color: var(--primary);
  text-shadow: 0 4px 0 color-mix(in srgb, var(--primary) 30%, transparent);
}

.logo span { color: #ff5c9a; }
.logo.small { font-size: clamp(2.2rem, 8vw, 3.2rem); }

.lead { margin: 16px auto 0; max-width: 46ch; font-size: 1.08rem; line-height: 1.5; color: var(--muted); }
.lead b { color: var(--ink); }
.fine { margin: 16px 0 0; font-size: 0.9rem; color: var(--muted); }
.fine a { color: var(--primary); font-weight: 800; }
a.btn { display: inline-block; text-decoration: none; }

.kicker {
  margin: 0 0 6px;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--phase);
}

.hero-emoji, .phase-emoji, .q-emoji { line-height: 1; user-select: none; }
.hero-emoji { font-size: 5rem; margin-bottom: 12px; }
.q-emoji { font-size: 3.4rem; margin: 4px 0 10px; }

.phase-emoji {
  width: 128px;
  height: 128px;
  margin: 16px auto;
  display: grid;
  place-items: center;
  font-size: 4.2rem;
  border-radius: 36px;
  background: color-mix(in srgb, var(--phase) 18%, var(--card));
  box-shadow: 0 8px 0 color-mix(in srgb, var(--phase) 45%, transparent);
  transform: rotate(-6deg);
}

.phase-title { font-size: clamp(1.7rem, 6vw, 2.3rem); color: var(--phase); }
.q-title { font-size: clamp(1.45rem, 5.4vw, 2rem); line-height: 1.15; }
.q-sub { margin: 8px auto 0; max-width: 44ch; color: var(--muted); }

.float { animation: float 3s ease-in-out infinite; }
.pop { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
.spin { animation: spin 1s linear infinite; display: inline-block; }

@keyframes float { 50% { transform: translateY(-10px) rotate(4deg); } }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Start form */

.start-form { display: flex; flex-direction: column; gap: 12px; max-width: 380px; margin: 24px auto 0; text-align: left; }
.start-form label { font-weight: 800; }

.field {
  width: 100%;
  font: inherit;
  font-size: 1.1rem; /* ≥16px so iOS doesn't zoom in */
  padding: 14px 16px;
  border-radius: 16px;
  border: 3px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field:focus { outline: none; border-color: var(--phase); box-shadow: 0 0 0 4px color-mix(in srgb, var(--phase) 25%, transparent); }
textarea.field { resize: vertical; min-height: 120px; }
.start-form .field:focus { border-color: var(--primary); }

.shake { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

/* --- Buttons */

.btn {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.1rem;
  padding: 14px 22px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s;
}

.btn.primary {
  color: #fff;
  background: var(--phase);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--phase) 60%, #000);
}

.start .btn.primary { background: var(--primary); box-shadow: 0 6px 0 var(--primary-dark); }
.btn.primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--phase) 60%, #000); }
.btn.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { font-size: 1.25rem; padding: 18px 26px; }

.btn.ghost { background: var(--soft); color: var(--muted); }
.btn.ghost:hover { color: var(--ink); }

.btn:focus-visible, .option:focus-visible, .chip-btn:focus-visible, .swatch:focus-visible, .scale-btn:focus-visible {
  outline: 3px solid var(--phase);
  outline-offset: 3px;
}

.actions { display: flex; gap: 12px; justify-content: space-between; margin-top: 28px; }
.actions.center { justify-content: center; flex-wrap: wrap; }
.actions .btn.primary { flex: 1; max-width: 280px; }
.actions.center .btn.primary { flex: 0 1 auto; }

/* --- Answers */

.q-body { margin-top: 22px; display: flex; flex-direction: column; gap: 16px; text-align: left; }

.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.option, .chip-btn, .swatch, .scale-btn {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  border: 3px solid var(--line);
  background: var(--card);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  font-weight: 700;
  font-size: 1.02rem;
  text-align: left;
}

.option-emoji { font-size: 1.6rem; line-height: 1; }

.option:hover, .chip-btn:hover, .swatch:hover, .scale-btn:hover { border-color: color-mix(in srgb, var(--phase) 50%, var(--line)); }

.option.selected, .chip-btn.selected, .scale-btn.selected, .swatch.selected {
  border-color: var(--phase);
  background: color-mix(in srgb, var(--phase) 20%, var(--card));
  box-shadow: 0 4px 0 color-mix(in srgb, var(--phase) 45%, transparent);
}

.chip-btn.selected { color: #fff; background: var(--phase); }

.options.multi .option.selected::after {
  content: "✓";
  margin-left: auto;
  width: 24px;
  height: 24px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--phase);
  font-size: 0.85rem;
}

.danger .option.selected { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--card)); }
.danger .options.multi .option.selected::after { content: "✕"; background: var(--danger); }
.danger .option.selected .option-label { text-decoration: line-through; text-decoration-thickness: 2px; }

.bump { animation: bump 0.3s; }
@keyframes bump { 40% { transform: scale(0.94); } 70% { transform: scale(1.04); } }

/* Sizes */

.sizes { display: flex; flex-direction: column; gap: 18px; }
.size-group h3 { font-size: 1.1rem; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip-btn {
  min-width: 54px;
  padding: 10px 12px;
  border-radius: 14px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
}

/* Colours */

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  border-radius: 18px;
  font-weight: 700;
  font-size: 0.92rem;
}

.swatch .dot {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 2px rgb(0 0 0 / 0.12);
  display: grid;
  place-items: center;
  transition: transform 0.2s;
}

.swatch.selected .dot { transform: scale(1.1); box-shadow: 0 0 0 4px var(--card), 0 0 0 7px var(--phase); }
.swatch.selected .dot::after { content: "✓"; color: #fff; font-weight: 800; text-shadow: 0 0 4px #000; }

.counter { margin: 0; text-align: center; color: var(--muted); }

/* Scale */

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.scale-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 4px;
  border-radius: 18px;
}

.scale-emoji { font-size: 2.2rem; line-height: 1; transition: transform 0.2s; }
.scale-btn.selected .scale-emoji { transform: scale(1.25); }
.scale-label { font-size: 0.8rem; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.15; }

/* Follow-up and "other" fields */

.extra { display: flex; flex-direction: column; gap: 8px; font-weight: 800; }
.extra.hidden { display: none; }
.follow { animation: enter 0.35s; }

/* --- Finish */

.score {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 10px 22px;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 1.4rem;
  color: #6b4b00;
  background: #ffe7a3;
}

.score b { font-size: 2rem; }

/* --- Floating bits */

.xp-pop {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, 0);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.3rem;
  color: #ffd166;
  text-shadow: 0 2px 0 #7a3e12, 0 0 12px rgb(0 0 0 / 0.4);
  white-space: nowrap;
  animation: rise 1.1s ease-out forwards;
}

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -10px) scale(1.15); }
  to { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 16px;
  font-weight: 700;
  color: #fff;
  background: rgb(20 12 44 / 0.92);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  opacity: 0;
  transform: translate(-50%, 140%);
  transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.25s;
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { display: none; position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }
.confetti.on { display: block; }

/* --- Small phones */

@media (max-width: 480px) {
  .card { padding: 26px 16px 20px; }
  .options { grid-template-columns: 1fr 1fr; }
  .option { flex-direction: column; text-align: center; gap: 6px; padding: 14px 8px; }
  .options.multi .option { position: relative; }
  .options.multi .option.selected::after { position: absolute; top: 6px; right: 6px; }
  .swatches { grid-template-columns: repeat(3, 1fr); }
  .scale { gap: 5px; }
  .scale-emoji { font-size: 1.8rem; }
  .scale-label { font-size: 0.7rem; }
  .actions .btn { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
