/* =========================================================================
 * TUMBLE BEANS - css/style.css
 * All DOM UI styling: chunky, rounded, bouncy party-game look.
 * System fonts only. #ui is pointer-events:none; only .screen.interactive
 * accepts input, so hidden/passive UI never blocks the game canvas.
 * ========================================================================= */

:root {
  --pink: #ff5d8f;
  --teal: #4ecdc4;
  --yellow: #ffd166;
  --purple: #845ec2;
  --orange: #ff9f1c;
  --red: #ff595e;
  --green: #8ac926;
  --blue: #1982c4;
  --cyan: #2ec4b6;
  --candy: #ff70a6;
  --ink: #3c2a5e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #7ee0ff;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold",
    "Hiragino Maru Gothic ProN", "Comic Sans MS", "Trebuchet MS",
    "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ------------------------------------------------------------- UI root */

#ui {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 10;
  pointer-events: none; /* inherited by everything unless overridden */
}

.hidden { display: none !important; }

/* Thick text with colored outline (ring of text-shadows, em-scaled). */
.ol {
  --oc: #fff;
  --ow: 0.055em;
  --dc: rgba(60, 42, 94, 0.28);
  --dy: 0.11em;
  text-shadow:
    var(--ow) 0 0 var(--oc),
    calc(-1 * var(--ow)) 0 0 var(--oc),
    0 var(--ow) 0 var(--oc),
    0 calc(-1 * var(--ow)) 0 var(--oc),
    calc(var(--ow) * 0.72) calc(var(--ow) * 0.72) 0 var(--oc),
    calc(var(--ow) * -0.72) calc(var(--ow) * 0.72) 0 var(--oc),
    calc(var(--ow) * 0.72) calc(var(--ow) * -0.72) 0 var(--oc),
    calc(var(--ow) * -0.72) calc(var(--ow) * -0.72) 0 var(--oc),
    0 var(--dy) 0 var(--dc);
}

/* ----------------------------------------------------------------- HUD */

.hud {
  position: absolute;
  top: 14px;
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 0 18px;
  transform: translateY(0);
  opacity: 1;
  transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.3s ease;
}
.hud.hud-hidden {
  transform: translateY(-140%);
  opacity: 0;
}
.hud-zone { display: flex; gap: 10px; align-items: center; }
.hud-left { justify-content: flex-start; }
.hud-center { justify-content: center; }
.hud-right { justify-content: flex-end; }

