/* Berry Rollercoaster — full-screen 3D canvas with a 2D HTML overlay HUD.
   Kid-friendly, strawberry-pink + blueberry-blue. Self-contained so it runs
   offline in the desktop/mobile shells. */

:root {
  --straw: #ff5a8a;
  --straw-deep: #d2316a;
  --blue: #4763d6;
  --blue-deep: #2b3a8c;
  --gold: #ffd23f;
  --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: #9fd9ff;
  user-select: none;
}

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

/* ===================== STANDINGS (top) ===================== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: none;
  padding: 10px 12px;
  pointer-events: none;
}
#standings {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "you goal" "rival goal";
  align-items: center;
  gap: 6px 10px;
  max-width: 760px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.72);
  border: 3px solid #fff;
  border-radius: 18px;
  padding: 8px 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(3px);
}
.lane { display: flex; align-items: center; gap: 8px; }
.lane:nth-child(1) { grid-area: you; }
.lane:nth-child(2) { grid-area: rival; }
.lane-tag {
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  min-width: 74px;
}
.lane-track {
  position: relative;
  flex: 1;
  height: 16px;
  background: #e7e0ee;
  border-radius: 999px;
  overflow: visible;
}
.lane-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.12s linear;
}
.lane-fill.you { background: linear-gradient(90deg, #ff9bc0, var(--straw)); }
.lane-fill.rival { background: linear-gradient(90deg, #93a3ee, var(--blue)); }
.lane-pip {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: 20px;
  transition: left 0.12s linear;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}
.goal {
  grid-area: goal;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 800;
  font-size: 12px;
  line-height: 1;
}
.goal span { margin-top: 2px; }
.goal { font-size: 26px; }
.goal span { font-size: 12px; }

/* ---- TEAM button (summon the mystery "?" coaster) ---- */
#team-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px auto 0;
  padding: 7px 16px 7px 8px;
  position: relative;
  pointer-events: auto;
  font-family: var(--ui-font);
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  border: 3px solid #fff;
  border-radius: 999px;
  background: linear-gradient(180deg, #3a3340, #15131a);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35), 0 8px 16px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s, opacity 0.15s;
}
#team-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
#team-btn .team-berry {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50% 50% 50% 50% / 45% 45% 60% 60%; /* berry teardrop-ish */
  background: #15131a;
  border: 2px solid #fff;
  color: #fff;
  font-size: 19px;
  line-height: 1;
}
#team-btn .team-label { letter-spacing: 0.5px; }
#team-btn .cnt {
  position: absolute;
  top: -8px; right: -6px;
  min-width: 22px; height: 22px;
  padding: 0 5px;
  font-size: 13px; font-weight: 800;
  color: #15131a;
  background: var(--gold);
  border: 2px solid #fff;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
}
#team-btn.empty { opacity: 0.4; }
#team-btn.empty .cnt { background: #9a9a9a; color: #fff; }

/* ===================== CONTROLS (bottom) ===================== */
#controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 12px max(12px, env(safe-area-inset-left, 0)) max(14px, env(safe-area-inset-bottom, 0)) 12px;
  pointer-events: none;
}
#traps { display: flex; gap: 10px; pointer-events: auto; }
.trap-btn {
  position: relative;
  width: 64px; height: 64px;
  font-size: 30px;
  border: none;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18), 0 8px 16px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s, opacity 0.15s;
}
.trap-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.trap-btn .cnt {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 22px; height: 22px;
  padding: 0 5px;
  font-size: 13px; font-weight: 800;
  color: #fff;
  background: var(--straw);
  border: 2px solid #fff;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
}
.trap-btn.empty { opacity: 0.4; }
.trap-btn.empty .cnt { background: #9a9a9a; }

#boost-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  pointer-events: auto;
}
#boost-meter {
  height: 12px;
  width: 100%;
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid #fff;
  border-radius: 999px;
  overflow: hidden;
}
#boost-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ffe27a, var(--gold));
  transition: width 0.1s linear;
}
#boost-fill.low { background: linear-gradient(90deg, #ff9b6a, #ff5a3a); }
#boost-btn {
  font-family: var(--ui-font);
  font-weight: 800;
  font-size: 22px;
  color: #6a4a00;
  padding: 14px 28px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffe27a, var(--gold));
  box-shadow: 0 6px 0 #d2a017, 0 10px 18px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  touch-action: none;
}
#boost-btn.on { transform: translateY(4px); box-shadow: 0 2px 0 #d2a017; }

