:root {
  --warm-bg: #f3dcc0;
  --ink: #3a2a22;
  --ink-soft: #6b5343;
  --cream: #fff6e8;
  --card: rgba(255, 248, 236, 0.94);
  --accent: #e2955f;
  --accent-deep: #cf7444;
  --good: #6fae74;
  --bad: #d1495b;
  --gold: #f0b64b;
  --shadow: 0 10px 30px rgba(70, 44, 26, 0.24);
  --font: "Nunito", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  overflow: hidden;
  background: var(--warm-bg);
  font-family: var(--font);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  position: fixed; inset: 0;
  display: block;
  width: 100vw; height: 100vh;
  touch-action: none;
}

#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  z-index: 10;
}
#hud button { pointer-events: auto; font-family: var(--font); cursor: pointer; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
}
#roundPill {
  background: rgba(58, 42, 34, 0.82);
  color: var(--cream);
  font-weight: 800;
  letter-spacing: 0.06em;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
#mistakesPill {
  background: rgba(255, 246, 232, 0.78);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 999px;
}
#mistakesPill.bump { animation: bump 0.3s ease; }
#mistakeCount { color: var(--bad); font-weight: 900; }
#muteBtn {
  margin-left: auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 246, 232, 0.8);
  color: var(--ink);
  font-size: 17px;
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
#muteBtn:active { transform: scale(0.92); }
#muteBtn.muted { opacity: 0.5; text-decoration: line-through; }

/* ---------- banner ---------- */
#banner {
  margin-top: 14px;
  text-align: center;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  text-shadow: 0 2px 12px rgba(255, 246, 232, 0.9), 0 1px 2px rgba(255,255,255,0.6);
}
#banner.show { opacity: 1; transform: translateY(0); }
#gagName {
  font-size: clamp(22px, 6.4vw, 30px);
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--ink);
  line-height: 1.05;
}
#gagHint {
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 3px;
}
#bannerSub {
  margin-top: 5px;
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-deep);
  background: rgba(255, 246, 232, 0.85);
  padding: 3px 12px;
  border-radius: 999px;
}

/* ---------- timer ---------- */
#timerWrap {
  margin-top: 10px;
  height: 9px;
  border-radius: 999px;
  background: rgba(58, 42, 34, 0.16);
  overflow: hidden;
  max-width: 520px;
  width: 100%;
  align-self: center;
  box-shadow: inset 0 1px 3px rgba(58, 42, 34, 0.2);
}
#timerBar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f0b64b, #e2955f);
  transform-origin: left center;
  transition: background 0.3s ease;
}
#timerBar.low { background: linear-gradient(90deg, #e2603a, var(--bad)); }

/* ---------- progress ---------- */
#progressWrap {
  margin: 10px auto 0;
  display: flex; align-items: center; gap: 9px;
  width: 100%;
  max-width: 520px;
}
#progressTrack {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: rgba(58, 42, 34, 0.14);
  overflow: hidden;
}
#progressBar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--good), #9fd08a);
  transition: width 0.25s ease;
}
#progressText {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink-soft);
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- packed row ---------- */
#packedRow {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
#packedLabel {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  opacity: 0.8;
}
#packedChips {
  display: flex; gap: 5px; flex-wrap: wrap; justify-content: center;
  max-width: 90vw;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px;
  font-weight: 800;
  color: var(--ink-soft);
  background: rgba(255, 246, 232, 0.72);
  padding: 3px 8px;
  border-radius: 999px;
  opacity: 0.45;
  transform: scale(0.92);
  transition: opacity 0.3s ease, transform 0.3s ease, background 0.3s ease;
}
.chip.on {
  opacity: 1;
  transform: scale(1);
  background: rgba(111, 174, 116, 0.22);
  color: #3d6b41;
}

