/* ==========================================================================
   PGame — Sci-Fi / Weltraum Theme
   Reines CSS-Restyling (Vanilla, kein Build). Alle Klassen/IDs, die app.js
   nutzt, bleiben erhalten; hier wird nur das Aussehen verbessert.
   CSS-Variablen --bg, --bg-2, --bg-3, --fg, --border werden auch inline von
   app.js referenziert und MÜSSEN bestehen bleiben.
   ========================================================================== */

/* WICHTIG: Das hidden-Attribut MUSS gewinnen (app.js blendet Views per .hidden ein/aus).
   Sonst bleibt z.B. die Login-Karte nach dem Login sichtbar. */
[hidden] { display: none !important; }

:root {
  /* Basis (von app.js inline referenziert — Namen NICHT ändern) */
  --bg: #070b16;
  --bg-2: #0e1426;
  --bg-3: #182038;
  --fg: #d7e3f4;
  --fg-dim: #8aa0c4;
  --accent: #4fd1ff;
  --warn: #ffb454;
  --err: #ff5d6c;
  --ok: #4ade80;
  --border: #233357;

  /* Erweiterte Sci-Fi-Palette */
  --accent-2: #a274ff;
  --accent-3: #2f6bff;
  --cyan: #4fd1ff;
  --violet: #a274ff;
  --metal: #c9d4e3;
  --crystal: #6fd3ff;
  --deut: #7af0c8;
  --energy: #ffd25e;

  --panel: linear-gradient(160deg, rgba(22,32,58,0.92), rgba(12,18,36,0.92));
  --panel-solid: #111a31;
  --glass: rgba(20,30,56,0.55);
  --glass-border: rgba(120,160,255,0.18);
  --shadow: 0 8px 28px rgba(0,0,0,0.45);
  --glow-cyan: 0 0 0 1px rgba(79,209,255,0.35), 0 0 18px rgba(79,209,255,0.25);
  --glow-violet: 0 0 18px rgba(162,116,255,0.30);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--fg);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100%;
}

/* Sternen-/Nebel-Hintergrund, rein per CSS (statisch -> Pi-schonend) */
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 700px at 80% -10%, rgba(47,107,255,0.18), transparent 60%),
    radial-gradient(1000px 600px at 0% 110%, rgba(162,116,255,0.16), transparent 60%),
    radial-gradient(700px 500px at 50% 50%, rgba(79,209,255,0.05), transparent 70%),
    /* feines Sternenfeld via wiederholten radial-gradients */
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 70% 65%, rgba(255,255,255,0.55), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 90% 20%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 55% 12%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 12% 70%, rgba(255,255,255,0.5), transparent);
  background-attachment: fixed;
  background-repeat: no-repeat;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { letter-spacing: 0.3px; }
h2 {
  font-size: 20px;
  margin: 4px 0 16px;
  color: #eaf2ff;
  position: relative;
  padding-left: 12px;
}
h2::before {
  content: "";
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 1.1em;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--cyan), var(--violet));
  box-shadow: var(--glow-cyan);
}
h3 { font-size: 15px; color: #cfe0ff; margin: 18px 0 8px; }

/* ===================== Topbar / Navigation ===================== */
header#topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: linear-gradient(180deg, rgba(16,24,46,0.95), rgba(10,15,30,0.92));
  border-bottom: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 18px rgba(79,209,255,0.25);
}

/* Zurück-zum-Hauptmenü-Button (Topbar, eingeloggt) */
.topbar-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
  text-decoration: none; color: var(--fg); white-space: nowrap;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--glass-border); border-radius: 8px;
}
.topbar-back:hover { background: rgba(79,209,255,0.10); border-color: var(--cyan); color: var(--cyan); }

/* Zurück-zum-Hauptmenü-Button (Login-Screen) */
.back-home {
  position: fixed; top: 12px; left: 14px; z-index: 100;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; font-size: 13px; font-weight: 600;
  text-decoration: none; color: var(--fg); white-space: nowrap;
  background: rgba(16,24,46,0.85);
  border: 1px solid var(--glass-border); border-radius: 8px;
  backdrop-filter: blur(8px);
}
.back-home:hover { background: rgba(79,209,255,0.10); border-color: var(--cyan); color: var(--cyan); }

