:root {
  --bg: #04050d;
  --panel: rgba(13, 18, 34, 0.88);
  --panel-border: rgba(140, 170, 255, 0.18);
  --card: rgba(255, 255, 255, 0.045);
  --text: #eef2ff;
  --muted: #9aa7c7;
  --accent: #8fb8ff;
  --accent2: #7ee8a0;
  --danger: #ff8f8f;
  --gold: #ffd77a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
canvas { display: block; }
#game { position: fixed; inset: 0; }
#game canvas { position: absolute; inset: 0; }

/* ---------- boot splash ---------- */
#boot-splash {
  position: fixed; inset: 0; z-index: 60; background: #04050d;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  color: #9fb6e8; font-size: 14px; transition: opacity 0.5s;
}
.splash-planet {
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, #9fd8a0 0%, #4d9a5c 32%, #2b6f9e 74%, #163a63 100%);
  box-shadow: 0 0 60px rgba(110, 180, 255, 0.55), inset -14px -10px 30px rgba(0, 0, 0, 0.35);
  animation: splash-spin 2.4s linear infinite;
}
.splash-planet::after {
  content: ''; display: block; width: 150px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(216, 196, 138, 0.6); border-top-color: transparent; border-bottom-color: transparent;
  position: relative; top: 37px; left: -27px; transform: rotate(-14deg);
}
@keyframes splash-spin { from { filter: hue-rotate(0deg); } 50% { filter: hue-rotate(40deg); } to { filter: hue-rotate(0deg); } }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 0 18px;
  background: linear-gradient(180deg, rgba(6, 9, 20, 0.92), rgba(6, 9, 20, 0.35));
  border-bottom: 1px solid rgba(140, 170, 255, 0.12);
  backdrop-filter: blur(10px);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.logo { font-size: 26px; filter: drop-shadow(0 0 8px rgba(140, 200, 255, 0.8)); }
