:root {
  --acc: #ff8a3d; --acc2: #ffd24d; --cyan: #4dd2ff; --ink: #f3ede4; --dim: #a59c90; --mut: #6f675e;
  --panel: rgba(18, 16, 18, 0.82); --panel2: rgba(30, 27, 29, 0.92); --line: rgba(255, 255, 255, 0.08);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  --zone: #e8c37a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #0b0a0d; color: var(--ink); overflow: hidden; overscroll-behavior: none; }
body { font-family: "Chakra Petch", system-ui, -apple-system, sans-serif; -webkit-user-select: none; user-select: none; touch-action: manipulation; position: fixed; inset: 0; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
#world { position: fixed; inset: 0; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5; pointer-events: none;
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 14px) 10px calc(var(--sal) + 14px);
  background: linear-gradient(180deg, rgba(6,5,7,0.94) 0%, rgba(6,5,7,0.78) 70%, rgba(6,5,7,0) 100%);
}
.hud-row.top { display: flex; align-items: center; justify-content: space-between; }
.logo { font-weight: 700; letter-spacing: 3px; font-size: 13px; color: #d9d1c5; }
.logo span { color: var(--acc); }
.logo.big { font-size: 34px; letter-spacing: 8px; }
.zone-pill { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 99px; background: rgba(255,255,255,0.06); border: 1px solid color-mix(in srgb, var(--zone) 45%, transparent); color: var(--zone); transition: color .8s, border-color .8s; }
.zone-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--zone); box-shadow: 0 0 8px var(--zone); }
.credits-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 4px; }
.credits { display: flex; align-items: center; gap: 8px; font-size: 34px; font-weight: 700; line-height: 1.05; text-shadow: 0 2px 12px rgba(255,160,60,0.25); font-variant-numeric: tabular-nums; }
.credits.bump { animation: bump .25s ease-out; }
@keyframes bump { 40% { transform: scale(1.06); color: #fff3c8; } }
.cr-icon { width: 20px; height: 20px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff2b0, #ffb83d 45%, #b35b12 100%); box-shadow: 0 0 10px rgba(255,180,60,0.6), inset 0 -2px 3px rgba(0,0,0,0.35); flex: none; }
.cps { font-size: 15px; font-weight: 600; color: var(--acc2); font-variant-numeric: tabular-nums; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 5px 9px; display: flex; flex-direction: column; }
.chip label { font-size: 9px; letter-spacing: 1.4px; color: var(--mut); font-weight: 600; }
.chip b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.bars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.bar-label { display: flex; justify-content: space-between; font-size: 9px; letter-spacing: 1.2px; color: var(--dim); font-weight: 600; margin-bottom: 3px; }
.bar-label span:last-child { color: var(--ink); letter-spacing: .4px; }
.track { position: relative; height: 7px; border-radius: 4px; background: rgba(255,255,255,0.07); overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.6); }
.fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 4px; }
.milestone .fill { background: linear-gradient(90deg, #ff6a2a, var(--acc2)); box-shadow: 0 0 8px rgba(255,170,60,0.6); }
.cargo .fill { background: linear-gradient(90deg, #6b4dff, #b47bff); transition: background .3s; }
.cargo.full .fill { background: linear-gradient(90deg, #ff2d4a, #ff6a5a); animation: blink .5s infinite alternate; }
.cargo.full .bar-label span:first-child { color: #ff5a64; }
.ship { position: absolute; left: 0; bottom: 0; height: 2px; background: rgba(255,255,255,0.75); width: 0; }
@keyframes blink { to { opacity: .55; } }
.buffs { display: flex; gap: 6px; margin-top: 7px; min-height: 20px; flex-wrap: wrap; }
.buff { font-size: 10px; font-weight: 700; letter-spacing: 1px; padding: 3px 8px; border-radius: 6px; display: flex; gap: 5px; align-items: center; }
.buff.b-od { background: rgba(255,100,30,0.22); color: #ffb070; border: 1px solid rgba(255,120,40,0.5); }
.buff.b-rare { background: rgba(80,255,200,0.15); color: #7fffd8; border: 1px solid rgba(80,255,200,0.45); }
.buff.b-warn { background: rgba(255,40,70,0.18); color: #ff7a86; border: 1px solid rgba(255,60,80,0.5); animation: blink .5s infinite alternate; }

/* ---------- bottom bar ---------- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr 1fr 92px 1fr 1fr; align-items: end;
  padding: 0 calc(var(--sar) + 6px) calc(var(--sab) + 6px) calc(var(--sal) + 6px);
  background: linear-gradient(180deg, rgba(20,18,20,0.96), rgba(10,9,11,0.99));
  border-top: 1px solid rgba(255,255,255,0.07); box-shadow: 0 -8px 30px rgba(0,0,0,0.5);
  height: calc(64px + var(--sab));
}
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 58px; color: var(--mut); font-size: 9.5px; letter-spacing: 1px; font-weight: 600; border-radius: 12px; transition: color .2s, background .2s; }
.tab svg { width: 22px; height: 22px; fill: currentColor; }
.tab.on { color: var(--acc); background: rgba(255,138,61,0.08); }
.tab:active { transform: scale(.94); }
.tab .dot { position: absolute; top: 8px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: #48ff9a; box-shadow: 0 0 8px #48ff9a; display: none; }
.tab .dot.show { display: block; }
.od-slot { position: relative; height: 58px; }
.od { position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%); width: 84px; height: 84px; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #3a3236, #171416 70%); border: 2px solid #2a2527;
  box-shadow: 0 6px 20px rgba(0,0,0,0.7), inset 0 2px 0 rgba(255,255,255,0.08); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.od .ring { position: absolute; inset: -2px; width: calc(100% + 4px); height: calc(100% + 4px); transform: rotate(-90deg); }
.od .ring circle { fill: none; stroke-width: 6; }
.od .ring .bg { stroke: rgba(255,255,255,0.08); }
.od .ring .fg { stroke: var(--acc); stroke-linecap: round; stroke-dasharray: 276.46; stroke-dashoffset: 276.46; filter: drop-shadow(0 0 4px rgba(255,138,61,0.8)); }
.od .bolt { width: 28px; height: 28px; fill: #6f675e; position: relative; }
.od span { position: relative; font-size: 10px; font-weight: 700; letter-spacing: 1px; color: var(--mut); margin-top: 1px; }
.od.ready { background: radial-gradient(circle at 50% 35%, #ff9a4a, #c2410c 75%); border-color: #ffb070; animation: odpulse 1.2s infinite; }
.od.ready .bolt { fill: #fff6e0; filter: drop-shadow(0 0 6px #fff); }
.od.ready span { color: #fff; }
.od.ready .ring .fg { stroke: #ffe1a0; }
.od.active { background: radial-gradient(circle at 50% 35%, #fff1c0, #ff6a1a 60%, #a3220a); border-color: #fff; }
.od.active .bolt { fill: #fff; }
.od.active span { color: #fff; }
.od.active .ring .fg { stroke: #fff; }
.od:active { transform: translateX(-50%) scale(.93); }
@keyframes odpulse { 0%,100% { box-shadow: 0 6px 20px rgba(0,0,0,0.7), 0 0 0 0 rgba(255,138,61,0.55); } 50% { box-shadow: 0 6px 20px rgba(0,0,0,0.7), 0 0 0 12px rgba(255,138,61,0); } }

/* ---------- sheet ---------- */
.sheet { position: fixed; left: 0; right: 0; bottom: calc(64px + var(--sab)); z-index: 15; max-height: 58vh; height: 58vh;
  background: linear-gradient(180deg, rgba(26,23,25,0.97), rgba(14,13,15,0.99)); border-top: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px 20px 0 0; box-shadow: 0 -16px 40px rgba(0,0,0,0.6);
  transform: translateY(calc(100% + 80px)); transition: transform .32s cubic-bezier(.2,.9,.25,1); display: flex; flex-direction: column; }
.sheet.open { transform: translateY(0); }
.sheet-head { position: relative; padding: 10px 16px 8px; display: flex; align-items: center; justify-content: space-between; }
.sheet-head .grab { position: absolute; left: 50%; top: 6px; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: rgba(255,255,255,0.15); }
.sheet-head h2 { margin: 6px 0 0; font-size: 15px; letter-spacing: 3px; color: var(--ink); }
.x { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.06); color: var(--dim); font-size: 14px; }
.sheet-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 12px 16px; overscroll-behavior: contain; }
.pane { display: none; }
.pane.on { display: block; }
.modes { display: flex; gap: 6px; margin-bottom: 10px; background: rgba(255,255,255,0.04); padding: 4px; border-radius: 12px; }
.modes button { flex: 1; height: 32px; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--dim); letter-spacing: 1px; }
.modes button.on { background: linear-gradient(180deg, #ff9a4a, #e0631e); color: #fff; box-shadow: 0 2px 8px rgba(255,120,40,0.35); }

.tier-card { position: relative; border-radius: 14px; padding: 12px; margin-bottom: 10px; overflow: hidden;
  background: linear-gradient(135deg, rgba(255,210,77,0.12), rgba(255,138,61,0.04) 60%), var(--panel2); border: 1px solid rgba(255,210,77,0.25); display: flex; gap: 12px; align-items: center; }
.tier-card canvas { width: 54px; height: 68px; flex: none; }
.tier-card .ti { flex: 1; min-width: 0; }
.tier-card small { font-size: 9px; letter-spacing: 1.5px; color: var(--acc2); font-weight: 700; }
.tier-card h3 { margin: 1px 0 2px; font-size: 15px; }
.tier-card p { margin: 0; font-size: 11.5px; color: var(--dim); line-height: 1.3; }
.tier-card .req { font-size: 11px; margin-top: 4px; color: var(--mut); }
.tier-card .req.ok { color: #7dffb0; }

.upg-list { display: flex; flex-direction: column; gap: 8px; }
.upg { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); position: relative; overflow: hidden; }
.upg::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--a); opacity: .8; }
.upg.locked { opacity: .45; }
.upg .ic { width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center; background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--a) 35%, #222), #161416); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--a) 45%, transparent); }
.upg .ic svg { width: 24px; height: 24px; fill: var(--a); filter: drop-shadow(0 0 4px var(--a)); }
.upg .mid { flex: 1; min-width: 0; }
.upg .nm { font-size: 14px; font-weight: 700; display: flex; gap: 6px; align-items: baseline; }
.upg .lv { font-size: 11px; color: var(--mut); font-weight: 600; }
.upg .ef { font-size: 11.5px; color: var(--dim); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upg .ef b { color: #8fffbf; font-weight: 600; }
.upg .ds { font-size: 10.5px; color: var(--mut); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.buy { flex: none; min-width: 86px; height: 48px; border-radius: 12px; padding: 0 8px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #3a3437, #262224); color: var(--mut); font-weight: 700; border: 1px solid rgba(255,255,255,0.06); transition: transform .08s; }
.buy small { font-size: 9px; letter-spacing: 1px; opacity: .85; }
.buy span { font-size: 14px; display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.buy span::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff2b0, #ffb83d 45%, #b35b12); }
.buy.can { background: linear-gradient(180deg, #ff9a4a, #d9561a); color: #fff; box-shadow: 0 3px 10px rgba(255,110,40,0.35), inset 0 1px 0 rgba(255,255,255,0.3); border-color: #ffb070; }
.buy.max { background: #1d1b1c; color: var(--acc2); }
.buy.max span::before { display: none; }
.buy:active { transform: scale(.94); }
.upg.flash { animation: flash .35s; }
@keyframes flash { 30% { background: rgba(255,190,90,0.22); } }

.btn { height: 42px; padding: 0 14px; border-radius: 12px; font-weight: 700; letter-spacing: 1px; font-size: 12.5px; background: linear-gradient(180deg, #34303a, #232026); border: 1px solid rgba(255,255,255,0.08); color: var(--ink); }
.btn.primary { background: linear-gradient(180deg, #ff9a4a, #d9561a); border-color: #ffb070; color: #fff; box-shadow: 0 3px 10px rgba(255,110,40,0.35); }
.btn.danger { color: #ff8a92; border-color: rgba(255,80,90,0.35); }
.btn.danger.armed { background: #a3172a; color: #fff; }
.btn.wide { width: 100%; height: 50px; font-size: 15px; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; }

.res-head { display: flex; justify-content: space-between; align-items: center; padding: 12px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); margin-bottom: 10px; }
.res-head label, .stat-list label, .m-grid label { display: block; font-size: 9px; letter-spacing: 1.4px; color: var(--mut); font-weight: 600; }
.res-head b { font-size: 20px; }
.res-head small { display: block; font-size: 11px; color: var(--dim); }
.res-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.res { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); min-width: 0; }
.res canvas { width: 36px; height: 36px; flex: none; }
.res .ri { min-width: 0; }
.res b { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res span { display: block; font-size: 10.5px; color: var(--dim); white-space: nowrap; }
.res em { font-style: normal; color: var(--acc2); }
.res.unk { opacity: .4; }
.res-zone { grid-column: 1 / -1; font-size: 10px; letter-spacing: 1.6px; color: var(--mut); font-weight: 700; margin: 6px 2px 0; }

.stat-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 9px 10px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); }
.stat b { font-size: 15px; font-variant-numeric: tabular-nums; }
h4 { font-size: 11px; letter-spacing: 2px; color: var(--dim); margin: 14px 2px 8px; }
.zone-list { display: flex; flex-direction: column; gap: 6px; }
.zl { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); }
.zl i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.zl div { flex: 1; font-size: 12.5px; font-weight: 600; }
.zl span { font-size: 11px; color: var(--dim); }
.zl.lock { opacity: .4; }
.zl.cur { border-color: color-mix(in srgb, var(--zone) 60%, transparent); }
.stat-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.stat-actions .btn { flex: 1 1 40%; }
.dev h4 { color: #b47bff; }
.credit { text-align: center; color: var(--mut); font-size: 11px; margin-top: 18px; letter-spacing: 1px; }

.research { padding: 4px 2px; }
.r-hero { text-align: center; padding: 16px; border-radius: 16px; background: radial-gradient(circle at 50% 0%, rgba(255,210,100,0.18), transparent 70%), var(--panel2); border: 1px solid var(--line); }
.r-core { width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff6d0, #ffc040 35%, #ff5aa0 70%, #401040); box-shadow: 0 0 30px rgba(255,190,90,0.6); animation: spin 8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.r-hero h3 { margin: 0; letter-spacing: 3px; font-size: 15px; }
.r-hero p { font-size: 12px; color: var(--dim); line-height: 1.4; margin: 6px 0; }
.r-req { font-size: 12px; color: var(--acc2); font-weight: 600; }
.r-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.r-node { padding: 10px; border-radius: 12px; background: var(--panel2); border: 1px dashed rgba(255,255,255,0.12); opacity: .6; }
.r-node b { display: block; font-size: 12.5px; } .r-node span { font-size: 11px; color: var(--dim); }
.soon { text-align: center; color: var(--mut); font-size: 11px; letter-spacing: 2px; margin-top: 14px; }

/* ---------- banners & toasts ---------- */
.banner { position: fixed; left: 50%; top: 30%; z-index: 12; transform: translate(-50%, 0) scale(.9); opacity: 0; pointer-events: none; text-align: center; width: 90%;
  transition: opacity .35s, transform .35s; text-shadow: 0 2px 20px rgba(0,0,0,0.9); }
.banner.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.banner small { display: block; font-size: 12px; letter-spacing: 5px; color: var(--zone); font-weight: 700; }
.banner strong { display: block; font-size: 32px; letter-spacing: 2px; line-height: 1.1; margin: 4px 0; }
.banner span { display: block; font-size: 13px; color: var(--dim); }
#toasts { position: fixed; left: 0; right: 0; z-index: 16; bottom: calc(98px + var(--sab)); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { max-width: 88%; padding: 8px 14px; border-radius: 12px; background: rgba(14,12,14,0.92); border: 1px solid rgba(255,255,255,0.1); box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; animation: toastIn .3s ease-out; transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translateY(8px); }
.toast i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.toast small { color: var(--dim); font-weight: 500; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.95); } }

/* ---------- modal & boot ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.65); display: none; align-items: center; justify-content: center; padding: 24px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal.show { display: flex; }
.modal-card { width: 100%; max-width: 340px; padding: 22px 20px 18px; border-radius: 20px; text-align: center; background: linear-gradient(180deg, #27222a, #151316); border: 1px solid rgba(255,210,77,0.25); box-shadow: 0 20px 60px rgba(0,0,0,0.7); animation: toastIn .35s; }
.modal-card small { font-size: 11px; letter-spacing: 3px; color: var(--acc2); font-weight: 700; }
.modal-card h3 { margin: 4px 0; font-size: 20px; }
.m-time { color: var(--dim); font-size: 13px; }
.m-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 8px; }
.m-grid div { padding: 10px; border-radius: 12px; background: rgba(255,255,255,0.05); }
.m-grid b { font-size: 20px; color: var(--acc2); }
.modal-card p { font-size: 11.5px; color: var(--mut); margin: 4px 0 14px; }
#boot { position: fixed; inset: 0; z-index: 60; background: #0b0a0d; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; transition: opacity .5s; }
#boot.done { opacity: 0; pointer-events: none; }
.boot-bar { width: 160px; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.08); overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff6a2a, var(--acc2)); transition: width .2s; }

@media (max-height: 700px) { .credits { font-size: 28px; } .chips { margin-top: 5px; } .chip b { font-size: 13px; } .bars { margin-top: 5px; } }
