:root {
  --bg: #05060a;
  --panel: rgba(16, 20, 32, 0.82);
  --panel-solid: #11151f;
  --border: rgba(120, 150, 220, 0.22);
  --text: #dfe6ff;
  --muted: #8b95b5;
  --accent: #4dabff;
  --accent2: #ffd23f;
  --danger: #ff5a5a;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: var(--text);
  background: rgba(40, 50, 72, 0.8);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: rgba(60, 74, 104, 0.9); }
button.primary { background: var(--accent); color: #04101f; border-color: transparent; font-weight: 600; }
button.primary:hover { background: #6cc0ff; }

input {
  font: inherit;
  color: var(--text);
  background: rgba(8, 11, 18, 0.9);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  outline: none;
}
input:focus { border-color: var(--accent); }

select {
  font: inherit;
  color: var(--text);
  background: rgba(8, 11, 18, 0.9);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }
.dim { color: var(--muted); }

/* ---------- canvas ---------- */
#space {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: grab;
  touch-action: none;
}

/* ---------- login overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 40%, rgba(20, 30, 60, 0.6), rgba(2, 3, 6, 0.95));
  z-index: 50;
}
.card {
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 36px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 4px; font-size: 2.2rem; letter-spacing: 0.04em; }
.card .sub { color: var(--muted); margin: 0 0 22px; font-size: 0.92rem; }
.card form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.card label { font-size: 0.85rem; color: var(--muted); }
.card .or { color: var(--muted); margin: 16px 0 12px; font-size: 0.8rem; }
.formerror { color: var(--danger); font-size: 0.82rem; min-height: 1em; }
#gbtn { display: flex; justify-content: center; }

/* ---------- HUD ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(rgba(5, 7, 12, 0.85), rgba(5, 7, 12, 0));
  z-index: 20;
}
.spacer { flex: 1; }
#me { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; }
.swatch { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: 0 0 8px currentColor; }
#status { font-size: 0.82rem; padding: 4px 8px; border-radius: 6px; }
#status.ok { color: #43d17a; }
#status.off { color: var(--muted); }

.panel {
  background: var(--panel);
  backdrop-filter: blur(7px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.phead { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }

#sidebar {
  position: fixed;
  top: 58px; right: 12px;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 15;
  max-height: calc(100vh - 130px);
}
.planetlist { max-height: 30vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.prow {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.prow:hover { background: rgba(80, 100, 150, 0.18); }
.prow.sel { background: rgba(77, 171, 255, 0.22); }
.prow .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .pcnt { color: var(--accent2); font-variant-numeric: tabular-nums; }

#log { max-height: 32vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.logrow { font-size: 0.82rem; color: var(--muted); line-height: 1.3; border-left: 2px solid var(--border); padding-left: 8px; }
.logtime { color: var(--accent2); opacity: 0.8; font-variant-numeric: tabular-nums; }

/* selected planet panel */
#selpanel {
  position: fixed;
  top: 58px; left: 12px;
  width: 250px;
  z-index: 16;
}
.seltitle { font-size: 1.2rem; font-weight: 600; margin-bottom: 6px; }
.selmeta { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.selmeta b { color: var(--accent2); }
.sendrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 6px; font-size: 0.88rem; }
.sendrow input { width: 90px; text-align: right; }
/* Range input must not inherit the generic input box (its 10px horizontal
   padding kept the thumb from reaching the ends; the border/background drew a
   box around the slider). */
#cntr { width: 100%; margin: 4px 0 10px; padding: 0; border: none; background: transparent; accent-color: var(--accent); }
.btnrow { display: flex; gap: 6px; }
.btnrow button { flex: 1; }
.btnrow .primary { flex: 2; }
.hint { font-size: 0.74rem; color: var(--muted); margin-top: 8px; line-height: 1.35; }
.enemymsg {
  margin: 10px 0 4px;
  padding: 8px 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  background: rgba(255, 90, 90, 0.1);
  border-left: 3px solid rgba(255, 90, 90, 0.5);
  border-radius: 6px;
}
.enemymsg .dim { color: var(--muted); font-size: 0.78rem; }