.brand-sub { color: var(--muted); font-size: 12px; margin-left: 6px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.mini-label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
#planet-select {
  background: #141b30; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 6px 8px; font-size: 13px; outline: none;
}
.dust-pill {
  background: rgba(255, 215, 122, 0.1); border: 1px solid rgba(255, 215, 122, 0.3);
  color: var(--gold); border-radius: 999px; padding: 5px 12px; font-size: 13px;
}
.save-badge { color: #7ee8a0; font-size: 12px; opacity: 0.85; transition: opacity 0.4s; }
.save-badge.flash { opacity: 1; }
.ghost-btn {
  background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 9px; padding: 7px 12px; cursor: pointer; font-size: 13px; transition: all 0.15s;
}
.ghost-btn:hover { background: rgba(255,255,255,0.12); transform: translateY(-1px); }
.ghost-btn.small { padding: 4px 9px; font-size: 12px; }
.ghost-btn.danger { color: var(--danger); }
.ghost-btn.active { border-color: var(--accent2); color: var(--accent2); background: rgba(126,232,160,0.1); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-row .ghost-btn { flex: 1 1 auto; white-space: nowrap; }
.btn-row .ghost-btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.primary-btn {
  background: linear-gradient(135deg, #4f7dff, #38b6c4); color: #fff; border: none;
  border-radius: 9px; padding: 8px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: filter 0.15s, transform 0.15s;
}
.primary-btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.primary-btn.small { padding: 5px 11px; font-size: 12px; }
.disabled-btn { opacity: 0.45; cursor: default; }

/* ---------- side panel ---------- */
#panel {
  position: fixed; top: 58px; right: 0; bottom: 0; width: 368px;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  display: flex; flex-direction: column;
  z-index: 20;
}
#tabs { display: flex; border-bottom: 1px solid var(--panel-border); padding: 0 6px; gap: 2px; }
.tab-btn {
  flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 12px 4px 10px; font-size: 13px; border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab { display: none; flex: 1; overflow-y: auto; padding: 12px; gap: 12px; }
.tab.active { display: flex; flex-direction: column; }
.tab::-webkit-scrollbar { width: 8px; }
.tab::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 4px; }

.card {
  background: var(--card); border: 1px solid var(--panel-border);
  border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.card h3 { font-size: 14px; color: var(--accent); font-weight: 700; }
.hint-text { color: var(--muted); font-size: 12px; line-height: 1.6; }

.field-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.field-row label { flex: 0 0 auto; }
.field-row input[type="text"], .field-row input[type="text"] {
  flex: 1; background: #12182b; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 7px 10px; outline: none; font-size: 13px; min-width: 0;
}
input[type="color"] {
  width: 38px; height: 28px; border: 1px solid var(--panel-border); border-radius: 6px;
  background: #12182b; cursor: pointer; padding: 2px;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.val { color: var(--gold); font-size: 12px; min-width: 26px; text-align: right; }

.biome-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.biome-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 12px;
  color: var(--text); cursor: pointer; padding: 8px 4px; display: flex; flex-direction: column;
  align-items: center; gap: 5px; font-size: 12px; transition: all 0.15s;
}
.biome-btn:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
.biome-btn.active { border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2), 0 0 16px rgba(126,232,160,0.25); }
.biome-btn svg { border-radius: 8px; }

.slider-row { display: grid; grid-template-columns: 86px 1fr 34px; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
input[type="range"] {
  accent-color: var(--accent); cursor: pointer; width: 100%; height: 20px;
}

/* ---------- component palette ---------- */
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.comp-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 12px;
  color: var(--text); cursor: pointer; padding: 8px 2px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; font-size: 11.5px; transition: all 0.15s;
}
.comp-btn:hover { background: rgba(255,255,255,0.1); }
.comp-btn.active { border-color: var(--accent2); box-shadow: 0 0 0 1px var(--accent2), 0 0 16px rgba(126,232,160,0.3); }
.comp-btn svg { border-radius: 8px; }

.custom-list { display: flex; flex-direction: column; gap: 8px; }
.custom-item {
  display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border); border-radius: 12px; padding: 8px 10px;
}
.custom-item svg { border-radius: 8px; }
.custom-name { flex: 1; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.placing-info { border-radius: 10px; padding: 9px 12px; font-size: 12.5px; }
.placing-info.idle { background: rgba(255,255,255,0.04); color: var(--muted); border: 1px dashed var(--panel-border); }
.placing-info.active { background: rgba(126,232,160,0.12); color: var(--accent2); border: 1px solid rgba(126,232,160,0.5); }

/* ---------- grow ---------- */
.meter {
  height: 16px; border-radius: 999px; overflow: hidden;
  background: rgba(255,255,255,0.08); border: 1px solid var(--panel-border);
}
.meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #4f7dff, #38b6c4, #7ee8a0);
  transition: width 0.4s;
}
.stat-line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.stat-line b { color: var(--text); }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-btn {
  position: relative; background: rgba(255,255,255,0.05); border: 1px solid var(--panel-border);
  border-radius: 12px; color: var(--text); padding: 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; transition: all 0.15s;
}
.action-btn:hover { background: rgba(255,255,255,0.11); transform: translateY(-1px); }
.action-icon { font-size: 22px; }
.action-name { font-size: 13px; font-weight: 600; }
.action-cost { font-size: 11px; color: var(--gold); }
.action-cd { font-size: 10.5px; color: var(--muted); min-height: 14px; }
.action-cd.busy { color: var(--danger); }

/* ---------- universe list ---------- */
.planet-list { display: flex; flex-direction: column; gap: 8px; }
.planet-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 9px 11px; transition: all 0.15s;
}
.planet-card:hover { background: rgba(255,255,255,0.08); }
.planet-card.current { border-color: rgba(126,232,160,0.5); background: rgba(126,232,160,0.07); }
.planet-card-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.planet-actions { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.planet-actions .primary-btn, .planet-actions .ghost-btn { text-align: center; white-space: nowrap; }
.planet-card-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.planet-card-info b { font-size: 13.5px; }
.planet-desc { font-size: 11.5px; color: var(--muted); }
.mini-bars { display: flex; gap: 3px; }
.mini-bars i { display: block; height: 4px; width: 0; border-radius: 2px; background: var(--accent2); opacity: 0.8; }

/* ---------- touch controls ---------- */
#touch-ui { position: fixed; inset: 0; pointer-events: none; z-index: 18; }
#joy-zone {
  position: absolute; left: 22px; bottom: 26px; width: 150px; height: 150px;
  pointer-events: auto; touch-action: none; border-radius: 50%;
}
#joy-base {
  position: absolute; left: 50%; top: 50%; width: 108px; height: 108px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(140, 200, 255, 0.35);
  backdrop-filter: blur(4px);
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(190, 225, 255, 0.95), rgba(90, 140, 220, 0.9));
  box-shadow: 0 0 14px rgba(140, 200, 255, 0.6);
}
#touch-jump {
  position: absolute; right: 26px; bottom: 40px; width: 88px; height: 88px;
  border-radius: 50%; border: 2px solid rgba(126, 232, 160, 0.5);
  background: radial-gradient(circle at 35% 30%, rgba(160, 255, 190, 0.9), rgba(60, 170, 110, 0.85));
  color: #06220f; font-size: 22px; font-weight: 800;
  pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none;
}

