:root {
  --sky1: #bae6fd;
  --sky2: #fef9c3;
  --card: #ffffff;
  --card2: #f1f5f9;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #7c3aed;
  --accent2: #ec4899;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --warn: #f59e0b;
  --rock: #a16207;
  --rock2: #78350f;
  --grass: #4ade80;
  --radius: 18px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: linear-gradient(180deg, var(--sky1) 0%, var(--sky2) 100%) fixed;
  color: var(--text);
  font: 17px/1.45 "Fredoka", "Segoe UI Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
}
body { padding: 10px 12px calc(16px + env(safe-area-inset-bottom)); max-width: 1000px; margin: 0 auto; }
h1, h2, h3 { margin: 0 0 6px; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 6px 0; }
code { font-size: 0.85em; background: var(--card2); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error-text { color: var(--bad); }
.big-h { text-align: center; font-size: 1.7rem; margin: 10px 0 4px; }
.big-text { font-size: 1.4rem; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.clickable { cursor: pointer; }
.who { display: flex; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 0; border-radius: 999px;
  padding: 6px 14px; font: inherit; font-weight: 600; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1); color: var(--text);
}
button.chip { cursor: pointer; }
.chip.score { background: #fde68a; }

/* cards & buttons */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.narrow { max-width: 440px; margin: 20px auto; }
.pastel-blue { background: #e0f2fe; }
.pastel-pink { background: #fce7f3; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.row.center { justify-content: center; }
.two-col { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: 10px 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  background: #fff; color: var(--text); border: 2px solid #cbd5e1; border-radius: 10px; padding: 9px 12px; font: inherit; min-width: 0; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }
.row > input[type="text"] { flex: 1 1 160px; width: auto; }

.btn {
  background: var(--card2); color: var(--text); border: 0; border-radius: 14px; padding: 10px 18px; font: inherit; font-weight: 700;
  cursor: pointer; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12); touch-action: manipulation; transition: transform 0.08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost.close { background: #fff; color: var(--text, #333); font-size: 1.1rem; padding: 6px 14px; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.btn.small { padding: 6px 12px; font-size: 0.9rem; }
.btn.big { font-size: 1.25rem; padding: 14px 28px; border-radius: 18px; }
.btn.hear { background: #fde68a; font-size: 1.15rem; padding: 12px 20px; }

.message { padding: 10px 12px; border-radius: 12px; background: #e0f2fe; margin: 8px 0; }
.message.error { background: var(--bad-bg); color: var(--bad); }
.message.ok { background: var(--good-bg); color: var(--good); }

/* choice grids (children, rewards, tables) */
.choice-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 14px 0; }
.pill-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); margin-top: 10px; }
.choice {
  background: var(--card); border: 3px solid transparent; border-radius: 22px; padding: 16px 10px; font: inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: var(--shadow); color: var(--text);
  transition: transform 0.12s;
}
.choice:hover { transform: translateY(-3px) scale(1.02); border-color: var(--accent); }
.choice:active { transform: translateY(2px); }
.choice.tall { padding: 22px 10px; }
.choice-emoji { font-size: 3rem; line-height: 1; }
.pill-grid .choice-emoji { font-size: 1.9rem; }
.choice-title { font-weight: 700; font-size: 1.15rem; }
.choice-sub { color: var(--muted); font-size: 0.85rem; }
.choice .badge { background: #fde68a; border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 0.95rem; }

/* ---------- game ---------- */
.game { display: grid; grid-template-columns: 1fr 190px; gap: 12px; align-items: stretch; }
.play-col { display: flex; flex-direction: column; min-width: 0; }
.status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.status .btn { margin-left: auto; }

.fall-zone {
  position: relative; height: 46vh; min-height: 300px; background: rgba(255, 255, 255, 0.55); border-radius: var(--radius); overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.9);
}
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 22px; background: linear-gradient(#86efac, #4ade80); border-top: 3px solid #22c55e; }
.falling {
  position: absolute; left: 50%; top: -80px; transform: translateX(-50%);
  background: #fff; border-radius: 20px; padding: 10px 26px; font-size: 2.6rem; font-weight: 700; white-space: nowrap;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12); border: 4px solid var(--accent); color: var(--accent);
}
.falling.right { border-color: var(--good); color: var(--good); background: var(--good-bg); animation: pop 0.5s; }
.falling.wrong { border-color: var(--bad); color: var(--bad); background: var(--bad-bg); animation: shake 0.45s; }
.falling.smash { border-color: var(--bad); color: var(--bad); animation: smash 0.5s forwards; }
.zone-msg {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: #fff; padding: 10px 20px; border-radius: 16px;
  font-size: 1.4rem; font-weight: 700; box-shadow: var(--shadow); text-align: center; white-space: nowrap;
}
.zone-msg.bad { color: var(--bad); }
.zone-msg.good { color: var(--good); }
.answers { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); margin-top: 10px; }
.answers .btn {
  font-size: 1.9rem; padding: 14px 6px; background: #fff; border: 3px solid #c4b5fd; border-radius: 18px; min-height: 68px;
}
.answers .btn.right { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.answers .btn.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }

/* spelling */
.spell { background: rgba(255, 255, 255, 0.55); border: 3px solid rgba(255, 255, 255, 0.9); border-radius: var(--radius); padding: 18px; min-height: 300px; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; }
.spell-top { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#spellForm { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 420px; align-items: center; }
#spellInput { font-size: 2rem; text-align: center; letter-spacing: 0.08em; padding: 12px; border-width: 3px; border-color: #c4b5fd; border-radius: 16px; }
.spell-msg { font-size: 1.4rem; font-weight: 700; text-align: center; padding: 10px 18px; border-radius: 16px; }
.spell-msg.good { background: var(--good-bg); color: var(--good); }
.spell-msg.bad { background: var(--bad-bg); color: var(--bad); }
.spell-msg .letters { display: inline-flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.spell-msg .letters span { background: #fff; border-radius: 8px; padding: 2px 9px; font-size: 1.5rem; letter-spacing: 0; color: var(--text); }

.feedback { margin-top: 10px; text-align: center; font-weight: 700; font-size: 1.2rem; }

/* the cliff */
.cliff-col { display: flex; }
.cliff {
  position: relative; flex: 1; min-height: 420px; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(180deg, #7dd3fc 0%, #bae6fd 55%, #fde68a 100%);
  border: 3px solid rgba(255, 255, 255, 0.9);
}
.cliff::after {
  /* the rock face on the right */
  content: ""; position: absolute; right: 0; top: 40px; bottom: 0; width: 46%;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.15) 0 10px, transparent 11px),
    radial-gradient(circle at 70% 60%, rgba(0, 0, 0, 0.12) 0 8px, transparent 9px),
    repeating-linear-gradient(170deg, var(--rock) 0 26px, #b45309 26px 52px);
  border-left: 5px solid var(--rock2); clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 12% 92%, 4% 80%, 14% 68%, 2% 55%, 12% 42%, 3% 30%, 14% 18%, 5% 8%);
}
.grass { position: absolute; right: 0; top: 30px; width: 46%; height: 16px; background: var(--grass); border-radius: 8px 0 0 8px; z-index: 2; box-shadow: inset 0 -4px 0 #22c55e; }
.cliff-reward { position: absolute; right: 14px; top: -2px; font-size: 2.2rem; z-index: 3; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.15)); animation: float 2.5s ease-in-out infinite; }
.sky-deco { position: absolute; left: 8px; top: 60px; font-size: 1.6rem; opacity: 0.9; animation: drift 14s linear infinite; }
.sky-deco.two { top: 150px; font-size: 1.1rem; animation-duration: 20s; animation-delay: -7s; }
.pit { position: absolute; left: 0; right: 0; bottom: 0; height: 30px; background: linear-gradient(#92400e, #451a03); z-index: 2; }
#ledges { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.ledge { position: absolute; right: 40%; width: 26px; height: 7px; background: var(--rock2); border-radius: 4px; }
.ledge.major { width: 36px; right: 38%; }
.ledge .lbl { position: absolute; right: 100%; top: -9px; margin-right: 6px; font-size: 0.75rem; color: #fff; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); font-weight: 700; white-space: nowrap; }
.lion {
  position: absolute; left: 50%; width: 76px; height: 76px; margin-left: -56px; bottom: 26px; z-index: 4;
  transition: bottom 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.lion svg { width: 100%; height: 100%; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.18)); }
.lion .mouth-sad { display: none; }
.lion.sad .mouth-sad { display: block; }
.lion.sad .mouth-happy { display: none; }
.lion.hop svg { animation: hop 0.6s; }
.lion.slip svg { animation: slip 0.7s; }
.lion.party svg { animation: party 0.6s infinite; }
.lion .bubble {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #fff; border-radius: 12px; padding: 4px 10px;
  font-weight: 700; white-space: nowrap; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12); font-size: 0.95rem; margin-bottom: 4px;
}
.lion .bubble::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; }

/* win */
.win { position: relative; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.win-card { text-align: center; max-width: 560px; margin: 30px auto; position: relative; z-index: 6; padding: 28px 20px; }
.win-emoji { font-size: 5rem; line-height: 1; animation: pop 0.8s; }
.win-card h2 { font-size: 2.2rem; color: var(--accent); }

/* rewards shelf */
.shelf { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); margin: 14px 0; }
.trophy { background: var(--card); border-radius: 18px; padding: 14px 10px; text-align: center; box-shadow: var(--shadow); }
.trophy .em { font-size: 2.6rem; line-height: 1.1; }
.trophy .nm { font-weight: 700; }
.trophy .dt { color: var(--muted); font-size: 0.8rem; }
.trophy .given { color: var(--good); font-size: 0.85rem; font-weight: 700; }

/* parent area */
.parent { font-size: 15px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; align-items: center; }
.tabs button { border: 0; background: rgba(255, 255, 255, 0.7); border-radius: 999px; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer; color: var(--text); }
.tabs button.active { background: var(--accent); color: #fff; }
.tabs .exit { margin-left: auto; background: transparent; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid #e2e8f0; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
td input[type="text"], td input[type="number"] { padding: 5px 8px; font-size: 0.95rem; }
td input.short { width: 70px; }
td input.tiny { width: 52px; }
td .btn.small { padding: 4px 9px; font-size: 0.8rem; margin-right: 4px; }
tr.off td { opacity: 0.5; }
.table-wrap { overflow-x: auto; }
.pct-good { color: var(--good); font-weight: 700; }
.pct-mid { color: var(--warn); font-weight: 700; }
.pct-bad { color: var(--bad); font-weight: 700; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-card { max-width: 420px; width: 100%; text-align: center; }

/* animations */
@keyframes pop { 0% { transform: translateX(-50%) scale(1); } 40% { transform: translateX(-50%) scale(1.18); } 100% { transform: translateX(-50%) scale(1); } }
.win-emoji { animation-name: pop-plain; }
@keyframes pop-plain { 0% { transform: scale(0.4); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(-50%); } 20% { transform: translateX(calc(-50% - 10px)); } 40% { transform: translateX(calc(-50% + 10px)); } 60% { transform: translateX(calc(-50% - 7px)); } 80% { transform: translateX(calc(-50% + 7px)); } }
@keyframes smash { 0% { transform: translateX(-50%) scale(1); opacity: 1; } 100% { transform: translateX(-50%) scale(1.4, 0.3); opacity: 0; } }
@keyframes hop { 0% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-14px) rotate(-8deg); } 70% { transform: translateY(2px) rotate(4deg); } 100% { transform: translateY(0); } }
@keyframes slip { 0% { transform: rotate(0); } 25% { transform: rotate(14deg) translateY(4px); } 50% { transform: rotate(-12deg); } 75% { transform: rotate(8deg); } 100% { transform: rotate(0); } }
@keyframes party { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-12px) rotate(6deg); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes drift { from { transform: translateX(-40px); } to { transform: translateX(120px); } }

@media (max-width: 640px) {
  .game { grid-template-columns: 1fr 120px; gap: 8px; }
  .fall-zone { height: 40vh; min-height: 240px; }
  .falling { font-size: 2rem; padding: 8px 18px; }
  .answers .btn { font-size: 1.6rem; min-height: 60px; }
  .lion { width: 56px; height: 56px; margin-left: -44px; }
  .ledge .lbl { display: none; }
  .cliff-reward { font-size: 1.7rem; }
  .big-h { font-size: 1.4rem; }
  .btn.big { font-size: 1.1rem; padding: 12px 20px; }
}

/* animal picker */
.choice-grid.animals { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); max-width: 640px; margin-left: auto; margin-right: auto; }
.animal-pic { display: block; width: 84px; height: 84px; margin: 0 auto; }
.animal-pic svg { width: 100%; height: 100%; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.15)); }
.animal-pic .mouth-sad { display: none; }
.choice.animal.last { border-color: var(--accent); }
.choice.animal:hover .animal-pic svg { animation: hop 0.6s; }