.pill {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  background: rgba(255, 255, 255, 0.94);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 8px 20px;
  font-weight: 900;
  box-shadow: 0 5px 0 rgba(60, 42, 94, 0.16), 0 8px 18px rgba(60, 42, 94, 0.12);
}
.pill-label {
  font-size: 13px;
  letter-spacing: 0.14em;
  opacity: 0.75;
}
.pill-value {
  font-size: 24px;
  line-height: 1;
  display: inline-block;
}
.pill-qual { color: #0d8f85; }
.pill-rem { color: #d97706; }
.pill-timer { color: var(--purple); }
.pill-timer .pill-value { font-size: 28px; min-width: 2.6em; text-align: center; }
.pill-timer.urgent {
  color: #fff;
  border-color: #ffd9e0;
  animation: pulseRed 0.6s ease-in-out infinite;
}

.pop { animation: valuePop 0.28s cubic-bezier(0.2, 1.8, 0.4, 1); }

@keyframes valuePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22) rotate(-2deg); }
  100% { transform: scale(1); }
}
@keyframes pulseRed {
  0%, 100% { background: #ff595e; transform: scale(1); }
  50% { background: #ff2e44; transform: scale(1.07); }
}

/* -------------------------------------------------------------- banner */

.banner-host {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  z-index: 25;
  display: flex;
  justify-content: center;
}
.banner {
  font-size: clamp(34px, 7vw, 64px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  padding: 10px 40px;
  border-radius: 26px;
  border: 5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 0 rgba(60, 42, 94, 0.2), 0 14px 30px rgba(60, 42, 94, 0.22);
  animation: bannerIn 0.45s cubic-bezier(0.18, 1.6, 0.4, 1);
}
.banner-good { background: linear-gradient(180deg, #9ee037, #6aa31e); --oc: #4d7a12; }
.banner-bad { background: linear-gradient(180deg, #ff6f7d, #e63950); --oc: #a3122a; }
.banner-info { background: linear-gradient(180deg, #ffd166, #ff9f1c); --oc: #c96f00; }
.banner-out { animation: bannerOut 0.45s ease forwards; }

@keyframes bannerIn {
  0% { transform: translateY(-46px) scale(0.5) rotate(-4deg); opacity: 0; }
  60% { transform: translateY(6px) scale(1.08) rotate(1deg); opacity: 1; }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
@keyframes bannerOut {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.6) translateY(-20px); opacity: 0; }
}

/* ----------------------------------------------------------- countdown */

.count-host {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}
.count-num {
  font-size: clamp(110px, 26vw, 250px);
  font-weight: 900;
  color: #fff;
  --ow: 0.06em;
  animation: countPop 0.78s cubic-bezier(0.2, 1.5, 0.5, 1) forwards;
}
.count-3 { --oc: var(--pink); }
.count-2 { --oc: var(--teal); }
.count-1 { --oc: var(--yellow); }
.count-go {
  --oc: var(--green);
  font-size: clamp(120px, 30vw, 290px);
  animation: goPop 0.7s cubic-bezier(0.2, 1.5, 0.5, 1) forwards;
}

@keyframes countPop {
  0% { transform: scale(0.15) rotate(-10deg); opacity: 0; }
  30% { transform: scale(1.18) rotate(3deg); opacity: 1; }
  55% { transform: scale(0.98) rotate(0deg); opacity: 1; }
  80% { transform: scale(1.02); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0; }
}
@keyframes goPop {
  0% { transform: scale(0.2); opacity: 0; }
  35% { transform: scale(1.3) rotate(-2deg); opacity: 1; }
  65% { transform: scale(1.12) rotate(1deg); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* ----------------------------------------------------- screens (base) */

.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: screenIn 0.35s ease;
}
.screen.interactive { pointer-events: auto; }
.screen-out { animation: screenOut 0.35s ease forwards; }

@keyframes screenIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes screenOut { from { opacity: 1; } to { opacity: 0; } }

@keyframes cardPop {
  0% { transform: scale(0.5) rotate(-4deg); opacity: 0; }
  60% { transform: scale(1.06) rotate(1deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* ------------------------------------------------------------- buttons */

.btn {
  pointer-events: auto;
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: #fff;
  font-size: 22px;
  padding: 15px 42px;
  border-radius: 999px;
  background: linear-gradient(180deg, #9b7fd4, #845ec2);
  box-shadow:
    0 6px 0 rgba(60, 42, 94, 0.28),
    0 12px 22px rgba(60, 42, 94, 0.22),
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.13s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.13s, filter 0.13s;
}
.btn:hover { transform: translateY(-3px) scale(1.05); filter: brightness(1.07); }
.btn:active {
  transform: translateY(3px) scale(0.96);
  box-shadow: 0 2px 0 rgba(60, 42, 94, 0.28), inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

.btn-primary { background: linear-gradient(180deg, #9ee037, #64a11a); }
.btn-danger { background: linear-gradient(180deg, #ff6f7d, #e0314b); }
.btn-secondary {
  background: linear-gradient(180deg, #ffffff, #e9e2f7);
  color: var(--purple);
  text-shadow: none;
}
.btn-play {
  font-size: clamp(26px, 4.5vw, 38px);
  padding: 20px 68px;
  background: linear-gradient(180deg, #ffd166, #ff9f1c);
  animation: btnThrob 1.5s ease-in-out infinite;
}

@keyframes btnThrob {
  0%, 100% { transform: scale(1) rotate(-1deg); }
  50% { transform: scale(1.06) rotate(1deg); }
}

.btn-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 26px;
}
.btn-row.btn-col { flex-direction: column; align-items: center; gap: 14px; }

.footnote {
  margin-top: 20px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: rgba(60, 42, 94, 0.6);
}

/* --------------------------------------------------------------- title */

.title-screen {
  background: linear-gradient(180deg, #7ee0ff 0%, #a9dcff 45%, #cdb4ff 100%);
}
.title-bg { position: absolute; inset: 0; overflow: hidden; }
.blob {
  position: absolute;
  border-radius: 46% 54% 52% 48% / 58% 56% 44% 42%;
  background: rgba(255, 255, 255, 0.35);
  animation: blobFloat 9s ease-in-out infinite;
}
@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) rotate(-6deg); }
  50% { transform: translate(14px, -34px) rotate(8deg); }
}

.title-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: cardPop 0.55s cubic-bezier(0.2, 1.5, 0.5, 1);
}

.logo { text-align: center; transform: rotate(-3deg); animation: logoSway 4s ease-in-out infinite; }
.logo-word { display: block; line-height: 0.92; white-space: nowrap; }
.logo-word-bottom { margin-top: 0.02em; }
.lg {
  display: inline-block;
  font-weight: 900;
  --ow: 0.06em;
  --dc: rgba(60, 42, 94, 0.3);
  animation: letterBounce 1.7s cubic-bezier(0.36, 0, 0.3, 1) infinite;
}
.logo-word-top .lg { font-size: clamp(44px, 10vw, 96px); }
.logo-word-bottom .lg { font-size: clamp(58px, 13.5vw, 128px); }

@keyframes letterBounce {
  0%, 52%, 100% { transform: translateY(0) scale(1, 1); }
  22% { transform: translateY(-0.16em) scale(0.95, 1.08); }
  38% { transform: translateY(0.03em) scale(1.08, 0.92); }
}
@keyframes logoSway {
  0%, 100% { transform: rotate(-3.5deg); }
  50% { transform: rotate(-1.5deg); }
}

.tagline {
  margin-top: 10px;
  font-size: clamp(20px, 3.4vw, 30px);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--pink);
  --oc: #fff;
  --dc: rgba(60, 42, 94, 0.2);
  transform: rotate(-2deg);
  animation: tagBob 2.4s ease-in-out infinite;
}
@keyframes tagBob {
  0%, 100% { transform: rotate(-2deg) scale(1); }
  50% { transform: rotate(-2deg) scale(1.05); }
}

.controls-card {
  margin-top: 26px;
  background: rgba(255, 255, 255, 0.88);
  border: 4px solid #fff;
  border-radius: 24px;
  padding: 16px 26px;
  box-shadow: 0 8px 0 rgba(60, 42, 94, 0.14), 0 14px 28px rgba(60, 42, 94, 0.14);
  display: grid;
  grid-template-columns: auto auto;
  gap: 10px 0;
}
.ctrl-row { display: contents; }
.ctrl-keys { display: flex; gap: 5px; justify-content: flex-end; padding-right: 14px; }
.ctrl-label {
  font-size: 17px;
  font-weight: 900;
  color: var(--ink);
  align-self: center;
  letter-spacing: 0.04em;
}
.kbd {
  display: inline-block;
  min-width: 30px;
  text-align: center;
  background: #fff;
  border: 2px solid #e5dcf6;
  border-radius: 9px;
  padding: 3px 9px;
  font-size: 14px;
  font-weight: 900;
  color: var(--purple);
  box-shadow: 0 3px 0 #d8ccf0;
}

.title-box .btn-play { margin-top: 28px; }

/* mascots */
.mascot {
  position: absolute;
  width: 74px;
  height: 100px;
  animation: mascotBob 2.2s ease-in-out infinite;
}
.mascot-left { left: -120px; bottom: 130px; transform: rotate(-8deg); }
.mascot-right { right: -120px; bottom: 150px; animation-delay: -1.1s; transform: rotate(8deg); }
.mascot-body {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50% 50% 46% 46% / 58% 58% 42% 42%;
  box-shadow: inset -6px -8px 0 rgba(0, 0, 0, 0.08), 0 8px 0 rgba(60, 42, 94, 0.15);
}
.mascot-eyes {
  position: absolute;
  top: 26%;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 12px;
}
.mascot-eye {
  width: 16px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 58%, #2b2440 0 34%, #fff 36%);
}
.mascot-smile {
  position: absolute;
  top: 52%;
  left: 50%;
  width: 18px;
  height: 10px;
  transform: translateX(-50%);
  border: 3px solid #2b2440;
  border-top: none;
  border-left-color: transparent;
  border-right-color: transparent;
  border-radius: 0 0 12px 12px;
}
@keyframes mascotBob {
  0%, 100% { transform: translateY(0) rotate(-7deg) scale(1, 1); }
  30% { transform: translateY(-16px) rotate(-4deg) scale(0.96, 1.06); }
  60% { transform: translateY(2px) rotate(-8deg) scale(1.05, 0.94); }
}

/* knocked-out mascot on the eliminated card */
.mascot-ko {
  position: relative;
  margin: 0 auto 6px;
  animation: koRock 2.6s ease-in-out infinite;
  transform: rotate(94deg);
}
.mascot-ko .mascot-eye { transform: scaleY(0.22); background: #2b2440; }
.mascot-ko .mascot-smile { transform: translateX(-50%) rotate(180deg); top: 56%; }
@keyframes koRock {
  0%, 100% { transform: rotate(90deg); }
  50% { transform: rotate(99deg); }
}

/* --------------------------------------------------------- round intro */

.intro-screen { background: rgba(40, 24, 70, 0.18); }
.intro-card {
  text-align: center;
  background: linear-gradient(160deg, #8f67cf 0%, #ff5d8f 100%);
  border: 6px solid #fff;
  border-radius: 34px;
  padding: 34px 60px 30px;
  box-shadow: 0 14px 0 rgba(60, 42, 94, 0.25), 0 26px 50px rgba(60, 42, 94, 0.3);
  animation: cardPop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
  transform-origin: center;
}
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 7px 24px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: #fff;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 0 rgba(60, 42, 94, 0.18);
  margin-bottom: 12px;
}
.badge-race { background: var(--teal); }
.badge-survival { background: var(--orange); }
.badge-final { background: linear-gradient(180deg, #ffd166, #ff9f1c); color: #7a4a00; }

.intro-title {
  font-size: clamp(40px, 7.5vw, 78px);
  font-weight: 900;
  color: #fff;
  --oc: rgba(60, 42, 94, 0.45);
  --ow: 0.045em;
  letter-spacing: 0.02em;
  line-height: 1.05;
}
.intro-sub {
  margin-top: 8px;
  font-size: clamp(15px, 2.2vw, 20px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.06em;
}
.intro-quota {
  margin-top: 18px;
  display: inline-block;
  background: rgba(255, 255, 255, 0.95);
  color: var(--pink);
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 900;
  letter-spacing: 0.1em;
  border-radius: 999px;
  padding: 9px 30px;
  box-shadow: 0 4px 0 rgba(60, 42, 94, 0.18);
  animation: valuePop 0.5s 0.35s cubic-bezier(0.2, 1.8, 0.4, 1) backwards;
}
.intro-players {
  margin-top: 12px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.85);
}

/* ------------------------------------------------------------- results */

.results-screen { z-index: 45; }
.eliminated-screen { background: rgba(30, 16, 56, 0.62); }
.winner-screen {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255, 214, 102, 0.5), rgba(255, 214, 102, 0) 60%),
    rgba(46, 22, 76, 0.5);
}

.results-card {
  position: relative;
  text-align: center;
  border-radius: 36px;
  border: 6px solid #fff;
  padding: 36px 64px 40px;
  animation: cardPop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1);
  box-shadow: 0 16px 0 rgba(30, 16, 56, 0.3), 0 30px 60px rgba(30, 16, 56, 0.35);
}
.winner-card { background: linear-gradient(170deg, #ffd166 0%, #ff9f1c 100%); }
.elim-card { background: linear-gradient(170deg, #6a5591 0%, #43306b 100%); }

.results-title {
  font-size: clamp(42px, 8vw, 84px);
  font-weight: 900;
  line-height: 1.05;
}
.win-title {
  color: #fff;
  --oc: #d97706;
  --dc: rgba(122, 74, 0, 0.4);
}
.elim-title {
  color: #ff6f7d;
  --oc: #fff;
  --dc: rgba(0, 0, 0, 0.3);
  animation: elimWobble 0.6s 0.2s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes elimWobble {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-3deg) scale(1.04); }
  45% { transform: rotate(2.5deg); }
  70% { transform: rotate(-1.5deg); }
}

.results-sub {
  margin-top: 12px;
  font-size: clamp(15px, 2.4vw, 20px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.03em;
}
.winner-card .results-sub { color: rgba(122, 74, 0, 0.85); }

.crown-big {
  font-size: clamp(64px, 12vw, 120px);
  line-height: 1;
  margin-bottom: 4px;
  filter: drop-shadow(0 8px 0 rgba(122, 74, 0, 0.3));
  animation: crownBounce 1.4s cubic-bezier(0.36, 0, 0.3, 1) infinite;
}
@keyframes crownBounce {
  0%, 55%, 100% { transform: translateY(0) rotate(-4deg); }
  25% { transform: translateY(-18px) rotate(4deg) scale(1.08); }
  40% { transform: translateY(2px) rotate(-2deg) scale(0.96, 1.02); }
}

/* confetti */
.confetti-layer { position: absolute; inset: 0; overflow: hidden; }
.confetti {
  position: absolute;
  top: -6%;
  border-radius: 2px;
  animation: confettiFall linear infinite;
  will-change: transform;
}
.confetti-round { border-radius: 50%; }
@keyframes confettiFall {
  0% { transform: translate3d(0, -6vh, 0) rotate(0deg); opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translate3d(var(--sway, 0px), 108vh, 0) rotate(var(--spin, 540deg)); opacity: 0.85; }
}

/* --------------------------------------------------------------- pause */

.pause-screen {
  z-index: 60;
  background: rgba(30, 16, 56, 0.55);
}
.pause-card {
  text-align: center;
  background: linear-gradient(170deg, #59d6cd 0%, #2ea89f 100%);
  border: 6px solid #fff;
  border-radius: 34px;
  padding: 34px 70px 26px;
  box-shadow: 0 14px 0 rgba(30, 16, 56, 0.3), 0 26px 50px rgba(30, 16, 56, 0.35);
  animation: cardPop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}
.pause-title {
  font-size: clamp(44px, 7vw, 72px);
  font-weight: 900;
  color: #fff;
  --oc: #157a72;
  --dc: rgba(10, 60, 55, 0.35);
}
.pause-card .footnote { color: rgba(255, 255, 255, 0.75); }
.pause-card .btn { min-width: 220px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 700px), (max-height: 560px) {
  .mascot-left, .mascot-right { display: none; }
  .controls-card { padding: 12px 18px; }
  .results-card, .intro-card, .pause-card { padding: 24px 30px; max-width: 92vw; }
  .btn { font-size: 19px; padding: 13px 32px; }
  .pill { padding: 6px 14px; }
  .pill-value { font-size: 19px; }
  .pill-timer .pill-value { font-size: 22px; }
  .pill-label { font-size: 11px; }
}

/* ---------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .lg, .blob, .btn-play, .mascot, .mascot-ko, .crown-big,
  .confetti, .logo, .tagline { animation: none !important; }
}
