:root {
  --bg: #070a14; --bg-top: #111733; --panel: #111629; --raised: #182040; --stroke: #2a3566; --locked: #0e1222;
  --text: #eef2ff; --dim: #8c96c2; --faint: #4c557e;
  --cyan: #33e6ff; --green: #4dff8f; --magenta: #ff4fd8; --gold: #ffd24d; --orange: #ff8a3d; --violet: #9b6bff; --red: #ff4d6a;
  --buy: #1fcf6e; --buy-off: #252c4a;
  --font: "Chakra Petch", "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; overscroll-behavior: none; }
body { background: radial-gradient(120% 60% at 50% 0%, var(--bg-top) 0%, var(--bg) 60%) fixed; }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }

#app { position: fixed; inset: 0; margin: 0 auto; max-width: 540px; display: flex; flex-direction: column;
  padding: calc(var(--sat) + 6px) 10px 0; }

/* ------------------------------------------------------------ HUD */
.hud { position: relative; flex: none; background: linear-gradient(180deg, rgba(17,23,51,.95), var(--panel) 55%);
  border-radius: 20px; padding: 10px 14px 12px; box-shadow: 0 0 0 1px rgba(42,53,102,.6), 0 10px 30px rgba(0,0,0,.4); text-align: center; overflow: hidden; }
.hud::before { content: ""; position: absolute; left: 10%; right: 10%; top: 0; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent); opacity: .8; }
.hud-label { font-size: 10.5px; font-weight: 700; letter-spacing: .18em; color: var(--dim); }
.points { font-size: clamp(34px, 11vw, 48px); font-weight: 700; line-height: 1.1; margin: 2px 0 6px; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(51,230,255,.55), 0 0 2px rgba(51,230,255,.9); display: inline-block; }
.points.punch { animation: punch .55s cubic-bezier(.2,1.6,.4,1); }
.points.punch-sm { animation: punchsm .3s ease-out; }
@keyframes punch { 0% { transform: scale(1); } 30% { transform: scale(1.18); color: var(--gold); } 100% { transform: scale(1); } }
@keyframes punchsm { 0% { transform: scale(1); } 40% { transform: scale(1.05); } 100% { transform: scale(1); } }
.chips { display: flex; gap: 8px; }
.chip { flex: 1; border-radius: 12px; padding: 6px 4px; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip.rate { color: var(--green); background: rgba(77,255,143,.10); box-shadow: inset 0 0 0 1px rgba(77,255,143,.25); }
.chip.mult { color: var(--magenta); background: rgba(255,79,216,.10); box-shadow: inset 0 0 0 1px rgba(255,79,216,.25); }
.milestone { margin-top: 10px; text-align: left; }
.ms-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ms-label { font-size: 10px; font-weight: 700; letter-spacing: .14em; color: var(--dim); }
.ms-reward { font-size: 10.5px; font-weight: 700; color: var(--text); }
.ms-name { font-size: 15px; font-weight: 700; color: var(--gold); text-shadow: 0 0 10px rgba(255,210,77,.35); }
.ms-eta { font-size: 11px; color: var(--dim); }
.ms-bar { height: 8px; border-radius: 6px; background: #0a0e1c; margin-top: 5px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(42,53,102,.6); }
.ms-bar > div { height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); border-radius: 6px;
  background: linear-gradient(90deg, #ffb52e, var(--gold)); box-shadow: 0 0 10px rgba(255,210,77,.6); transition: transform .12s linear; }

/* ------------------------------------------------------------ factory */
.floor { flex: 1 1 auto; min-height: 150px; position: relative; }
.floor canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ------------------------------------------------------------ shop */
.shop { flex: none; height: 46%; display: flex; flex-direction: column; position: relative;
  background: var(--panel); border-radius: 22px 22px 0 0; margin: 0 -4px; box-shadow: 0 -1px 0 rgba(255,79,216,.35), 0 -12px 30px rgba(0,0,0,.45); }
.shop::before { content: ""; position: absolute; left: 8%; right: 8%; top: -1px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--magenta), transparent); }
.shop-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 8px; }
.shop-head h2 { margin: 0; font-size: 15px; letter-spacing: .08em; font-weight: 700; }
.buymode { display: flex; background: #0a0e1c; border-radius: 10px; padding: 3px; gap: 3px; }
.buymode.hidden { visibility: hidden; }
.buymode button { width: 46px; height: 28px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--dim); background: var(--raised); transition: transform .12s, background .15s; }
.buymode button.on { background: var(--cyan); color: #061018; box-shadow: 0 0 12px rgba(51,230,255,.5); }
.buymode button:active { transform: scale(.92); }

.pages { flex: 1 1 auto; position: relative; min-height: 0; }
.page { position: absolute; inset: 0; padding: 0 10px 10px; display: none; }
.page.show { display: block; animation: pagein .22s ease-out; }
@keyframes pagein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.page.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.page.scroll::-webkit-scrollbar { display: none; }

/* rows */
.row { position: relative; display: flex; align-items: center; gap: 10px; min-height: 78px; padding: 8px 8px 8px 12px; margin-bottom: 8px;
  background: var(--raised); border-radius: 16px; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(42,53,102,.5); transition: background .2s; }
.row-accent { position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent); opacity: .85; }
.icon { flex: none; width: 54px; height: 54px; border-radius: 14px; background: #0b1022; position: relative; display: grid; place-items: center;
  box-shadow: 0 0 0 2px var(--accent), 0 0 16px -2px var(--accent); }
