:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #0a0a14;
  --panel-2: #10101e;
  --fg: #aaaaaa;
  --fg-bright: #ffffff;
  --cyan: #55ffff;
  --green: #55ff55;
  --yellow: #ffff55;
  --red: #ff5555;
  --blue: #5555ff;
  --border: #5555ff;
  --mono: "Perfect DOS VGA 437", "IBM VGA 8x16", "Cascadia Mono", "DejaVu Sans Mono", Consolas, "Courier New", monospace;
  --touch: 44px;
  accent-color: var(--cyan);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
}

body { display: flex; flex-direction: column; }

::selection { background: var(--cyan); color: #000; }

:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

[hidden] { display: none !important; }

/* ---- offline banner ---- */
.offline-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0.6rem 1rem;
  background: #aa0000;
  color: #fff;
  font-weight: bold;
  text-align: center;
  letter-spacing: 0.05em;
  border-bottom: 3px solid var(--yellow);
  animation: banner-pulse 1.2s steps(2, end) infinite;
}

@keyframes banner-pulse { 50% { background: #770000; } }

/* ---- login ---- */
.login-view {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
}

.login-card {
  width: min(100%, 28rem);
  padding: 1.5rem;
  background: var(--panel);
  border: 3px double var(--border);
  box-shadow: 0 0 24px rgba(85, 85, 255, 0.35);
}

.login-title { margin: 0; color: var(--yellow); font-size: 1.75rem; letter-spacing: 0.1em; text-transform: uppercase; }
.login-sub { margin: 0.25rem 0 1rem; color: var(--cyan); }
.login-help { margin: 0 0 1.25rem; color: var(--fg-bright); line-height: 1.4; }

.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: 0.35rem; color: var(--green); font-weight: bold; }
.hint { margin: 0.3rem 0 0; font-size: 0.85rem; color: #8a8a8a; }

input[type="text"], input[type="password"], .command-input, select {
  width: 100%;
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  color: var(--fg-bright);
  background: #000;
  border: 2px solid var(--blue);
  border-radius: 0;
}

input::placeholder { color: #7a7a7a; }

input:user-invalid { border-color: var(--red); background: #1a0000; }
input:user-valid { border-color: var(--green); }

.login-error { margin: 0 0 1rem; padding: 0.5rem 0.75rem; color: #fff; background: #770000; border-left: 4px solid var(--red); }

/* ---- buttons ---- */
.btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.4rem 0.9rem;
  font: inherit;
  font-size: 1rem;
  font-weight: bold;
  color: var(--fg-bright);
  background: var(--panel-2);
  border: 2px solid var(--blue);
  border-radius: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover { background: #1c1c3a; }
.btn:active { background: var(--blue); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { color: #000; background: var(--cyan); border-color: var(--cyan); }
.btn-primary:hover { background: #8dffff; }
.btn-danger { border-color: var(--red); color: var(--red); }
.btn-toggle[aria-pressed="true"] { color: #000; background: var(--green); border-color: var(--green); }

/* ---- game layout ---- */
.game-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
}

.terminal-wrap { flex: 1; min-width: 0; min-height: 0; display: flex; }

.terminal {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 0.5rem;
  background: #000;
  border: 2px solid var(--blue);
  color: var(--fg);
  font-family: var(--mono);
  font-size: clamp(0.62rem, 1.9vw, 1rem);
  line-height: 1.2;
  white-space: pre;
  overscroll-behavior: contain;
  /* NOTE: no user-select: none — terminal output must stay copyable. */
}

.tw-line { min-height: 1.2em; }
.tw-s { white-space: pre; }
.tw-dim { opacity: 0.65; }
.tw-ul { text-decoration: underline; }
.tw-blink { animation: tw-blink 1s steps(2, start) infinite; }
.tw-cursor { background: #aaaaaa; color: #000; animation: tw-cursor 1s steps(2, start) infinite; }

@keyframes tw-blink { to { visibility: hidden; } }
@keyframes tw-cursor { to { background: transparent; color: inherit; } }

.crt-on .terminal {
  text-shadow: 0 0 3px rgba(170, 255, 255, 0.45);
  background-image: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 3px);
  box-shadow: inset 0 0 40px rgba(0, 80, 160, 0.35);
}

.crt-on .terminal-wrap { filter: saturate(1.15); }

/* ---- HUD ---- */
.hud {
  width: 20rem;
  flex: none;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.hud-card { padding: 0.6rem 0.75rem; background: var(--panel); border: 2px solid var(--blue); }
.hud-title { margin: 0 0 0.4rem; font-size: 1rem; color: var(--yellow); text-transform: uppercase; letter-spacing: 0.05em; }
.hud-count { color: var(--green); }
.hud-stats { display: grid; grid-template-columns: auto 1fr; gap: 0.15rem 0.75rem; margin: 0; }
.hud-stats dt { color: var(--cyan); }
.hud-stats dd { margin: 0; color: var(--fg-bright); text-align: right; overflow-wrap: anywhere; }
.hud-sub { margin: 0.6rem 0 0.25rem; color: var(--cyan); }
.hud-cargo-text, .hud-sector-info, .hud-hint { margin: 0.3rem 0 0; color: #b0b0b0; font-size: 0.8rem; }
.hud-empty { color: #9a9a9a; list-style: none; }

.cargo-bar { display: flex; height: 14px; background: #000; border: 1px solid var(--fg); }
.cargo-seg { display: block; height: 100%; width: 0; }
.seg-ore { background: #aa5500; }
.seg-org { background: #00aa00; }
.seg-eq { background: #00aaaa; }

.hud-pilots { margin: 0; padding: 0; list-style: none; max-height: 9rem; overflow: auto; }
.hud-pilot { padding: 0.1rem 0; color: var(--fg-bright); }
.carrier-led { color: var(--green); }
.hud-pilot-meta { color: #9aa; font-size: 0.8rem; }

.hud-map { display: grid; place-items: center; }
.sector-map { width: 100%; max-width: 20rem; height: auto; background: #000; border: 1px solid #333; }
.map-edge { stroke: #5555ff; stroke-width: 1.5; opacity: 0.8; }
.map-circle { fill: #000; stroke: #aaaaaa; stroke-width: 2; }
.map-label { fill: #fff; font: bold 11px var(--mono); pointer-events: none; }
.map-marks { fill: var(--yellow); font: 10px var(--mono); pointer-events: none; }
.map-hit { fill: transparent; }
.is-current .map-circle { stroke: var(--green); stroke-width: 3; fill: #003300; }
.is-ghost .map-circle { stroke-dasharray: 3 3; stroke: #777; }
.is-adjacent { cursor: pointer; }
.is-adjacent .map-circle { stroke: var(--cyan); }
.is-adjacent:hover .map-circle, .is-adjacent:focus-visible .map-circle { fill: #004a4a; stroke: var(--yellow); }
.is-sol .map-circle { stroke: var(--yellow); }
.has-cabal .map-circle { stroke: var(--red); stroke-width: 3; }

/* ---- hotkeys ---- */
.hotkeys { display: flex; flex-wrap: wrap; gap: 0.35rem; padding: 0 0.5rem 0.5rem; }
.hotkeys .btn { flex: 1 1 auto; padding: 0.4rem 0.6rem; }

/* ---- command form ---- */
.command-form { display: flex; align-items: center; gap: 0.5rem; padding: 0 0.5rem 0.5rem; }
.prompt-label { flex: none; max-width: 40%; color: var(--green); font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.command-input { flex: 1; min-width: 0; }
.btn-send { flex: none; }

/* ---- status bar ---- */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.4rem 0.75rem calc(0.4rem + env(safe-area-inset-bottom));
  background: #0000aa;
  color: #fff;
  border-top: 2px solid var(--cyan);
  font-size: 0.9rem;
}

.status-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.status-ping { color: var(--yellow); min-width: 4.5ch; }
.statusbar .btn { min-height: var(--touch); }
.statusbar select { width: auto; min-height: var(--touch); padding: 0.2rem 0.5rem; }
.statusbar .btn-toggle[aria-pressed="false"] { background: #000; color: #fff; border-color: #fff; }
.statusbar #logout-button { margin-left: auto; background: #000; }

.led { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 50%; border: 1px solid #000; }
.led-on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.led-degraded { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.led-off { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* ---- narrow viewports ---- */
@media (max-width: 899px) {
  .workspace { flex-direction: column; overflow: auto; }
  .terminal-wrap { flex: none; height: 55dvh; min-height: 14rem; }
  .hud { width: 100%; overflow: visible; }
  .prompt-label { max-width: 30%; }
}

@media (prefers-reduced-motion: reduce) {
  .offline-banner, .tw-blink, .tw-cursor { animation: none; }
}
