:root {
  color-scheme: dark;
  --ink: #e8eef3;
  --muted: #93a2ae;
  --line: rgba(216, 228, 236, 0.16);
  --panel: rgba(10, 14, 18, 0.78);
  --amber: #e8a849;
  --amber-deep: #c46a2f;
  --critical: #e15b4c;
  --teal: #7ed6c4;
  --twitch: #9146ff;
  font-family: Bahnschrift, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #070b10;
  color: var(--ink);
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.labels3d {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.label3d {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-shadow: 0 1px 4px #000;
}

.label3d-name {
  font: 600 12px Bahnschrift, "Segoe UI", sans-serif;
  color: #f4f7f8;
  white-space: nowrap;
}

.label3d-bars {
  width: 52px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.label3d-bars b {
  display: block;
  height: 3px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.label3d-bars i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0.5);
}

.label3d-bars i.energy { background: #d6e35a; }
.label3d-bars i.shield { background: #67d0e6; }
.label3d-bars i.hull { background: #ef6d5e; }

.hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.panel, .alert, .flash, #logout, #dock button, #combat button, #hangar button, #shop button, #rescue {
  pointer-events: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.pilot, .status, .dock, .target, .combat, #map, .alert, .flash {
  position: fixed;
}

.pilot {
  top: 16px;
  left: 16px;
  width: min(340px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.pilot img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.kicker {
  margin: 0;
  color: var(--amber);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 11px;
}

h1, h2, p { margin: 0; }

h1 { font-size: 22px; font-weight: 600; }
#sector { color: var(--muted); font-size: 13px; margin-top: 2px; }

#hangar {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}
#hangar button {
  flex: 0 0 92px;
  min-width: 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  background: #12181e;
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}
#hangar button[aria-pressed="true"] { border-color: var(--amber); }
#hangar img { width: 46px; height: 46px; object-fit: contain; }

#logout, #refuel, .primary, .ghost {
  border: 0;
  cursor: pointer;
  font: inherit;
}

#logout {
  margin-left: auto;
  background: transparent;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 0 0 2px;
}

.status {
  top: 108px;
  left: 16px;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 250px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px;
}

.meters { display: flex; flex-direction: column; gap: 8px; }

.hangar-label { margin-top: 14px; }

.quest {
  margin-top: 12px;
  color: var(--amber);
  font-size: 13px;
  line-height: 1.35;
}

.fuel-head, .stats, .station-meta, .dock-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.fuel-head { margin: 8px 0; }

.bar {
  height: 10px;
  background: #1a242c;
  overflow: hidden;
}

#fuel-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--amber-deep), var(--amber));
}

#fuel-fill[data-level="low"] { background: #d9843b; }
#fuel-fill[data-level="critical"],
#fuel-fill[data-level="empty"] { background: var(--critical); }

.stats {
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.stats div { display: flex; flex-direction: column; gap: 2px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0; font-size: 16px; }

#stations {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#stations li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.station-name { font-weight: 600; }
.station-meta { color: var(--muted); line-height: 1.35; }
.station-tag { color: var(--teal); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
#stations .out .station-tag { color: #e7a19a; }
#stations .here .station-name { color: var(--teal); }

[hidden] { display: none !important; }

#map {
  top: 16px;
  right: 16px;
  width: 180px;
  height: 180px;
  border: 1px solid var(--line);
  background: rgba(7, 11, 16, 0.72);
  pointer-events: none;
}

#star-map {
  position: fixed;
  top: 204px;
  right: 16px;
  z-index: 2;
  width: 180px;
  pointer-events: auto;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

#star-map[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); }

.star-chart {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: min(460px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 16px 16px 12px;
  pointer-events: auto;
}

.star-chart header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.star-chart h2 { font-size: 22px; margin-top: 4px; }

#star-close {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}

#star-svg { width: 100%; height: auto; display: block; margin-top: 8px; }
.star-chart .hint { margin: 4px 0 0; }

.mission-board:not([hidden]) {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 5;
  width: min(520px, calc(100vw - 32px));
  max-height: min(560px, calc(100vh - 48px));
  transform: translate(-50%, -50%);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.mission-board header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mission-board h2 { font-size: 22px; margin-top: 4px; }

#mission-close {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}

#mission-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mission-group {
  margin: 8px 0 0;
  color: var(--amber);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mission {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #10161c;
}

.mission.active { border-color: var(--amber); }
.mission.open, .mission.active { cursor: pointer; }
.mission.done, .mission.locked { opacity: 0.5; }
.mission[data-disabled="true"] { cursor: default; }

.mission .mission-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mission strong { font-size: 14px; }
.mission p { color: var(--muted); font-size: 13px; line-height: 1.35; }

.mission button {
  border: 1px solid var(--line);
  background: #12181e;
  color: var(--ink);
  font: inherit;
  padding: 6px 8px;
  cursor: pointer;
}

.mission button:disabled { opacity: 0.45; cursor: default; }
.mission.active button { border-color: var(--amber); color: var(--amber); }

.target {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(280px, calc(100vw - 420px));
  padding: 10px 12px;
}

.bar.slim { height: 7px; margin-top: 6px; }

#party:not([hidden]) { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
#party-note { color: var(--muted); font-size: 13px; }
.party-actions, #party-members { display: flex; flex-wrap: wrap; gap: 6px; }
#party-members { list-style: none; margin: 0; padding: 0; }
#party-members li, #party button, #party-invite {
  border: 1px solid var(--line);
  background: #12181e;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
}
#party-members li { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; }
#party button, #party-invite { cursor: pointer; }
#party-invite { margin-top: 8px; }
#target-shield { height: 100%; width: 100%; transform-origin: left center; background: #67d0e6; }
#target-hull { height: 100%; width: 100%; transform-origin: left center; background: var(--critical); }
#target.mining #target-hull { background: #e8a849; }

.flash, .alert {
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 14px;
  max-width: min(520px, calc(100vw - 32px));
}

.flash {
  bottom: 132px;
  background: rgba(232, 168, 73, 0.94);
  color: #24180a;
}

.alert {
  bottom: 78px;
  background: rgba(225, 91, 76, 0.92);
  color: white;
}

#rescue {
  position: fixed;
  left: 50%;
  bottom: 124px;
  transform: translateX(-50%);
  z-index: 3;
  border: 0;
  background: var(--teal);
  color: #06211c;
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
  cursor: pointer;
}

#rescue:disabled {
  background: #2a343c;
  color: var(--muted);
  cursor: default;
}

.dock {
  top: 212px;
  right: 16px;
  bottom: 128px;
  left: auto;
  width: min(360px, calc(100vw - 400px));
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.combat {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: min(760px, calc(100vw - 400px));
  padding: 8px;
}

.combat button, .dock-actions button, .clan-row button, .offer {
  border: 1px solid var(--line);
  background: #12181e;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.combat button, .dock-actions button, .clan-row button {
  padding: 8px 10px;
}

.combat button[aria-pressed="true"], .offer:not(:disabled):hover {
  border-color: var(--amber);
}

.mode-tip {
  position: fixed;
  z-index: 6;
  width: min(280px, calc(100vw - 16px));
  padding: 10px 12px;
  background: rgba(10, 14, 18, 0.96);
  border: 1px solid var(--amber);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.mode-tip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--amber);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-tip span {
  display: block;
  font-size: 13px;
  line-height: 1.4;
}

.dock-actions, .clan-row { display: flex; flex-wrap: wrap; gap: 6px; }
.clan-row input { width: 72px; padding: 8px; }

#shop { display: flex; flex-direction: column; gap: 6px; }
.offer {
  display: flex;
  gap: 8px;
  text-align: left;
  padding: 6px;
}
.offer img { width: 46px; height: 46px; object-fit: contain; background: #070b10; }
.offer span { display: flex; flex-direction: column; gap: 2px; }
.offer small { color: var(--muted); line-height: 1.3; }
.offer:disabled { opacity: 0.45; cursor: default; }

#shield-fill, #hull-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
}
#shield-fill { background: #67d0e6; }
#hull-fill { background: linear-gradient(90deg, #8e2f2a, var(--critical)); }
#energy-fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #8ea832, #d6e35a);
}
#energy-fill[data-level="low"] { background: #c9a227; }
#energy-fill[data-level="critical"],
#energy-fill[data-level="empty"] { background: var(--critical); }

#dock h2 { font-size: 20px; }
#dock-meta, #dock-note { color: var(--muted); }

#refuel {
  background: var(--teal);
  color: #06211c;
  border: 0;
  font-weight: 700;
}

#refuel:disabled, #repair-hull:disabled, #sell-ore:disabled, #buy-drone:disabled, #buy-attack:disabled, #buy-repair:disabled, #drop-drone:disabled, #drop-attack:disabled, #drop-repair:disabled, #enter-portal:disabled {
  background: #2a343c;
  color: var(--muted);
  cursor: default;
}

