/* Solarstorm — pixel-retro theme */
:root {
  --bg-deep: #050018;
  --bg-mid: #0a0030;
  --fg: #e8f4ff;
  --accent: #ffd966;
  --accent2: #ff5577;
  --hull: #6dff6d;
  --shield: #66aaff;
  --fuel: #ffd966;
  --cargo: #ff9966;
  --border: #2a2a55;
  --panel-bg: rgba(10, 0, 30, 0.92);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg-deep);
  color: var(--fg);
  font-family: 'Courier New', monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #000010;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  outline: none;
}

/* ---------- Mini-Radar (top-right of game viewport) ---------- */
#radar {
  position: fixed !important;
  top: 64px !important;
  right: 8px !important;
  left: auto !important;
  bottom: auto !important;
  transform: none !important;
  width: 160px !important;
  height: 160px !important;
  background: rgba(0, 0, 16, 0.78);
  border: 1px solid var(--accent);
  border-radius: 4px;
  image-rendering: pixelated;
  z-index: 11;
  pointer-events: none;
  margin: 0 !important;
}
#radar-label {
  position: fixed;
  top: 50px;
  right: 14px;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--accent);
  z-index: 11;
  pointer-events: none;
  text-shadow: 0 0 4px #000;
}

#galaxy-canvas {
  position: static !important;
  display: block !important;
  width: 860px;
  height: 520px;
  max-width: 100%;
  margin: 0 auto;
  background: #000020;
  image-rendering: pixelated;
}

/* Force the galaxy panel-body to center its children horizontally. */
#panel-galaxy .panel-body {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  align-content: start;
  gap: 8px;
}

/* ---------- Login overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at center, rgba(0,0,40,0.9), rgba(0,0,0,0.99));
  z-index: 100;
}
.login-card {
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  padding: 36px 48px;
  text-align: center;
  box-shadow: 0 0 40px rgba(255,217,102,0.3);
  min-width: 360px;
}
.title {
  margin: 0 0 4px 0;
  font-size: 36px;
  color: var(--accent);
  letter-spacing: 8px;
  text-shadow: 0 0 20px var(--accent);
}
.subtitle {
  margin: 0 0 24px 0;
  font-size: 12px;
  opacity: 0.7;
  letter-spacing: 3px;
}
.login-card input {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
}
.login-card input:focus { outline: 1px solid var(--accent); }
.login-actions { display: flex; gap: 12px; margin-top: 18px; }
.login-actions button { flex: 1; }
.hint { font-size: 11px; opacity: 0.6; margin-top: 18px; line-height: 1.5; }
.error-msg { color: var(--accent2); font-size: 12px; min-height: 16px; margin-bottom: 8px; }

/* ---------- Buttons (pixel) ---------- */
button {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 10px 14px;
  font-family: inherit;
  font-weight: bold;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 1px;
  text-transform: uppercase;
}
button:hover:not(:disabled) { background: #fff; }
button:disabled { background: #555; color: #888; cursor: not-allowed; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  font-size: 12px;
  letter-spacing: 1px;
}
.hud-top {
  position: fixed; top: 8px; left: 8px; right: 8px;
  display: flex; gap: 16px;
}
.hud-stat {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  flex: 1;
  display: flex; align-items: center; gap: 8px;
}
.hud-stat .lbl { font-weight: bold; min-width: 50px; }
.bar {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border: 1px solid #444;
  position: relative;
}
.bar .fill { height: 100%; transition: width 0.2s; }
.fill-hull  { background: var(--hull); }
.fill-shield{ background: var(--shield); }
.fill-fuel  { background: var(--fuel); }
.fill-cargo { background: var(--cargo); }
.hud-stat .val { min-width: 80px; text-align: right; opacity: 0.85; }

.hud-bottom {
  position: fixed; bottom: 8px; left: 8px; right: 8px;
  display: flex; gap: 16px;
  font-size: 11px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
}
.hud-bottom > * { flex: 1; }

.hud-events {
  position: fixed; left: 8px;
  top: 80px;
  width: 280px;
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
}
.hud-events > div {
  background: rgba(10,0,30,0.7);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  font-size: 11px;
  animation: fadeOut 4s forwards;
}
@keyframes fadeOut { 0% { opacity: 1 } 70% { opacity: 1 } 100% { opacity: 0; transform: translateX(-10px); } }

.hud-message {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255,80,80,0.9);
  color: #fff;
  padding: 16px 32px;
  font-weight: bold;
  letter-spacing: 2px;
  z-index: 50;
  display: none;
}

