* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0c1222; color: #eaf2ff;
  display: flex; justify-content: center;
}
#app { width: 100%; max-width: 430px; min-height: 100dvh; display: flex; flex-direction: column; background: #101830; position: relative; }
.hidden { display: none !important; }

/* ---- top bar ---- */
#topbar { background: linear-gradient(180deg, #1b2a52, #14203f); padding: 8px 10px 10px; border-bottom: 3px solid #ffd23f; position: sticky; top: 0; z-index: 20; }
.title { font-weight: 800; letter-spacing: 1px; font-size: 17px; color: #ffd23f; text-align: center; }
.title .proto { color: #8fb4ff; font-size: 11px; font-weight: 600; letter-spacing: 0; }
#resources { display: flex; justify-content: space-between; margin-top: 7px; gap: 4px; }
.res { background: #0c1428; border: 1px solid #2c4478; border-radius: 9px; padding: 4px 5px; flex: 1; text-align: center; min-width: 0; }
.res b { display: block; font-size: 13px; color: #fff; }
.rlabel { font-size: 9px; text-transform: uppercase; letter-spacing: .4px; color: #9db8e8; }
.ric { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 3px; vertical-align: -1px; }
.ric.cash { background: #57e389; border-radius: 50%; }
.ric.silicon { background: #cfd8e3; }
.ric.wafers { background: #6ee7ff; border-radius: 50%; }
.ric.chips { background: #ffd23f; }
.ric.compute { background: #c792ff; clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; }

/* ---- views ---- */
.view { flex: 1; overflow-y: auto; padding: 10px; padding-bottom: 76px; }
.view-title { font-size: 18px; margin-bottom: 4px; }
.hint { font-size: 12px; color: #9db8e8; line-height: 1.45; margin: 8px 2px; }

/* ---- factory ---- */
#event-banner { background: linear-gradient(90deg, #7a1020, #b3122e); border: 2px solid #ff5d73; border-radius: 10px; padding: 8px 10px; font-size: 12px; margin-bottom: 10px; }
#event-banner b { display: block; font-size: 13px; letter-spacing: .5px; }
#company-card { position: relative; border-radius: 14px; overflow: hidden; border: 2px solid #2c4478; background: #16233f; margin-bottom: 10px; }
#company-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .35; }
#fab-img-slot { position: relative; z-index: 2; display: flex; justify-content: center; padding-top: 10px; }
#fab-img-slot img { width: 110px; height: 110px; object-fit: cover; border-radius: 16px; border: 3px solid #ffd23f; background: #fff; }
#fab-img-slot .slot-fallback { width: 110px; height: 110px; border-radius: 16px; border: 3px dashed #ffd23f; background: #27406e; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; color: #ffd23f; padding: 8px; }
.fab-caption { position: relative; z-index: 2; text-align: center; font-size: 12px; color: #fff; padding: 4px 0 10px; font-weight: 700; text-shadow: 0 1px 4px #000; }
.gl-wrap { border: 2px solid #2c4478; border-radius: 14px; overflow: hidden; background: #8fd3ff; touch-action: none; }
.gl-wrap canvas { display: block; }
#factory-3d { height: 300px; }
#defense-3d { height: 470px; max-width: 390px; margin: 0 auto; }

#trade-row { display: flex; gap: 8px; margin: 10px 0; }
.trade-btn { flex: 1; background: #1d3a24; border: 2px solid #57e389; color: #d9ffe6; border-radius: 11px; padding: 9px 6px; font-size: 14px; font-weight: 700; cursor: pointer; }
.trade-btn small { color: #8fe3ae; font-weight: 600; }
.trade-btn:active { transform: scale(.98); }

.station { background: #182747; border: 2px solid #2c4478; border-radius: 13px; padding: 10px; margin-bottom: 9px; display: flex; gap: 10px; align-items: center; }
.station .sicon { width: 46px; height: 46px; border-radius: 11px; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 11px; color: #081226; text-align: center; }
.sicon.intake { background: #cfd8e3; } .sicon.wafer { background: #6ee7ff; } .sicon.assembly { background: #ffd23f; }
.sicon.testlab { background: #ff9f6e; } .sicon.data { background: #c792ff; }
.station .sinfo { flex: 1; min-width: 0; }
.station .sname { font-weight: 700; font-size: 14px; }
.station .sdesc { font-size: 11px; color: #9db8e8; line-height: 1.35; }
.station .srate { font-size: 11px; color: #8fe3ae; font-weight: 600; }
.station .sbtn { flex: none; background: #ffd23f; color: #231a00; border: none; border-radius: 10px; padding: 9px 10px; font-weight: 800; font-size: 12px; cursor: pointer; min-width: 86px; }
.station .sbtn:disabled { background: #44557c; color: #aab; cursor: default; }
.buildbar { height: 6px; background: #0c1428; border-radius: 3px; overflow: hidden; margin-top: 5px; }
.buildbar i { display: block; height: 100%; background: #57e389; width: 0%; }

/* ---- defense ---- */
.threat-card { display: flex; gap: 10px; align-items: center; background: #2a1220; border: 2px solid #ff5d73; border-radius: 13px; padding: 10px; margin-bottom: 10px; font-size: 13px; }
.threat-card img { width: 62px; height: 62px; object-fit: cover; border-radius: 11px; background: #fff; flex: none; }
.threat-card small { color: #ffb3c0; line-height: 1.4; }
#stage-buttons { display: flex; flex-direction: column; gap: 8px; }
.stage-btn { background: #182747; border: 2px solid #2c4478; color: #eaf2ff; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; text-align: left; cursor: pointer; width: 100%; }
.stage-btn small { display: block; color: #9db8e8; font-weight: 500; font-size: 12px; margin-top: 2px; }
.stage-btn:disabled { opacity: .45; cursor: default; }
.stage-btn .cleared { color: #57e389; }
#defense-hud { display: flex; justify-content: space-between; align-items: center; background: #0c1428; border: 1px solid #2c4478; border-radius: 9px; padding: 6px 10px; font-size: 13px; margin-bottom: 8px; }
#hero-portrait { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid #ffd23f; background: #fff; }
#turret-shop { display: flex; gap: 8px; margin-top: 9px; }
.turret-btn { flex: 1; background: #182747; border: 2px solid #2c4478; color: #eaf2ff; border-radius: 11px; padding: 9px 6px; font-size: 13px; font-weight: 700; cursor: pointer; }
.turret-btn small { color: #9db8e8; font-weight: 500; }
.turret-btn.selected { border-color: #ffd23f; background: #2a3f6e; }
.turret-btn:disabled { opacity: .45; }
.defense-actions { display: flex; gap: 8px; margin-top: 9px; }
.primary-btn { flex: 1; background: #ffd23f; color: #231a00; border: none; border-radius: 11px; padding: 12px; font-size: 15px; font-weight: 800; cursor: pointer; }
.ghost-btn { background: transparent; border: 2px solid #44557c; color: #cfe0ff; border-radius: 11px; padding: 12px 14px; font-size: 14px; font-weight: 700; cursor: pointer; }

/* ---- research ---- */
.research-card { background: #182747; border: 2px solid #2c4478; border-radius: 13px; padding: 12px; margin-bottom: 9px; }
.research-card h3 { font-size: 15px; }
.research-card p { font-size: 12px; color: #9db8e8; margin: 3px 0 8px; line-height: 1.4; }
.research-card .rcost { font-size: 12px; color: #ffd23f; font-weight: 700; margin-bottom: 8px; }
.research-card button { background: #ffd23f; color: #231a00; border: none; border-radius: 9px; padding: 9px 14px; font-weight: 800; font-size: 13px; cursor: pointer; }
.research-card button:disabled { background: #44557c; color: #aab; }
.research-card.owned { border-color: #57e389; }
.owned-tag { color: #57e389; font-weight: 800; font-size: 13px; }

/* ---- nav / modals / toast ---- */
#bottomnav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 430px; display: flex; background: #0c1428; border-top: 2px solid #2c4478; z-index: 30; }
.nav-btn { flex: 1; background: none; border: none; color: #9db8e8; font-size: 14px; font-weight: 700; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); cursor: pointer; }
.nav-btn.active { color: #ffd23f; box-shadow: inset 0 3px 0 #ffd23f; }
.modal { position: fixed; inset: 0; background: rgba(3,6,14,.78); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px; }
.modal-card { background: #182747; border: 2px solid #2c4478; border-radius: 16px; padding: 18px; max-width: 360px; width: 100%; }
.modal-card h2 { font-size: 18px; margin-bottom: 8px; }
.modal-card p { font-size: 13px; line-height: 1.5; color: #cfe0ff; margin-bottom: 10px; }
.modal-card .primary-btn { width: 100%; }
.modal-card.news { border-color: #ff5d73; background: #2a1220; }
.news-tag { display: inline-block; background: #e01e37; color: #fff; font-weight: 800; font-size: 12px; letter-spacing: 1px; padding: 4px 9px; border-radius: 6px; margin-bottom: 10px; }
.news-effect { background: rgba(255,210,63,.12); border: 1px dashed #ffd23f; border-radius: 9px; padding: 8px; }
#toast { position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); background: #ffd23f; color: #231a00; font-weight: 700; font-size: 13px; padding: 9px 16px; border-radius: 999px; z-index: 60; box-shadow: 0 4px 18px rgba(0,0,0,.5); max-width: 92%; text-align: center; }
