:root {
  --ink: #3a2440;
  --ink-soft: #6d5673;
  --cream: #fff8ee;
  --cream-deep: #f1dfca;
  --coral: #ff7657;
  --coral-deep: #d4513b;
  --teal: #20b3a3;
  --gold: #ffc53a;
  --plum: #5a2b6c;
  --shade: rgba(46, 24, 56, 0.28);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #5aa7f2;
  color: var(--ink);
  font-family: var(--font);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body { position: fixed; inset: 0; }

.sprites { position: absolute; width: 0; height: 0; overflow: hidden; }

svg { width: 1.1em; height: 1.1em; flex: none; }

/* ------------------------------------------------------------ canvas (the sky is drawn in WebGL) */

#scene, #touch { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#touch { touch-action: none; cursor: grab; }
#touch:active { cursor: grabbing; }

#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.floater {
  position: absolute;
  transform: translate(-50%, -50%);
  font: 900 22px var(--font);
  color: #fff4c2;
  text-shadow: 0 2px 0 #b36b00, 0 0 8px rgba(120, 60, 0, 0.5);
  animation: float-up 0.9s ease-out forwards;
}
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

/* ------------------------------------------------------------ screens */

#ui { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute;
  inset: 0;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 14px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 14px);
}
[hidden] { display: none !important; }
button, .card, .sheet { pointer-events: auto; }

.veil { background: rgba(38, 20, 48, 0.42); display: grid; place-items: center; pointer-events: auto; animation: veil-in 0.25s ease both; }
@keyframes veil-in { from { opacity: 0; } }

body.frozen *, body.frozen *::before, body.frozen *::after { animation-play-state: paused !important; }
/* The pause menu appears while everything is frozen, so it has no entrance animation. */
#pause, #pause .card { animation: none; }

/* ------------------------------------------------------------ bits */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 12px 22px;
  font: 800 18px/1 var(--font);
  letter-spacing: 0.01em;
  white-space: nowrap;
  color: #fff;
  background: linear-gradient(#ff8c6c, var(--coral));
  box-shadow: 0 5px 0 var(--coral-deep), 0 10px 18px var(--shade);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--coral-deep), 0 4px 10px var(--shade); }
.btn:focus-visible, .round:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.btn.big { font-size: 24px; padding: 16px 40px; min-width: 210px; }
.btn.soft { color: var(--ink); background: linear-gradient(#fffdf8, var(--cream)); box-shadow: 0 4px 0 var(--cream-deep), 0 8px 16px var(--shade); }
.btn.soft:active { box-shadow: 0 1px 0 var(--cream-deep), 0 3px 8px var(--shade); }
.btn.square { padding: 12px 14px; }
.btn.square svg { width: 1.3em; height: 1.3em; }

.round {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 250, 242, 0.92);
  box-shadow: 0 3px 0 var(--cream-deep), 0 6px 14px var(--shade);
  cursor: pointer;
}
.round svg { width: 22px; height: 22px; }
.round:active { transform: translateY(2px); }

.row { display: flex; gap: 12px; justify-content: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px 7px 10px;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.94);
  box-shadow: 0 3px 0 var(--cream-deep), 0 6px 14px var(--shade);
  font: 800 17px/1 var(--font);
}
.chip svg { color: var(--gold); width: 22px; height: 22px; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  font: 800 0.9em var(--font);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}

/* ------------------------------------------------------------ loading */

