* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #04060c; font-family: 'Segoe UI', system-ui, sans-serif; color: #cfd8e3; }
#view { position: fixed; inset: 0; display: block; }
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud .panel { pointer-events: auto; }

.panel {
  position: absolute;
  background: rgba(8, 14, 24, 0.82);
  border: 1px solid rgba(120, 160, 210, 0.22);
  border-radius: 6px;
  padding: 10px 12px;
  backdrop-filter: blur(4px);
  font-size: 13px;
}
.ptitle { font-weight: 600; letter-spacing: 0.04em; font-size: 14px; color: #e8eef6; }
.sub { color: #8fa2b8; margin-top: 2px; font-size: 12px; }
.hidden { display: none !important; }

#sys { top: 12px; left: 12px; min-width: 160px; }
#ship { bottom: 12px; left: 12px; min-width: 160px; }
#overview { top: 12px; right: 12px; width: 250px; max-height: 58vh; overflow-y: auto; }
#selpanel { bottom: 12px; left: 50%; transform: translateX(-50%); min-width: 300px; text-align: center; }
#chat { bottom: 12px; right: 12px; width: 280px; }

.ovrow { display: flex; justify-content: space-between; gap: 8px; padding: 3px 6px; border-radius: 4px; cursor: pointer; }
.ovrow:hover { background: rgba(90, 140, 200, 0.18); }
.ovrow.sel { background: rgba(90, 140, 200, 0.32); }
.ovname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ovd { color: #8fa2b8; white-space: nowrap; }
.k-station .ovname { color: #9fd4ff; }
.k-gate .ovname { color: #c9a7ff; }
.k-belt .ovname { color: #d9c08a; }
.k-ship .ovname { color: #e8eef6; }
.k-npc .ovname { color: #ff8c7a; }

button {
  background: rgba(60, 110, 170, 0.35);
  border: 1px solid rgba(120, 170, 230, 0.4);
  color: #dbe7f3;
  padding: 5px 12px;
  margin: 6px 3px 0 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
button:hover { background: rgba(80, 140, 210, 0.5); }
button.primary { background: rgba(60, 170, 120, 0.4); border-color: rgba(110, 220, 160, 0.5); }
.btnrow { margin-top: 6px; }

#chatlog { max-height: 130px; overflow-y: auto; font-size: 12px; margin-bottom: 6px; }
#chatlog b { color: #9fd4ff; font-weight: 600; }
#chatin { width: 100%; background: rgba(20, 30, 46, 0.9); border: 1px solid rgba(120, 160, 210, 0.25); color: #dbe7f3; padding: 5px 8px; border-radius: 4px; font-size: 12px; }

#toast {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%);
  background: rgba(10, 18, 30, 0.92); border: 1px solid rgba(140, 190, 250, 0.4);
  padding: 8px 18px; border-radius: 6px; opacity: 0; transition: opacity 0.3s; pointer-events: none;
  font-size: 14px;
}
#toast.show { opacity: 1; }

#login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #0a1322 0%, #04060c 70%);
}
.loginbox { text-align: center; padding: 40px; }
.loginbox h1 { font-size: 42px; letter-spacing: 0.35em; color: #e8eef6; font-weight: 300; text-shadow: 0 0 24px rgba(120, 190, 255, 0.4); }
.tag { color: #7d93ad; margin: 10px 0 26px; font-style: italic; }
.fine { color: #5d6f84; margin-top: 14px; font-size: 12px; }
#handle { display: block; width: 260px; margin: 0 auto 12px; background: rgba(16, 26, 42, 0.9); border: 1px solid rgba(120, 160, 210, 0.35); color: #e8eef6; padding: 10px 14px; border-radius: 6px; font-size: 15px; text-align: center; }
#loginbtn { font-size: 15px; padding: 9px 38px; letter-spacing: 0.2em; }



/* Combat panel */
#combat { bottom: 86px; left: 12px; width: 250px; }
.bar { position: relative; height: 14px; background: rgba(30,40,56,0.9); border-radius: 3px; margin: 3px 0; overflow: hidden; }
.bar .fill { height: 100%; transition: width 0.4s; }
.bar span { position: absolute; inset: 0; font-size: 10px; text-align: center; line-height: 14px; color: #dfe9f5; text-shadow: 0 1px 2px #000; }
.b-shield { background: #3d7dc9; }
.b-armor { background: #a98134; }
.b-hull { background: #b04a3a; }
.b-cap { background: #43a58c; }
.modrack { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
button.mod { position: relative; width: 68px; height: 40px; font-size: 10px; overflow: hidden; }
button.mod.on { background: rgba(80, 200, 140, 0.35); border-color: rgba(120, 240, 180, 0.6); }
button.mod.burnt { background: rgba(200, 70, 40, 0.4); }
button.mod .modk { display: block; font-size: 9px; color: #8fa2b8; }
button.mod .heat { position: absolute; right: 0; bottom: 0; width: 4px; background: #ff6a3a; }
#restune { width: 130px; vertical-align: middle; }

/* Station screen */
#station { position: fixed; inset: 6vh 8vw; background: rgba(7, 12, 20, 0.97); border: 1px solid rgba(120,160,210,0.3); border-radius: 10px; padding: 18px; z-index: 40; overflow-y: auto; }
.stn-head { display: flex; justify-content: space-between; align-items: start; flex-wrap: wrap; gap: 10px; border-bottom: 1px solid rgba(120,160,210,0.2); padding-bottom: 10px; }
.stn-body { padding-top: 12px; font-size: 13px; }
.stn-body h3 { color: #9fd4ff; font-size: 14px; margin: 10px 0 6px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 3px 0; border-bottom: 1px dotted rgba(120,160,210,0.12); }
.row.locked { opacity: 0.45; }
.row.mk { justify-content: flex-start; gap: 14px; }
.mission { border: 1px solid rgba(120,160,210,0.2); border-radius: 6px; padding: 8px 10px; margin: 6px 0; }
.mission.accepted { border-color: rgba(120, 220, 160, 0.4); }
.stn-body input { background: rgba(20,30,46,0.9); border: 1px solid rgba(120,160,210,0.25); color: #dbe7f3; padding: 4px 8px; border-radius: 4px; width: 110px; }
button.tab { text-transform: capitalize; }

/* Codex */
#codexbtn { position: fixed; top: 12px; left: 190px; z-index: 30; }
#codex { position: fixed; inset: 8vh 12vw; z-index: 50; overflow: hidden; display: flex; flex-direction: column; }
.cdx-head { display: flex; justify-content: space-between; border-bottom: 1px solid rgba(120,160,210,0.25); padding-bottom: 8px; }
.cdx-body { display: flex; gap: 18px; overflow: hidden; flex: 1; padding-top: 10px; }
.cdx-nav { width: 190px; overflow-y: auto; flex-shrink: 0; }
.cdx-cat { color: #7d93ad; text-transform: uppercase; font-size: 10px; letter-spacing: 0.15em; margin: 10px 0 3px; }
.cdx-link { padding: 3px 8px; border-radius: 4px; cursor: pointer; }
.cdx-link:hover, .cdx-link.sel { background: rgba(90,140,200,0.25); }
.cdx-text { overflow-y: auto; flex: 1; line-height: 1.65; font-size: 14px; padding-right: 12px; }
.cdx-text h2 { color: #e8eef6; font-weight: 400; letter-spacing: 0.08em; margin-bottom: 12px; }
.cdx-text p { margin-bottom: 12px; color: #b9c6d6; }
#firststeps { top: 64px; left: 12px; width: 240px; font-size: 12px; }
.step { color: #8fa2b8; padding: 1px 0; }
.step.done { color: #6fd47b; }


/* Cinematics */
#cinema { position: fixed; inset: 0; z-index: 90; background: #03040a; }
#cinema-stars { position: absolute; inset: 0; opacity: 0.7; animation: stardrift 60s linear infinite; }
@keyframes stardrift { from { transform: scale(1) translateY(0); } to { transform: scale(1.12) translateY(-30px); } }
.cinema-bar { position: absolute; left: 0; right: 0; height: 11vh; background: #000; z-index: 2; }
.cinema-bar.top { top: 0; }
.cinema-bar.bottom { bottom: 0; }
.cinema-content { position: absolute; inset: 14vh 12vw; z-index: 3; display: flex; flex-direction: column; }
.cinema-title { font-size: 26px; letter-spacing: 0.3em; color: #e8eef6; font-weight: 300; margin-bottom: 26px; text-shadow: 0 0 22px rgba(120,190,255,0.5); }
.cinema-body { flex: 1; white-space: pre-wrap; line-height: 1.8; font-size: 16px; color: #b9c6d6; overflow-y: auto; max-width: 760px; font-family: Georgia, 'Times New Roman', serif; }
.cinema-objective { color: #9fd4ff; margin: 14px 0; letter-spacing: 0.06em; }
.cinema-next { align-self: flex-start; font-size: 14px; padding: 8px 30px; letter-spacing: 0.15em; }
.cinema-skip { position: absolute; top: -8vh; right: 0; opacity: 0.5; }
#jumpflash { position: fixed; inset: 0; z-index: 80; pointer-events: none; background: radial-gradient(circle, rgba(190,240,255,0.9), rgba(120,200,255,0.4) 40%, transparent 75%); opacity: 0; }
#jumpflash.on { animation: jflash 0.7s ease-out; }
@keyframes jflash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }

/* Maps */
#mapbtn { position: fixed; top: 12px; left: 258px; z-index: 30; }
#reachbtn { position: fixed; top: 12px; left: 316px; z-index: 30; }
#mappanel { position: fixed; inset: 10vh 14vw; z-index: 45; display: flex; flex-direction: column; }
.map-head { display: flex; align-items: center; gap: 14px; border-bottom: 1px solid rgba(120,160,210,0.25); padding-bottom: 6px; }
.map-head button { margin-left: auto; }
#mapcanvas { flex: 1; width: 100%; height: 100%; cursor: crosshair; }

#mutebtn { position: fixed; bottom: 12px; left: 285px; z-index: 30; }

/* ============ Mobile shell ============ */
#view { touch-action: none; }

body.mobile #hud .panel, body.mobile #firststeps { transition: none; }
body.mobile button { min-height: 40px; min-width: 40px; }
body.mobile .ovrow { min-height: 34px; align-items: center; }

/* Tab bar */
#mtabs { position: fixed; top: 8px; right: 8px; z-index: 60; display: flex; gap: 6px; }
#mtabs button { width: 44px; height: 44px; font-size: 17px; padding: 0; }

/* Compact persistent chrome */
body.mobile #sys { top: 8px; left: 8px; min-width: 0; padding: 6px 10px; }
body.mobile #sys .ptitle { font-size: 12px; }
body.mobile #sys .sub { font-size: 10px; }
body.mobile #codexbtn, body.mobile #mapbtn, body.mobile #reachbtn, body.mobile #mutebtn { position: static; }

/* All sheet panels hidden until summoned */
body.mobile #overview, body.mobile #chat, body.mobile #firststeps, body.mobile #ship { display: none; }
body.mobile[data-sheet="overview"] #overview,
body.mobile[data-sheet="chat"] #chat,
body.mobile[data-sheet="steps"] #firststeps,
body.mobile[data-sheet="ship"] #ship { display: block; z-index: 55; }

/* Portrait: bottom sheet above the combat strip */
body.mobile.portrait[data-sheet="overview"] #overview,
body.mobile.portrait[data-sheet="chat"] #chat,
body.mobile.portrait[data-sheet="steps"] #firststeps,
body.mobile.portrait[data-sheet="ship"] #ship {
  position: fixed; left: 0; right: 0; bottom: 128px; top: auto;
  width: auto; max-height: 42vh; overflow-y: auto; border-radius: 10px 10px 0 0;
}
/* Landscape: right dock */
body.mobile.landscape[data-sheet="overview"] #overview,
body.mobile.landscape[data-sheet="chat"] #chat,
body.mobile.landscape[data-sheet="steps"] #firststeps,
body.mobile.landscape[data-sheet="ship"] #ship {
  position: fixed; top: 60px; right: 0; bottom: 8px; left: auto;
  width: min(46vw, 340px); max-height: none; overflow-y: auto; border-radius: 10px 0 0 10px;
}

/* Combat strip: compact, always visible, horizontally scrollable modules */
body.mobile #combat { left: 8px; right: 8px; bottom: 8px; width: auto; padding: 6px 8px; }
body.mobile #combat .bar { height: 8px; margin: 2px 0; }
body.mobile #combat .bar span { display: none; }
body.mobile .modrack { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
body.mobile button.mod { flex: 0 0 auto; width: 58px; height: 44px; }

/* Target panel sits above the combat strip */
body.mobile #selpanel { bottom: 132px; left: 8px; right: 8px; transform: none; min-width: 0; width: auto; }
body.mobile.landscape #selpanel { left: 8px; right: auto; max-width: 46vw; bottom: 128px; }
body.mobile #selpanel .btnrow { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }

/* Full-screen station, codex, maps, cinema on mobile */
body.mobile #station { inset: 0; border-radius: 0; padding: 10px; padding-top: 60px; }
body.mobile .stn-head { position: sticky; top: -10px; background: rgba(7,12,20,0.97); z-index: 2; padding-top: 10px; }
body.mobile .stn-head > div:last-child { display: flex; flex-wrap: wrap; gap: 4px; }
body.mobile #codex { inset: 0; border-radius: 0; }
body.mobile .cdx-nav { width: 130px; }
body.mobile #mappanel { inset: 0; border-radius: 0; z-index: 58; }
body.mobile .cinema-content { inset: 9vh 6vw; }
body.mobile .cinema-title { font-size: 19px; margin-bottom: 12px; }
body.mobile .cinema-body { font-size: 14px; line-height: 1.6; }
body.mobile #toast { top: 64px; width: max-content; max-width: 90vw; }

/* Ship/status panel when opened as a sheet keeps content compact */
body.mobile #ship .ptitle { font-size: 13px; }

/* Mobile polish */
body.mobile #sys { max-width: 128px; overflow: hidden; }
body.mobile #sys .ptitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.mobile #mtabs button { font-size: 17px; }
body.mobile #codexbtn, body.mobile #mapbtn, body.mobile #reachbtn { width: 44px; height: 44px; font-size: 0; padding: 0; }
body.mobile #codexbtn::after { content: '✦'; font-size: 17px; }
body.mobile #mapbtn::after { content: '⌖'; font-size: 19px; }
body.mobile #reachbtn::after { content: '✧'; font-size: 17px; }
body.mobile.portrait[data-sheet] #overview, body.mobile.portrait[data-sheet] #chat,
body.mobile.portrait[data-sheet] #firststeps, body.mobile.portrait[data-sheet] #ship { bottom: 142px; }
