/* Rose Tree Rescue: how everything looks. */

:root {
  --sky-top: #aee3ff;
  --sky-bottom: #fde2ff;
  --ink: #2b2250;
  --accent: #e0357f;
  --accent-dark: #a8245e;
  --good: #34c759;
  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: 10px; justify-content: center; align-items: flex-end; flex-wrap: wrap; }
.hero-row svg { height: 19vh; width: auto; 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(320px, 400px);
  gap: 16px;
  padding: 0 20px 20px;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-radius: 28px;
  background: linear-gradient(#bfe9ff, #eefbff 70%);
  touch-action: none;
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage.over-target { box-shadow: inset 0 0 0 6px #ffd54a; }

.bubble {
  position: absolute;
  top: 16px;
  right: 20px;
  max-width: min(560px, 74%);
  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);
  z-index: 2;
}
.bubble::before { content: "🔊 "; }
.bubble:empty { visibility: hidden; }

.wipe {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .38s ease;
  z-index: 3;
}
.wipe.on { opacity: 1; }

/* ---------- the right-hand panel ---------- */
.panel {
  background: rgba(255, 255, 255, .7);
  border-radius: 28px;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  touch-action: none;
}
.panel h2 { margin: 4px 0 12px; font-size: 26px; text-align: center; font-weight: normal; line-height: 1.25; }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.panel-note { font-size: 22px; text-align: center; margin: 0; line-height: 1.35; }
.one-tile { flex: 1; display: grid; place-items: center; }
.tile-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; flex: 1; max-height: 260px; }
.tile-row.small { flex: 0 0 auto; height: 120px; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
.tile.pedal .emoji { font-size: clamp(60px, 11vh, 100px); }
.tile.pedal.pressed { transform: translateY(4px) scale(.97); background: #fff3a0; box-shadow: 0 1px 0 rgba(0, 0, 0, .12); }

.tile {
  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;
  touch-action: none;
  transition: transform .1s;
}
.tile:hover { transform: translateY(-3px) scale(1.04); }
.tile:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }
.tile[data-drag] { cursor: grab; }
.tile .emoji { font-size: clamp(34px, 6vh, 62px); line-height: 1; pointer-events: none; }
.tile .label { font-size: 17px; pointer-events: none; }
.tile.big { width: min(240px, 90%); aspect-ratio: 1; }
.tile.big .emoji { font-size: clamp(70px, 13vh, 120px); }
.tile.big .label { font-size: 24px; }
.tile.lifted { opacity: .35; }
.tile.worked { background: #eaffea; }
.tile.worked::after { content: "✅"; position: absolute; top: 6px; right: 8px; font-size: 20px; }
.tile.hint { animation: glow .8s ease-in-out infinite alternate; }

.helper-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 1fr;
  gap: 12px;
}

.meter { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 34px; }
.meter .dot {
  width: 50px; height: 50px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  border: 3px dashed rgba(0, 0, 0, .25);
  display: grid; place-items: center;
  font-size: 28px;
}
.meter .dot.full { background: #fff; border: 3px solid var(--good); animation: pop .4s ease-out; }

/* ---------- see-the-code panel ---------- */
.code-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(500px, 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: 17px/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; }

/* ---------- things that fly or get dragged ---------- */
.flying, .ghost {
  position: fixed;
  left: 0; top: 0;
  text-align: center;
  pointer-events: none;
  z-index: 40;
}
.flying { width: 56px; height: 56px; font-size: 50px; line-height: 56px; }
.ghost { width: 90px; height: 90px; font-size: 76px; line-height: 90px; filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .25)); }
.confetti { position: fixed; top: -60px; font-size: 34px; pointer-events: none; z-index: 50; }

/* ---------- characters ---------- */
.pbody, .hbody, .abody { transform-box: fill-box; transform-origin: 50% 100%; }
.person.stuck .pbody { animation: wobble 1.4s ease-in-out infinite; }
.person.ouch .pbody { animation: wobble 2.4s ease-in-out infinite; }
.person.happy .pbody { animation: jump .7s ease-in-out infinite; }
.person.shake .pbody { animation: shake .5s ease-in-out; }
.person.stuck .arms-down, .person.stuck .face-happy, .person.stuck .owies { display: none; }
.person.ouch .arms-up, .person.ouch .face-happy { display: none; }
.person.happy .arms-down, .person.happy .face-worried, .person.happy .tear, .person.happy .owies { display: none; }
.person .tear { animation: drip 1.4s ease-in infinite; }
.owie .patch { display: none; }
.owie.healed .patch { display: inline; }
.owie.healed .scratch { display: none; }
.owie .patch { animation: pop .4s ease-out; transform-box: fill-box; transform-origin: center; }
.drop-glow { filter: drop-shadow(0 0 14px #ffd54a) drop-shadow(0 0 6px #fff); }

.hero .cape { transform-box: fill-box; transform-origin: 50% 0; animation: cape 1.1s ease-in-out infinite alternate; }

.ambulance { cursor: pointer; }
.ambulance .wheel { transform-box: fill-box; transform-origin: center; }
.ambulance.driving .abody { 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; }

.ladder-ghost { animation: blink 1s ease-in-out infinite alternate; }
.arrow-hint { transform-box: fill-box; transform-origin: center; animation: nudge .6s ease-in-out infinite alternate; }

/* ---------- 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 drip { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(14px); opacity: 0; } }
@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 blink { from { opacity: .5; } to { opacity: 1; } }
@keyframes nudge { from { transform: scale(.9); } to { transform: scale(1.15); } }
@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 buttons underneath. */
@media (orientation: portrait) and (max-width: 900px) {
  .play-main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .helper-grid { grid-auto-rows: 84px; }
  .tile-row { max-height: 150px; }
  .tile.big { width: 150px; }
  .game-title { display: none; }
}
@media (orientation: portrait) and (max-width: 600px) {
  #title, #end { gap: 12px; }
  .title-amb { height: 15vh; }
  .hero-row svg { height: 11vh; }
  .subtitle { font-size: 19px; }
  .turn-hint { display: block; }
  .stickers { display: none; }
  .bubble { font-size: 16px; padding: 8px 12px; min-height: 0; }
  .panel h2 { font-size: 18px; margin: 0 0 6px; }
  .helper-grid { grid-auto-rows: 74px; gap: 8px; }
  .tile .emoji { font-size: 30px; }
  .tile .label { font-size: 12px; line-height: 1.1; }
}

/* 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(210px, 32vw); gap: 8px; padding: 0 8px 8px; }
  .stage, .panel { border-radius: 18px; }
  .panel { padding: 8px 10px 10px; }
  .panel h2 { font-size: 16px; margin: 2px 0 6px; }
  .panel-body { gap: 8px; }
  .panel-note { font-size: 14px; }
  .bubble { font-size: 15px; padding: 7px 12px; min-height: 0; top: 8px; right: 10px; border-radius: 16px; max-width: 80%; }
  .tile { border-radius: 14px; box-shadow: 0 3px 0 rgba(0, 0, 0, .12); }
  .tile .emoji { font-size: clamp(22px, 8vh, 40px); }
  .tile .label { font-size: 11px; }
  .tile.big { width: min(140px, 90%); }
  .tile.big .emoji { font-size: 56px; }
  .tile.big .label { font-size: 15px; }
  .tile.pedal .emoji { font-size: 44px; }
  .tile-row { gap: 8px; }
  .tile-row.small { height: 64px; }
  .helper-grid { gap: 6px; }
  .meter { font-size: 20px; gap: 4px; }
  .meter .dot { width: 28px; height: 28px; font-size: 16px; border-width: 2px; }
  #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: 17vh; }
  .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; }
}
