* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Rounded", system-ui, sans-serif;
  background: #f6e3ec; color: #5e3a52;
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
#wrap { position: relative; width: 100%; height: 100%; max-width: 520px; max-height: 100%; }
#game { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.hidden { display: none !important; }

/* springy iOS press physics on everything tappable */
button { font-family: inherit; touch-action: manipulation; }
.big-btn, .ghost-btn, .shop-item, .power-btn, .owned-btn, .skip-link, #hud-sound {
  transition: transform .16s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, background-color .2s ease, opacity .2s ease;
}

/* ---------- enemy HP plate (floats above the canvas enemy) ---------- */
#enemy {
  position: absolute; top: calc(56px + env(safe-area-inset-top)); right: 8px;
  width: 190px; text-align: center; pointer-events: none; z-index: 5;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(224,184,204,.8); border-radius: 16px;
  padding: 8px 10px 9px;
  box-shadow: 0 4px 16px rgba(94,58,82,.12);
}
#enemy-name { font-size: 13px; font-weight: 800; letter-spacing: 1px; color: #c25e7a; margin-bottom: 4px; text-shadow: 0 2px 8px rgba(255,255,255,.8); }
#enemy-hpbar {
  height: 10px; border-radius: 999px; background: rgba(255,255,255,.6);
  border: 1px solid rgba(194,94,122,.45); overflow: hidden;
}
#enemy-hp-fill {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #e0637f, #f0a35e);
  transition: width .25s ease-out;
}
#enemy-tell { font-size: 11px; color: #d63a5c; font-weight: 700; min-height: 15px; margin-top: 3px; }

/* ---------- feat callout ---------- */
#feat {
  position: absolute; top: 30%; left: 0; right: 0; z-index: 12;
  text-align: center; pointer-events: none; opacity: 0;
}
#feat.play { animation: featPop 1.9s ease-out forwards; }
@keyframes featPop {
  0% { opacity: 0; transform: scale(.5); }
  12% { opacity: 1; transform: scale(1.12); }
  22% { transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05) translateY(-14px); }
}
#feat-name {
  font-size: 38px; font-weight: 900; letter-spacing: 2px; color: #e8930c;
  text-shadow: 0 0 22px rgba(255,200,90,.9), 0 2px 0 #fff;
}
#feat-sub { font-size: 15px; font-weight: 700; color: #5e3a52; margin-top: 4px; text-shadow: 0 1px 0 #fff; }