#loading { display: grid; place-content: center; justify-items: center; gap: 14px; color: #fff; font-weight: 800; text-shadow: 0 2px 6px rgba(0,0,0,0.25); }
.loader { display: flex; gap: 10px; }
.loader span { width: 16px; height: 16px; border-radius: 50%; background: #fff; animation: bob 0.8s ease-in-out infinite; }
.loader span:nth-child(2) { animation-delay: 0.12s; }
.loader span:nth-child(3) { animation-delay: 0.24s; }
@keyframes bob { 50% { transform: translateY(-12px); } }

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

#title { display: flex; flex-direction: column; align-items: center; justify-content: space-between; }
#title .wallet { position: absolute; top: calc(var(--safe-t) + 12px); left: calc(var(--safe-l) + 14px); }
.brand { margin-top: 58px; text-align: center; pointer-events: none; }
.logo { margin: 0; line-height: 0.9; animation: logo-bob 3.2s ease-in-out infinite; }
.logo span, .logo strong {
  display: block;
  font-weight: 900;
  color: #fff;
  paint-order: stroke fill;
  -webkit-text-stroke: 8px var(--plum);
  text-shadow: 0 6px 0 var(--plum), 0 12px 22px rgba(40, 10, 50, 0.35);
}
.logo span { font-size: clamp(34px, 10vw, 58px); letter-spacing: 0.01em; }
.logo strong { font-size: clamp(50px, 16vw, 92px); color: #ffd35a; letter-spacing: 0.03em; }
@keyframes logo-bob { 50% { transform: translateY(-5px) rotate(-1deg); } }

.title-foot { display: grid; justify-items: center; gap: 14px; width: min(100%, 420px); }
.records { display: flex; gap: 10px; }
.records div {
  min-width: 118px;
  padding: 8px 14px;
  border-radius: 16px;
  text-align: center;
  background: rgba(255, 250, 242, 0.9);
  box-shadow: 0 3px 0 var(--cream-deep), 0 6px 14px var(--shade);
}
.records small, .stats small, .big-score small { display: block; font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }
.records b { font-size: 24px; font-weight: 900; }
.hint { margin: 0; max-width: 340px; text-align: center; font-size: 14px; font-weight: 700; line-height: 1.45; color: #fff; text-shadow: 0 1px 3px rgba(20, 10, 40, 0.65); }

/* ------------------------------------------------------------ hud */

.hud-top { display: flex; align-items: flex-start; gap: 10px; }
.hud-top button { pointer-events: auto; }
.scorebox { display: grid; line-height: 1; color: #fff; text-shadow: 0 2px 0 rgba(58, 36, 64, 0.85), 0 0 10px rgba(58, 36, 64, 0.45); }
.scorebox > b { font-size: 40px; font-weight: 900; }
.scorebox span { display: flex; align-items: center; gap: 4px; margin-top: 4px; font-size: 16px; font-weight: 800; }
.scorebox em { font-style: normal; }
.scorebox i { width: 5px; height: 5px; margin: 0 4px; border-radius: 50%; background: currentColor; }
.scorebox svg { color: var(--gold); width: 18px; height: 18px; filter: drop-shadow(0 1px 0 rgba(58,36,64,0.8)); }
.scorebox.bump-a > b { animation: bump-a 0.25s ease; }
.scorebox.bump-b > b { animation: bump-b 0.25s ease; }
@keyframes bump-a { 40% { transform: scale(1.18); } }
@keyframes bump-b { 40% { transform: scale(1.18); } }

#toast {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-t) + 92px);
  transform: translateX(-50%);
  padding: 10px 22px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 20px;
  font-weight: 900;
  color: var(--ink);
  background: rgba(255, 250, 242, 0.95);
  box-shadow: 0 4px 0 var(--cream-deep), 0 8px 18px var(--shade);
  opacity: 0;
}
#toast.show-a { animation: toast-a 2.4s ease forwards; }
#toast.show-b { animation: toast-b 2.4s ease forwards; }
@keyframes toast-a {
  0% { opacity: 0; transform: translate(-50%, -12px) scale(0.9); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}
@keyframes toast-b {
  0% { opacity: 0; transform: translate(-50%, -12px) scale(0.9); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

#coach {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 7%);
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 6px;
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  text-shadow: 0 2px 0 rgba(58, 36, 64, 0.8);
}
#coach[hidden] { display: none; }
#coach p { margin: 0; }
#coach small { font-size: 14px; font-weight: 800; opacity: 0.95; }
.hand {
  width: 44px;
  height: 44px;
  border-radius: 50% 50% 46% 46%;
  background: #fff;
  box-shadow: 0 3px 0 rgba(58, 36, 64, 0.4);
  animation: swipe 1.4s ease-in-out infinite;
}
@keyframes swipe { 0%, 100% { transform: translateX(-60px); } 50% { transform: translateX(60px); } }

/* ------------------------------------------------------------ cards */

.card {
  width: min(92vw, 360px);
  max-height: calc(100% - 8px);
  overflow: auto;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 22px 20px 20px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 8px 0 var(--cream-deep), 0 18px 40px rgba(30, 10, 40, 0.35);
  text-align: center;
  animation: card-in 0.32s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes card-in { from { transform: translateY(24px) scale(0.92); opacity: 0; } }
.card h2 { margin: 0; font-size: 30px; font-weight: 900; }
.cause { margin: 0; font-size: 20px; font-weight: 900; color: var(--coral-deep); }
.big-score b { font-size: 60px; font-weight: 900; line-height: 1; }
.badge {
  margin: -4px 0 0;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 900;
  color: #5a3210;
  background: linear-gradient(#ffe685, var(--gold));
  box-shadow: 0 3px 0 #d69a12;
  animation: badge 0.9s ease-in-out infinite alternate;
}
.badge[hidden], .milestone[hidden] { display: none; }
.badge.tied { color: var(--ink); background: #e6e0f5; box-shadow: 0 3px 0 #c3b8de; animation: none; }
@keyframes badge { to { transform: scale(1.07) rotate(-2deg); } }
.stats { display: flex; gap: 8px; margin: 0; padding: 0; list-style: none; width: 100%; }
.stats li { flex: 1; padding: 8px 4px; border-radius: 14px; background: #fff; box-shadow: inset 0 -3px 0 var(--cream-deep); }
.stats b { font-size: 20px; font-weight: 900; }
.milestone { margin: 0; padding: 8px 12px; border-radius: 14px; font-weight: 800; color: #0e5f56; background: #d4f6f0; }

/* ------------------------------------------------------------ coats */

.sheet {
  width: min(94vw, 560px);
  max-height: calc(100% - 4px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 28px;
  background: var(--cream);
  box-shadow: 0 8px 0 var(--cream-deep), 0 18px 40px rgba(30, 10, 40, 0.35);
  animation: card-in 0.3s cubic-bezier(.2, 1.4, .4, 1) both;
}
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 26px; font-weight: 900; }
.sheet-head .chip { box-shadow: inset 0 -3px 0 var(--cream-deep); background: #fff; }
.sheet-note { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.coat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; overflow: auto; padding: 4px 2px 8px; touch-action: pan-y; }
.coat {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 10px 6px 12px;
  border: 3px solid transparent;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 4px 0 var(--cream-deep);
  font: 800 15px var(--font);
  color: var(--ink);
  cursor: pointer;
}
.coat canvas { width: 72px; height: 72px; }
.coat .tag { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--cream); display: inline-flex; align-items: center; gap: 3px; }
.coat .tag svg { color: var(--gold); width: 16px; height: 16px; }
.coat.worn { border-color: var(--teal); }
.coat.worn .tag { background: var(--teal); color: #fff; }
.coat.buy .tag, .coat.claim .tag { background: var(--coral); color: #fff; }
.coat.locked, .coat.short { opacity: 0.72; }
.coat.nope { animation: nope 0.3s ease; }
@keyframes nope { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ------------------------------------------------------------ layouts */

@media (max-width: 380px) {
  .coat-grid { grid-template-columns: repeat(2, 1fr); }
  .btn.big { min-width: 180px; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .brand { margin-top: 0; }
  #title { align-items: flex-start; justify-content: center; padding-left: calc(var(--safe-l) + 28px); }
  #title .wallet { top: calc(var(--safe-t) + 10px); }
  .brand, .title-foot { width: min(38vw, 340px); }
  .logo span { font-size: clamp(26px, 5.2vw, 44px); }
  .logo strong { font-size: clamp(38px, 8vw, 66px); }
  .title-foot { gap: 10px; margin-top: 10px; }
  .records div { min-width: 100px; padding: 6px 10px; }
  .records b { font-size: 20px; }
  .btn.big { font-size: 21px; padding: 13px 30px; min-width: 180px; }
  .hint { font-size: 13px; }
  .card { gap: 8px; padding: 16px 18px; width: min(70vw, 420px); }
  .card.result { grid-template-columns: 1fr 1fr; align-items: center; column-gap: 14px; }
  .card.result .cause, .card.result .milestone, .card.result .row { grid-column: 1 / -1; }
  .card.result .big-score { grid-row: span 2; }
  .card.result .btn.big { min-width: 0; width: 100%; padding: 14px 18px; }
  .big-score b { font-size: 48px; }
  .coat-grid { grid-template-columns: repeat(6, 1fr); }
  .coat canvas { width: 60px; height: 60px; }
  #toast { top: calc(var(--safe-t) + 14px); }
  #coach { bottom: calc(var(--safe-b) + 5%); }
}

@media (min-width: 900px) and (min-height: 600px) {
  .brand { margin-top: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .logo, .badge, .hand { animation: none; }
}

/* ?debug=collision badge */
body.debug-collision::after {
  content: 'collision debug';
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 6px);
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 8px;
  font: 800 12px/1.4 var(--font);
  color: #0b2;
  background: rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