#footer {
  position: fixed;
  bottom: 10px; left: 12px;
  z-index: 14;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 360px;
}
#footer .legend { margin-top: 6px; opacity: 0.8; }
#params b { color: var(--text); }

#toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- landing ---------- */
body.landing { display: grid; place-items: center; overflow: auto; }
.hero {
  text-align: center;
  max-width: 560px;
  padding: 40px;
}
.hero h1 { font-size: 3.4rem; margin: 0; letter-spacing: 0.05em; }
.hero .sub { color: var(--muted); font-size: 1.1rem; }
.feat { list-style: none; padding: 0; margin: 28px 0; text-align: left; display: inline-block; }
.feat li { padding: 6px 0; font-size: 1rem; }
.cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.btn {
  text-decoration: none;
  color: var(--text);
  background: rgba(40, 50, 72, 0.8);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 22px;
  font-weight: 500;
}
.btn.primary { background: var(--accent); color: #04101f; border-color: transparent; }

/* ---------- dev grid ---------- */
body.devgrid { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
#devbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--border);
}
#devbar .muted { color: var(--muted); font-size: 0.85rem; }
#devbar .spacer { flex: 1; }
#devbar label { font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#grid {
  flex: 1;
  display: grid;
  gap: 2px;
  background: #000;
  padding: 2px;
  overflow: hidden;
}
.cell { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; min-height: 0; }
.cellbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: var(--panel-solid);
  font-size: 0.85rem; border-bottom: 1px solid var(--border);
}
.cellbar a { color: var(--accent); text-decoration: none; font-size: 0.78rem; }
.cell iframe { flex: 1; width: 100%; border: 0; background: #000; min-height: 0; }

/* ---------- rules (page + pop-up share the .rules typography) ---------- */
.rules { color: var(--text); line-height: 1.6; font-size: 0.95rem; }
.rules h1 { font-size: 1.9rem; margin: 0 0 6px; letter-spacing: 0.02em; }
.rules .lead { color: var(--muted); margin: 0 0 20px; }
.rules h2 {
  font-size: 1.12rem; margin: 24px 0 8px; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 5px;
}
.rules ul { margin: 6px 0 14px; padding-left: 20px; }
.rules li { margin: 5px 0; }
.rules strong { color: var(--text); }
.rules .param { color: var(--accent2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rules .note { color: var(--muted); font-size: 0.82rem; margin-top: 22px; font-style: italic; }

/* standalone /rules page */
body.rules-page { overflow-y: auto; display: block; }
.rules-wrap { max-width: 760px; margin: 0 auto; padding: 40px 22px 64px; }
.backlink { margin-top: 28px; font-size: 0.9rem; }
.backlink a { color: var(--accent); text-decoration: none; }
.backlink a:hover { text-decoration: underline; }

/* landing-page link to the rules */
.ruleslink { margin: 4px 0 22px; }
.ruleslink a { color: var(--accent); text-decoration: none; font-size: 0.95rem; }
.ruleslink a:hover { text-decoration: underline; }

/* ---------- generic modal (in-game rules pop-up) ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: rgba(2, 3, 6, 0.72); backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  width: min(760px, 96vw); max-height: 88vh; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 32px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: transparent; border: none; color: var(--muted);
  font-size: 1.7rem; line-height: 1; padding: 2px 8px; cursor: pointer;
}
.modal-close:hover { color: var(--text); background: transparent; }

/* settings modal rows */
.setrow {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  margin: 8px 0; font-size: 0.9rem;
}
.setrow > span:first-child { color: var(--muted); }
.setfield { display: flex; flex-direction: column; gap: 4px; margin: 14px 0 4px; font-size: 0.88rem; color: var(--muted); }
.setfield input, .setfield select { width: 100%; }
