:root {
  --forest: #153d32;
  --forest-2: #225b49;
  --leaf: #54a96c;
  --lime: #d9ef8b;
  --sun: #ffd45d;
  --coral: #f06f5d;
  --cream: #fffaf0;
  --ink: #17362f;
  --muted: #688077;
  --shadow: 0 18px 46px rgba(17, 55, 44, .18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--forest);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; border: 0; cursor: pointer; color: inherit; }
button:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.hidden { display: none !important; }

#app { width: 100%; height: 100vh; height: 100dvh; position: relative; overflow: hidden; }
.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: max(18px, env(safe-area-inset-top)) 20px max(22px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: screen-in .28s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }

.eyebrow { margin: 0 0 7px; font-size: .72rem; font-weight: 900; letter-spacing: .18em; color: #4c816d; }
.icon-button {
  width: 44px; height: 44px; border-radius: 16px; background: rgba(255,255,255,.82);
  display: grid; place-items: center; font-size: 2rem; line-height: 1; box-shadow: 0 8px 24px rgba(20,63,50,.12);
}
.icon-button.light { background: rgba(255,255,255,.14); color: white; box-shadow: none; backdrop-filter: blur(8px); }
.primary-button, .secondary-button, .danger-button {
  width: 100%; min-height: 56px; border-radius: 19px; padding: 0 20px; font-weight: 900; font-size: 1rem;
}
.primary-button { background: var(--sun); color: #3b351b; box-shadow: 0 12px 28px rgba(173,128,21,.28); }
.primary-button span { float: right; font-size: 1.35rem; }
.secondary-button { background: rgba(255,255,255,.88); color: var(--forest); }
.danger-button { background: var(--coral); color: white; }
.text-button { background: transparent; color: var(--forest-2); font-weight: 900; padding: 14px; }

/* Home */
#homeScreen {
  flex-direction: column;
  justify-content: space-between;
  background:
    radial-gradient(circle at 85% 17%, rgba(255,224,116,.75) 0 7%, transparent 7.4%),
    linear-gradient(165deg, #eaf5cd 0%, #c9e8b4 48%, #8fc99d 100%);
  isolation: isolate;
}
#homeScreen::before, #homeScreen::after {
  content: ""; position: absolute; left: -10%; right: -10%; bottom: -5%; height: 31%; z-index: -1;
  border-radius: 55% 45% 0 0 / 55% 45% 0 0; background: #397b5d; transform: rotate(3deg);
}
#homeScreen::after { bottom: -14%; left: 22%; right: -22%; height: 34%; background: #1f5946; transform: rotate(-6deg); }
.exit-button { align-self: flex-end; position: relative; z-index: 4; }
.home-cloud { position: absolute; width: 110px; height: 33px; border-radius: 40px; background: rgba(255,255,255,.45); z-index: -1; }
.home-cloud::before, .home-cloud::after { content:""; position:absolute; border-radius:50%; background:inherit; }
.home-cloud::before { width:45px;height:45px;left:19px;bottom:0; }.home-cloud::after{width:58px;height:58px;right:13px;bottom:0}
.cloud-one { top: 8%; left: -34px; }.cloud-two { top: 27%; right: -46px; transform:scale(.75); }
.hero-copy { margin-top: clamp(5px, 2vh, 22px); max-width: 540px; }
.hero-copy h1 { margin: 0; font-size: clamp(3.6rem, 17vw, 6.8rem); line-height: .74; letter-spacing: -.075em; color: var(--forest); text-shadow: 0 3px 0 rgba(255,255,255,.4); }
.hero-copy h1 span { color: var(--coral); margin-left: .38em; }
.tagline { max-width: 410px; margin: 20px 0 0; font-weight: 700; line-height: 1.42; color: #315c4c; }
.hero-characters { min-height: 170px; display: flex; align-items: center; justify-content: center; gap: 10px; position: relative; }
.character-card { width: clamp(105px, 31vw, 150px); aspect-ratio: 1; overflow: hidden; border: 5px solid rgba(255,255,255,.88); border-radius: 50%; box-shadow: var(--shadow); background: #1c604a; }
.character-card img { width: 100%; height: 100%; object-fit: cover; }
.child-card { transform: rotate(-5deg); }.child-card img { object-position: 50% 22%; }
.mother-card { transform: rotate(5deg); }.mother-card img { object-position: 50% 18%; }
.trail-dots { display: flex; gap: 5px; transform: rotate(-12deg); }
.trail-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.9); animation: blink 1.2s infinite alternate; }
.trail-dots i:nth-child(2){animation-delay:.2s}.trail-dots i:nth-child(3){animation-delay:.4s}
@keyframes blink { to { opacity:.25; transform:scale(.7); } }
.home-actions { display: grid; gap: 10px; z-index: 2; }
.offline-note { margin: 10px 0 0; text-align: center; color: rgba(255,255,255,.8); font-size: .78rem; font-weight: 700; z-index:2; }
.offline-note span { display:inline-block;width:7px;height:7px;border-radius:50%;background:#8fee9b;margin-right:6px; }

/* Level map */
#levelScreen { background: #f5f3e7; flex-direction: column; }
.topbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 13px; }
.topbar h2 { margin: 0; font-size: 1.55rem; }.topbar .eyebrow { margin-bottom:2px; }
.progress-card { margin: 22px 0 15px; padding: 17px 18px; border-radius: 22px; color: white; background: linear-gradient(135deg,#1d5b48,#347b5b); box-shadow: var(--shadow); }
.progress-card > div:first-child { display:flex; justify-content:space-between; align-items:end; }
.progress-label { display:block;font-size:.76rem;color:rgba(255,255,255,.7);font-weight:700; }.progress-card strong{font-size:1.15rem}
.progress-track { height:8px;margin-top:12px;background:rgba(0,0,0,.18);border-radius:8px;overflow:hidden; }
.progress-track span { display:block;height:100%;width:0;border-radius:inherit;background:var(--sun);transition:width .4s ease; }
.level-grid { display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:13px;padding-bottom:16px; }
.level-card { position:relative;min-height:158px;padding:15px;border-radius:24px;text-align:left;overflow:hidden;color:white;box-shadow:0 12px 28px rgba(24,58,48,.16); }
.level-card::after { content:"";position:absolute;width:92px;height:92px;border:20px solid rgba(255,255,255,.09);border-radius:50%;right:-35px;bottom:-34px; }
.level-card .number { display:grid;place-items:center;width:34px;height:34px;border-radius:12px;background:rgba(255,255,255,.2);font-weight:900;backdrop-filter:blur(5px); }
.level-card h3 { position:relative;margin:19px 0 5px;font-size:1rem;line-height:1.05;z-index:1; }
.level-card .difficulty { position:relative;display:block;font-size:.7rem;color:rgba(255,255,255,.72);font-weight:700;z-index:1; }
.level-card .level-best { position:relative;display:block;margin-top:5px;font-size:.64rem;font-weight:800;color:var(--sun);z-index:1; }
.level-stars { position:absolute;right:13px;top:13px;font-size:.8rem;letter-spacing:1px;color:var(--sun);z-index:1; }
.level-card.locked { filter:saturate(.15);opacity:.58;box-shadow:none; }
.level-card.locked::before { content:"🔒";position:absolute;inset:0;display:grid;place-items:center;font-size:1.5rem;background:rgba(28,47,42,.25);z-index:3; }

/* Game */
.game-screen { flex-direction:column;background:var(--forest);padding-left:14px;padding-right:14px;color:white;overflow:hidden; }
.game-topbar { display:grid;grid-template-columns:44px 1fr 44px;align-items:center;gap:10px;flex:0 0 auto; }
.game-title { text-align:center;min-width:0; }.game-title span{display:block;font-size:.61rem;letter-spacing:.16em;color:#a8c9b8;font-weight:900}.game-title strong{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:1.05rem;margin-top:2px}
.hud { margin:10px 3px 9px;display:grid;grid-template-columns:repeat(3,1fr);background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.08);border-radius:17px;flex:0 0 auto; }
.hud div { text-align:center;padding:8px 3px; }.hud div+div{border-left:1px solid rgba(255,255,255,.1)}.hud span{display:block;font-size:.61rem;color:#a8c9b8;font-weight:700}.hud strong{font-size:1.05rem;color:var(--sun)}
.maze-shell { position:relative;width:100%;max-width:600px;min-height:0;flex:1 1 auto;align-self:center;border-radius:27px;overflow:hidden;background:#315c48;box-shadow:0 16px 34px rgba(0,0,0,.22); }
#mazeCanvas { display:block;width:100%;height:100%;touch-action:none; }
.maze-instruction { position:absolute;left:50%;top:14px;transform:translateX(-50%);white-space:nowrap;background:rgba(15,47,38,.83);border:1px solid rgba(255,255,255,.12);border-radius:999px;padding:8px 13px;font-size:.7rem;font-weight:800;pointer-events:none;transition:opacity .4s,transform .4s; }
.maze-instruction.hide { opacity:0;transform:translate(-50%,-8px); }
.game-tools { display:flex;justify-content:center;gap:6px;margin:9px 0 7px;flex:0 0 auto;width:100%;max-width:600px;align-self:center; }
.tool-button { flex:1 1 0;min-width:0;padding:9px 4px;border-radius:14px;background:rgba(255,255,255,.1);color:#d8eee3;font-size:.7rem;font-weight:800;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;transition:background .2s,color .2s; }
.tool-button span{color:var(--sun);margin-right:3px}
.tool-button em{font-style:normal}
.tool-button.hint{background:#2d7458}
.tool-button.active{background:var(--sun);color:#3b351b}.tool-button.active span{color:#3b351b}
.dpad { width:182px;height:112px;display:grid;grid-template-columns:repeat(3,56px);grid-template-rows:repeat(2,50px);gap:6px;align-self:center;flex:0 0 auto; }
.dpad button { border-radius:16px;background:rgba(255,255,255,.16);color:white;font-size:1rem;box-shadow:inset 0 1px rgba(255,255,255,.12);touch-action:manipulation; }
.dpad button:active { background:var(--sun);color:var(--forest);transform:scale(.94); }
.dpad button[data-dir="0"]{grid-column:2}.dpad button[data-dir="3"]{grid-column:1;grid-row:2}.dpad-center{display:none}.dpad button[data-dir="1"]{grid-column:3;grid-row:2}.dpad button[data-dir="2"]{display:block;grid-column:2;grid-row:2}

/* Modals */
.modal { position:fixed;inset:0;z-index:30;display:none;align-items:center;justify-content:center;padding:22px;background:rgba(9,34,27,.7);backdrop-filter:blur(10px); }
.modal.show { display:flex;animation:fade-in .2s ease; }.modal.show .modal-card{animation:pop-in .35s cubic-bezier(.2,.9,.2,1.15)}
@keyframes fade-in{from{opacity:0}}@keyframes pop-in{from{opacity:0;transform:translateY(18px) scale(.94)}}
.modal-card { position:relative;width:min(100%,410px);border-radius:30px;padding:27px 22px;background:var(--cream);text-align:center;box-shadow:0 28px 70px rgba(0,0,0,.3);overflow:hidden; }
.modal-card h2{margin:4px 0 9px;font-size:1.75rem}.modal-card p{color:var(--muted);line-height:1.4}.modal-card .primary-button{margin-top:17px}
.reunion { height:112px;display:flex;justify-content:center;align-items:center;gap:8px;position:relative;z-index:2; }.reunion img{width:88px;height:88px;border-radius:50%;object-fit:cover;border:4px solid white;box-shadow:0 8px 18px rgba(20,60,47,.2)}.reunion-child{object-position:50% 20%}.reunion-mother{object-position:50% 18%}.reunion span{font-size:1.6rem;color:var(--coral);animation:heart .7s infinite alternate}@keyframes heart{to{transform:scale(1.25)}}
.win-rays { position:absolute;left:50%;top:-105px;width:270px;height:270px;transform:translateX(-50%);border-radius:50%;background:repeating-conic-gradient(rgba(255,211,88,.18) 0 12deg,transparent 12deg 24deg); }
.win-stars { color:#e8aa21;font-size:2.35rem;letter-spacing:5px;line-height:1;margin:14px 0; }
.win-stats{display:grid;grid-template-columns:1fr 1fr;gap:1px;margin:16px 0 0;background:#e1e7dc;border-radius:18px;overflow:hidden}.win-stats div{background:#f0f1e8;padding:12px}.win-stats span{display:block;font-size:.7rem;color:var(--muted)}.win-stats strong{font-size:1.25rem;color:var(--forest)}
.compact-card{padding-top:32px}.compact-card .secondary-button{margin-top:9px;background:#e8ece3}.exit-icon{width:62px;height:62px;margin:0 auto 14px;display:grid;place-items:center;border-radius:20px;background:#dcebd7;color:var(--forest);font-size:2rem}.compact-card p{margin:0 0 20px}
.toast { position:fixed;z-index:50;left:50%;bottom:max(25px,env(safe-area-inset-bottom));transform:translate(-50%,20px);max-width:calc(100% - 40px);padding:11px 16px;border-radius:14px;background:#102f27;color:white;font-size:.78rem;font-weight:700;opacity:0;pointer-events:none;transition:.25s;box-shadow:var(--shadow); }.toast.show{opacity:1;transform:translate(-50%,0)}

@media (min-width: 680px) {
  .screen { padding-left:max(30px,calc((100vw - 720px)/2));padding-right:max(30px,calc((100vw - 720px)/2)); }
  .level-grid{grid-template-columns:repeat(3,1fr)}
  .hero-copy h1{font-size:6rem}.hero-characters{min-height:210px}
}
@media (max-height: 690px) {
  .hero-copy h1{font-size:3.4rem}.tagline{margin-top:12px;font-size:.86rem}.hero-characters{min-height:120px}.character-card{width:98px}.offline-note{display:none}
  .hud{margin-top:6px;margin-bottom:6px}.game-tools{margin:5px 0}.dpad{height:104px;transform:scale(.9);transform-origin:top center;margin-bottom:-10px}
}
@media (max-height: 570px) { .dpad{display:none}.game-tools{margin-bottom:2px}.maze-instruction{display:none} }