/* ---------- pack button ---------- */
#packBtn {
  display: none;
  margin: 10px auto 0;
  border: none;
  border-radius: 20px;
  background: linear-gradient(180deg, #f2a866, var(--accent-deep));
  color: #fff;
  font-weight: 900;
  font-size: clamp(18px, 5vw, 22px);
  letter-spacing: 0.03em;
  padding: 16px 28px;
  width: min(88vw, 380px);
  box-shadow: 0 10px 0 #a8552f, 0 16px 26px rgba(168, 85, 47, 0.42);
  transform: translateY(-4px);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  animation: packPulse 1.1s ease-in-out infinite;
}
#packBtn.show { display: block; }
#packBtn:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 #a8552f, 0 8px 16px rgba(168, 85, 47, 0.36);
  animation: none;
}
#packBtn.flash {
  animation: packFlash 0.5s ease;
}

/* ---------- toast ---------- */
#toast {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(58, 42, 34, 0.92);
  color: var(--cream);
  font-weight: 800;
  font-size: 14px;
  text-align: center;
  padding: 12px 20px;
  border-radius: 16px;
  max-width: 82vw;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- cards ---------- */
.card {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  pointer-events: none;
  background: radial-gradient(circle at 50% 40%, rgba(58, 42, 34, 0.14), rgba(58, 42, 34, 0.5));
  opacity: 1;
  transition: opacity 0.45s ease;
  z-index: 30;
}
.card.hidden { opacity: 0; pointer-events: none; visibility: hidden; }
.cardInner {
  pointer-events: auto;
  width: min(92vw, 400px);
  background: var(--card);
  border-radius: 28px;
  padding: 28px 26px 24px;
  box-shadow: 0 24px 60px rgba(58, 36, 20, 0.4), inset 0 1px 0 rgba(255,255,255,0.7);
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.6);
  animation: cardIn 0.5s cubic-bezier(0.2, 1.1, 0.3, 1) both;
}
.cardKicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-deep);
  margin-bottom: 8px;
}
.card h1 {
  font-size: clamp(30px, 8.6vw, 40px);
  line-height: 1.02;
  margin: 0 0 12px;
  font-weight: 900;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.card h2 {
  font-size: clamp(26px, 7.4vw, 34px);
  margin: 2px 0 12px;
  font-weight: 900;
  color: var(--accent-deep);
}
.cardBody {
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 20px;
  font-weight: 600;
}
.endJoke { font-size: 15px; line-height: 1.6; color: var(--ink); }
.endJoke b { color: var(--accent-deep); }
.cardFoot {
  margin-top: 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
  opacity: 0.6;
  letter-spacing: 0.04em;
}
.bigBtn {
  border: none;
  border-radius: 18px;
  background: linear-gradient(180deg, #f2a866, var(--accent-deep));
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.02em;
  padding: 15px 26px;
  width: 100%;
  box-shadow: 0 8px 0 #a8552f, 0 14px 22px rgba(168, 85, 47, 0.36);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.bigBtn:active {
  transform: translateY(4px);
  box-shadow: 0 3px 0 #a8552f, 0 8px 14px rgba(168, 85, 47, 0.3);
}

/* ---------- bad flash ---------- */
#badFlash {
  position: absolute; inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 90px rgba(209, 73, 91, 0);
  transition: box-shadow 0.2s ease;
  z-index: 15;
}
#badFlash.on { box-shadow: inset 0 0 90px rgba(209, 73, 91, 0.55); transition: none; }

/* ---------- keyframes ---------- */
@keyframes bump { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes packPulse {
  0%, 100% { transform: translateY(-4px) scale(1); }
  50% { transform: translateY(-4px) scale(1.035); }
}
@keyframes packFlash {
  0% { background: linear-gradient(180deg, #b7f0b0, #6fae74); }
  100% { background: linear-gradient(180deg, #f2a866, var(--accent-deep)); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-height: 620px) {
  #banner { margin-top: 6px; }
  #gagName { font-size: 20px; }
  .cardInner { padding: 20px 20px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  #packBtn { animation: none; }
  .cardInner { animation: none; }
}
