/* Crumb Run — warm bakery UI. Brand palette only: navy #0e1730 / blue #3b6fe0 /
   gold #f3c849 / amber #ffb347 / creams & terracotta. NO green/teal (site rule). */

@font-face {
  font-family: "Lilita One";
  src: url("fonts/lilita-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Baloo 2";
  src: url("fonts/baloo2-var.woff2") format("woff2");
  font-weight: 400 800;
  font-display: swap;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: "Baloo 2", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #2a1c10;
  color: #fff6e8;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#stage { position: fixed; inset: 0; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

/* ---------- loader ---------- */
#loader {
  position: absolute; inset: 0; z-index: 60;
  background: linear-gradient(#ffe9c4, #e8b073);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.ld-crumb { font-size: 56px; animation: hop 0.7s ease-in-out infinite alternate; }
@keyframes hop { from { transform: translateY(0) } to { transform: translateY(-18px) } }
.ld-bar { width: min(46vw, 260px); height: 10px; border-radius: 5px; background: rgba(90, 60, 30, 0.25); overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 40%; border-radius: 5px; background: #f3c849; animation: ldslide 1s ease-in-out infinite alternate; }
@keyframes ldslide { from { margin-left: 0 } to { margin-left: 60% } }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 40;
  background: linear-gradient(170deg, #ffe9c4 0%, #f5c98a 55%, #e8a05e 100%);
  color: #4a2f18;
  display: flex; flex-direction: column; align-items: center;
  overflow-y: auto; overflow-x: hidden;
  padding: max(14px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  touch-action: pan-y;
}
.back-link { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 14px; color: #7a4c22; font-weight: 700; text-decoration: none; font-size: 14px; }
.menu-top { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 14px; display: flex; gap: 8px; }
body.no-fs #mFs, body.no-fs #paFs { display: none; }

.logo {
  font-family: "Lilita One", "Baloo 2", system-ui;
  font-size: clamp(42px, 9vw, 74px);
  margin-top: clamp(40px, 9vh, 90px);
  color: #a3541e;
  text-shadow: 0 3px 0 #ffe9c4, 0 6px 14px rgba(90, 40, 0, 0.35);
  letter-spacing: 1px;
}
.tagline { font-weight: 600; color: #7a4c22; margin: 6px 0 18px; text-align: center; max-width: 34ch; }
.story { color: #7a4c22; font-size: 13.5px; text-align: center; max-width: 46ch; margin: 18px 0 10px; opacity: 0.9; }
.fineprint { font-size: 12px; margin-top: 8px; opacity: 0.7; }
.fineprint a { color: #7a4c22; }

.menu-cards { display: flex; flex-direction: column; gap: 10px; width: min(92vw, 420px); }
.mode-card {
  display: grid; grid-template-columns: 52px 1fr; grid-template-rows: auto auto; align-items: center;
  text-align: left; padding: 12px 16px; border-radius: 18px;
  background: #fff6e0; box-shadow: 0 4px 0 #d9a05b, 0 8px 18px rgba(90, 40, 0, 0.18);
  transition: transform 0.08s;
}
.mode-card:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9a05b; }
.mc-emoji { grid-row: span 2; font-size: 34px; }
.mc-name { font-family: "Lilita One", "Baloo 2"; font-size: 22px; color: #a3541e; }
.mc-sub { font-size: 12.5px; color: #8a6242; font-weight: 600; }

.chip {
  background: #fff6e0; color: #7a4c22; font-weight: 700; font-size: 14px;
  border-radius: 999px; padding: 7px 14px; box-shadow: 0 2px 0 #d9a05b;
}
.chip:active { transform: translateY(2px); box-shadow: none; }
.chip.gold { background: #f3c849; color: #5c3a10; }
.chip[disabled] { opacity: 0.45; pointer-events: none; }
.menu-set { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }

.big {
  font-family: "Lilita One", "Baloo 2"; font-size: 20px; letter-spacing: 0.5px;
  background: #fff6e0; color: #7a4c22; border-radius: 16px; padding: 12px 26px;
  box-shadow: 0 4px 0 #d9a05b;
}
.big.gold { background: linear-gradient(#ffd25e, #f3b028); color: #5c3a10; box-shadow: 0 4px 0 #b87f1e; }
.big:active { transform: translateY(3px); box-shadow: none; }

.scr-head {
  width: min(94vw, 560px);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 0 10px; position: sticky; top: 0; z-index: 5;
}
.scr-head h2 { font-family: "Lilita One", "Baloo 2"; color: #a3541e; font-size: 26px; }

/* ---------- world map ---------- */
#mapScroll { width: min(94vw, 560px); flex: 1; overflow-y: auto; border-radius: 20px; box-shadow: inset 0 0 0 3px rgba(160, 100, 40, 0.25); touch-action: pan-y; }
#mapCanvas { width: 100%; display: block; }

/* ---------- bakery ---------- */
.bk-scroll { width: min(94vw, 560px); }
.bk-h { font-family: "Lilita One", "Baloo 2"; color: #a3541e; margin: 14px 0 8px; }
.envoy-grid { display: flex; flex-direction: column; gap: 10px; }
.envoy-card {
  background: #fff6e0; border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 3px 0 #d9a05b; position: relative;
}
.envoy-card.sel { outline: 3px solid #f3b028; }
.envoy-card.locked { opacity: 0.62; }
.ec-emoji { font-size: 30px; float: left; margin-right: 10px; }
.ec-name { font-weight: 800; color: #a3541e; font-size: 17px; }
.ec-title { color: #8a6242; font-weight: 700; font-size: 13px; }
.ec-desc { font-size: 13px; color: #6d4c31; margin: 2px 0 6px; }
.ec-lvl { font-size: 12.5px; font-weight: 700; color: #8a6242; margin-bottom: 6px; }
.ec-btns { display: flex; gap: 8px; }
.upg-list { display: flex; flex-direction: column; gap: 8px; }
.upg-row {
  display: flex; align-items: center; gap: 10px;
  background: #fff6e0; border-radius: 14px; padding: 10px 12px; box-shadow: 0 3px 0 #d9a05b;
}
.ur-info { flex: 1; font-size: 13px; color: #6d4c31; }
.ur-info b { color: #a3541e; font-size: 14.5px; }
.ur-eff { font-weight: 800; color: #b87f1e; margin-left: 4px; }
.ur-pips { display: flex; gap: 3px; }
.ur-pips i { width: 9px; height: 14px; border-radius: 3px; background: rgba(160, 100, 40, 0.22); }
.ur-pips i.on { background: #f3b028; }
.skin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding-bottom: 24px; }
.skin-chip {
  background: #fff6e0; border-radius: 14px; padding: 10px 6px; box-shadow: 0 3px 0 #d9a05b;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-weight: 700; color: #6d4c31; font-size: 13px;
}
.skin-chip.sel { outline: 3px solid #f3b028; }
.skin-chip[disabled] { opacity: 0.5; }
.sk-emoji { font-size: 28px; }
.sk-cost { font-size: 12px; color: #b87f1e; font-weight: 800; }

/* ---------- moments ---------- */
.cr-moments-empty { text-align: center; color: #7a4c22; font-weight: 600; padding: 40px 20px; }
.cr-moment { background: #fff6e0; border-radius: 16px; overflow: hidden; box-shadow: 0 3px 0 #d9a05b; margin-bottom: 12px; }
.cr-moment video { width: 100%; display: block; background: #2a1c10; max-height: 42vh; }
.cr-moment-meta { padding: 10px 12px; }
.cr-moment-label { font-weight: 800; color: #a3541e; }
.cr-moment-date { font-size: 12px; color: #8a6242; margin: 2px 0 8px; }
.cr-moment-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.cr-moment-btns button { background: #ffe9c4; border-radius: 999px; padding: 6px 12px; font-weight: 700; color: #7a4c22; font-size: 13px; box-shadow: 0 2px 0 #d9a05b; }
.cr-moment-btns .danger { background: #ffd9cc; color: #a3341e; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#hud button { pointer-events: auto; }
#count {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  font-family: "Lilita One", "Baloo 2"; font-size: clamp(40px, 8vw, 62px); color: #fff;
  text-shadow: 0 3px 0 #a3541e, 0 6px 16px rgba(60, 25, 0, 0.5);
}
#count.popup { animation: cpop 0.25s ease-out; }
@keyframes cpop { 40% { transform: translateX(-50%) scale(1.22); } }
#count.danger { color: #ffb3a0; }
#sprk {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 14px;
  font-weight: 800; font-size: 16px; color: #ffe9a0; text-shadow: 0 2px 4px rgba(60, 25, 0, 0.6);
}
#banked {
  position: absolute; top: max(38px, calc(env(safe-area-inset-top) + 26px)); left: 14px;
  font-weight: 800; font-size: 15px; color: #ffd27a; text-shadow: 0 2px 4px rgba(60, 25, 0, 0.6);
}
/* Difficulty segmented control (menu + pre-stage panel) */
.diff-pick {
  display: flex; gap: 6px; justify-content: center; margin: 10px auto 4px;
  max-width: 420px; width: 100%;
}
.diff-pick .dp {
  flex: 1 1 0; min-width: 0; padding: 8px 4px 7px; border-radius: 12px;
  font-weight: 800; font-size: 13px; line-height: 1.15; color: #8a5a2c;
  background: rgba(255, 246, 224, 0.72); box-shadow: inset 0 0 0 2px rgba(190, 140, 80, 0.35);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.diff-pick .dp span { font-size: 17px; }
.diff-pick .dp.on {
  color: #5a3312; background: linear-gradient(180deg, #ffe6a8, #ffcf7a);
  box-shadow: inset 0 0 0 2px #c9922f, 0 2px 0 rgba(160, 100, 40, 0.5);
}
.diff-sub {
  text-align: center; font-size: 12.5px; font-weight: 600; color: #7a5836;
  margin: 2px auto 8px; max-width: 420px; min-height: 1.2em;
}
.res-diff { font-size: 12.5px; font-weight: 700; color: #8a5a2c; text-align: center; margin: -2px 0 8px; }

/* Crumb Streak — the multiplier you carry to the door. Sits under the count so
   the two numbers that decide the score read together. */
/* The Feast quota, live. A fail condition you only discover at the door is a
   gotcha; sitting it right under the count makes it a target you can steer to. */
#quotaTag {
  position: absolute; top: max(78px, calc(env(safe-area-inset-top) + 66px)); left: 50%;
  transform: translateX(-50%); font-weight: 800; font-size: 12.5px; white-space: nowrap;
  color: #ffe9a0; text-shadow: 0 2px 4px rgba(60, 25, 0, 0.7); pointer-events: none;
}
#quotaTag.short { color: #ffb3a0; animation: quotapulse 1.1s ease-in-out infinite; }
@keyframes quotapulse { 50% { opacity: 0.55; } }
#streak {
  position: absolute; top: max(112px, calc(env(safe-area-inset-top) + 100px)); left: 50%;
  transform: translateX(-50%); text-align: center; line-height: 1.05;
  pointer-events: none; transition: opacity 0.2s;
}
#streak b {
  display: block; font-family: "Lilita One", system-ui, sans-serif; font-size: 26px;
  color: #ffd27a; text-shadow: 0 2px 6px rgba(80, 30, 0, 0.75); margin-bottom: 5px;
}
#streak i {
  display: block; font-style: normal; font-weight: 800; font-size: 12px;
  color: #ffe9a0; opacity: 0.85; letter-spacing: 1px; text-shadow: 0 2px 4px rgba(80, 30, 0, 0.7);
}
#streak.hot b { color: #fff0c0; text-shadow: 0 0 14px rgba(255, 190, 80, 0.9), 0 2px 6px rgba(80, 30, 0, 0.75); }
#streak.pop { animation: streakpop 0.34s ease-out; }
@keyframes streakpop { 0% { transform: translateX(-50%) scale(1); } 45% { transform: translateX(-50%) scale(1.28); } 100% { transform: translateX(-50%) scale(1); } }
#streak.broke b { color: #ffb3a0; }
#streak.broke { animation: streakbreak 0.4s ease-out; }
@keyframes streakbreak { 0% { opacity: 1; } 40% { opacity: 0.35; transform: translateX(-50%) rotate(-4deg); } 100% { opacity: 1; } }
#windArr {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 52px)); left: 14px;
  font-size: 18px; animation: windshake 0.5s ease-in-out infinite alternate;
}
@keyframes windshake { from { transform: translateX(-3px); } to { transform: translateX(3px); } }
#ghostDelta {
  position: absolute; top: max(90px, calc(env(safe-area-inset-top) + 78px)); left: 14px;
  font-weight: 800; font-size: 14.5px; color: #e8ecff; text-shadow: 0 2px 4px rgba(20, 20, 50, 0.7);
}
#ghostDelta.ahead { color: #ffd27a; }
#ghostDelta.behind { color: #ffb3a0; }
.sp-icons { font-size: 22px; letter-spacing: 4px; margin: 6px 0; }
.sp-rows { font-size: 14px; color: #6d4c31; font-weight: 600; margin: 4px 0 10px; }
.sp-rows b { color: #a3541e; }
#btnPause {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 12px;
  font-size: 22px; width: 44px; height: 44px; border-radius: 12px;
  background: rgba(255, 246, 224, 0.85); color: #7a4c22; box-shadow: 0 2px 0 rgba(160, 100, 40, 0.6);
}
#progress {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 52px)); right: 12px;
  width: 9px; height: min(34vh, 240px); border-radius: 6px; background: rgba(60, 30, 5, 0.35);
}
#progFill {
  position: absolute; bottom: 0; width: 100%; border-radius: 6px;
  background: linear-gradient(#f3c849, #ffb347); height: 0%;
  transition: height 0.2s linear;
}
#progHome { position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font-size: 15px; }
#btnAbility {
  position: absolute; right: 16px; bottom: max(18px, env(safe-area-inset-bottom));
  width: 76px; height: 76px; border-radius: 50%; font-size: 34px;
  background: conic-gradient(#f3c849 var(--chg, 0deg), rgba(255, 246, 224, 0.3) var(--chg, 0deg));
  box-shadow: 0 4px 12px rgba(60, 25, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
}
#btnAbility::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: rgba(42, 28, 16, 0.55); z-index: -1; }
#btnAbility.ready { animation: abGlow 1s ease-in-out infinite alternate; }
@keyframes abGlow { from { box-shadow: 0 4px 12px rgba(60, 25, 0, 0.4); } to { box-shadow: 0 0 26px #f3c849; } }

#banner {
  position: absolute; top: 22%; left: 50%; transform: translateX(-50%);
  font-family: "Lilita One", "Baloo 2"; text-align: center; white-space: nowrap;
  padding: 8px 26px; border-radius: 999px; pointer-events: none;
  animation: bpop 0.4s ease-out;
}
/* entrance pops — deliberately NO opacity/offset in `from`: on very slow frames
   (or software-GL headless) the timeline can stall at the first keyframe, and
   the UI must stay legible there */
@keyframes bpop { from { transform: translateX(-50%) scale(0.55); } }
@keyframes cardpop { from { transform: scale(0.65); } }
#banner.tier2 { font-size: clamp(22px, 5vw, 34px); color: #fff; background: rgba(59, 111, 224, 0.85); box-shadow: 0 4px 18px rgba(20, 40, 120, 0.45); }
#banner.tier3 { font-size: clamp(26px, 6vw, 40px); color: #5c3a10; background: linear-gradient(#ffd25e, #ffb347); box-shadow: 0 4px 22px rgba(200, 120, 0, 0.55); }
#banner.tier4 { font-size: clamp(30px, 7vw, 48px); color: #fff; background: linear-gradient(100deg, #e8632c, #f3b028, #e8632c); box-shadow: 0 0 34px #f3c849; animation: bpop 0.4s ease-out, bshine 1.2s linear infinite; }
@keyframes bshine { from { filter: brightness(1); } 50% { filter: brightness(1.25); } to { filter: brightness(1); } }

#countdown {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font-family: "Lilita One", "Baloo 2"; font-size: clamp(72px, 16vw, 130px);
  color: #fff; text-shadow: 0 4px 0 #a3541e, 0 10px 30px rgba(60, 25, 0, 0.55);
  pointer-events: none;
}
#countdown.zoom { animation: cdz 0.5s ease-out; }
@keyframes cdz { from { transform: translate(-50%, -50%) scale(1.8); opacity: 0.2; } }

/* ---------- hint spotlight ---------- */
#hint { position: absolute; inset: 0; z-index: 45; background: rgba(30, 18, 8, 0.62); display: flex; align-items: center; justify-content: center; }
.hint-card {
  background: #fff6e0; color: #4a2f18; border-radius: 22px; padding: 22px 26px;
  width: min(86vw, 380px); text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  animation: cardpop 0.3s ease-out;
}
.hint-emoji { font-size: 44px; }
.hint-card h3 { font-family: "Lilita One", "Baloo 2"; color: #a3541e; font-size: 24px; margin: 6px 0; }
.hint-card p { font-size: 15px; color: #6d4c31; margin-bottom: 16px; }

/* ---------- results / pause ---------- */
#results, #pause { background: rgba(30, 18, 8, 0.55); justify-content: center; z-index: 42; }
.res-card {
  background: #fff8e6; color: #4a2f18; border-radius: 26px;
  padding: 24px 26px; width: min(90vw, 420px); text-align: center;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.5);
  animation: cardpop 0.35s ease-out;
  max-height: 86vh; overflow-y: auto;
}
.res-title { font-family: "Lilita One", "Baloo 2"; color: #a3541e; font-size: 30px; }
.res-sub { color: #7a4c22; margin: 6px 0; }
.res-stars { font-size: 44px; margin: 6px 0; }
.res-stars .star { color: rgba(140, 100, 50, 0.3); display: inline-block; }
.res-stars .star.on { color: #f3b028; animation: starPop 0.5s back both; }
@keyframes starPop { from { transform: scale(0) rotate(-40deg); } 70% { transform: scale(1.4) rotate(8deg); } to { transform: scale(1); } }
.res-rows { margin: 10px 0; }
.res-rows > div { display: flex; justify-content: space-between; padding: 5px 8px; font-weight: 600; color: #6d4c31; }
.res-rows b { color: #a3541e; }
.res-score b { font-family: "Lilita One", "Baloo 2"; font-size: 26px; color: #b87f1e; }
.res-flawless { color: #b87f1e; font-weight: 800; margin: 6px 0; }
.res-newbest { font-family: "Lilita One", "Baloo 2"; color: #e8632c; font-size: 22px; animation: bshine 1s linear infinite; }
.res-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.res-board { margin-top: 14px; text-align: left; }
.res-board h4 { color: #a3541e; margin: 8px 0 4px; }
.lb-row { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: #6d4c31; padding: 2px 6px; }
.lb-name { font-size: 13px; color: #6d4c31; font-weight: 700; }
.lb-name input {
  font-family: inherit; font-weight: 700; color: #a3541e; background: #fff;
  border: 2px solid #d9a05b; border-radius: 8px; padding: 4px 8px; width: 140px; font-size: 14px;
}

/* ---------- toast ---------- */
#toast {
  position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%;
  transform: translate(-50%, 200%); transition: transform 0.3s ease-out, visibility 0.3s;
  visibility: hidden;              /* parked off-screen it still peeked above the edge (owner report) */
  background: rgba(42, 28, 16, 0.92); color: #ffe9c4; font-weight: 700; font-size: 14px;
  border-radius: 999px; padding: 10px 20px; z-index: 55; pointer-events: none; white-space: nowrap;
}
#toast.show { transform: translate(-50%, 0); visibility: visible; }

@media (max-width: 480px) {
  .skin-grid { grid-template-columns: repeat(2, 1fr); }
  #btnAbility { width: 68px; height: 68px; font-size: 30px; }
}
