:root {
  --warm-bg: #f6e3cc;
  --ink: #3a2a22;
  --ink-soft: #6b5343;
  --cream: #fff6e8;
  --card: rgba(255, 249, 239, 0.96);
  --accent: #e2955f;
  --accent-deep: #cf7444;
  --good: #6fae74;
  --shadow: 0 10px 30px rgba(70, 44, 26, 0.22);
  --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(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  z-index: 10;
  transition: opacity 0.4s ease;
}
#hud.ending #topbar,
#hud.ending #hint,
#hud.ending #chips,
#hud.ending #closeLidBtn { opacity: 0; pointer-events: none; }
#hud button { pointer-events: auto; font-family: var(--font); cursor: pointer; }

#topbar {
  display: flex; align-items: center; gap: 8px;
}
#brand {
  font-weight: 900;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: rgba(255, 248, 236, 0.78);
  padding: 6px 11px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(70, 44, 26, 0.12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}
#packedLabel {
  background: rgba(58, 42, 34, 0.84);
  color: var(--cream);
  font-weight: 800;
  letter-spacing: 0.05em;
  font-size: 11.5px;
  padding: 7px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
#packedLabel b { font-size: 13px; }
#packedLabel.bump { animation: bump 0.34s ease; }
#muteBtn {
  margin-left: auto;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 248, 236, 0.85);
  color: var(--ink);
  font-size: 15px;
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
#muteBtn:active { transform: scale(0.9); }
#muteBtn.muted { opacity: 0.55; }

#hint {
  margin: 10px auto 0;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  background: rgba(255, 248, 236, 0.7);
  padding: 6px 14px;
  border-radius: 999px;
  max-width: 92vw;
  box-shadow: 0 3px 10px rgba(70, 44, 26, 0.1);
  transition: color 0.25s ease, background 0.25s ease;
}
#hint.pulse { animation: hintPulse 0.4s ease; }
#hint.cat { color: #a8552f; background: rgba(255, 233, 214, 0.92); }

#chips {
  margin-top: 8px;
  display: flex; gap: 5px; flex-wrap: wrap; justify-content: center;
  max-width: 96vw;
  align-self: center;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px;
  font-weight: 800;
  color: var(--ink-soft);
  background: rgba(255, 248, 236, 0.62);
  padding: 3px 8px;
  border-radius: 999px;
  opacity: 0.5;
  transform: scale(0.94);
  transition: opacity 0.3s ease, transform 0.3s ease, background 0.3s ease;
}
.chip .tick {
  display: inline-grid; place-items: center;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: rgba(58, 42, 34, 0.16);
  color: transparent;
  font-size: 8px;
  line-height: 1;
  transition: background 0.3s ease, color 0.3s ease;
}
.chip.on {
  opacity: 1;
  transform: scale(1);
  background: rgba(111, 174, 116, 0.24);
  color: #3d6b41;
}
.chip.on .tick { background: var(--good); color: #fff; }
.chip.pop { animation: chipPop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }

#closeLidBtn {
  display: none;
  margin: 12px auto 0;
  border: none;
  border-radius: 18px;
  background: linear-gradient(180deg, #f2a866, var(--accent-deep));
  color: #fff;
  font-weight: 900;
  font-size: clamp(16px, 4.6vw, 20px);
  letter-spacing: 0.04em;
  padding: 15px 26px;
  width: min(82vw, 340px);
  box-shadow: 0 8px 0 #a8552f, 0 14px 24px rgba(168, 85, 47, 0.4);
  transform: translateY(-3px);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  animation: lidPulse 1.15s ease-in-out infinite;
}
#closeLidBtn.show { display: block; }
#closeLidBtn:active {
  transform: translateY(3px);
  box-shadow: 0 4px 0 #a8552f, 0 8px 14px rgba(168, 85, 47, 0.34);
}

.card {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 22px;
  pointer-events: none;
  background: radial-gradient(circle at 50% 38%, rgba(58, 42, 34, 0.1), rgba(58, 42, 34, 0.46));
  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.38), 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.34);
  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);
}

@keyframes bump { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
@keyframes chipPop { 0% { transform: scale(0.9); } 55% { transform: scale(1.16); } 100% { transform: scale(1); } }
@keyframes hintPulse { 0% { transform: scale(0.96); } 60% { transform: scale(1.03); } 100% { transform: scale(1); } }
@keyframes lidPulse {
  0%, 100% { transform: translateY(-3px) scale(1); }
  50% { transform: translateY(-3px) scale(1.035); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-height: 640px) {
  .cardInner { padding: 20px 20px 18px; }
  #hint { font-size: 12px; }
}

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