:root {
  --pink: #ff4f9a;
  --pink-deep: #d9307a;
  --blue: #2f8cff;
  --blue-deep: #1a66d1;
  --green: #2fbf55;
  --gold: #ffc531;
  --purple: #b45cff;
  --pearl: #ffd6e8;
  --aqua: #5fd6d8;
  --bg: #0e1f27;
  --bg-2: #183440;
  --text: #f6f3ee;
  --text-dim: #b6c8cc;
  --glyph: #8e8e93;
  --ink: #1c1c1e;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body { overflow: hidden; }

button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.6; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

#app {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 16px);
}

.p0 { --pc: var(--pink); --pc-deep: var(--pink-deep); }
.p1 { --pc: var(--blue); --pc-deep: var(--blue-deep); }

/* ---------- Icon tiles (grey, Shortcuts-style) ---------- */
.tile {
  --s: 44px;
  width: var(--s);
  height: var(--s);
  flex: none;
  border-radius: 24%;
  background: linear-gradient(180deg, #fbfbfd, #e4e4ea);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 2px 6px rgba(0, 0, 0, 0.25);
  display: grid;
  place-items: center;
}
.tile svg { width: 62%; height: 62%; fill: var(--glyph); }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 15px 28px;
  font-size: 19px;
  font-weight: 700;
  background: #fff;
  color: var(--pc-deep, var(--ink));
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18), 0 8px 20px rgba(0, 0, 0, 0.2);
  transition: transform 0.08s ease;
  min-height: 52px;
}
.btn:active { transform: translateY(2px) scale(0.98); }
.btn-green { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-dim); box-shadow: none; font-weight: 600; font-size: 16px; padding: 10px 16px; min-height: 44px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

/* ---------- Setup ---------- */
.setup { overflow-y: auto; gap: 14px; }
.title {
  margin: 4px 0 0;
  text-align: center;
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.title .t-pink { color: var(--pink); }
.title .t-purple { color: var(--purple); }
.subtitle { margin: 0; text-align: center; color: var(--text-dim); font-size: 15px; }
.players { display: grid; gap: 14px; }
.player-panel {
  background: rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  border-top: 5px solid var(--pc);
  padding: 12px 14px 14px;
  display: grid;
  gap: 10px;
  min-width: 0;
}
.player-panel h2 { margin: 0; font-size: 16px; color: var(--pc); text-transform: uppercase; letter-spacing: 0.06em; }
.name-input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: 12px;
  border: 3px solid transparent;
  background: #fff;
  color: var(--ink);
}
.name-input:focus { outline: none; border-color: var(--pc); }
.icon-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 50px);
  grid-auto-columns: 50px;
  gap: 10px;
  overflow-x: auto;
  padding: 4px;
  scrollbar-width: none;
}
.icon-grid::-webkit-scrollbar { display: none; }
.icon-choice { border: 0; padding: 0; background: none; border-radius: 24%; }
.icon-choice .tile { --s: 50px; }
.icon-choice[aria-pressed="true"] { outline: 4px solid var(--pc); outline-offset: 2px; }
.icon-random .tile { background: transparent; box-shadow: none; border: 2px dashed var(--glyph); }
.icon-random .tile svg { fill: var(--text-dim); }
.setup-footer { margin-top: auto; display: flex; justify-content: center; padding-top: 6px; }