/* ---------- HUD: balls (big), depth, goal. Nothing else. ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  pointer-events: none; z-index: 5;
}
.hud-left {
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(224,184,204,.8); border-radius: 18px;
  padding: 8px 16px 10px;
  box-shadow: 0 4px 16px rgba(94,58,82,.12);
}
#hud-level { font-size: 11px; letter-spacing: 2px; color: #a06a86; font-weight: 700; }
#hud-balls {
  font-size: 30px; font-weight: 900; font-variant-numeric: tabular-nums;
  color: #5e3a52; text-shadow: 0 0 18px rgba(232,147,12,.4); line-height: 1.15;
}
#hud-orange { font-size: 14px; color: #e07f2e; font-weight: 800; margin-top: 2px; }
.hud-right { text-align: right; }
#hud-sound {
  pointer-events: auto;
  background: rgba(255,255,255,.75);
  border: 1px solid #e0b8cc;
  border-radius: 10px;
  font-size: 14px; line-height: 1; padding: 6px 9px;
  cursor: pointer; color: #5e3a52;
}
#hud-sound:active { transform: scale(.9); }

#fade { position: absolute; inset: 0; background: #fff0f5; opacity: 0; pointer-events: none; z-index: 20; }

#hint {
  position: absolute; left: 16px; right: 16px;
  bottom: calc(150px + env(safe-area-inset-bottom));
  z-index: 8; text-align: center; font-size: 13px; font-weight: 600;
  color: #5e3a52; background: rgba(255,255,255,.96);
  border: 1px solid #e0b8cc; border-radius: 14px;
  padding: 12px 14px; line-height: 1.5;
  box-shadow: 0 4px 24px rgba(0,0,0,.25);
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(255,240,246,.92); backdrop-filter: blur(6px);
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  text-align: center; overflow-y: auto; overflow-x: hidden;
  touch-action: pan-y manipulation;
}
.overlay > * { max-width: 100%; flex-shrink: 0; }
/* unified springy entrance: backdrop fades, children rise in with a stagger */
.overlay:not(.hidden) { animation: overlayFade .22s ease-out; }
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
.overlay:not(.hidden) > * { animation: overlayIn .45s cubic-bezier(.22,1.4,.36,1) backwards; }
.overlay:not(.hidden) > *:nth-child(2) { animation-delay: .045s; }
.overlay:not(.hidden) > *:nth-child(3) { animation-delay: .09s; }
.overlay:not(.hidden) > *:nth-child(4) { animation-delay: .135s; }
.overlay:not(.hidden) > *:nth-child(5) { animation-delay: .18s; }
.overlay:not(.hidden) > *:nth-child(6) { animation-delay: .225s; }
.overlay:not(.hidden) > *:nth-child(7) { animation-delay: .27s; }
@keyframes overlayIn {
  from { opacity: 0; transform: translateY(22px) scale(.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- home ---------- */
#menu { justify-content: center; }
.home-art { position: relative; width: 230px; height: 158px; margin-bottom: 6px; }
.home-kitten { position: absolute; left: 26px; top: 8px; animation: floaty 3.4s ease-in-out infinite; }
.hk-ear {
  position: absolute; top: -13px; width: 0; height: 0;
  border-left: 17px solid transparent; border-right: 17px solid transparent;
  border-bottom: 28px solid #e8b04b;
}
.hk-ear::after {
  content: ""; position: absolute; left: -10px; top: 9px; width: 0; height: 0;
  border-left: 10px solid transparent; border-right: 10px solid transparent;
  border-bottom: 16px solid #f8d3de;
}
.hk-ear.l { left: 8px; transform: rotate(-13deg); }
.hk-ear.r { right: 8px; transform: rotate(13deg); }
.hk-face {
  position: relative; width: 106px; height: 98px;
  background: #fff7ee; border: 3px solid #e8b04b; border-radius: 50%;
  box-shadow: 0 8px 24px rgba(232,147,12,.25);
}
.hk-eye {
  position: absolute; top: 36px; width: 17px; height: 10px;
  border-bottom: 3.5px solid #5e3a52; border-radius: 0 0 17px 17px;
}
.hk-eye.l { left: 22px; } .hk-eye.r { right: 22px; }
.hk-blush { position: absolute; top: 48px; width: 15px; height: 9px; background: #f8a8b8; border-radius: 50%; opacity: .75; }
.hk-blush.l { left: 10px; } .hk-blush.r { right: 10px; }
.hk-nose {
  position: absolute; top: 42px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent; border-right: 6px solid transparent;
  border-top: 5px solid #e07f8a;
}
.hk-mouth {
  position: absolute; top: 47px; left: 50%; transform: translateX(-50%);
  width: 17px; height: 9px; border-bottom: 2.5px solid #c96f8a; border-radius: 0 0 17px 17px;
}
.home-yarn { position: absolute; right: 14px; bottom: 2px; animation: floaty 2.7s ease-in-out infinite reverse; }
.hy-ball {
  width: 58px; height: 58px; border-radius: 50%;
  background: repeating-linear-gradient(45deg, #f5b8c9 0 5px, #ef8ba5 5px 10px);
  border: 2.5px solid #e07f8a;
  box-shadow: 0 8px 20px rgba(224,127,138,.45);
}
.hy-string {
  width: 3px; height: 30px; background: #e07f8a; border-radius: 2px;
  margin: -3px auto 0; transform: rotate(10deg); transform-origin: top center;
}
@keyframes floaty { 50% { transform: translateY(-9px); } }
.title {
  font-size: 66px; font-weight: 900; letter-spacing: 8px; margin-left: 8px;
  background: linear-gradient(180deg, #ffb37e 0%, #ff8a5e 32%, #f0647a 66%, #a05ce0 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(255,255,255,.95)) drop-shadow(0 12px 30px rgba(240,99,122,.45));
  margin-bottom: 4px;
}
.tagline { color: #8a5a72; font-size: 15px; margin-bottom: 30px; }
.hint { color: #a06a86; font-size: 13px; max-width: 300px; line-height: 1.5; margin-bottom: 18px; }
.ghost-btn { background: none; border: 1px solid #e0b8cc; color: #a06a86; border-radius: 999px; padding: 8px 18px; font-size: 13px; cursor: pointer; }
.ghost-btn:active { transform: scale(.94); }
#btn-newrun { margin-bottom: 14px; font-size: 20px; padding: 16px 34px; width: 240px; }
#btn-continue { margin-bottom: 14px; width: 240px; }
#run-best { margin-bottom: 14px; min-height: 18px; font-size: 14px; color: #8a5a72; font-weight: 600; }
#menu-global { margin-bottom: 16px; }
#ver { margin-top: 14px; font-size: 11px; opacity: 0.4; }

.big-btn {
  border: 1px solid #e0b8cc; background: #ffffff; color: #5e3a52;
  font-size: 16px; font-weight: 700; border-radius: 16px; padding: 14px 22px; min-height: 52px;
  cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.big-btn.primary {
  background: linear-gradient(180deg, #ff9a3d, #ff5e7a); border: none; color: #fff;
  box-shadow: 0 6px 26px rgba(255,110,80,.45);
}
.big-btn:active { transform: scale(.95); }
.big-btn:disabled { opacity: .45; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; }

/* ---------- result (fail / death) ---------- */
#result-title {
  font-size: 52px; font-weight: 900; letter-spacing: 3px; margin-bottom: 8px;
  background: linear-gradient(180deg, #e8930c, #e07f2e 50%, #d63a5c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 30px rgba(255,170,60,.6));
  animation: dreamPulse .6s ease-in-out infinite alternate;
}
@keyframes dreamPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
#result.lost #result-title {
  background: linear-gradient(180deg, #aab4e8, #5c669e);
  -webkit-background-clip: text; background-clip: text;
  animation: none; filter: none;
}
#result-sub { color: #8a5a72; font-size: 15px; margin-bottom: 14px; max-width: 320px; line-height: 1.5; }
#result-score { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
#result-best { color: #a06a86; font-size: 14px; margin-bottom: 26px; }

/* ---------- saga map: winding left-to-right path ---------- */
#map { justify-content: flex-start; padding-top: calc(52px + env(safe-area-inset-top)); }
#map-title {
  font-size: 28px; font-weight: 900; letter-spacing: 3px; margin-bottom: 6px;
  background: linear-gradient(180deg, #e8930c, #e07f2e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255,180,60,.5));
}
#map-stats { color: #8a5a72; font-size: 14px; font-weight: 700; margin-bottom: 10px; line-height: 1.7; }
#map-stats b { color: #5e3a52; }
#map-track-wrap {
  flex: 1 1 auto; min-height: 320px; align-self: stretch;
  width: 100%; max-width: 460px;
  overflow-x: hidden; overflow-y: auto;
  padding: 8px 0; margin-bottom: 4px;
  -webkit-overflow-scrolling: touch; scroll-behavior: smooth;
  touch-action: pan-x pan-y;
  scrollbar-width: none;
}
#map-track-wrap::-webkit-scrollbar { display: none; }
#map-track {
  display: flex; align-items: flex-start; justify-content: center;
  min-height: 100%; width: 100%;
}
.mt-svg { display: block; flex-shrink: 0; }
.mt-hit { fill: transparent; }
.mt-node.future { opacity: .5; pointer-events: none; }
.mt-node.locked { opacity: .45; pointer-events: none; }
.mt-node.missed { opacity: .35; pointer-events: none; }
.mt-edge.taken { stroke: #4dffa6; }
.mt-ghost { fill: none; stroke: #dfb9cb; stroke-width: 3; stroke-dasharray: 6 7; }
.mt-edge.to-future { stroke: #e8c9d8; stroke-dasharray: 2 8; }
.mt-edge { fill: none; stroke: #dfb9cb; stroke-width: 4; stroke-linecap: round; }
.mt-edge.to-choice { stroke: #f0a35e; stroke-width: 3.5; stroke-dasharray: 1 9; }
.mt-node .mt-ring { fill: #ffffff; stroke: #dfb9cb; stroke-width: 3; }
.mt-node.done .mt-ring { fill: #f4fff8; stroke: #4dffa6; stroke-width: 3; }
.mt-node.done { opacity: .75; }
.mt-node.cur .mt-ring {
  fill: #fff7ee; stroke: #e8930c; stroke-width: 4;
  transform-box: fill-box; transform-origin: center;
  animation: nodePulse 1.5s ease-in-out infinite;
}
@keyframes nodePulse { 50% { transform: scale(1.14); } }
.mt-node.choice { cursor: pointer; }
.mt-node.choice .mt-ring {
  fill: #ffffff; stroke: #f0a35e; stroke-width: 3.5;
  filter: drop-shadow(0 0 10px rgba(240,163,94,.65));
  transform-box: fill-box; transform-origin: center;
  transition: transform .16s cubic-bezier(.34,1.56,.64,1);
}
.mt-node.choice:active .mt-ring { transform: scale(.9); }
.mt-ic { font-size: 26px; text-anchor: middle; pointer-events: none; }
.mt-lb { font-size: 10px; font-weight: 800; letter-spacing: 1.5px; fill: #a06a86; text-anchor: middle; pointer-events: none; }
.mt-node.cur .mt-lb { fill: #e8930c; }
.mt-check { fill: #4dffa6; pointer-events: none; }
.mt-check-t { font-size: 12px; font-weight: 900; fill: #ffffff; text-anchor: middle; pointer-events: none; }

/* ---------- upgrades ---------- */
#upgrade-title {
  font-size: 30px; font-weight: 900; letter-spacing: 3px; margin-bottom: 12px;
  background: linear-gradient(180deg, #c86bff, #5aa2ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 24px rgba(150,110,255,.5));
}
#upgrade-owned { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px; align-items: center; font-size: 13px; color: #a06a86; }
.owned-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid #e0b8cc; background: #fff; color: #5e3a52; font-size: 13px; font-weight: 700;
  cursor: pointer;
}
.owned-btn:active { transform: scale(.94); }
.owned-btn.cur { border-color: #4dffa6; box-shadow: 0 0 12px rgba(77,255,166,.5); }
.cur-tag { font-size: 10px; color: #1d9e5e; font-weight: 900; }
.coin-line { width: 100%; font-weight: 800; color: #b8860b; margin-top: 4px; }
.peg-key { width: 100%; text-align: center; font-size: 12.5px; color: #9a8a93; margin-top: 6px; line-height: 1.5; }
#upgrade-single { display: flex; justify-content: center; margin: 4px 0 8px; }
.power-btn.single { width: 244px; padding: 26px 16px; cursor: pointer; }
.power-btn.single:active { transform: scale(.96); }
.pow-tap { margin-top: 12px; font-size: 12px; font-weight: 800; letter-spacing: 1.5px; color: #e8930c; }
.skip-link {
  background: none; border: none; color: #a06a86;
  font-size: 14px; font-weight: 600; padding: 14px 22px; cursor: pointer;
}
.skip-link:active { transform: scale(.94); color: #5e3a52; }
.maxed { font-size: 16px; font-weight: 800; color: #1d9e5e; margin-bottom: 12px; }

/* ---------- kitten shop ---------- */
#shop-title {
  font-size: 40px; font-weight: 900; letter-spacing: 2px; margin-bottom: 4px;
  background: linear-gradient(180deg, #e8930c, #b8860b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(232,147,12,.5));
}
#shop-sub { color: #8a5a72; font-size: 14px; margin-bottom: 10px; }
#shop-treats { font-size: 22px; font-weight: 900; color: #b8860b; margin-bottom: 14px; }
#shop-grid { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 18px; }
.shop-item {
  width: 118px; padding: 16px 8px; border-radius: 18px;
  border: 1px solid #e0b8cc; background: #ffffff; color: #5e3a52;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  box-shadow: 0 4px 18px rgba(0,0,0,.1); cursor: pointer;
}
.shop-item:active { transform: scale(.94); }
.shop-item:disabled { opacity: .55; }
.shop-item.sold { border-color: #4dffa6; background: #f2fff7; }
.shop-price { font-size: 15px; font-weight: 900; color: #b8860b; }
.shop-item.sold .shop-price { color: #1d9e5e; }

/* ---------- death screen stats ---------- */
#result-stats {
  display: flex; flex-direction: column; gap: 8px; width: 240px;
  margin: 6px 0 16px; padding: 14px 18px;
  background: rgba(255,255,255,.65); border: 1px solid #e8cfdd; border-radius: 16px;
}
.stat-line { display: flex; justify-content: space-between; font-size: 14px; color: #8a5a72; }
.stat-line b { color: #5e3a52; font-variant-numeric: tabular-nums; }

/* ---------- HUD counter scale-pop (neutral, never red) ---------- */
#hud-balls.pop, #hud-treats.pop { animation: hudPop .25s ease; }
@keyframes hudPop { 35% { transform: scale(1.35); } }
#hud-treats { font-size: 15px; font-weight: 800; color: #8a6a3a; }
.power-btn {
  width: 132px; padding: 18px 10px; border-radius: 20px;
  border: 1px solid #e0b8cc; background: #ffffff; color: #5e3a52;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: 0 4px 18px rgba(0,0,0,.1);
}
.power-btn:active { transform: scale(.94); border-color: #c86bff; box-shadow: 0 0 22px rgba(200,107,255,.5); }
.power-btn.elite-pick { border-color: #c86bff; box-shadow: 0 0 18px rgba(200,107,255,.4); }
.pow-ic { font-size: 38px; }
.pow-nm { font-size: 14px; font-weight: 800; color: #a05ce0; }
.pow-nm .lv { color: #1d9e5e; }
.pow-ds { font-size: 12px; color: #8a5a72; line-height: 1.45; }
.maxed { font-size: 16px; font-weight: 800; color: #1d9e5e; margin-bottom: 12px; }

/* ---------- boss / chapter banner ---------- */
#boss-banner {
  position: absolute; top: 24%; left: 0; right: 0; z-index: 15;
  text-align: center; pointer-events: none;
  animation: bannerIn .5s ease-out;
}
@keyframes bannerIn { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: scale(1); } }
#boss-banner-icon { font-size: 72px; filter: drop-shadow(0 0 24px rgba(255,94,122,.7)); }
#boss-banner-name {
  font-size: 42px; font-weight: 900; letter-spacing: 4px; color: #d63a5c;
  text-shadow: 0 0 30px rgba(214,58,92,.5), 0 2px 0 #fff;
}
#boss-banner-sub { color: #5e3a52; font-size: 15px; margin-top: 6px; font-style: italic; text-shadow: 0 1px 0 #fff; }

/* ---------- victory ---------- */
#victory-title {
  font-size: 52px; font-weight: 900; letter-spacing: 4px; margin-bottom: 8px;
  background: linear-gradient(180deg, #e8930c, #1d9e5e);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 30px rgba(77,255,166,.6));
}
#victory-stats { font-size: 17px; line-height: 2; margin-bottom: 26px; color: #8a5a72; }
#victory-stats b { color: #5e3a52; }