/* ---------- Panels ---------- */
.panel {
  position: fixed;
  background: var(--panel-bg);
  border: 2px solid var(--accent);
  padding: 0;
  min-width: 320px;
  max-width: 90vw;
  max-height: 80vh;
  z-index: 30;
  box-shadow: 0 0 30px rgba(255,217,102,0.4);
  display: flex; flex-direction: column;
}
#panel-character { top: 60px; right: 20px; width: 360px; }
#panel-inventory { top: 60px; right: 20px; width: 480px; }
#panel-comm { top: 60px; left: 20px; width: 480px; }
#panel-galaxy { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 960px; }
#trade-modal { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 760px; }
#jump-modal { top: 50%; left: 50%; transform: translate(-50%, -50%); width: 400px; }

.panel-header {
  background: var(--accent);
  color: #000;
  padding: 10px 16px;
  font-weight: bold;
  letter-spacing: 2px;
  display: flex; justify-content: space-between; align-items: center;
}
.close-btn {
  background: transparent;
  color: #000;
  padding: 0;
  width: 24px; height: 24px;
  line-height: 1;
}
.panel-body { padding: 16px; overflow: auto; max-height: 70vh; }
.panel-body h3 { color: var(--accent); margin: 16px 0 8px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--accent); letter-spacing: 1px; font-size: 11px; }
td button { font-size: 11px; padding: 4px 10px; }

/* Galaxy panel */
.galaxy-controls {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; font-size: 12px;
}
.galaxy-controls button { padding: 8px 16px; }
.galaxy-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 11px; opacity: 0.75;
  margin-top: 12px;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot-g { background: #fff4e8; }
.dot-k { background: #ffd2a1; }
.dot-m { background: #ffcc6f; }
.dot-d { background: #ffffff; }

/* Comm panel */
.comm-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tab-btn { background: rgba(255,255,255,0.1); color: var(--fg); padding: 6px 12px; font-size: 11px; }
.tab-btn.active { background: var(--accent); color: #000; }
.comm-messages {
  height: 320px; overflow-y: auto;
  border: 1px solid var(--border);
  padding: 8px;
  background: rgba(0,0,0,0.4);
  font-size: 12px;
  margin-bottom: 12px;
}
.comm-messages .msg { margin-bottom: 4px; }
.comm-messages .msg .sender { color: var(--accent); font-weight: bold; }
.comm-messages .msg .time { opacity: 0.5; font-size: 10px; margin-right: 8px; }
.comm-input { display: flex; gap: 8px; }
.comm-input input { flex: 1; background: rgba(255,255,255,0.08); border: 1px solid var(--border); color: var(--fg); padding: 8px; font-family: inherit; }

/* Upgrade list */
.upgrade-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px; border: 1px solid var(--border); margin-bottom: 4px;
  font-size: 12px;
}
.upgrade-row .lvl { color: var(--accent); }
.upgrade-row button { padding: 4px 8px; font-size: 10px; }
.upgrade-row .maxed { color: var(--hull); font-weight: bold; }

/* Trade panel */
#trade-table th, #trade-table td { padding: 8px; }
#trade-table .qty-input { width: 50px; background: rgba(255,255,255,0.08); border: 1px solid var(--border); color: var(--fg); padding: 2px 6px; font-family: inherit; }

/* Pixel border helper */
.pixel-border {
  position: relative;
}
.pixel-border::before {
  content: '';
  position: absolute;
  inset: -8px;
  border: 1px solid rgba(255,217,102,0.3);
  pointer-events: none;
}