:root {
  --pink-50: #fff6fb;
  --pink-100: #ffe9f4;
  --pink-200: #ffd0e7;
  --pink-300: #ffaed4;
  --pink-400: #ff85bd;
  --pink-500: #f45fa3;
  --pink-700: #c23a7e;
  --ink: #6b2c55;
  --ink-soft: #a46b8f;
  --white: #ffffff;
  --card: rgba(255, 255, 255, 0.72);
  --shadow: 0 20px 50px -20px rgba(214, 72, 145, 0.45);
  --font-display: "Pacifico", "Brush Script MT", cursive;
  --font-body: "Fredoka", "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: #fff3fa;
  overflow-x: hidden;
}

/* ---------- dreamy background ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(40px); opacity: .3;
  animation: drift 18s ease-in-out infinite alternate;
}
.blob.b1 { width: 380px; height: 380px; background: #ffc4e1; top: 8%; left: -80px; }
.blob.b2 { width: 320px; height: 320px; background: #dcc8ff; top: 40%; right: -60px; animation-delay: -6s; }
.blob.b3 { width: 280px; height: 280px; background: #c8e8ff; bottom: -60px; left: 30%; animation-delay: -12s; }
@keyframes drift { to { transform: translate(40px, -30px) scale(1.08); } }

.twinkle {
  position: absolute; color: var(--white); text-shadow: 0 0 8px #ffb6da, 0 0 16px #ffd6ec;
  animation: twinkle 3.2s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: .15; transform: scale(.6) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.1) rotate(25deg); }
}

/* ---------- layout ---------- */
main {
  position: relative; z-index: 1;
  max-width: 1120px; margin: 0 auto;
  padding-block: 48px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

header { text-align: center; margin-bottom: 36px; }
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 16px; border-radius: 999px;
  background: rgba(255,255,255,.7); border: 1.5px solid var(--pink-200);
  font-weight: 500; font-size: 14px; color: var(--pink-700); letter-spacing: .04em;
  box-shadow: 0 6px 18px -10px rgba(244, 95, 163, .6);
}
h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(44px, 8vw, 84px); line-height: 1.45;
  margin: 14px 0 16px; text-wrap: balance;
  color: var(--pink-500);
  filter: drop-shadow(0 4px 0 rgba(255,255,255,.9)) drop-shadow(0 10px 22px rgba(244,95,163,.3));
}
.lead { font-size: clamp(16px, 2.2vw, 19px); color: var(--ink-soft); max-width: 560px; margin: 0 auto; }

.stage {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 22px; align-items: start;
}
@media (max-width: 820px) { .stage { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--card);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 28px; padding: 22px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,190,222,.35);
  position: relative; min-width: 0;
}
.card::before {
  content: "🎀"; position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: 30px; filter: drop-shadow(0 4px 6px rgba(244,95,163,.35));
}

.card h2 { margin: 6px 0 4px; font-size: 20px; font-weight: 600; }
.hint { margin: 0 0 14px; font-size: 14px; color: var(--ink-soft); }

