:root {
  --night: #170826;
  --grape: #2a1147;
  --grape-2: #3a1862;
  --jelly: #9b4dff;
  --pink: #ff4fc8;
  --ember: #ff9a3c;
  --cream: #fff0fa;
  --muted: #b99bd8;
  --line: #ffffff14;
  --fill: #ffffff0f;
  --heat-1: #ff9a3c;
  --heat-2: #ff4a3d;
  --heat-3: #ff4fc8;
  --heat-4: #a855ff;
  --display: "Lilita One", "Baloo 2", system-ui, sans-serif;
  --body: "Baloo 2", system-ui, sans-serif;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 500 17px/1.35 var(--body);
  color: var(--cream);
  background:
    url("assets/bg.png") center / cover no-repeat,
    radial-gradient(120% 60% at 50% 110%, #ff4fc833, transparent 60%),
    radial-gradient(90% 50% at 10% -10%, #9b4dff40, transparent 60%),
    var(--night);
  background-attachment: fixed;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
input { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ember); outline-offset: 2px; }

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
}

/* ---------- jelly buttons: the one signature element ---------- */
.jelly {
  --c: var(--jelly);
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font: 400 20px/1 var(--display);
  letter-spacing: .02em;
  color: #fff;
  background:
    radial-gradient(120% 90% at 30% 15%, #ffffff66, transparent 45%),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 85%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 70%, #000));
  box-shadow:
    inset 0 -6px 10px color-mix(in srgb, var(--c) 60%, #000),
    inset 0 3px 4px #ffffff55,
    0 8px 22px color-mix(in srgb, var(--c) 45%, transparent);
  text-shadow: 0 2px 0 #0003;
  transition: transform .35s var(--spring), filter .2s;
  cursor: pointer;
}
.jelly:active { transform: scale(1.06, .88); transition-duration: .08s; }
.jelly:disabled { filter: saturate(.3) brightness(.7); cursor: not-allowed; }
.jelly.big { font-size: 28px; padding: 20px 28px; }
.jelly.wide { width: 100%; }
.jelly.pink { --c: var(--pink); }
.jelly.ember { --c: var(--ember); }
.jelly.red, .jelly.danger { --c: var(--heat-2); }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: var(--fill);
  cursor: pointer;
  transition: transform .35s var(--spring);
}
.icon-btn:active { transform: scale(.88); }

.ico { width: 1.6em; height: 1.6em; object-fit: contain; vertical-align: middle; }
.li {
  flex: none;
  width: 1.25em; height: 1.25em;
  fill: none; stroke: currentColor; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -.22em;
}
.icon-btn .li { width: 22px; height: 22px; }
/* Pepper fallback (until icon-pepper.png exists): filled flames read better than outlines. */
.peppers .li { fill: currentColor; fill-opacity: .35; }

/* ---------- native-style controls ---------- */
/* Segmented control with a sliding thumb (iOS-like). */
.seg {
  position: relative; flex: none;
  display: grid; grid-template-columns: 1fr 1fr;
  width: 104px; height: 34px; padding: 2px;
  border-radius: 10px;
  background: #ffffff1c;
}
.seg::before {
  content: ""; position: absolute; top: 2px; bottom: 2px; left: 2px; width: calc(50% - 2px);
  border-radius: 8px;
  background: var(--jelly);
  box-shadow: 0 3px 8px #0000004d, inset 0 1px 0 #ffffff40;
  transition: transform .3s var(--ease), background .3s;
}
.seg.f::before { transform: translateX(100%); background: var(--pink); }
.seg button {
  position: relative; z-index: 1;
  border: 0; background: none; padding: 0;
  font-weight: 800; font-size: 15px; color: var(--muted);
  cursor: pointer; transition: color .3s;
}
.seg button[aria-pressed="true"] { color: #fff; }

/* Switch (iOS-like). */
.toggle { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 14px; cursor: pointer; position: relative; }
.toggle + .toggle::before { content: ""; position: absolute; top: 0; left: 14px; right: 0; height: 1px; background: var(--line); }
.toggle .lbl { flex: 1; display: grid; }
.toggle .lbl b { font-weight: 700; }
.toggle .lbl small { color: var(--muted); font-size: 13px; line-height: 1.25; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle .sw { flex: none; width: 51px; height: 31px; border-radius: 999px; background: #ffffff26; position: relative; transition: background .25s var(--ease); }
.toggle .sw::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px #00000040, 0 1px 1px #00000029;
  transition: transform .3s var(--ease);
}
.toggle input:checked + .sw { background: var(--pink); }
.toggle input:checked + .sw::after { transform: translateX(20px); }
.toggle input:focus-visible + .sw { outline: 3px solid var(--ember); outline-offset: 2px; }
.toggle:has(input:disabled) { opacity: .4; cursor: not-allowed; }

/* Inset grouped list (rows share one rounded container). */
.group { border-radius: 16px; background: var(--fill); overflow: hidden; }

/* ---------- lobby ---------- */
.lobby { display: flex; flex-direction: column; gap: 14px; min-height: 0; flex: 1; }

.hero { position: relative; display: flex; align-items: center; justify-content: center; padding-top: 4px; }
.hero .mascot { width: 104px; margin-right: -16px; z-index: 1; animation: bob 3.2s ease-in-out infinite; }
.logo-img { height: 76px; }
.logo-text {
  margin: 0;
  font: 400 50px/1 var(--display);
  color: #fff;
  -webkit-text-stroke: 3px #5a1a9e;
  paint-order: stroke fill;
  text-shadow: 0 5px 0 #5a1a9e, 0 0 30px var(--pink);
  transform: rotate(-5deg);
}
.settings-btn { position: absolute; top: 0; right: 0; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }

.crew { flex: 1; min-height: 0; overflow-y: auto; }
.players { list-style: none; margin: 0; padding: 0; border-radius: 16px; background: var(--fill); }
.player { position: relative; display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 6px 0 12px; }
.player + .player::before { content: ""; position: absolute; top: 0; left: 60px; right: 0; height: 1px; background: var(--line); }
.player.new { animation: rowIn .35s var(--ease); }
.player.leaving { animation: rowOut .22s var(--ease) forwards; }
@keyframes rowIn { from { opacity: 0; transform: translateY(-8px); } }
@keyframes rowOut { to { opacity: 0; transform: translateX(-24px); } }
.avatar {
  position: relative; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font: 400 18px/1 var(--display);
  background: radial-gradient(circle at 35% 30%, #fff8, transparent 40%), var(--av, var(--jelly));
  box-shadow: inset 0 -3px 6px #0005;
}
.player .name { flex: 1; min-width: 0; font-weight: 700; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-del { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.p-del .li { width: 18px; height: 18px; }
.p-del:active { background: var(--fill); }
.empty { margin: 0; padding: 18px; text-align: center; color: var(--muted); }

.add { display: flex; align-items: center; gap: 8px; height: 50px; padding: 0 6px 0 14px; border-radius: 16px; background: var(--fill); }
.add input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font: 700 18px var(--body); color: var(--cream); }
.add input::placeholder { color: var(--muted); font-weight: 500; }
.add-btn {
  flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; color: #fff;
  background: var(--ember); box-shadow: 0 3px 10px #ff9a3c55;
  transition: transform .3s var(--spring);
}
.add-btn:active { transform: scale(.88); }
.add-btn .li { width: 20px; height: 20px; stroke-width: 2.75; }

/* ---------- game ---------- */
.game { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 12px; }
.topbar { display: flex; align-items: center; gap: 8px; }
.fx-list { flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 2px; }
.fx-list::-webkit-scrollbar { display: none; }
/* Shared challenge counter: linked avatars, names, what they do, rounds left. */
.fx {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--pink) 18%, var(--fill));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--pink) 45%, transparent);
  animation: fx-in .45s var(--spring);
}
@keyframes fx-in { from { transform: scale(.6); opacity: 0; } }
.fx-avs { display: flex; align-items: center; }
.fx .avatar { width: 30px; height: 30px; font-size: 15px; }
.fx-link { width: 18px; margin: 0 -5px; z-index: 1; display: grid; place-items: center; color: var(--pink); filter: drop-shadow(0 1px 2px #0008); }
.fx-link .li { width: 16px; height: 16px; fill: currentColor; }
.fx-txt { display: grid; line-height: 1.1; max-width: 140px; }
.fx-txt b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-txt small { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-left { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font: 400 15px/1 var(--display); background: var(--pink); color: #fff; }

.stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; perspective: 1200px; }

.card-wrap { width: min(100%, 360px); aspect-ratio: 2 / 3; max-height: 100%; }
.card-wrap.enter { animation: deal .45s var(--ease) both; }
.card-wrap.tossed { animation: toss .26s ease-in forwards; }
@keyframes toss { to { transform: translate(-30vw, -70vh) rotate(-24deg); opacity: 0; } }
.card {
  --h: var(--heat-1);
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  will-change: transform;
  /* Flip starts while the card is still sliding in, so the question shows ~.6s after landing. */
  transition: transform .6s cubic-bezier(.3, 1.3, .5, 1) .15s;
  touch-action: none;
}
.card.l2 { --h: var(--heat-2); }
.card.l3 { --h: var(--heat-3); }
.card.l4 { --h: var(--heat-4); }
.card.flipped { transform: rotateY(180deg); }
@keyframes deal { from { transform: translateY(60vh) rotate(-10deg) scale(.8); } }
.face {
  position: absolute; inset: 0;
  border-radius: 28px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.back {
  background:
    var(--back-img, none) center / cover no-repeat,
    radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--h) 60%, transparent), transparent 55%),
    repeating-linear-gradient(45deg, #ffffff08 0 12px, transparent 12px 24px),
    var(--grape);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--h) 70%, #fff), 0 20px 50px #0008, 0 0 40px color-mix(in srgb, var(--h) 45%, transparent);
  display: grid; place-items: center;
}
.back .peppers { display: flex; }
.back .peppers .ico, .back .peppers .li { width: 48px; height: 48px; color: color-mix(in srgb, var(--h) 70%, #fff); }
.has-card-art .back .peppers { display: none; }
.front {
  transform: rotateY(180deg);
  background:
    radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--h) 40%, transparent), transparent 60%),
    linear-gradient(180deg, var(--grape-2), var(--grape));
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--h) 80%, #fff), 0 20px 50px #0008;
  display: flex; flex-direction: column;
  padding: 18px 20px 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kind { display: flex; align-items: center; gap: 6px; font: 400 19px var(--display); }
.kind .li { color: color-mix(in srgb, var(--h) 60%, #fff); }
.card-head .peppers { display: flex; }
.card-head .peppers .ico, .card-head .peppers .li { width: 20px; height: 22px; margin-left: -4px; color: var(--h); }
.who { margin: 10px 0 0; font: 400 36px/1 var(--display); color: color-mix(in srgb, var(--h) 55%, #fff); }
.text { flex: 1; display: flex; align-items: center; margin: 0; padding-bottom: 40px; font-size: clamp(24px, 7.4vw, 30px); font-weight: 800; line-height: 1.2; text-wrap: pretty; }
.card .mascot { position: absolute; right: -14px; bottom: -10px; width: 96px; transform: rotate(-8deg); pointer-events: none; }
.timer-btn { align-self: flex-start; display: flex; align-items: center; gap: 8px; }
.timer-ring { font: 400 30px var(--display); }

/* Swipe verdict: the front face tints green (right) or red (left) as it moves. */
.tint {
  --tc: #ff3d4f; --tx: 0%;
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(130% 100% at var(--tx) 50%, color-mix(in srgb, var(--tc) 75%, transparent), transparent 80%);
  box-shadow: inset 0 0 0 4px var(--tc);
  opacity: var(--swa, 0);
}
.card[data-dir="yes"] .tint { --tc: #2ee66b; --tx: 100%; }
/* Duel: tint in the colour of the player being swiped towards, and their name grows. */
.card.duel .tint { --tc: var(--lc); }
.card.duel[data-dir="yes"] .tint { --tc: var(--rc); }
.duel-who span { display: inline-block; transition: transform .2s var(--spring), color .2s; }
.card.duel[data-dir="no"] .duel-who .l, .card.duel[data-dir="yes"] .duel-who .r { transform: scale(calc(1 + var(--swa, 0) * .25)); color: #fff; }
.duel-who { font-size: 30px; }

.actions { display: flex; gap: 10px; }
.actions .jelly { flex: 1; }
.verdict { justify-content: center; }
.skip {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; border: 0; border-radius: 999px;
  background: var(--fill); color: var(--muted);
  font: 800 15px var(--body); cursor: pointer;
  transition: transform .3s var(--spring);
}
.skip:active { transform: scale(.92); }
.skip .li, .skip-ico .li { width: 18px; height: 18px; }
.actions .skip-ico { flex: none; align-self: center; color: var(--muted); }
.who small { font: 400 .55em var(--display); opacity: .7; }

/* ---------- penalty overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 24px;
  background: #0c0316cc;
  backdrop-filter: blur(6px);
  animation: fade .2s both;
}
@keyframes fade { from { opacity: 0; } }
.penalty { width: min(100%, 380px); text-align: center; display: grid; gap: 14px; justify-items: center; }
.penalty .mascot { width: 160px; }
.stamp {
  font: 400 64px/1 var(--display);
  color: var(--heat-2);
  padding: 4px 22px;
  border: 5px solid currentColor; border-radius: 18px;
  transform: rotate(-9deg);
  animation: slam .5s cubic-bezier(.2, 1.6, .4, 1) both;
  text-shadow: 0 0 20px #ff4a3d88;
}
@keyframes slam { from { transform: rotate(-9deg) scale(3); opacity: 0; } }
.penalty p { margin: 0; font-size: 24px; font-weight: 800; line-height: 1.25; }
.penalty p:has(+ p), .penalty p + p { font-size: 20px; }

/* ---------- settings sheet ---------- */
dialog#sheet {
  margin: auto auto 0;
  width: 100%; max-width: 480px;
  max-height: 88dvh;
  border: 0; padding: 0;
  border-radius: 24px 24px 0 0;
  background: #22103a;
  color: var(--cream);
  box-shadow: 0 -10px 40px #000a;
}
dialog#sheet[open] { animation: rise .4s var(--ease); }
@keyframes rise { from { transform: translateY(100%); } }
dialog#sheet::backdrop { background: #0c0316aa; backdrop-filter: blur(3px); }
.sheet-inner { padding: 8px 16px max(16px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: #ffffff33; margin: 0 auto; }
.sheet-inner h2 { margin: 0; font: 400 24px var(--display); }
.sheet-inner h3 { margin: 4px 0 -6px 14px; font-size: 13px; font-weight: 700; color: var(--muted); }
#sheet-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
