/* Danyal's Patterns - styles */
:root {
  --ink: #2b2650;
  --ink-soft: #5b5683;
  --sky-top: #bfe6ff;
  --sky-bot: #effaff;
  --accent: #ff6fae;
  --font: "Nunito", "Baloo 2", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bot) 70%);
  font-family: var(--font); color: var(--ink);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
svg { display: block; }

#app {
  position: relative; margin: 0 auto; width: 100%; max-width: 560px;
  height: 100vh; height: 100dvh; overflow: hidden;
}

/* ---------- scenery ---------- */
.scenery { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.cloud { position: absolute; opacity: .9; }
.cloud.c1 { width: 110px; top: calc(14% + var(--safe-t)); left: -22px; animation: drift 38s ease-in-out infinite alternate; }
.cloud.c2 { width: 80px; top: calc(30% + var(--safe-t)); right: -14px; animation: drift 46s ease-in-out infinite alternate-reverse; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(26px); } }
.grass { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: calc(96px + var(--safe-b)); }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

/* ---------- shared buttons ---------- */
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px;
  background: #fff; color: var(--ink);
  display: grid; place-items: center;
  box-shadow: 0 3px 0 rgba(43,38,80,.14), 0 6px 14px rgba(43,38,80,.10);
  transition: transform .08s;
}
.icon-btn:active { transform: translateY(2px) scale(.96); }
.icon-btn svg { width: 26px; height: 26px; }
.snd .offi { display: none; }
.snd.off .on { display: none; }
.snd.off .offi { display: block; color: #9b97b8; }
.top-right { position: absolute; top: calc(12px + var(--safe-t)); right: 14px; z-index: 3; }
.top-left { position: absolute; top: calc(12px + var(--safe-t)); left: 14px; z-index: 3; }

.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-width: 200px; height: 68px; padding: 0 30px; border-radius: 34px;
  font-weight: 900; font-size: 26px; color: #fff; letter-spacing: .3px;
  text-shadow: 0 2px 0 rgba(0,0,0,.14);
  transition: transform .08s, box-shadow .08s;
}
.big-btn svg { width: 28px; height: 28px; flex: none; }
.big-btn.green { background: #4cc43a; box-shadow: 0 6px 0 #34972a, 0 12px 20px rgba(52,151,42,.28); }
.big-btn.blue  { background: #2f9bff; box-shadow: 0 6px 0 #1f73c4, 0 12px 20px rgba(31,115,196,.25); }
.big-btn.small { height: 56px; min-width: 170px; font-size: 22px; }
.big-btn:active { transform: translateY(4px); }
.big-btn.green:active { box-shadow: 0 2px 0 #34972a; }
.big-btn.blue:active { box-shadow: 0 2px 0 #1f73c4; }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%; background: #fff; color: var(--ink);
  display: grid; place-items: center;
  box-shadow: 0 4px 0 rgba(43,38,80,.14);
}
.round-btn svg { width: 28px; height: 28px; }
.round-btn:active { transform: translateY(2px); }

/* ---------- home ---------- */
.home-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 0 24px 80px; text-align: center;
}
.logo {
  width: 148px; height: 148px; border-radius: 34px;
  box-shadow: 0 8px 0 rgba(43,38,80,.10), 0 16px 30px rgba(43,38,80,.18);
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px); } }
.wordmark {
  margin: 8px 0 0; font-size: clamp(52px, 17vw, 76px); line-height: 1; font-weight: 900; letter-spacing: 1px;
  display: flex; justify-content: center;
}
.wordmark span {
  color: var(--c);
  -webkit-text-stroke: 2px #fff; paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(43,38,80,.16);
  display: inline-block; animation: wave 2.8s ease-in-out infinite;
}
.wordmark span:nth-child(2) { animation-delay: .1s; } .wordmark span:nth-child(3) { animation-delay: .2s; }
.wordmark span:nth-child(4) { animation-delay: .3s; } .wordmark span:nth-child(5) { animation-delay: .4s; }
.wordmark span:nth-child(6) { animation-delay: .5s; } .wordmark span:nth-child(7) { animation-delay: .6s; }
.wordmark span:nth-child(8) { animation-delay: .7s; }
@keyframes wave { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-7px); } }
.tagline { margin: 0 0 14px; font-weight: 800; color: var(--ink-soft); font-size: 18px; }
.today { display: flex; gap: 7px; margin-top: 10px; }
.today i { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid #c9d3f4; display: block; }
.today i.on { background: #ffd51f; border-color: #e0a800; }
.today-cap { margin: 0; font-size: 14px; font-weight: 800; color: var(--ink-soft); }
.caterpillar { position: absolute; left: 14px; bottom: calc(26px + var(--safe-b)); width: 120px; z-index: 2; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 4px; gap: 10px; min-height: 68px;
}
.bar-title { flex: 1; text-align: center; font-size: 22px; font-weight: 900; }
.bar-title.level { display: flex; align-items: center; justify-content: center; gap: 10px; }
.bar-title .badge { width: 54px; height: 54px; display: block; }
.bar-title .txt { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; }
.bar-title .txt b { font-size: 24px; }
.bar-title .txt small { font-size: 14px; font-weight: 800; color: var(--ink-soft); }

/* ---------- level select ---------- */
.level-wrap { flex: 1; overflow: auto; padding: 16px 18px calc(110px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 14px 6px; justify-items: center; }
.lvl { display: flex; flex-direction: column; align-items: center; gap: 2px; transition: transform .1s; }
.lvl:active { transform: scale(.94); }
.lvl > svg { filter: drop-shadow(0 4px 0 rgba(43,38,80,.12)); }
.mini-stars { display: flex; gap: 1px; }
.lvl.helper .mini-stars i { width: 22px; height: 22px; }
.mini-stars i { width: 20px; height: 20px; display: block; }
.mini-stars svg { width: 100%; height: 100%; }

/* ---------- game ---------- */
.stage {
  flex: 1; display: flex; flex-direction: column; justify-content: space-evenly;
  padding: 0 10px calc(100px + var(--safe-b)); gap: 12px; min-height: 0; overflow-y: auto;
}
.prompt { text-align: center; }
.prompt span {
  display: inline-block; padding: 10px 24px; border-radius: 26px;
  background: #fff7f4; border: 3px dashed #ff8a9a;
  font-size: clamp(19px, 5.6vw, 25px); font-weight: 900; color: var(--ink);
}
.strip-card {
  --accent: #ff6fae;
  --tint: #fff2f8; --edge: #ffc2dd; --edge2: #ffe0ee;
  background: var(--tint);
  border: 4px solid var(--edge);
  border-radius: 28px; padding: 18px 8px;
  display: flex; justify-content: center;
  box-shadow: 0 5px 0 var(--edge2), 0 14px 24px rgba(43,38,80,.08);
}
.strip-wrap { position: relative; width: 100%; }
.strip { --tile: 56px; --gap: 4px; display: flex; flex-wrap: nowrap; justify-content: center; gap: var(--gap); width: 100%; margin: 0 auto; }
.marks { position: absolute; left: 0; right: 0; top: 0; height: 0; pointer-events: none; }
.bracket { position: absolute; height: 12px; border: 4px solid var(--bc, #9a5be0); border-top: 0; border-radius: 0 0 12px 12px; animation: bracketIn .35s ease-out; }
@keyframes bracketIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.strip-card.has-marks { padding-bottom: 30px; }
.cell { flex: none; width: var(--tile); height: var(--tile); border-radius: 12px; position: relative; }
.cell svg { width: 100%; height: 100%; }
.cell.blank {
  background: #fff; border: 2.5px dashed var(--ink); border-radius: calc(var(--tile) * .22);
  opacity: .9;
}
.cell.blank.active {
  border-color: var(--accent); opacity: 1;
  animation: pulse 1.1s ease-in-out infinite;
}
.cell.blank.active::after {
  content: "?"; position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 900; font-size: calc(var(--tile) * .5); color: var(--accent);
}
@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 var(--edge); }
  50% { transform: scale(1.07); box-shadow: 0 0 0 7px rgba(255,255,255,0); }
}
.cell.pop { animation: pop .42s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.3) rotate(-12deg); } 100% { transform: none; } }
.cell.hint { animation: hint 1s ease-in-out 3; z-index: 1; }
@keyframes hint {
  0%, 100% { transform: scale(1); filter: none; }
  50% { transform: scale(1.18); filter: drop-shadow(0 0 8px #ffd51f) drop-shadow(0 0 3px #ffd51f); }
}

.tray-wrap { text-align: center; }
.tray-label { font-weight: 800; color: var(--ink-soft); font-size: 15px; margin-bottom: 10px; }
.tray {
  --cols: 4; --tgap: 12px;
  /* choice size: as big as fits `cols` across the screen (16px gutters, 10px stage, 14px tray padding) */
  --ch: clamp(52px, calc((100vw - 32px - 20px - 28px - (var(--cols) - 1) * var(--tgap)) / var(--cols)), 86px);
  display: flex; flex-wrap: wrap; justify-content: center; gap: var(--tgap);
  max-width: calc(var(--cols) * var(--ch) + (var(--cols) - 1) * var(--tgap) + 28px); margin: 0 auto;
  background: rgba(255,255,255,.7); border-radius: 28px; padding: 14px;
  box-shadow: 0 4px 0 rgba(43,38,80,.08);
}
.choice {
  width: var(--ch); height: var(--ch); padding: 10px; border-radius: 22px; background: #fff;
  box-shadow: 0 5px 0 rgba(43,38,80,.16), 0 10px 14px rgba(43,38,80,.08);
  transition: transform .08s, box-shadow .08s;
}
.choice svg { width: 100%; height: 100%; }
.choice:active { transform: translateY(4px) scale(.96); box-shadow: 0 1px 0 rgba(43,38,80,.16); }
.choice.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: none; } 20% { transform: translateX(-8px) rotate(-3deg); }
  40% { transform: translateX(8px) rotate(3deg); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}

/* ladybird buddy */
.bug { position: absolute; left: 14px; bottom: calc(14px + var(--safe-b)); width: 64px; z-index: 2; pointer-events: none; }
.bug.happy .bug-body { animation: hop .55s ease-out; transform-origin: 50% 90%; }
.bug.oops .bug-body { animation: wiggle .5s ease-in-out; transform-origin: 50% 90%; }
@keyframes hop { 40% { transform: translateY(-18px) scale(1.06); } 100% { transform: none; } }
@keyframes wiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } 100% { transform: none; } }