textarea {
  width: 100%; min-height: 240px; resize: vertical;
  font: 500 16px/1.7 var(--font-body); color: var(--ink);
  padding: 14px 16px; border-radius: 20px;
  border: 2px solid var(--pink-200); background: var(--pink-50);
  background-image: repeating-linear-gradient(transparent 0 26.2px, #ffe0ef 26.2px 27.2px);
  background-position: 0 13px; background-attachment: local;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
textarea:focus { border-color: var(--pink-400); box-shadow: 0 0 0 5px rgba(255,133,189,.18); }
textarea::placeholder { color: #d9a3c2; }

.count { margin-top: 8px; font-size: 13px; color: var(--ink-soft); text-align: right; }

.go {
  position: relative; overflow: hidden;
  width: 100%; margin-top: 14px; padding: 16px 20px;
  font: 700 22px var(--font-body); letter-spacing: .08em; color: var(--white);
  border: none; border-radius: 999px; cursor: pointer;
  background: var(--pink-500);
  box-shadow: 0 10px 0 -2px #d94a92, 0 18px 30px -10px rgba(244,95,163,.7);
  text-shadow: 0 2px 0 rgba(194,58,126,.45);
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.go::after {
  content: ""; position: absolute; top: 0; left: -60%; width: 40%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255,255,255,.65), transparent);
  transform: skewX(-20deg); animation: shine 2.8s ease-in-out infinite;
}
@keyframes shine { 0%, 60% { left: -60%; } 100% { left: 130%; } }
.go:hover { filter: brightness(1.05) saturate(1.1); }
.go:active { transform: translateY(6px); box-shadow: 0 4px 0 -2px #d94a92, 0 10px 20px -10px rgba(244,95,163,.7); }
.go:disabled { cursor: default; filter: grayscale(.3) opacity(.75); }
.go:disabled::after { animation: none; }
.go:focus-visible, .ghost:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 3px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- track ---------- */
.track-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin: 6px 0 14px; flex-wrap: wrap;
}
.leader {
  font-size: 14px; padding: 6px 14px; border-radius: 999px;
  background: var(--white); border: 1.5px solid var(--pink-200); color: var(--pink-700);
  min-height: 32px; display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.track {
  position: relative; border-radius: 22px; overflow: hidden;
  background: #fffafd;
  border: 2px solid var(--pink-200);
}

.lane {
  display: grid; grid-template-columns: var(--label-w, 120px) minmax(0, 1fr);
  height: var(--lane-h, 56px); align-items: center;
  /* Bobbing racers and sparkles stay inside their lane, so the track never flashes a scrollbar mid-race. */
  overflow: hidden;
}
.lane:nth-child(odd) { background: rgba(255, 214, 234, .32); }
.lane + .lane { border-top: 2px dashed #ffd9ec; }

.label {
  padding: 0 10px 0 14px; font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .2s;
}
.lane.leading .label { color: var(--pink-500); }

.run {
  position: relative; height: 100%;
  border-left: 3px solid var(--white);
  margin-right: 22px;
}
.run::after {
  content: ""; position: absolute; top: 0; bottom: 0; right: -22px; width: 14px;
  background: conic-gradient(#ff85bd 0 25%, #fff 0 50%, #ff85bd 0 75%, #fff 0) 0 0 / 14px 14px;
  opacity: .85;
}

.racer {
  position: absolute; top: 50%; left: 0;
  width: var(--bubble, 46px); height: var(--bubble, 46px);
  margin-top: calc(var(--bubble, 46px) / -2);
  will-change: transform; z-index: 2;
}
.bubble {
  width: 100%; height: 100%; border-radius: 50%;
  display: grid; place-items: center;
  font-size: calc(var(--bubble, 46px) * .56);
  background: var(--white); border: 3px solid var(--c, #ff85bd);
  box-shadow: 0 6px 14px -6px var(--c, #ff85bd), inset 0 -4px 0 rgba(0,0,0,.04);
}
.racing .bubble { animation: bob .32s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-3px) rotate(-6deg); } to { transform: translateY(3px) rotate(6deg); } }
.lane.won .bubble { animation: pop .6s ease-out infinite alternate; box-shadow: 0 0 0 6px rgba(255,255,255,.8), 0 0 24px var(--c); }
@keyframes pop { to { transform: scale(1.15); } }

.spark {
  position: absolute; top: 50%; pointer-events: none; z-index: 1;
  font-size: 12px; color: var(--c, #ff85bd);
  animation: spark .7s ease-out forwards;
}
@keyframes spark {
  from { opacity: 1; transform: translate(0, -50%) scale(1); }
  to { opacity: 0; transform: translate(-18px, calc(-50% + var(--dy, 0px))) scale(.3) rotate(90deg); }
}

.empty { padding: 60px 20px; text-align: center; color: var(--ink-soft); }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }

.flash {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 5;
  font-family: var(--font-display); font-size: clamp(56px, 10vw, 110px); color: var(--white);
  text-shadow: 0 4px 0 var(--pink-500), 0 0 30px rgba(244,95,163,.6);
  opacity: 0;
}
.flash.show { animation: flash .8s ease-out; }
@keyframes flash {
  0% { opacity: 0; transform: scale(.4); }
  30% { opacity: 1; transform: scale(1.1); }
  100% { opacity: 0; transform: scale(1.4); }
}

.track-wrap { position: relative; }

/* ---------- winner modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; display: none; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: rgba(255, 220, 238, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal.open { display: grid; animation: fade .3s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal .card { width: min(420px, 100%); text-align: center; padding: 34px 24px 26px; animation: rise .5s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes rise { from { transform: translateY(30px) scale(.9); opacity: 0; } }
.modal .label-top { font-size: 15px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-soft); }
.modal .w-emoji { font-size: 72px; margin: 6px 0 0; animation: pop .7s ease-in-out infinite alternate; display: inline-block; }
.modal .w-name {
  font-family: var(--font-display); font-size: clamp(32px, 8vw, 46px); line-height: 1.3;
  margin: 4px 0 18px; word-break: break-word;
  color: var(--pink-500);
}
.row { display: flex; gap: 10px; }
.row .go { margin-top: 0; font-size: 17px; padding: 13px 16px; }
.ghost {
  flex: 1; padding: 13px 16px; border-radius: 999px; cursor: pointer;
  font: 600 17px var(--font-body); color: var(--pink-700);
  background: var(--white); border: 2px solid var(--pink-200);
}
.ghost:hover { border-color: var(--pink-400); }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; }

footer { text-align: center; margin-top: 40px; color: var(--ink-soft); font-size: 14px; }

/* ---------- host dashboard ---------- */
.home-stage { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 820px) { .home-stage { grid-template-columns: minmax(0, 1fr); } }
.solo { max-width: 520px; margin: 0 auto; text-align: center; }
.solo .big { font-size: 52px; display: block; margin: 8px 0 4px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.text-input {
  width: 100%; font: 500 16px var(--font-body); color: var(--ink);
  padding: 12px 16px; border-radius: 999px;
  border: 2px solid var(--pink-200); background: var(--pink-50); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.text-input:focus { border-color: var(--pink-400); box-shadow: 0 0 0 5px rgba(255,133,189,.18); }
.form-note { margin: 10px 0 0; font-size: 13px; line-height: 1.45; color: var(--ink-soft); min-height: 1em; }
.form-note.error { color: var(--pink-700); font-weight: 500; }

.race-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.race-item {
  background: var(--white); border: 2px solid var(--pink-100); border-radius: 22px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px; transition: border-color .3s, box-shadow .3s;
}
.race-item.fresh { border-color: var(--pink-400); box-shadow: 0 0 0 5px rgba(255,133,189,.18); }
.race-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.race-title { font-weight: 600; font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.race-meta { font-size: 13px; color: var(--ink-soft); }
.link-row { display: flex; gap: 8px; }
.link-row .text-input { font-size: 13px; padding: 8px 14px; min-width: 0; flex: 1; color: var(--ink-soft); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-sm {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font: 600 14px var(--font-body); color: var(--pink-700);
  background: var(--white); border: 2px solid var(--pink-200); white-space: nowrap;
}
.btn-sm:hover { border-color: var(--pink-400); }
.btn-sm.primary { color: var(--white); border-color: transparent; background: var(--pink-500); }
.btn-sm.danger.armed { color: var(--white); background: var(--pink-700); border-color: var(--pink-700); }
.btn-sm:focus-visible, .text-input:focus-visible, .back:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 2px; }
.list-empty { text-align: center; padding: 30px 10px; color: var(--ink-soft); }
.list-empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; padding: 0; list-style: none; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--white);
  border: 2px solid var(--pink-100); font-weight: 500; font-size: 15px; overflow-wrap: anywhere;
}
.back {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 14px;
  font: 600 14px var(--font-body); color: var(--pink-700); background: none; border: none; cursor: pointer; padding: 4px 0;
}
.back:hover { text-decoration: underline; }

/* ---------- racer photos ---------- */
.photo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.photo-row {
  display: flex; align-items: center; gap: 10px; padding: 5px 6px 5px 5px;
  background: var(--white); border: 2px solid var(--pink-100); border-radius: 999px;
}
.photo-av, .chip-av {
  flex: none; width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; font-size: 18px;
  background: var(--pink-50); border: 2px solid var(--pink-200);
}
.photo-av img, .chip-av img, .bubble img, .w-emoji img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.photo-name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-row .btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-sm:disabled { opacity: .6; cursor: default; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; }
.chip-av { width: 28px; height: 28px; font-size: 15px; }
.bubble { overflow: hidden; }
.modal .w-emoji img { width: 112px; height: 112px; border: 4px solid var(--white); box-shadow: var(--shadow); }

/* ---------- admin ---------- */
.topbar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 14px; color: var(--ink-soft); }
.topbar form { margin: 0; }
.login { max-width: 400px; margin: 0 auto; }
.login .go { margin-top: 4px; }
a.btn-sm { text-decoration: none; display: inline-flex; align-items: center; }

/* ---------- monthly challenge ---------- */
.report {
  margin-top: 16px; padding: 14px 16px; text-align: left; font-size: 14px;
  background: var(--white); border: 2px dashed var(--pink-200); border-radius: 18px;
}
.report p { margin: 0 0 6px; }
.report ul { margin: 0; padding-left: 20px; overflow-wrap: anywhere; }
.tabs {
  display: flex; gap: 6px; width: fit-content; margin: 0 auto 30px; padding: 5px;
  background: rgba(255,255,255,.7); border: 2px solid var(--pink-200); border-radius: 999px;
}
.tab {
  padding: 9px 26px; border: none; border-radius: 999px; cursor: pointer;
  font: 600 16px var(--font-body); color: var(--pink-700); background: none;
}
.tab[aria-selected="true"] { color: var(--white); background: var(--pink-500); }
.tab:disabled { opacity: .5; cursor: default; }
.tab:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 2px; }

.gallery { list-style: none; margin: 0; padding: 0; columns: 4 200px; column-gap: 14px; }
.gallery li { break-inside: avoid; margin-bottom: 14px; }
.shot {
  display: block; position: relative; overflow: hidden;
  border-radius: 20px; border: 3px solid var(--white); background: var(--pink-50);
  box-shadow: 0 10px 24px -14px rgba(214, 72, 145, .7);
  transition: transform .2s, box-shadow .2s;
}
.shot:hover { transform: translateY(-3px) rotate(-1deg); box-shadow: 0 16px 30px -14px rgba(214, 72, 145, .8); }
.shot:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 3px; }
.shot img { width: 100%; height: auto; display: block; }
.shot .by {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; color: var(--pink-700); background: rgba(255,255,255,.9);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.lightbox {
  position: fixed; inset: 0; z-index: 25;
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: rgba(255, 220, 238, .82); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: fade .25s ease-out;
}
.lightbox[hidden] { display: none; }
.lb-figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 0; width: 100%; }
.lb-stage { position: relative; width: 100%; height: calc(100vh - 170px); height: calc(100dvh - 170px); }
.lb-stage img {
  position: absolute; object-fit: cover; border-radius: 18px; background: var(--white);
  box-shadow: 0 0 0 4px var(--white), var(--shadow);
  animation: fade .3s ease-out;
}
.lb-figure figcaption { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; justify-content: center; }
.lb-by { font-family: var(--font-display); font-size: clamp(26px, 5vw, 38px); color: var(--pink-500); line-height: 1.3; overflow-wrap: anywhere; }
.lb-count { font-size: 14px; color: var(--ink-soft); }
.lb-btn {
  width: 48px; height: 48px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center;
  font: 600 28px/1 var(--font-body); color: var(--pink-700);
  background: var(--white); border: 2px solid var(--pink-200);
  box-shadow: 0 8px 18px -10px rgba(214, 72, 145, .7);
}
.lb-btn:hover { border-color: var(--pink-400); }
.lb-btn:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 2px; }
.lb-top { position: absolute; top: max(16px, env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); display: flex; gap: 8px; }
.lb-top .lb-btn { font-size: 18px; }
.lb-progress { position: absolute; top: 0; left: 0; right: 0; height: 5px; background: rgba(255,255,255,.6); }
.lb-progress span { display: block; height: 100%; width: 0; background: var(--pink-500); border-radius: 0 99px 99px 0; }
.w-emoji.zoomable { cursor: zoom-in; border-radius: 50%; }
.w-emoji.zoomable:focus-visible { outline: 3px solid var(--pink-500); outline-offset: 4px; }
.gallery-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

@media (max-width: 520px) {
  main { padding-block: 32px 48px; }
  .gallery { columns: 2; column-gap: 10px; }
  .gallery li { margin-bottom: 10px; }
  .lightbox { grid-template-columns: minmax(0, 1fr); }
  .lb-prev, .lb-next { display: none; }
  .lane { --label-w: 86px; }
  .label { font-size: 13px; padding-left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .twinkle, .go::after { animation: none; }
}