.icon::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: radial-gradient(circle, var(--accent) 0%, transparent 70%); opacity: .3; }
.glyph { position: relative; font-size: 24px; font-weight: 700; color: var(--accent); text-shadow: 0 0 8px var(--accent); }
.glyph.small { font-size: 15px; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.col-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.title { font-size: 14.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 10.5px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.info { font-size: 11px; color: var(--dim); line-height: 1.25; }
.foot { font-size: 9.5px; font-weight: 700; letter-spacing: .03em; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot.good { color: var(--green); } .foot.warn { color: var(--orange); } .foot.accent { color: var(--accent); }
.bar { height: 5px; border-radius: 4px; background: #0a0e1c; overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 4px; background: var(--accent); box-shadow: 0 0 8px var(--accent); transition: width .15s linear; }
.action { flex: none; width: 104px; height: 60px; border-radius: 13px; background: var(--buy-off); color: var(--dim);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; transition: transform .1s, background .2s, box-shadow .2s; }
.action:active { transform: scale(.93); }
.action.can { background: linear-gradient(180deg, #2be07e, var(--buy)); color: #fff; box-shadow: 0 0 16px rgba(31,207,110,.45), inset 0 1px 0 rgba(255,255,255,.25); }
.action .a-top { font-size: 9.5px; font-weight: 700; letter-spacing: .04em; opacity: .9; }
.action .a-main { font-size: 16px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.action.bounce { animation: bounce .4s cubic-bezier(.2,1.8,.4,1); }
@keyframes bounce { 0% { transform: scale(.9); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
.flash { position: absolute; inset: 0; border-radius: inherit; background: var(--accent); opacity: 0; pointer-events: none; }
.flash.go { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .5; } 100% { opacity: 0; } }
.locked-row { background: var(--locked); }
.locked-row .icon { opacity: .55; }
.locked-row .title { color: var(--dim); }
.locked-row .action { opacity: .8; }

/* locked tabs */
.page.locked { text-align: center; padding-top: 8px; }
.page.locked.show { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--locked); border-radius: 16px; margin: 0 10px 10px; }
.lock { position: relative; width: 56px; height: 64px; margin-bottom: 10px; filter: drop-shadow(0 0 18px var(--accent)); }
.shackle { position: absolute; left: 10px; top: 0; width: 36px; height: 40px; border: 7px solid var(--accent); border-bottom: 0; border-radius: 20px 20px 0 0; }
.lbody { position: absolute; left: 0; bottom: 0; width: 56px; height: 38px; border-radius: 9px; background: var(--accent); }
.lbody::after { content: ""; position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -7px 0 0 -5px; border-radius: 50%; background: var(--locked); }
.page.locked h3 { margin: 0; font-size: 20px; letter-spacing: .06em; }
.phase { margin: 4px 0 8px; font-size: 13px; font-weight: 700; color: var(--accent); text-shadow: 0 0 10px var(--accent); }
.page.locked p { margin: 0 18px; font-size: 12px; color: var(--dim); line-height: 1.4; }

/* stats */
.stats-card { background: var(--raised); border-radius: 16px; padding: 12px 14px; box-shadow: inset 0 0 0 1px rgba(42,53,102,.5); }
.stats-head { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--green); margin-bottom: 6px; }
dl { display: grid; grid-template-columns: 1fr auto; margin: 0; row-gap: 5px; font-size: 12.5px; }
dt { color: var(--dim); } dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-note { font-size: 10px; color: var(--faint); text-align: center; margin: 10px 0 8px; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.set { height: 40px; border-radius: 11px; background: var(--panel); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; transition: transform .1s; box-shadow: inset 0 0 0 1px rgba(42,53,102,.7); }
.set:active { transform: scale(.94); }
.set.cyan { color: var(--cyan); } .set.green { color: var(--green); } .set.red { color: var(--red); } .set.violet { color: var(--violet); }

/* tabs */
.tabs { flex: none; display: flex; padding: 4px 6px calc(var(--sab) + 4px); background: #0a0e1c; border-top: 1px solid rgba(42,53,102,.4); }
.tabs button { flex: 1; position: relative; height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  color: var(--dim); font-size: 9.5px; font-weight: 700; letter-spacing: .05em; transition: transform .1s, color .15s; }
.tabs button:active { transform: scale(.92); }
.tabs button i { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.tabs button.lockedtab i { opacity: .35; box-shadow: none; }
.tabs button.active { color: var(--accent); }
.tabs button.active::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.badge-count { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--magenta);
  color: #fff; font-size: 10px; line-height: 17px; display: none; box-shadow: 0 0 10px rgba(255,79,216,.7); }
.badge-count.show { display: block; animation: bounce .35s; }
.dot { position: absolute; top: 7px; left: calc(50% + 8px); width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: none; box-shadow: 0 0 8px var(--green); }
.dot.show { display: block; }

/* toast */
.toast { position: absolute; left: 50%; top: calc(var(--sat) + 10px); width: min(92%, 480px); transform: translate(-50%, -160%) scale(.92);
  opacity: 0; pointer-events: none; z-index: 10; border-radius: 18px; padding: 2px; background: var(--tc, var(--gold)); }
.toast.cyan { --tc: var(--cyan); } .toast.gold { --tc: var(--gold); }
.toast.in { animation: toastin .4s cubic-bezier(.2,1.4,.4,1) forwards; }
.toast.out { animation: toastout .3s ease-in forwards; }
@keyframes toastin { from { transform: translate(-50%, -160%) scale(.92); opacity: 0; } to { transform: translate(-50%, 0) scale(1); opacity: 1; } }
@keyframes toastout { from { transform: translate(-50%, 0); opacity: 1; } to { transform: translate(-50%, -160%); opacity: 0; } }
.t-inner { background: #161230; border-radius: 16px; padding: 10px 12px; text-align: center; box-shadow: 0 0 40px color-mix(in srgb, var(--tc) 45%, transparent); }
.t-title { font-size: 11px; font-weight: 700; letter-spacing: .14em; color: var(--tc); }
.t-body { font-size: 22px; font-weight: 700; margin: 2px 0; text-shadow: 0 0 14px color-mix(in srgb, var(--tc) 60%, transparent); }
.t-extra { font-size: 11.5px; font-weight: 700; color: var(--green); }

@media (min-height: 860px) { .row { min-height: 84px; } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ------------------------------------------------------------ compact phones (iPhone SE / mini) */
@media (max-width: 380px) {
  .row { gap: 8px; padding: 7px 7px 7px 10px; }
  .icon { width: 46px; height: 46px; border-radius: 12px; }
  .glyph { font-size: 20px; } .glyph.small { font-size: 13px; }
  .title { font-size: 13.5px; }
  .action { width: 90px; height: 56px; }
  .action .a-main { font-size: 15px; }
}
@media (max-height: 720px) {
  .hud { padding: 7px 12px 9px; border-radius: 16px; }
  .hud-label { display: none; }
  .points { font-size: 34px; margin: 0 0 4px; }
  .chip { font-size: 13.5px; padding: 4px; }
  .milestone { margin-top: 6px; }
  .shop { height: 48%; }
  .shop-head { padding: 7px 12px 5px; }
  .row { min-height: 70px; margin-bottom: 6px; }
  .info { font-size: 10.5px; }
  .tabs button { height: 46px; }
  .toast .t-body { font-size: 19px; }
}
