/* Goblin Ice Cream Stand — full-screen 3D canvas with a 2D HTML overlay UI.
   Kid-friendly, goblin-green + ice-cream-pink. Self-contained: system fonts,
   no network dependencies, so it runs offline in the desktop/mobile shells. */

:root {
  --goblin: #6aae4a;
  --goblin-deep: #3f7a2c;
  --pink: #ff8fbf;
  --pink-deep: #e0428a;
  --cream: #fff6fb;
  --ink: #2f2435;
  --ui-font: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ui-font);
  color: var(--ink);
  background: #ffe9f4;
  user-select: none;
}

#game-shell { position: fixed; inset: 0; }

#game-canvas { display: block; width: 100%; height: 100%; }

/* ===================== HUD ===================== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 16px;
  pointer-events: none;
}
#hud .hud-left, #hud .hud-right {
  display: flex; gap: 8px; align-items: center;
  pointer-events: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-weight: 800;
  font-size: clamp(0.95rem, 3.6vw, 1.25rem);
  padding: 0.35em 0.8em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
  color: var(--ink);
}

.power-btn {
  cursor: pointer;
  border: none;
  font-family: inherit;
  background: var(--goblin);
  color: #fff;
  box-shadow: 0 4px 0 var(--goblin-deep);
  transition: transform 0.07s ease, box-shadow 0.07s ease, opacity 0.1s;
}
.power-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--goblin-deep); }
.power-btn:disabled { opacity: 0.45; cursor: default; box-shadow: 0 4px 0 var(--goblin-deep); }

#timer-bar {
  flex: 1 0 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 2px;
}
#timer-fill {
  height: 100%;
  width: 100%;
  background: #7bd86f;
  border-radius: 999px;
  transition: width 0.1s linear, background 0.2s;
}

/* ===================== ORDER SPEECH BUBBLE ===================== */
#order {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  /* #choices comes later in the markup, so without this it would paint over the
     order — and the order is the one thing you can't play without. */
  z-index: 2;
  text-align: center;
  background: #fffdf7;
  border: 5px solid var(--goblin);
  border-radius: 26px;
  padding: 14px 22px 16px;
  box-shadow: 0 12px 30px rgba(63, 122, 44, 0.28);
  max-width: 86vw;
}
#order::after { /* speech-bubble tail */
  content: "";
  position: absolute;
  bottom: -18px; left: 50%;
  transform: translateX(-50%);
  border: 14px solid transparent;
  border-top-color: var(--goblin);
}
#order-topping { font-size: clamp(2.6rem, 12vw, 4rem); line-height: 1; }
#order-text {
  margin-top: 4px;
  font-size: clamp(1.05rem, 4.2vw, 1.5rem);
  font-weight: 700;
  line-height: 1.2;
}

/* The goblin's cheer ("Yay!" / "Goblin it up!" / 😁) bounces in happily. */
#order.bubble-cheer {
  animation: cheer-pop 0.5s ease;
}
#order.bubble-cheer #order-topping {
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-weight: 800;
}
@keyframes cheer-pop {
  0%   { transform: translateX(-50%) scale(0.6); }
  45%  { transform: translateX(-50%) scale(1.18) rotate(-3deg); }
  70%  { transform: translateX(-50%) scale(0.96) rotate(2deg); }
  100% { transform: translateX(-50%) scale(1) rotate(0); }
}

/* ===================== TOPPING CHOICES ===================== */
#choices {
  position: absolute;
  left: 50%;
  bottom: calc(clamp(14px, 4vh, 34px) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.4vw, 14px);
  width: min(680px, 94vw);
  /* The grid is anchored to the bottom and grows upward, so it needs a ceiling.
     game.js caps the count at six, which is two rows; this is the backstop that
     keeps the buttons off the order bubble and the flavor signs even if that
     cap is ever raised again. */
  max-height: min(40vh, 300px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 8px;   /* room for the last row's drop shadow */
}
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  font-family: inherit;
  cursor: pointer;
  border: 4px solid #fff;
  border-radius: 20px;
  padding: clamp(8px, 2vw, 14px) 4px clamp(6px, 1.6vw, 10px);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.14);
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.12s, border-color 0.12s;
}
.choice:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.14); }
.choice:disabled { cursor: default; }