/* ===================== TOAST ===================== */
#toast {
  position: absolute;
  top: 90px; left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(47, 36, 53, 0.92);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  padding: 10px 20px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== OVERLAY (title / win / lose) ===================== */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  /* index.html asks for viewport-fit=cover, so keep the card out from under the
     notch and the home indicator. */
  padding: max(20px, env(safe-area-inset-top, 0px))
           max(20px, env(safe-area-inset-right, 0px))
           max(20px, env(safe-area-inset-bottom, 0px))
           max(20px, env(safe-area-inset-left, 0px));
  background: radial-gradient(120% 90% at 50% 0%, rgba(159, 217, 255, 0.55), rgba(255, 159, 196, 0.6));
}
/* The card is a column with the button pinned to the bottom of it: the rules
   list is the only part allowed to scroll. Before this the whole card scrolled,
   so on a phone "Start the Race" sat below the fold of a scroll box with no
   scrollbar to hint at it — the game looked like it had no start button.
   dvh, not vh: vh is the tallest the viewport ever gets, so on a phone with a
   visible URL bar a 92vh card is taller than the screen it's sitting on. */
.card {
  width: min(520px, 94vw);
  max-height: 92vh;
  max-height: min(92vh, 92dvh);
  display: flex;
  flex-direction: column;
  text-align: center;
  background: #fff;
  border: 5px solid var(--straw);
  border-radius: 28px;
  padding: 22px 22px 26px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}
.card.win { border-color: var(--gold); }
.card.lose { border-color: var(--blue); }
/* Everything on this card scales with the screen. It used to be fixed px, which
   is what made it look wacky on a phone: seven rules rows set at 14.5px wrapped
   to twenty-odd lines and shoved the button off the bottom. */
.big-emoji { font-size: clamp(34px, 11vw, 56px); line-height: 1; flex: none; }
.card h1 {
  margin: 8px 0 6px;
  font-size: clamp(21px, 6.2vw, 30px);
  color: var(--straw-deep);
  flex: none;
}
.card.win h1 { color: #c79100; }
.card.lose h1 { color: var(--blue-deep); }
.lead { font-size: clamp(14px, 3.9vw, 17px); margin: 6px 0 14px; flex: none; }
.how {
  text-align: left;
  background: #fff4f8;
  border-radius: 16px;
  padding: 10px 12px;
  /* Plain margins, not `0 auto`: auto side-margins in a flex column stop the
     panel stretching to the card's width and shrink it to its content instead. */
  margin: 0 0 16px;
  /* The rules are the one part that may scroll, so the button never leaves. */
  min-height: 0;
  overflow-y: auto;
}
.how-row {
  display: flex;
  /* flex-start, not center: these rows wrap to three or four lines on a phone,
     and centering floated the emoji halfway down its own paragraph. */
  align-items: flex-start;
  gap: 8px;
  font-size: clamp(13px, 3.6vw, 14.5px);
  line-height: 1.35;
  padding: 4px 0;
}
/* min-width, not a hard 28px: 🏖️ and 👥 are multi-codepoint and render wider
   than that, so a fixed column let them spill into the text beside them. */
.how-row span {
  font-size: 1.5em;
  min-width: 1.6em;
  text-align: center;
  flex: none;
  line-height: 1.05;
}
.play-btn {
  font-family: var(--ui-font);
  font-weight: 800;
  font-size: clamp(18px, 5vw, 22px);
  color: #fff;
  /* The card is a flex column now, so without this the button would stretch
     the full width of it instead of sitting centered at its natural size. */
  flex: none;
  align-self: center;
  padding: clamp(11px, 3vw, 14px) clamp(22px, 7vw, 30px);
  border: none;
  border-radius: 999px;
  background: linear-gradient(180deg, #ff7da8, var(--straw));
  box-shadow: 0 6px 0 var(--straw-deep), 0 10px 20px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--straw-deep); }

/* Smaller phones: shrink the controls a touch. */
@media (max-width: 420px) {
  .trap-btn { width: 56px; height: 56px; font-size: 26px; }
  #boost-btn { font-size: 19px; padding: 12px 20px; }
  .lane-tag { min-width: 60px; font-size: 12px; }
  .card { padding: 16px 14px 18px; border-width: 4px; }
  .how { padding: 8px 10px; margin-bottom: 12px; }
  /* The toast is nowrap, so on a narrow screen it runs off both edges. */
  #toast { white-space: normal; max-width: 92vw; font-size: 15px; }
}

/* Short screens (a phone in landscape, or a small window): the rules list is
   what gives, so the title and the Start button always stay on screen. */
@media (max-height: 720px) {
  .big-emoji { font-size: clamp(26px, 7vh, 40px); }
  .card h1 { font-size: clamp(19px, 5vh, 26px); margin: 4px 0 4px; }
  .lead { margin: 4px 0 8px; }
  .how { margin-bottom: 10px; }
  .how-row { padding: 3px 0; }
}
