:root {
  --bg-space: #05070f;
  --panel-bg: rgba(12, 20, 38, 0.95);
  --panel-border: #2a4d7a;
  --accent: #4a9eff;
  --accent-dim: #2a5a9a;
  --text: #cfe0f5;
  --text-dim: #7f98b8;
  --good: #5bff8a;
  --bad: #ff5b5b;
  --warn: #ffd24a;
  --gold: #ffc14a;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg-space);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ============ SETUP SCREEN ============ */
#setup-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(74,158,255,0.12), transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(200,107,255,0.1), transparent 60%),
    var(--bg-space);
}
.setup-box {
  width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 30px 40px;
  box-shadow: 0 0 60px rgba(74,158,255,0.15);
}
.game-logo {
  text-align: center;
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 8px;
  background: linear-gradient(180deg, #cfe6ff, #4a9eff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 30px rgba(74,158,255,0.5);
}
.subtitle { text-align: center; color: var(--text-dim); margin-bottom: 24px; letter-spacing: 3px; }
.setup-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-dim); }
.setup-form input, .setup-form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: #0a1428;
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 4px;
  font-size: 14px;
}
.setup-row { display: flex; gap: 14px; }
.setup-row label { flex: 1; }
.ethics-box { margin-top: 8px; border-top: 1px solid var(--panel-border); padding-top: 12px; }
.ethics-title { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
#ethics-list { display: flex; flex-wrap: wrap; gap: 6px; }
.ethic-chip {
  padding: 5px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  background: #0a1428;
  transition: all 0.15s;
}
.ethic-chip:hover { border-color: var(--accent); }
.ethic-chip.selected { background: var(--accent-dim); border-color: var(--accent); color: #fff; }
.ethic-chip.fanatic { box-shadow: inset 0 0 0 1px var(--gold); }
.ethics-points { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
.big-btn {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s;
}
.big-btn:hover { filter: brightness(1.15); }

/* ============ GAME SCREEN ============ */
#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 44px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 20;
}
#resource-bar { display: flex; gap: 14px; flex-wrap: wrap; }
.res-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  cursor: default;
  position: relative;
}
.res-icon { font-size: 14px; }
.res-val { font-weight: 600; min-width: 28px; }
.res-flow { font-size: 11px; }
.flow-pos { color: var(--good); }
.flow-neg { color: var(--bad); }
#time-controls { display: flex; align-items: center; gap: 8px; }
#game-date { font-size: 14px; font-weight: 600; letter-spacing: 1px; margin-right: 8px; }
.speed-btn {
  background: #0a1428;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.speed-btn.active { background: var(--accent-dim); border-color: var(--accent); }

#map-container { position: absolute; top: 44px; left: 0; right: 0; bottom: 48px; overflow: hidden; }
#galaxy-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#galaxy-canvas:active { cursor: grabbing; }
#view-label {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  font-size: 15px; letter-spacing: 2px; color: var(--text-dim);
  pointer-events: none; text-shadow: 0 0 8px #000;
}
#back-to-galaxy {
  position: absolute; top: 10px; left: 10px;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  color: var(--text); padding: 6px 12px; border-radius: 4px; cursor: pointer; z-index: 5;
}

#outliner {
  position: absolute;
  top: 54px; right: 8px;
  width: 220px;
  max-height: calc(100vh - 120px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 10;
}
.outliner-header { padding: 8px 12px; font-weight: 600; border-bottom: 1px solid var(--panel-border); font-size: 13px; }
#outliner-content { overflow-y: auto; padding: 4px 0; }
.outliner-group-title { font-size: 11px; color: var(--text-dim); padding: 6px 12px 2px; text-transform: uppercase; letter-spacing: 1px; }
.outliner-item {
  padding: 5px 12px; font-size: 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px;
}
.outliner-item:hover { background: rgba(74,158,255,0.12); }
.outliner-item .sub { color: var(--text-dim); font-size: 11px; }

#bottombar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 48px;
  background: var(--panel-bg);
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  z-index: 20;
}
.tool-btn {
  background: #0a1428;
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.tool-btn:hover { border-color: var(--accent); }

#detail-panel {
  position: absolute;
  top: 54px; left: 8px; bottom: 56px;
  width: 380px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow-y: auto;
  z-index: 15;
  padding: 16px;
}
#detail-close {
  position: absolute; top: 8px; right: 8px;
  background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer;
}
#detail-close:hover { color: var(--bad); }

.panel-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.panel-subtitle { font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--accent); margin: 14px 0 6px; border-bottom: 1px solid var(--accent-dim); padding-bottom: 3px; }

.card {
  background: #0a1428;
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 10px;
  margin-bottom: 8px;
}
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; display: flex; justify-content: space-between; }
.card-desc { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: var(--accent); background: #0e1a34; }

.btn {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin: 2px;
}
.btn:hover { filter: brightness(1.2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.danger { background: #6a2020; border-color: var(--bad); }

.progress-bar { height: 8px; background: #0a1428; border-radius: 4px; overflow: hidden; margin: 4px 0; border: 1px solid var(--panel-border); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); transition: width 0.3s; }

.res-cost { display: inline-flex; align-items: center; gap: 2px; margin-right: 8px; font-size: 12px; }

.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tab { padding: 6px 12px; background: #0a1428; border: 1px solid var(--panel-border); border-radius: 4px 4px 0 0; cursor: pointer; font-size: 13px; }
.tab.active { background: var(--accent-dim); border-color: var(--accent); }

.tech-option { display: flex; flex-direction: column; }
.tech-tier { font-size: 10px; color: var(--gold); }

.district-row, .building-row, .job-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; background: #0a1428; border: 1px solid var(--panel-border);
  border-radius: 4px; margin-bottom: 5px; font-size: 13px;
}
.district-controls { display: flex; align-items: center; gap: 6px; }
.mini-btn { width: 22px; height: 22px; border-radius: 3px; background: var(--accent-dim); border: 1px solid var(--accent); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }
.mini-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#notifications {
  position: absolute;
  bottom: 56px; right: 8px;
  width: 280px;
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 30;
  pointer-events: none;
}
.notification {
  background: var(--panel-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  animation: slideIn 0.3s ease;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.notification.good { border-left-color: var(--good); }
.notification.bad { border-left-color: var(--bad); }
.notification.warn { border-left-color: var(--warn); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

#modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 24px; max-width: 520px; max-height: 80vh; overflow-y: auto;
}

.tooltip {
  position: absolute; background: #0a1428; border: 1px solid var(--accent);
  border-radius: 4px; padding: 8px 10px; font-size: 12px; z-index: 200;
  max-width: 240px; pointer-events: none; box-shadow: 0 2px 12px rgba(0,0,0,0.6);
}
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.stat-line { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.stat-line .val { font-weight: 600; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; font-size: 11px; background: var(--accent-dim); margin-right: 4px; }
hr { border: none; border-top: 1px solid var(--panel-border); margin: 10px 0; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0a1428; }
::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 4px; }