/* ---------- achievements ---------- */
.ach-list { display: flex; flex-direction: column; gap: 8px; }
.ach-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border); border-radius: 12px;
}
.ach-item.locked { opacity: 0.55; }
.ach-item.unlocked { border-color: rgba(255, 215, 122, 0.45); background: rgba(255, 215, 122, 0.07); }
.ach-icon { font-size: 24px; }
.ach-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ach-name { font-size: 13px; font-weight: 700; }
.ach-desc { font-size: 11.5px; color: var(--muted); }
.ach-state { font-size: 11.5px; color: var(--gold); white-space: nowrap; }

/* ---------- HUD / toast ---------- */
#hud {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 15; pointer-events: none;
}
#hint {
  background: rgba(10, 14, 30, 0.75); border: 1px solid var(--panel-border);
  border-radius: 999px; padding: 7px 18px; font-size: 12.5px; color: #cdd8f5;
  backdrop-filter: blur(8px); white-space: nowrap;
}
#charge-wrap { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--accent2); }
#charge-track { width: 180px; height: 10px; border-radius: 999px; background: rgba(255,255,255,0.1); overflow: hidden; border: 1px solid var(--panel-border); }
#charge-bar { height: 100%; width: 0; background: linear-gradient(90deg, #7ee8a0, #ffd77a, #ff8f8f); transition: width 0.05s; }
.hidden { display: none !important; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(16px);
  background: rgba(13, 18, 34, 0.94); border: 1px solid rgba(140, 200, 255, 0.35);
  color: var(--text); border-radius: 12px; padding: 10px 20px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 40; max-width: 70vw;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(2, 4, 12, 0.72); z-index: 50;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px);
}
.modal-box {
  width: min(560px, 92vw); max-height: 86vh; background: #101527;
  border: 1px solid var(--panel-border); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.7);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--panel-border); font-size: 15px;
}
.modal-close { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-close:hover { color: #fff; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; font-size: 13px; line-height: 1.7; }
.modal-body h3 { color: var(--accent); font-size: 14px; margin-top: 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 13px 18px; border-top: 1px solid var(--panel-border); }

.diy-preview { display: flex; justify-content: center; padding: 6px; }
.part-row {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.part-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--accent); font-weight: 600; }
.mini-del { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; }
.part-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.part-grid label { display: grid; grid-template-columns: 42px 1fr 34px; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.part-grid select {
  grid-column: 2 / 4; background: #12182b; color: var(--text);
  border: 1px solid var(--panel-border); border-radius: 6px; padding: 4px; font-size: 12px;
}
.part-grid input[type="range"] { grid-column: 2 / 4; }
.part-grid input[type="color"] { grid-column: 2 / 3; }
.part-grid output { font-size: 11px; color: var(--gold); text-align: right; }

/* ---------- error overlay ---------- */
#error-overlay { position: fixed; inset: 0; z-index: 99; display: flex; align-items: center; justify-content: center; background: #0a0d18; }
.error-box { max-width: 640px; width: 90vw; display: flex; flex-direction: column; gap: 14px; }
.error-box h3 { color: #ff8f8f; }
.error-box pre { white-space: pre-wrap; color: #cdd8f5; background: #101527; padding: 16px; border-radius: 12px; border: 1px solid rgba(255,143,143,0.3); }
#error-reload { align-self: flex-start; }

@media (max-width: 900px) {
  #panel { width: 310px; }
  .brand-sub { display: none; }
  #hint { white-space: normal; text-align: center; max-width: 80vw; }
}