/* ---------- win overlay ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10; display: grid; place-items: center;
  background: rgba(43,38,80,.0); transition: background .3s;
}
.overlay[hidden] { display: none; }
.overlay.on { background: rgba(43,38,80,.35); }
.sheet {
  background: #fff; border-radius: 34px; padding: 26px 26px 22px; width: min(88%, 380px);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  box-shadow: 0 10px 0 rgba(43,38,80,.12), 0 24px 40px rgba(43,38,80,.25);
  position: relative; z-index: 2;
  transform: scale(.7); opacity: 0; transition: transform .4s cubic-bezier(.2, 1.5, .4, 1), opacity .25s;
}
.overlay.on .sheet { transform: none; opacity: 1; }
.sheet h2 { margin: 0; font-size: 34px; font-weight: 900; }
.win-stars { display: flex; gap: 6px; }
.win-stars i { width: 70px; height: 70px; display: block; animation: starIn .6s cubic-bezier(.2, 1.8, .4, 1) both; }
.win-stars i.dim { animation: none; opacity: .9; }
.win-stars i:nth-child(2) { margin-top: -12px; }
.win-stars svg { width: 100%; height: 100%; }
@keyframes starIn { 0% { transform: scale(0) rotate(-40deg); } 100% { transform: none; } }
.sheet-row { display: flex; gap: 18px; }
.sheet .big-btn { width: 100%; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.conf { position: absolute; top: -20px; width: 16px; height: 16px; animation: fall linear forwards; }
.conf.c { border-radius: 50%; }
.conf.s { border-radius: 3px; }
.conf.t { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
@keyframes fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), 105vh) rotate(540deg); opacity: .9; }
}

/* small phones */
@media (max-height: 680px) {
  .bar { min-height: 60px; padding-top: 8px; }
  .stage { gap: 8px; padding-bottom: calc(84px + var(--safe-b)); }
  .tray-label { margin-bottom: 6px; }
  .logo { width: 120px; height: 120px; }
  .home-body { gap: 10px; padding-bottom: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- rest screen (daily limit) ---------- */
.rest-body {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 0 28px 120px; text-align: center;
}
.moon { width: 132px; height: 132px; animation: bob 3.2s ease-in-out infinite; }
.rest-body h2 { margin: 6px 0 0; font-size: 34px; font-weight: 900; }
.rest-body p { margin: 0 0 10px; font-size: 19px; font-weight: 800; color: var(--ink-soft); max-width: 18em; }
.grown {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 18px; border-radius: 22px;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 15px;
  box-shadow: 0 3px 0 rgba(43,38,80,.14);
}
.grown svg { width: 18px; height: 18px; }

/* ---------- grown-ups gate ---------- */
.gate-sheet { gap: 12px; }
.gate-view { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gate-view[hidden] { display: none; }
.gate-sheet h2 { font-size: 28px; }
.gate-sub { margin: 0; text-align: center; font-weight: 800; color: var(--ink-soft); font-size: 15px; }
.pin-dots { display: flex; gap: 12px; margin: 2px 0 4px; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--ink); display: block; }
.pin-dots i.on { background: var(--ink); }
.pin-dots.shake { animation: shake .4s; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; }
.key {
  height: 56px; border-radius: 18px; background: #f1efff; color: var(--ink);
  font-weight: 900; font-size: 26px; display: grid; place-items: center;
  box-shadow: 0 3px 0 rgba(43,38,80,.14);
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(43,38,80,.14); }
.key svg { width: 28px; height: 28px; }
.link-btn { font-weight: 800; font-size: 15px; color: var(--ink-soft); padding: 8px 14px; border-radius: 12px; text-decoration: underline; }
.panel-stats { margin: 0; text-align: center; font-size: 20px; font-weight: 800; line-height: 1.5; }
.panel-stats b { font-size: 26px; font-weight: 900; }
.gate-view .big-btn { width: 100%; min-width: 0; }
.win-today { margin: -6px 0 0; font-weight: 800; color: var(--ink-soft); font-size: 15px; }
.win-today:empty { display: none; }

/* ---------- helper coach, glow, locked tray ---------- */
.coach {
  background: #fff; border: 3px solid #ffd51f; border-radius: 24px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 4px 0 #f0c400, 0 12px 20px rgba(43,38,80,.10);
}
.coach[hidden] { display: none; }
.coach-text { margin: 0; font-weight: 800; font-size: clamp(16px, 4.7vw, 19px); line-height: 1.35; }
.coach-row { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.icon-btn.small { width: 44px; height: 44px; border-radius: 14px; background: #fff8d6; }
.icon-btn.small svg { width: 24px; height: 24px; }
.coach .big-btn { height: 48px; min-width: 124px; padding: 0 20px; font-size: 19px; }
.coach .big-btn[hidden] { display: none; }
.cell.glow { z-index: 1; animation: glowpulse 1s ease-in-out infinite; }
@keyframes glowpulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 #ffd51f); }
  50% { transform: scale(1.16); filter: drop-shadow(0 0 7px #ffd51f) drop-shadow(0 0 3px #ffd51f); }
}
.tray.off .choice { opacity: .45; pointer-events: none; }
.cell.shake { animation: shake .4s; }