#gate {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(7, 11, 16, 0.2), rgba(7, 11, 16, 0.72));
}

.card {
  width: min(460px, 100%);
  padding: 28px 26px;
  background: rgba(10, 14, 18, 0.9);
  border: 1px solid var(--line);
}

.card h2 {
  margin: 8px 0 10px;
  font-size: 34px;
  letter-spacing: -0.03em;
}

.lede { color: var(--muted); line-height: 1.45; }

#login-form, .field { display: flex; flex-direction: column; gap: 8px; }
#login-form { margin-top: 22px; }

label { font-size: 13px; color: var(--muted); }

input {
  background: #12181e;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 12px;
  font: inherit;
}

.primary, .ghost { padding: 12px 14px; font-weight: 700; }
.primary { background: var(--twitch); color: white; }
a.primary {
  display: block;
  text-align: center;
  text-decoration: none;
}
.ghost {
  margin-top: 10px;
  width: 100%;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.hint, #login-error { margin-top: 12px; font-size: 13px; line-height: 1.4; }
.hint { color: var(--muted); }
#login-error { color: #ffb0a8; min-height: 1.2em; }
code { color: var(--amber); }

.factions { display: flex; gap: 8px; margin-top: 16px; }
.faction {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 8px;
  background: #12181e;
  color: var(--ink);
  border: 1px solid var(--line);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.faction span { color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.25; }
.faction[aria-pressed="true"] { border-color: var(--amber); }
.faction[data-faction="ed"][aria-pressed="true"] { border-color: var(--critical); }
.faction[data-faction="sc"][aria-pressed="true"] { border-color: #8eb4ff; }
.faction[data-faction="neu"][aria-pressed="true"] { border-color: var(--teal); }

@media (max-width: 800px) {
  .status { max-height: 28vh; top: 96px; display: flex; flex-direction: column; }
  .status .hangar-label { order: -2; margin-top: 0; }
  .status #hangar { order: -1; margin-top: 8px; }
  #map { width: 112px; height: 112px; }
  #star-map { top: 136px; width: 112px; font-size: 11px; padding: 6px; }
  .target { display: none; }
  .combat { width: calc(100vw - 24px); bottom: 8px; }
  .dock {
    top: auto;
    left: 16px;
    right: auto;
    bottom: 210px;
    width: min(360px, calc(100vw - 32px));
    max-height: min(30vh, calc(100vh - 96px - 28vh - 226px));
  }
  .flash { bottom: 168px; }
  .alert { bottom: 132px; }
  #rescue { bottom: 176px; }
  .card h2 { font-size: 28px; }
}