/* ---------- Cover screens (round intro, welcome back) ---------- */
.cover {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  background: radial-gradient(120% 90% at 50% 20%, var(--pc, var(--bg-2)), var(--pc-deep, var(--bg)));
}
.cover.neutral { background: radial-gradient(120% 90% at 50% 20%, #2b5560, var(--bg)); }
.cover .tile { --s: 104px; margin-bottom: 4px; }
.cover .kicker { font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.85; margin: 0; }
.cover h1 { margin: 0; font-size: clamp(30px, 8.5vw, 44px); line-height: 1.1; font-weight: 800; max-width: 16ch; }
.cover p { margin: 0; font-size: 19px; max-width: 26ch; line-height: 1.35; opacity: 0.95; }
.cover .btn { margin-top: 14px; }

/* ---------- Game screen ---------- */
.game { gap: 8px; padding-bottom: 0; }
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "p0 mid p1" "banner banner banner";
  align-items: center;
  gap: 8px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 5px 10px 5px 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid transparent;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chip.p0 { grid-area: p0; justify-self: start; }
.chip.p1 { grid-area: p1; justify-self: end; flex-direction: row-reverse; padding: 5px 5px 5px 10px; }
.chip.active { border-color: var(--pc); box-shadow: 0 0 14px color-mix(in srgb, var(--pc) 55%, transparent); }
.chip .tile { --s: 34px; }
.chip-text { display: grid; min-width: 0; line-height: 1.1; }
.chip.p1 .chip-text { text-align: right; }
.chip-name { font-size: 14px; font-weight: 700; color: var(--pc); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9ch; }
.chip-score { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mid { grid-area: mid; display: grid; justify-items: center; gap: 4px; }
.dots { display: flex; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--text-dim); }
.dot.now { border-color: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, 0.6); }
.dot.won0 { background: var(--pink); border-color: var(--pink); }
.dot.won1 { background: var(--blue); border-color: var(--blue); }
.menu-btn { border: 0; background: rgba(255, 255, 255, 0.08); border-radius: 999px; width: 44px; height: 28px; color: var(--text-dim); font-size: 18px; line-height: 1; }
.banner {
  grid-area: banner;
  border-radius: 14px;
  padding: 9px 12px;
  text-align: center;
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  background: var(--pc, #6c3d8f);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--pc, #6c3d8f) 40%, transparent);
  transition: background 0.25s;
}

/* ---------- The scene: canopy, bar, pool ---------- */
.scene {
  --drink: 100px;
  --canopy-h: 80px;
  --bar-h: 220px;
  --pool-h: 120px;
  flex: 1;
  min-height: 0;
  position: relative;
  /* Full bleed: the pool runs to the bottom edge of the screen. */
  margin: 0 calc(-16px - var(--safe-right)) 0 calc(-16px - var(--safe-left));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.canopy {
  flex: none;
  height: var(--canopy-h);
  position: relative;
  z-index: 3;
  background: url("../art/canopy.webp") center bottom / cover no-repeat;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35));
}
html:not(.art-ok) .canopy {
  background: repeating-linear-gradient(90deg, #f6a2c6 0 12.5%, #fdf4f8 12.5% 25%);
  border-radius: 0 0 22px 22px;
}

/* The chrome pole from the canopy down to the bar, behind the drinks. */
.pole {
  position: absolute;
  z-index: 0;
  left: calc(50% - 4px);
  width: 8px;
  top: calc(var(--canopy-h) - 8px);
  height: calc(var(--ellipse-t) + var(--ellipse-h) * 0.45 + 8px);
  border-radius: 4px;
  background: linear-gradient(90deg, #7d8a92, #f4f7f9 40%, #b9c3c9 60%, #6f7b83);
  opacity: 0.85;
}

.bar { flex: none; height: var(--bar-h); position: relative; z-index: 1; }
/* A warm glow behind the bar, as if the scene were lit from inside. */
.bar::before {
  content: "";
  position: absolute;
  left: 5%;
  right: 5%;
  top: -10%;
  bottom: 0;
  background: radial-gradient(closest-side, rgba(255, 214, 232, 0.28), transparent);
  pointer-events: none;
}
.bar-top {
  position: absolute;
  left: var(--ellipse-l);
  top: var(--ellipse-t);
  width: var(--ellipse-w);
  height: var(--ellipse-h);
  background: url("../art/bar.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.4));
}
html:not(.art-ok) .bar-top {
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, #fffafc 0 55%, #f1e3ea 70%, #c8d0d6 90%, #8d99a1 100%);
}

.drink {
  position: absolute;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  display: block;
  -webkit-touch-callout: none;
  z-index: 2;
}
.drink.front { z-index: 3; }
.drink img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
  transform-origin: 50% 92%;
  filter: drop-shadow(0 4px 5px rgba(0, 40, 50, 0.35)) drop-shadow(0 0 12px rgba(255, 236, 210, 0.22));
  transition: opacity 0.25s ease;
}
.drink:active img { transform: scale(0.94); }
.drink.poisoned img {
  animation: poison-glow 1.1s ease-in-out infinite alternate;
}
@keyframes poison-glow {
  from { filter: drop-shadow(0 0 6px rgba(180, 92, 255, 0.7)) drop-shadow(0 4px 5px rgba(0, 40, 50, 0.35)); }
  to { filter: drop-shadow(0 0 18px rgba(200, 120, 255, 0.95)) drop-shadow(0 4px 5px rgba(0, 40, 50, 0.35)); }
}
.bubble {
  position: absolute;
  z-index: 7;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #c98bff 45%, #8a3fe0);
  pointer-events: none;
}

.scene.locked .drink { pointer-events: none; }
.scene.loading .drink img { opacity: 0; }
.scene.loading .bar::after {
  content: "Mixing the drinks…";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 800;
  animation: pulse 1.2s ease-in-out infinite;
}

/* The poison cloud covers the whole bar, so nobody can see which drink got it. */
.cloud {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(var(--canopy-h) - 10px);
  height: calc(var(--bar-h) + 20px);
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse 48% 44% at 30% 45%, rgba(200, 130, 255, 0.85), transparent),
    radial-gradient(ellipse 48% 44% at 70% 50%, rgba(170, 90, 240, 0.85), transparent),
    radial-gradient(ellipse 70% 60% at 50% 55%, rgba(230, 180, 255, 0.75), transparent 80%);
  filter: blur(4px);
}
.sparkle {
  position: absolute;
  z-index: 6;
  width: 16px;
  height: 16px;
  pointer-events: none;
  background: radial-gradient(circle, #fff 0 18%, rgba(255, 255, 255, 0) 20%),
    conic-gradient(from 45deg, transparent 0 20%, #fff 22% 28%, transparent 30% 45%, #fff 47% 53%, transparent 55% 70%, #fff 72% 78%, transparent 80% 95%, #fff 97%);
  -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%);
  mask: radial-gradient(circle, #000 30%, transparent 70%);
  opacity: 0;
}

.pool {
  flex: 1 0 var(--pool-h);
  position: relative;
  z-index: 0;
  margin-top: calc(var(--drink) * -0.12);
  background: url("../art/pool.webp") center top / cover no-repeat;
  box-shadow: inset 0 10px 18px rgba(255, 255, 255, 0.18), inset 0 -20px 30px rgba(0, 30, 40, 0.35);
}
html:not(.art-ok) .pool {
  background:
    repeating-radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.12) 0 4px, transparent 4px 22px),
    linear-gradient(180deg, #7fe3e0, #2fb3c0 60%, #1a8fa3);
}

.flamingo {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 6px 8px rgba(0, 40, 50, 0.4));
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 70%;
  z-index: 40;
  width: max-content;
  max-width: min(86vw, 360px);
  padding: 14px 20px;
  border-radius: 18px;
  background: rgba(20, 20, 22, 0.9);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%) scale(0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- Eyes closed (while the flamingo poisons) ---------- */
/* The whole screen goes dark, so a peek shows nothing. */
.eyes {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 20px) 24px calc(var(--safe-bottom) + 20px);
  text-align: center;
  background: radial-gradient(110% 80% at 50% 40%, #2a1640, #07060c 75%);
  animation: fade-in 0.35s ease;
}
.eyes p { margin: 0; }
.eyes-icon { width: 120px; height: 60px; fill: none; stroke: var(--pearl); stroke-width: 6; stroke-linecap: round; }
.eyes-title { font-size: clamp(30px, 8.5vw, 44px); line-height: 1.1; font-weight: 800; max-width: 14ch; }
.eyes-text { font-size: 19px; max-width: 24ch; line-height: 1.35; color: var(--text-dim); }
.eyes-count { font-size: 96px; line-height: 1; font-weight: 800; color: var(--purple); min-height: 1em; font-variant-numeric: tabular-nums; }
.eyes.open .eyes-icon { display: none; }
.eyes.open .eyes-text { visibility: hidden; }
.eyes.open .eyes-title { color: var(--pearl); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 15, 18, 0.55);
  animation: fade-in 0.2s ease;
}
.modal-backdrop.low { place-items: end center; padding-bottom: calc(var(--safe-bottom) + 20px); background: rgba(10, 15, 18, 0.3); }
.modal {
  width: min(100%, 360px);
  background: #fff;
  color: var(--ink);
  border-radius: 26px;
  padding: 24px 20px 20px;
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: pop-in 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.modal h2 { margin: 0; font-size: 26px; line-height: 1.15; font-weight: 800; }
.modal p { margin: 0; font-size: 17px; color: #48484a; }
.modal .winner { font-size: 21px; font-weight: 800; color: var(--pc-deep); }
.modal .tile { --s: 72px; }
.modal .btn { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15); }
.modal .btn-primary { background: var(--pc, var(--green)); color: #fff; }
.modal .btn-plain { background: #ececf0; color: var(--ink); }
.mini-score { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-score .s0 { color: var(--pink-deep); }
.mini-score .s1 { color: var(--blue-deep); }

/* ---------- Results ---------- */
.results { align-items: center; justify-content: center; text-align: center; gap: 12px; overflow-y: auto; }
.results .tile { --s: 110px; }
.results h1 { margin: 0; font-size: clamp(34px, 10vw, 52px); font-weight: 800; line-height: 1.05; color: var(--pc); }
.results .final-score { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.results .final-score .s0 { color: var(--pink); }
.results .final-score .s1 { color: var(--blue); }
.results .dots { justify-content: center; }
.results .dot { width: 16px; height: 16px; }
.results-flamingo { width: min(40vw, 170px); filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35)); }

/* ---------- Effects ---------- */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
.balloons { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 59; }
.balloon { position: absolute; bottom: -180px; will-change: transform; }
.balloon svg { display: block; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.25)); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(0.85); opacity: 0; } }
@keyframes pulse { 50% { opacity: 0.45; } }

@media (min-width: 700px) {
  .players { grid-template-columns: 1fr 1fr; }
}

/* Short screens: a tighter top bar. */
@media (max-height: 600px) {
  .screen { padding-top: calc(var(--safe-top) + 8px); }
  .game { gap: 6px; }
  .hud { gap: 6px; }
  .chip .tile { --s: 30px; }
  .chip-score { font-size: 19px; }
  .banner { padding: 7px 12px; font-size: 16px; }
  .cover { gap: 10px; }
  .cover .tile { --s: 80px; }
  .eyes-count { font-size: 72px; }
}

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