/* Ressourcen-Leiste */
.resources { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
.resource {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.resource::before {
  content: "";
  width: 12px; height: 12px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 8px currentColor;
}
.resource .label {
  color: var(--fg-dim);
  margin-right: 2px;
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
/* Farb-Zuordnung über die Reihenfolge in der Leiste (Metall/Kristall/Deut/Energie) */
.resource:nth-child(1)::before { background: var(--metal); color: var(--metal); }
.resource:nth-child(2)::before { background: var(--crystal); color: var(--crystal); }
.resource:nth-child(3)::before { background: var(--deut); color: var(--deut); }
.resource:nth-child(4)::before { background: var(--energy); color: var(--energy); }
.resource.cap-full { color: var(--warn); border-color: rgba(255,180,84,0.5); box-shadow: 0 0 14px rgba(255,180,84,0.25); }
.resource.negative { color: var(--err); border-color: rgba(255,93,108,0.5); box-shadow: 0 0 14px rgba(255,93,108,0.25); }

/* Haupt-Navigation */
.nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}
.nav button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  color: var(--fg-dim);
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: color 0.18s, background 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.nav button:hover {
  color: #eaf2ff;
  background: rgba(79,209,255,0.08);
  border-color: var(--glass-border);
}
.nav button:focus-visible {
  outline: none;
  box-shadow: var(--glow-cyan);
  color: #eaf2ff;
}
.nav button.ghost {
  color: var(--err);
  margin-left: auto;
}
.nav button.ghost:hover { background: rgba(255,93,108,0.10); border-color: rgba(255,93,108,0.4); }

/* ===================== Buttons ===================== */
button {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 7px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background 0.18s, border-color 0.18s, box-shadow 0.18s, transform 0.08s;
}
button:hover { background: #20294a; border-color: #36487a; }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--glow-cyan); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:hover { background: var(--bg-3); border-color: var(--border); }

button.primary {
  background: linear-gradient(135deg, var(--accent-3), #5a9bff);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(47,107,255,0.35);
}
button.primary:hover {
  background: linear-gradient(135deg, #3b7cff, #6aa8ff);
  box-shadow: 0 6px 18px rgba(47,107,255,0.5);
}
button.primary:disabled { background: var(--bg-3); color: var(--fg); box-shadow: none; }
button.ghost { background: transparent; border-color: var(--glass-border); }
button.ghost:hover { background: rgba(255,255,255,0.04); }

/* ===================== Inputs ===================== */
input, select, textarea {
  background: rgba(7,11,22,0.7);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.18s, box-shadow 0.18s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,209,255,0.18);
}
select { cursor: pointer; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--fg-dim); font-weight: 500; }

.err { color: var(--err); min-height: 1em; font-weight: 600; }

main#app { padding: 0; }

/* ===================== Auth ===================== */
#auth-view { display: flex; justify-content: center; align-items: flex-start; padding: 80px 16px; min-height: 100vh; }
.auth-card {
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 32px;
  width: 380px;
  box-shadow: var(--shadow), var(--glow-violet);
  backdrop-filter: blur(10px);
}
.auth-card h1 {
  margin-top: 0;
  font-size: 34px;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-card > .muted { text-align: center; margin-top: -8px; }
.muted { color: var(--fg-dim); }

.tabs { display: flex; gap: 4px; margin: 20px 0 18px; border-bottom: 1px solid var(--border); }
.tab { background: transparent; border: none; border-bottom: 2px solid transparent; padding: 9px 14px; color: var(--fg-dim); border-radius: 0; }
.tab:hover { color: var(--fg); background: transparent; }
.tab.active { border-bottom-color: var(--accent); color: var(--accent); }
.tab-pane { display: none; flex-direction: column; gap: 14px; }
.tab-pane.active { display: flex; }
.tab-pane input { font-size: 14px; }

/* ===================== Game-Layout ===================== */
#game-view {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 18px;
  padding: 18px;
  min-height: calc(100vh - 56px);
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  height: fit-content;
  backdrop-filter: blur(6px);
  position: sticky;
  top: 78px;
}
.sidebar h3 { margin: 0 0 10px; color: #eaf2ff; text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
#planets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#planets li {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.16s, border-color 0.16s;
}
#planets li > div:first-child { font-weight: 600; }
#planets li:hover { background: rgba(79,209,255,0.07); border-color: var(--glass-border); }
#planets li.active {
  background: linear-gradient(135deg, rgba(47,107,255,0.35), rgba(162,116,255,0.25));
  border-color: rgba(79,209,255,0.4);
  box-shadow: inset 0 0 12px rgba(79,209,255,0.15);
}
#planets li.active > div:first-child { color: #fff; }
#planets li .coord { font-size: 11px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
#planets li.active .coord { color: rgba(255,255,255,0.85); }
#planets li.moon { opacity: 0.92; font-size: 13px; }

#main-pane { min-width: 0; }

#planet-header {
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  box-shadow: var(--shadow);
}
#planet-header:empty { display: none; }
#planet-header .stat { font-size: 12px; color: var(--fg-dim); }
#planet-header .stat .v { color: var(--fg); font-size: 15px; font-weight: 700; display: block; }

#view-container {
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

/* ===================== Tabellen (Karten-Look) ===================== */
table { width: 100%; border-collapse: separate; border-spacing: 0 6px; }
table th, table td { padding: 11px 12px; text-align: left; vertical-align: middle; }
table th {
  background: transparent;
  color: var(--fg-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
/* Zeilen als Karten/Kacheln */
table tr { transition: background 0.15s; }
table td {
  background: rgba(18,26,48,0.55);
  border-top: 1px solid rgba(120,160,255,0.08);
  border-bottom: 1px solid rgba(120,160,255,0.08);
}
table td:first-child { border-left: 1px solid rgba(120,160,255,0.08); border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
table td:last-child { border-right: 1px solid rgba(120,160,255,0.08); border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
tr:not(:first-child):hover td { background: rgba(79,209,255,0.06); }
/* Header-Zeile soll keinen Karten-Look haben */
tr:first-child td { background: transparent; }
table b { color: #eaf2ff; }

.lvl {
  display: inline-block;
  min-width: 34px;
  padding: 3px 9px;
  background: linear-gradient(135deg, rgba(47,107,255,0.25), rgba(162,116,255,0.18));
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #eaf2ff;
}
.cost { font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.cost .ok { color: var(--ok); font-weight: 600; }
.cost .bad { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); }
.bad { color: var(--err); }

/* ===================== Bau-/Forschungs-Queue ===================== */
.queue-box {
  background: linear-gradient(135deg, rgba(47,107,255,0.14), rgba(162,116,255,0.10));
  border: 1px solid rgba(79,209,255,0.4);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  box-shadow: inset 0 0 18px rgba(79,209,255,0.08), var(--shadow);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
}
.queue-box > div { margin: 0; }
/* dezent animierter Scan-Streifen oben (kein Dauer-Repaint des ganzen Boxinhalts) */
.queue-box::after {
  content: "";
  position: absolute;
  top: 0; left: -40%;
  width: 40%; height: 3px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  animation: queue-scan 2.6s linear infinite;
}
@keyframes queue-scan { to { left: 120%; } }
.queue-box .timer {
  color: var(--cyan);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 8px rgba(79,209,255,0.4);
}
/* Saubere Bau-Queue: Positionsnummer · Info · Abbrechen */
.queue { margin-bottom: 18px; }
.queue h3 { margin: 0 0 10px; color: var(--cyan); font-size: 1rem; }
.queue-box .qpos { flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: rgba(79,209,255,0.18); border: 1px solid rgba(79,209,255,0.5); color: var(--cyan); }
.queue-box .qmain { flex: 1 1 auto; min-width: 0; }
.queue-box .qsub { display: block; font-size: 0.82rem; color: #93a4c8; margin-top: 2px; }
.queue-box .qcancel { flex: 0 0 auto; background: rgba(255,80,80,0.14); border: 1px solid rgba(255,80,80,0.45); color: #ffb3b3; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-weight: 700; }
.queue-box .qcancel:hover { background: rgba(255,80,80,0.28); }

.timer { font-variant-numeric: tabular-nums; }
.reason { color: var(--warn); font-size: 12px; margin-top: 4px; }

/* Nachrichten: ungelesen hervorheben */
tr.unread td { box-shadow: inset 3px 0 0 var(--accent); }
tr.unread b { color: #fff; }

pre, code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
pre {
  background: rgba(7,11,22,0.7) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm);
}
code {
  background: rgba(7,11,22,0.6);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--cyan);
}

/* Schmale Scrollbars passend zum Theme */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { height: 8px; width: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ===================== Responsiv ===================== */
@media (max-width: 860px) {
  #game-view { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .sidebar { position: static; }
  #planet-header { grid-template-columns: repeat(2, 1fr); }
  .nav button { padding: 6px 10px; font-size: 13px; }
  .brand { width: 100%; text-align: center; }
}
@media (max-width: 560px) {
  header#topbar { padding: 10px 12px; gap: 10px; }
  .resources { gap: 6px; }
  .resource { padding: 5px 10px; font-size: 12px; }
  #view-container { padding: 14px; }
  .auth-card { padding: 22px; }
  /* Tabellen horizontal scrollbar machen statt zu quetschen */
  #view-container table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .queue-box::after { animation: none; display: none; }
}

/* Gebäude stilllegen/aktivieren */
button.toggle { font-size: 0.72rem; padding: 2px 7px; margin-left: 6px; border-radius: 6px;
  border: 1px solid #5a6b8c; background: #1c2740; color: #cdd8ef; cursor: pointer; vertical-align: middle; }
button.toggle:hover { background: #28344f; }
button.toggle.off { border-color: #b9892f; background: #3a2e15; color: #f1c878; }
tr.inactive { opacity: 0.55; }
.offtag { font-size: 0.7rem; color: #f1c878; border: 1px solid #b9892f; border-radius: 5px; padding: 0 5px; margin-left: 4px; }

/* Energie-Vorschau & ETA in der Gebäudeliste */
.eta { font-size: 0.72rem; margin-top: 3px; color: #9fb0d0; }
.eta.ok { color: #86efac; }
.eta.bad { color: #fca5a5; }
.enrg.bad { color: #fca5a5; }
.enrg.ok { color: #86efac; }
.enrg-delta { font-size: 0.72rem; margin-top: 3px; font-weight: 600; }
.enrg-delta.bad { color: #fca5a5; }
.enrg-delta.ok { color: #86efac; }