/* The ice-cream picture on each button: a flavored scoop on a cone. */
.choice .scoop {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(46px, 15vw, 66px);
  height: clamp(46px, 15vw, 66px);
  border-radius: 50% 50% 46% 46%;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.14), inset 0 6px 0 rgba(255, 255, 255, 0.3);
}
.choice .scoop-tops {
  font-size: clamp(0.85rem, 3.6vw, 1.25rem);
  line-height: 1;
  letter-spacing: -1px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
.choice .cone {
  width: 0;
  height: 0;
  border-left: clamp(11px, 3.6vw, 16px) solid transparent;
  border-right: clamp(11px, 3.6vw, 16px) solid transparent;
  border-top: clamp(16px, 5vw, 24px) solid #e0a86b;
  margin-top: -2px;
}
.choice-label { margin-top: 4px; font-size: clamp(0.7rem, 2.8vw, 0.95rem); font-weight: 800; }

.choice-right { background: #d7f7c9; border-color: #7bd86f; }
.choice-wrong { background: #ffd6d6; border-color: #ff6a6a; }
.choice-hint {
  border-color: var(--pink);
  animation: hintPulse 0.6s ease-in-out infinite alternate;
}
@keyframes hintPulse {
  from { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.14), 0 0 0 0 rgba(255, 143, 191, 0.6); }
  to   { box-shadow: 0 6px 0 rgba(0, 0, 0, 0.14), 0 0 0 12px rgba(255, 143, 191, 0); }
}

/* ===================== TOAST ===================== */
.toast {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  font-weight: 800;
  padding: 0.3em 0.8em;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transition: transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.25s;
}
.toast-show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast-good { color: var(--goblin-deep); }
.toast-bad { color: var(--pink-deep); }

/* ===================== OVERLAY SCREENS ===================== */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  /* Above the order bubble, which now lifts itself over the choice grid. */
  z-index: 10;
  padding: 18px;
  background: radial-gradient(circle at 50% 30%, rgba(255, 230, 245, 0.65), rgba(122, 191, 90, 0.45));
  backdrop-filter: blur(2px);
}
.card {
  background: #fffdf7;
  border: 5px solid var(--goblin);
  border-radius: 28px;
  padding: clamp(20px, 5vw, 36px);
  max-width: 540px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(63, 122, 44, 0.3);
}
.card-emoji { font-size: clamp(2.6rem, 12vw, 4rem); }
.card h1 {
  margin: 0.2em 0 0.3em;
  font-size: clamp(1.7rem, 7vw, 2.6rem);
  color: var(--goblin-deep);
  line-height: 1.05;
}
.card p {
  margin: 0.5em 0;
  font-size: clamp(1rem, 3.6vw, 1.2rem);
  line-height: 1.5;
}
.card .sub { color: #8a7d92; font-size: 1rem; }
.new-best { color: var(--pink-deep); font-weight: 800; font-size: 1.2rem; }

.big-btn, .small-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  font-weight: 800;
}
.big-btn {
  margin-top: 14px;
  padding: 0.7em 2em;
  font-size: clamp(1.15rem, 4.4vw, 1.5rem);
  color: #fff;
  background: var(--goblin);
  border-radius: 999px;
  box-shadow: 0 7px 0 var(--goblin-deep);
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--goblin-deep); }
.small-btn {
  display: block;
  margin: 12px auto 0;
  padding: 0.5em 1.4em;
  font-size: 1rem;
  color: var(--goblin-deep);
  background: transparent;
  border: 3px solid var(--goblin);
  border-radius: 999px;
}

/* ===================== GOBLIN SELECT ===================== */
.goblin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.4vw, 14px);
  margin-top: 14px;
}
.goblin-card {
  font-family: inherit;
  cursor: pointer;
  border: 4px solid #ffe0ef;
  border-radius: 20px;
  padding: 14px 6px;
  background: #fff;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.1s ease, border-color 0.12s, box-shadow 0.1s;
}
.goblin-card:hover { border-color: var(--goblin); transform: translateY(-3px); }
.goblin-card:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1); }
.goblin-face { font-size: clamp(2.4rem, 11vw, 3.4rem); line-height: 1; }
.goblin-name { font-weight: 800; font-size: 1.1rem; margin-top: 4px; color: var(--goblin-deep); }
.goblin-flavor { font-weight: 700; font-size: 0.9rem; }

/* ===================== LOADING ===================== */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--goblin-deep);
  background: #ffe9f4;
}

@media (prefers-reduced-motion: reduce) {
  .choice-hint { animation: none; }
}
