:root {
  --bg: #04060d; --panel: rgba(18, 22, 40, .92); --panel2: #121830; --line: rgba(140, 160, 255, .16);
  --text: #e8ecff; --muted: #8e98c4; --accent: #7fa6ff; --accent2: #b78cff; --good: #6ee7b7; --warn: #fbbf24; --bad: #fb7185;
  --ease: cubic-bezier(.23, 1, .32, 1); --sheet: cubic-bezier(.32, .72, 0, 1);
  --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); overscroll-behavior: none;
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body { min-height: calc(100vh + 1px); }
button { font: inherit; color: inherit; touch-action: manipulation; }
textarea, input { -webkit-user-select: text; user-select: text; font-family: inherit; font-size: 16px; }
#app { display: flex; flex-direction: column; height: var(--ah, 100dvh); overflow: hidden; max-width: 640px; margin: 0 auto; position: relative; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
b { font-weight: 650; }
[hidden] { display: none !important; }

/* HUD */
#hud { flex: none; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px;
  padding: calc(var(--sat) + 18px) 14px 6px; }
.hud-main .lbl { font-size: 11px; letter-spacing: .16em; color: var(--muted); }
.hud-main .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; line-height: 1.05;
  background: linear-gradient(180deg, #fff, #b7c6ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hud-main .sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; display: flex; gap: 8px; align-items: center; }
.badge { background: rgba(251, 191, 36, .16); color: var(--warn); border: 1px solid rgba(251, 191, 36, .4); border-radius: 99px; padding: 1px 8px; font-size: 12px; }
.hud-side { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 3px 9px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.chip b { color: var(--accent2); }

/* map */
#mapwrap { flex: 0 0 clamp(130px, 27dvh, 280px); position: relative; margin: 0 10px; border-radius: 16px; overflow: hidden; border: 1px solid var(--line);
  background: radial-gradient(ellipse at 50% 50%, #0b1030 0%, #04060d 70%); }
#map { width: 100%; height: 100%; display: block; touch-action: none; }
#mapnote { position: absolute; left: 10px; bottom: 6px; font-size: 11px; color: rgba(190, 200, 255, .5); pointer-events: none; transition: opacity .6s; }
#maptip { cursor: pointer; position: absolute; left: 10px; top: 10px; right: 10px; background: rgba(8, 12, 30, .9); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 13px; pointer-events: none; }

/* panes */
#panes { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 10px 10px 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 9px; }
.card p { margin: 6px 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.gap { gap: 8px; margin-top: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; }
.bar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 9px; }

/* buttons */
.btn { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 600;
  transition: transform 140ms var(--ease), background-color 140ms var(--ease), opacity 140ms var(--ease); }
.btn.primary { background: linear-gradient(180deg, #4f74ff, #3a55d6); border-color: rgba(160, 180, 255, .5); }
.btn.danger { color: var(--bad); }
.btn[disabled], .btn.off { opacity: .42; }
.press, .btn:active, .seg button:active, #tabs button:active { transform: scale(.96); }
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { min-height: 38px; min-width: 52px; border: 0; background: transparent; border-radius: 9px; color: var(--muted); font-weight: 600;
  transition: background-color 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease); }
.seg button.on { background: #2a3a7a; color: #fff; }
@media (hover: hover) and (pointer: fine) { .btn:hover { background: #1a2246; } .btn.primary:hover { filter: brightness(1.1); } }

/* tier cards */
.tier { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 11px 12px; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid hsl(var(--h) 80% 62%); border-radius: 14px; }
.tier.locked { opacity: .55; border-left-color: #333a66; }
.tier .nm { font-weight: 650; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tier .nm small { font-weight: 400; color: var(--muted); font-size: 12px; }
.tier .st { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; grid-column: 1; }
.tier .st b { color: var(--text); }
.tier .buy { grid-column: 2; grid-row: 1 / span 2; min-width: 112px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; padding: 4px 10px; }
.tier .buy small { font-weight: 500; opacity: .85; font-size: 12px; font-variant-numeric: tabular-nums; }
.msbar { grid-column: 1 / -1; height: 5px; border-radius: 4px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.msbar i { display: block; height: 100%; width: 0; background: hsl(var(--h) 80% 62%); transition: width 300ms var(--ease); }
.mslab { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: -2px; }

/* worlds */
.slots { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; justify-content: center; }
.slot { width: 64px; height: 76px; border-radius: 14px; border: 1.5px dashed var(--line); background: rgba(255, 255, 255, .03); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted); transition: transform 140ms var(--ease), border-color 140ms var(--ease), background-color 140ms var(--ease); padding: 0; }
.slot .ic { font-size: 24px; line-height: 1; }
.slot.full { border-style: solid; background: hsl(var(--h) 50% 20% / .55); border-color: hsl(var(--h) 70% 55% / .6); color: var(--text); }
.slot.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(127, 166, 255, .35); }
.slot.syn { box-shadow: 0 0 12px hsl(var(--h) 90% 60% / .5); }
.world { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 12px; margin-bottom: 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.world .orb { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 20px; background: radial-gradient(circle at 35% 30%, hsl(var(--h) 85% 70%), hsl(var(--h) 70% 28%)); }
.world.shiny .orb { box-shadow: 0 0 14px hsl(var(--h) 100% 70%); }
.world .nm { font-weight: 650; } .world .ef { font-size: 12.5px; color: var(--muted); }
.world.in { border-color: rgba(127, 166, 255, .4); }

/* research */
.res { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 11px 12px; margin-bottom: 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; align-items: center; }
.res .nm { font-weight: 650; } .res .ds { font-size: 12.5px; color: var(--muted); grid-column: 1; }
.res .rb { grid-column: 2; grid-row: 1 / span 2; min-width: 96px; min-height: 48px; line-height: 1.15; padding: 4px 8px; }
.res.max { opacity: .6; } .res.locked { opacity: .5; }
.branch { font-size: 11px; letter-spacing: .14em; color: var(--muted); margin: 12px 4px 6px; text-transform: uppercase; }

/* prestige */
.layer h3 { margin: 0; font-size: 17px; }
.layer .gain { font-size: 22px; font-weight: 700; color: var(--accent2); font-variant-numeric: tabular-nums; }
.layer .eff { font-size: 13px; color: var(--muted); }
.layer.locked { opacity: .55; }

/* settings */
.setrow { display: flex; align-items: center; justify-content: space-between; min-height: 48px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.sw { width: 50px; height: 30px; border-radius: 99px; border: 0; background: #2a3055; position: relative; padding: 0; transition: background-color 160ms var(--ease); }
.sw i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 200ms var(--ease); }
.sw[aria-checked="true"] { background: #4f74ff; } .sw[aria-checked="true"] i { transform: translateX(20px); }
.ach { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; }
.ach .lv { color: var(--accent2); font-weight: 650; white-space: nowrap; }

/* tabs */
#tabs { flex: none; display: flex; background: rgba(8, 11, 26, .96); border-top: 1px solid var(--line); padding: 4px 4px calc(var(--sab) + 4px); }
#tabs button { flex: 1; min-height: 50px; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; position: relative;
  border-radius: 12px; transition: color 140ms var(--ease), transform 140ms var(--ease); }
#tabs button i { font-style: normal; font-size: 19px; line-height: 1; } #tabs button span { font-size: 11px; }
#tabs button.on { color: #fff; background: rgba(127, 166, 255, .12); }
.dot { position: absolute; top: 6px; right: calc(50% - 22px); width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); }

/* toasts, tip, modal */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--sab) + 72px); display: flex; flex-direction: column-reverse; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
.toast { background: rgba(12, 16, 38, .96); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; max-width: 88vw; animation: tin 260ms var(--ease); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 200ms ease-out, transform 200ms ease-out; }
@keyframes tin { from { opacity: 0; transform: translateY(8px) scale(.97); } }
#tip { position: fixed; z-index: 40; max-width: 260px; background: #0c1230; border: 1px solid rgba(160, 180, 255, .4); border-radius: 10px; padding: 8px 10px; font-size: 13px; pointer-events: none; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
#scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 50; animation: fin 200ms ease-out; }
@keyframes fin { from { opacity: 0; } }
#modal { position: fixed; left: 12px; right: 12px; bottom: calc(var(--sab) + 12px); max-width: 616px; margin: 0 auto; z-index: 60; background: #0d1230; border: 1px solid rgba(160, 180, 255, .35); border-radius: 18px; padding: 16px; max-height: 80dvh; overflow-y: auto;
  animation: sheet 280ms var(--sheet); }
@keyframes sheet { from { transform: translateY(24px); opacity: 0; } }
#modal h2 { margin: 0 0 6px; font-size: 19px; }
#modal textarea { width: 100%; height: 130px; background: #070a1c; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
#modal .row { margin-top: 12px; }
body.lite *, body.lite *::before, body.lite *::after { animation: none !important; transition: none !important; text-shadow: none !important; box-shadow: none !important; }
.logrow { display: flex; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.logrow .t { margin-left: auto; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: 1ms !important; transition-duration: 1ms !important; } }

/* next-goal card */
.goal { background: linear-gradient(135deg, rgba(79, 116, 255, .18), rgba(183, 140, 255, .12)); border: 1px solid rgba(160, 180, 255, .3); border-radius: 14px; padding: 10px 12px; margin-bottom: 9px; }
.goal .gt { font-size: 13.5px; line-height: 1.35; }
.goal .gbar { height: 5px; border-radius: 4px; background: rgba(255, 255, 255, .08); margin-top: 7px; overflow: hidden; }
.goal .gbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 400ms var(--ease); }
.layer .rec { font-size: 13px; margin-top: 4px; }
.layer .rec.good { color: var(--good); } .layer .rec.wait { color: var(--warn); }
.tabnew { animation: pulse 1.2s ease-out 2; }
@keyframes pulse { 0% { background: rgba(127, 166, 255, .5); } 100% { background: transparent; } }

/* ================= full-screen layout: galaxy first, menus as overlays ================= */
:root { --dock: calc(66px + var(--sab)); }
#app { position: relative; max-width: none; margin: 0; width: 100%; background: #02030a; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hud { position: absolute; top: 0; left: 0; right: 0; z-index: 5; pointer-events: none;
  padding: calc(var(--sat) + 22px) 16px 26px;
  background: linear-gradient(180deg, rgba(2, 3, 10, .86) 0%, rgba(2, 3, 10, .5) 55%, rgba(2, 3, 10, 0) 100%); }
.hud-main { pointer-events: auto; }
.hud-main .big { text-shadow: 0 0 22px rgba(130, 160, 255, .45); }
.chip { pointer-events: auto; background: rgba(14, 20, 48, .72); }
#mapnote { white-space: nowrap; position: absolute; left: 16px; top: calc(var(--sat) + 104px); z-index: 4; font-size: 11px; color: rgba(225, 233, 255, .9); text-shadow: 0 1px 6px #000; pointer-events: none; transition: opacity .8s; }
#maptip { position: absolute; left: 12px; right: 12px; top: calc(var(--sat) + 112px); z-index: 7; max-width: 420px; margin: 0 auto; background: rgba(8, 12, 30, .92); border: 1px solid var(--line); border-radius: 14px; padding: 9px 12px; font-size: 13px; pointer-events: auto; }

#goalpill { position: absolute; left: 12px; right: 112px; bottom: calc(var(--dock) + 12px); z-index: 6; padding: 9px 12px; border-radius: 16px; font-size: 12.5px; line-height: 1.3;
  background: rgba(10, 14, 36, .78); border: 1px solid rgba(160, 180, 255, .28); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: opacity 200ms var(--ease), transform 280ms var(--sheet); }
#goalpill .gbar { height: 4px; border-radius: 3px; background: rgba(255, 255, 255, .09); margin-top: 6px; overflow: hidden; }
#goalpill .gbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 400ms var(--ease); }
#fabbuy { position: absolute; right: 12px; bottom: calc(var(--dock) + 12px); z-index: 6; min-width: 88px; min-height: 52px; border-radius: 16px; box-shadow: 0 6px 22px rgba(60, 90, 255, .4);
  transition: opacity 200ms var(--ease), transform 140ms var(--ease); }
#app.so #goalpill, #app.so #fabbuy { opacity: 0; pointer-events: none; transform: translateY(8px); }
@media (max-width: 380px) { #goalpill { right: 104px; font-size: 12px; } }

#sheet { position: absolute; left: 8px; right: 8px; max-width: 640px; margin: 0 auto; bottom: calc(var(--dock) + 8px); height: clamp(250px, 42dvh, 380px); z-index: 8;
  display: flex; flex-direction: column; border-radius: 22px; overflow: hidden;
  background: rgba(9, 13, 34, .9); border: 1px solid rgba(150, 170, 255, .26); box-shadow: 0 -10px 40px rgba(0, 0, 0, .5);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transform: translateY(calc(100% + var(--dock) + 24px)); visibility: hidden;
  transition: transform 280ms var(--sheet), visibility 0s linear 280ms; }
#sheet.open { transform: none; visibility: visible; transition: transform 280ms var(--sheet), visibility 0s; }
.sh-head { flex: none; position: relative; display: flex; align-items: center; justify-content: space-between; padding: 16px 8px 4px 16px; touch-action: none; }
.sh-head .grab { position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 3px; background: rgba(255, 255, 255, .22); }
.sh-head b { font-size: 17px; }
.sh-head .x { width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 18px; border-radius: 12px; }
#panes { flex: 1; min-height: 0; position: relative; }
.pane { padding: 4px 12px 16px; }
.card, .tier, .res, .world { background: rgba(20, 26, 58, .72); }

#tabs { position: absolute; left: 8px; right: 8px; max-width: 640px; margin: 0 auto; bottom: calc(var(--sab) + 6px); z-index: 9; height: 58px;
  border: 1px solid rgba(150, 170, 255, .26); border-radius: 22px; padding: 4px; gap: 2px;
  background: rgba(9, 13, 34, .86); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 6px 28px rgba(0, 0, 0, .5); }
#tabs button { min-height: 0; border-radius: 17px; }
#tabs button.on { background: rgba(110, 140, 255, .22); box-shadow: inset 0 0 0 1px rgba(150, 175, 255, .35); }
.dot { top: 4px; right: calc(50% - 20px); }
#toasts { top: calc(var(--sat) + 124px); bottom: auto; flex-direction: column; }
.pane .goal { display: block; }
.awl { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.awl.sub { padding: 3px 0 3px 10px; border-top: 0; font-size: 12.5px; color: var(--muted); }
.awl b { color: var(--accent2); font-variant-numeric: tabular-nums; }
.layer .prev { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.slotrow { border-top: 1px solid var(--line); padding: 10px 0 8px; margin-top: 6px; }
.slotrow .sname { display: flex; align-items: center; gap: 8px; }
.slotrow .tag { font-size: 11px; padding: 1px 8px; border-radius: 99px; background: rgba(110, 231, 183, .16); color: var(--good); border: 1px solid rgba(110, 231, 183, .4); }
.slotrow.active { border-left: 3px solid var(--accent); padding-left: 10px; }
.sbtns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sbtns .btn { min-height: 42px; padding: 0 14px; font-size: 14px; }
.cxrow{display:flex;gap:8px;align-items:center;padding:5px 0;border-top:1px solid rgba(255,255,255,.06)}.cxrow .ic{font-size:20px;width:26px;text-align:center}.cxrow .grow{flex:1;min-width:0}.cxbar{height:4px;border-radius:2px;background:rgba(255,255,255,.1);margin:3px 0}.cxbar i{display:block;height:100%;border-radius:2px;background:#9cf}.cxb{color:#9cf}
