/* T-Rex Tummy Rescue: how everything looks. */

:root {
  --sky-top: #aee3ff;
  --sky-bottom: #fde2ff;
  --ink: #2b2250;
  --accent: #e0357f;
  --accent-dark: #a8245e;
  --good: #34c759;
  --road: #6b6f80;
  --grass: #7cc56b;
  font-family: "Arial Rounded MT Bold", ui-rounded, "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* no "save image" pop-up when a finger rests on something */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom */
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* ---------- big pink buttons ---------- */
.big-btn {
  font-size: 30px;
  padding: 14px 34px;
  border: none;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 0 var(--accent-dark);
  animation: breathe 1.4s ease-in-out infinite;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-dark); animation: none; }

.icon-btn {
  font-size: 22px;
  border: none;
  background: #fff;
  border-radius: 14px;
  padding: 6px 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .12);
}

/* ---------- title + end screens ---------- */
#title, #end {
  flex-direction: column;
  align-items: center;
  justify-content: safe center; /* never push the Play button off a small screen */
  overflow-y: auto;
  gap: 18px;
  text-align: center;
  padding: 20px;
}
#title h1, #end h1 {
  font-size: clamp(40px, 7vw, 86px);
  margin: 0;
  color: #fff;
  text-shadow: 0 4px 0 var(--accent), 0 9px 0 rgba(0, 0, 0, .12);
}
.subtitle { font-size: 26px; }
.title-amb { height: 24vh; aspect-ratio: 340 / 210; }
.title-amb svg { width: 100%; height: 100%; display: block; overflow: visible; }
.hero-row { display: flex; gap: 6px; justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.hero-row svg { height: 19vh; width: auto; aspect-ratio: 240 / 340; overflow: visible; }

.warnings {
  background: #fff7d1;
  border: 3px dashed #e0b400;
  border-radius: 16px;
  padding: 10px 18px;
  max-width: 780px;
  text-align: left;
  font-size: 17px;
}
.warnings ul { margin: 6px 0 0; padding-left: 22px; }

/* ---------- playing ---------- */
#play { flex-direction: column; }

.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 20px; }
.game-title { font-size: 26px; white-space: nowrap; }
.stickers { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.slot {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 3px dashed rgba(43, 34, 80, .3);
  background: rgba(255, 255, 255, .4);
  display: grid; place-items: center;
  font-size: 26px;
}
.slot.filled { border: 3px solid gold; background: #fff; }
.slot.new { animation: pop .6s ease-out; }

.play-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr minmax(340px, 430px);
  gap: 16px;
  padding: 0 20px 20px;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border-radius: 28px;
  background: linear-gradient(#c9efff, #effcff 75%);
}

.bubble {
  align-self: flex-end;
  margin: 16px 24px 0 auto;
  max-width: min(560px, 72%);
  min-height: 64px;
  background: #fff;
  border: none;
  border-radius: 24px;
  padding: 14px 20px;
  font-size: 23px;
  line-height: 1.3;
  text-align: left;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .1);
  position: relative;
  z-index: 2;
}
.bubble::before { content: "🔊 "; }
.bubble::after {
  content: "";
  position: absolute;
  bottom: -24px;
  right: 22%;
  border: 12px solid transparent;
  border-top: 14px solid #fff;
}
.bubble:empty { visibility: hidden; }

.scene {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4%;
  padding: 0 4%;
  position: relative;
  z-index: 1;
}
.amb-wrap { height: 31vh; aspect-ratio: 340 / 210; margin-bottom: -8px; flex-shrink: 0; }
.hero-wrap { height: 50vh; aspect-ratio: 240 / 340; margin-bottom: -10px; flex-shrink: 0; }
.amb-wrap svg, .hero-wrap svg { width: 100%; height: 100%; display: block; overflow: visible; }

.road { height: 54px; background: var(--road); position: relative; flex-shrink: 0; }
.road::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 6px; margin-top: -3px;
  background: repeating-linear-gradient(90deg, #ffd54a 0 40px, transparent 40px 80px);
}

.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--grass);
  min-height: 84px;
  flex-shrink: 0;
}
.meter { display: flex; align-items: center; gap: 10px; font-size: 34px; }
.meter .dot {
  width: 54px; height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  border: 3px dashed rgba(0, 0, 0, .25);
  display: grid; place-items: center;
  font-size: 30px;
}
.meter .dot.full { background: #fff; border: 3px solid var(--good); animation: pop .4s ease-out; }

/* ---------- helper buttons ---------- */
.helpers {
  background: rgba(255, 255, 255, .7);
  border-radius: 28px;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.helpers h2 { margin: 4px 0 12px; font-size: 26px; text-align: center; font-weight: normal; }
.helper-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 12px;
}
.helper {
  border: none;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  position: relative;
  transition: transform .1s;
}
.helper:hover { transform: translateY(-3px) scale(1.04); }
.helper:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.helper .emoji { font-size: clamp(34px, 6vh, 62px); line-height: 1; }
.helper .label { font-size: 17px; }
.helper.worked { background: #eaffea; }
.helper.worked::after { content: "✅"; position: absolute; top: 6px; right: 8px; font-size: 20px; }
.helper.hint { animation: glow .8s ease-in-out infinite alternate; }

/* ---------- see-the-code panel ---------- */
.code-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(470px, 92vw);
  background: #1e1b3a;
  color: #e8e6ff;
  border-radius: 18px;
  padding: 16px 18px 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  z-index: 30;
}
.code-panel .note { font-size: 16px; color: #cfc8ff; margin: 0 30px 8px 0; line-height: 1.35; }
.code-panel pre { font: 18px/1.5 ui-monospace, "SF Mono", Menlo, monospace; margin: 0 0 10px; white-space: pre-wrap; user-select: text; }
.code-panel .close { position: absolute; top: 10px; right: 12px; border: none; background: none; color: #fff; font-size: 20px; }
.k { color: #7ee0ff; }
.s { color: #ffd580; }
.n { color: #a6f28c; }
.swatch {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 1px solid rgba(255, 255, 255, .6);
}

/* ---------- bug screen ---------- */
#bug {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 30px;
  background: #fff7d1;
  font-size: 22px;
}
#bug h1 { margin: 0; font-size: 44px; }
#bug p { margin: 6px 0; }
.bug-emoji { font-size: 120px; animation: wiggle 1s ease-in-out infinite alternate; }
.bug-where { font-size: 32px; color: var(--accent-dark); }
.bug-tip { font-size: 26px; }
.bug-computer { font: 17px ui-monospace, Menlo, monospace; color: #7a6a2a; user-select: text; }
.bug-tips { text-align: left; }

/* ---------- flying things ---------- */
.flying {
  position: fixed;
  left: 0; top: 0;
  width: 56px; height: 56px;
  font-size: 50px;
  line-height: 56px;
  text-align: center;
  pointer-events: none;
  z-index: 40;
}
.confetti { position: fixed; top: -60px; font-size: 34px; pointer-events: none; z-index: 50; }

/* ---------- the hero ---------- */
.hero { transform-origin: 50% 100%; }
.hero.sick { animation: wobble 1.6s ease-in-out infinite; }
.hero.happy { animation: jump .7s ease-in-out infinite; }
.hero.shake { animation: shake .5s ease-in-out; }
.hero.sick .only-happy, .hero.happy .only-sick { display: none; }
.hero .cape { transform-origin: 120px 122px; animation: cape 1.1s ease-in-out infinite alternate; }
.hero .ache { transform-origin: 120px 188px; animation: ache .7s ease-in-out infinite alternate; }
.hero .sweat { animation: drip 1.4s ease-in infinite; }

.hero-wrap.land { animation: land .9s cubic-bezier(.3, 1.4, .5, 1) both; }
.hero-wrap.fly-away { animation: fly-away 1s ease-in forwards; }

/* ---------- the T-Rex ambulance ---------- */
.ambulance { cursor: pointer; }
.ambulance .wheel { transform-box: fill-box; transform-origin: center; }
.ambulance.driving { animation: bob .22s ease-in-out infinite alternate; }
.ambulance.driving .wheel { animation: spin .35s linear infinite; }
.ambulance.siren-on .siren-red { animation: flash .4s steps(1) infinite; }
.ambulance.siren-on .siren-blue { animation: flash .4s steps(1) infinite reverse; }
.ambulance .dino-head { transform-box: fill-box; transform-origin: 20% 90%; }
.ambulance .dino-arm { transform-box: fill-box; transform-origin: 0% 0%; }
.ambulance.cheer .dino-head { animation: roar .25s ease-in-out 4 alternate; }
.ambulance.cheer .dino-arm { animation: wave .2s ease-in-out 6 alternate; }

.amb-wrap.drive-in { animation: drive-in 1.8s cubic-bezier(.2, .7, .3, 1) both; }
.amb-wrap.drive-away { animation: drive-away 1.4s ease-in forwards; }

/* ---------- animations ---------- */
@keyframes breathe { 50% { transform: scale(1.05); } }
@keyframes pop { 0% { transform: scale(.3); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes glow {
  from { box-shadow: 0 0 0 4px #ffd54a, 0 5px 0 rgba(0, 0, 0, .12); }
  to { box-shadow: 0 0 0 10px #ffd54a, 0 0 30px 12px #fff3a0; }
}
@keyframes wobble { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes jump { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9%); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6%); }
  40%, 80% { transform: translateX(6%); }
}
@keyframes cape { from { transform: skewX(-4deg); } to { transform: skewX(4deg); } }
@keyframes ache { from { transform: scale(.75) rotate(0deg); } to { transform: scale(1.2) rotate(40deg); } }
@keyframes drip { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(14px); opacity: 0; } }
@keyframes land { from { transform: translateY(-90vh); } to { transform: none; } }
@keyframes fly-away { to { transform: translateY(-110vh) rotate(-8deg); } }
@keyframes drive-in { from { transform: translateX(-120vw); } to { transform: none; } }
@keyframes drive-away { to { transform: translateX(130vw); } }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-2%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flash { 0% { opacity: 1; } 50% { opacity: .2; } }
@keyframes roar { from { transform: rotate(0deg); } to { transform: rotate(-12deg); } }
@keyframes wave { from { transform: rotate(0deg); } to { transform: rotate(-40deg); } }
@keyframes wiggle { from { transform: rotate(-10deg); } to { transform: rotate(10deg); } }

/* ---------- tablets and phones ---------- */
.turn-hint { display: none; font-size: 15px; background: #fff; border-radius: 12px; padding: 4px 10px; }

/* Held upright (portrait): the scene on top, the helpers underneath. */
@media (orientation: portrait) and (max-width: 900px) {
  .play-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .helper-grid { grid-auto-rows: 90px; }
  .game-title { display: none; }
}
@media (orientation: portrait) and (max-width: 600px) {
  #title, #end { gap: 12px; }
  .title-amb { height: 15vh; }
  .hero-row svg { height: 10vh; }
  .subtitle { font-size: 19px; }
  .turn-hint { display: block; }
  .stickers { display: none; }
  .bubble { font-size: 16px; padding: 8px 12px; min-height: 0; }
  .amb-wrap { height: 13vh; }
  .hero-wrap { height: 24vh; }
  .helpers h2 { font-size: 18px; margin: 0 0 6px; }
  .helper-grid { grid-auto-rows: 70px; gap: 8px; }
  .helper .emoji { font-size: 30px; }
  .helper .label { font-size: 12px; }
  .stage-footer { min-height: 60px; padding: 8px 12px; }
  .meter { font-size: 24px; } .meter .dot { width: 36px; height: 36px; font-size: 20px; }
  .big-btn { font-size: 22px; padding: 10px 22px; }
}

/* Phones held sideways: short screens, so everything gets smaller. */
@media (orientation: landscape) and (max-height: 560px) {
  .topbar { padding: 4px 12px; gap: 8px; }
  .game-title { font-size: 17px; }
  .slot { width: 28px; height: 28px; font-size: 16px; border-width: 2px; }
  .icon-btn { font-size: 15px; padding: 3px 10px; border-radius: 10px; }
  .play-main { grid-template-columns: 1fr minmax(220px, 34vw); gap: 8px; padding: 0 8px 8px; }
  .stage, .helpers { border-radius: 18px; }
  .helpers { padding: 8px 10px 10px; }
  .helpers h2 { font-size: 16px; margin: 2px 0 6px; }
  .bubble { font-size: 15px; padding: 7px 12px; min-height: 0; margin: 8px 10px 0 auto; border-radius: 16px; max-width: 80%; }
  .bubble::after { display: none; }
  .amb-wrap { height: 30vh; }
  .hero-wrap { height: 44vh; }
  .road { height: 26px; }
  .stage-footer { min-height: 46px; padding: 4px 10px; }
  .meter { font-size: 20px; gap: 4px; }
  .meter .dot { width: 28px; height: 28px; font-size: 16px; border-width: 2px; }
  .helper-grid { gap: 6px; }
  .helper { border-radius: 14px; box-shadow: 0 3px 0 rgba(0, 0, 0, .12); }
  .helper .emoji { font-size: clamp(22px, 8vh, 40px); }
  .helper .label { font-size: 11px; }
  #title, #end { gap: 8px; padding: 8px; }
  #title h1, #end h1 { font-size: clamp(28px, 9vh, 52px); }
  .subtitle { font-size: 16px; }
  .title-amb { height: 22vh; }
  .hero-row svg { height: 15vh; }
  .big-btn { font-size: 20px; padding: 8px 24px; border-radius: 16px; }
  .warnings { font-size: 13px; }
}
.home-btn { text-decoration: none; }

/* ---------- Andika: a font made for children learning to read ---------- */
@font-face { font-family: "Andika"; src: url("../fonts/andika-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Andika"; src: url("../fonts/andika-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
:root { font-family: "Andika", "Arial Rounded MT Bold", ui-rounded, system-ui, sans-serif; font-weight: 700; }

/* ---------- points: they only ever go up ---------- */
.score {
  display: flex; align-items: center; gap: 6px;
  background: #fff; border-radius: 18px; padding: 4px 14px;
  font-size: 26px; min-width: 96px; justify-content: center;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .12);
}
.score.bump { animation: bump .45s ease-out; }
.points-pop {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none;
  font-size: 44px; font-weight: 700; color: #ff7a00; white-space: nowrap;
  -webkit-text-stroke: 3px #fff; paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(43, 34, 80, .18);
}
.end-points { font-size: clamp(24px, 4vw, 40px); background: #fff; border-radius: 22px; padding: 8px 26px; box-shadow: 0 4px 0 rgba(0, 0, 0, .1); }
.end-points small { display: block; font-size: 16px; font-weight: 400; color: #5b5480; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------- start screen words ---------- */
.about-game { margin: 0; max-width: 620px; font-size: clamp(17px, 2.2vw, 22px); font-weight: 400; line-height: 1.35; }
.made-by { white-space: nowrap; }
.device-note { margin: 0; font-size: 15px; font-weight: 400; color: #5b5480; }

/* ---------- 🏠: hold to go home, so a stray tap doesn't end the game ---------- */
.home-btn { position: relative; overflow: hidden; }
.home-btn::after { content: ""; position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: #ff5fa2; }
.home-btn.holding::after { width: 100%; transition: width .7s linear; }

@media (orientation: landscape) and (max-height: 560px) {
  .score { font-size: 17px; padding: 2px 10px; min-width: 64px; border-radius: 12px; }
  .points-pop { font-size: 28px; }
  .about-game { font-size: 15px; }
  .device-note { display: none; }
}
@media (orientation: portrait) and (max-width: 600px) {
  .score { font-size: 20px; min-width: 70px; }
}

/* ---------- calmer motion for people who ask for it ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* 🔊 reads the start screen out loud, for children who can't read yet */
.read-btn {
  font: inherit; font-size: 18px; font-weight: 700;
  border: none; border-radius: 16px; padding: 8px 18px; min-height: 44px;
  background: #fff; color: var(--ink); box-shadow: 0 3px 0 rgba(0, 0, 0, .12);
}
.read-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }
@media (orientation: landscape) and (max-height: 560px) { .read-btn { font-size: 14px; padding: 4px 12px; min-height: 36px; } }

/* ---------- "show me" hand ---------- */
.show-hand {
  position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none;
  width: 80px; height: 80px; margin: -8px 0 0 -40px; /* the fingertip sits on the spot */
}
.hand-finger { display: block; font-size: 78px; line-height: 1; text-align: center; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .3)); }
.hand-item { position: absolute; left: -36px; top: -56px; font-size: 70px; line-height: 1; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .25)); }
@media (orientation: landscape) and (max-height: 560px) {
  .hand-finger { font-size: 44px; }
  .hand-item { font-size: 38px; left: -20px; top: -30px; }
}

/* ---------- the speech bubble: tap to hear it, tap again to stop ---------- */
.bubble::before { content: none; }
.bubble { cursor: pointer; transition: transform .12s ease; }
.bubble:active { transform: scale(.97); }
.bubble.new { animation: bubble-in .35s ease-out; }
@keyframes bubble-in { 0% { transform: scale(.9); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
.start-row { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
@media (max-height: 860px) {
  #title { gap: 12px; }
  #title .title-amb { height: 20vh; }
  #title .hero-row svg { height: 15vh; }
}
@media (orientation: portrait) and (max-width: 600px) {
  #title .hero-row { flex-wrap: nowrap; gap: 2px; }
  #title .hero-row svg { height: 8vh; }
  #title .title-amb { height: 12vh; }
}
