:root {
  --bg: #070b14;
  --bg-2: #0c1322;
  --panel: rgba(16, 26, 44, .82);
  --panel-2: #142039;
  --line: rgba(110, 200, 255, .16);
  --line-strong: rgba(110, 200, 255, .38);
  --text: #e3eefc;
  --muted: #8193b0;
  --cyan: #4fd8ff;
  --bio: #7cf29a;
  --gold: #ffd166;
  --warn: #ffab5c;
  --bad: #ff6b81;
  --radius: 12px;
  --sans: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(79, 216, 255, .12), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(124, 242, 154, .08), transparent 60%),
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 70% 60%, rgba(255,255,255,.35), transparent),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,.4), transparent),
    var(--bg);
}

button { font: inherit; color: inherit; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(7, 11, 20, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.home {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 18px;
}
.home:hover { color: var(--cyan); border-color: var(--line-strong); }
.logo { font-size: 28px; filter: drop-shadow(0 0 8px rgba(79, 216, 255, .5)); }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .08em; }
.brand-sub { color: var(--muted); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }

.status { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stat {
  display: flex; flex-direction: column;
  padding: 4px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-2);
  min-width: 120px;
}
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: .1em; }
.stat-value { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.coin { color: var(--gold); }
.tech { color: var(--bio); }
.stat-sm { min-width: 0; }
#coins-box.flash { animation: flash .8s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 rgba(255, 209, 102, .7); border-color: var(--gold); }
  100% { box-shadow: 0 0 0 14px rgba(255, 209, 102, 0); }
}

.speed { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.speed button {
  min-width: 40px; height: 38px;
  border: 0; border-right: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); cursor: pointer;
  font-family: var(--mono);
}
.speed button:last-child { border-right: 0; }
.speed button:hover { color: var(--text); }
.speed button.active { background: rgba(79, 216, 255, .18); color: var(--cyan); }
.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-2); color: var(--muted); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { color: var(--cyan); border-color: var(--cyan); }
.icon-btn.danger:hover { color: var(--bad); border-color: var(--bad); }

/* ---------- 分頁 ---------- */
.tabs { display: flex; gap: 6px; max-width: 1280px; margin: 0 auto; padding: 12px 20px 0; overflow-x: auto; }
.tab {
  padding: 8px 16px;
  border: 1px solid var(--line); border-bottom: 0; border-radius: 10px 10px 0 0;
  background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--panel); color: var(--text); border-color: var(--line-strong); }
.tab:disabled { cursor: not-allowed; opacity: .55; }
.tab small { font-size: 10px; margin-left: 4px; }
#lab-badge { color: var(--bio); font-family: var(--mono); }

/* ---------- 版面 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  padding: 16px 20px 40px;
  max-width: 1280px;
  margin: 0 auto;
}
.layout[hidden] { display: none; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-head h2 { font-size: 15px; letter-spacing: .12em; color: var(--cyan); }

/* ---------- 按鈕 ---------- */
.btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--panel-2); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); background: rgba(79, 216, 255, .12); }
.btn:disabled { cursor: not-allowed; opacity: .5; }
.btn.primary { background: linear-gradient(135deg, #1fb87a, #2aa6d6); border-color: transparent; color: #04121a; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); background: rgba(255, 107, 129, .08); }
.btn.sm { width: auto; padding: 4px 10px; font-size: 12px; white-space: nowrap; }

/* ---------- 進度條 ---------- */
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.07); overflow: hidden; }
.bar.small { height: 6px; }
.bar-fill { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--bio)); }
.bar.ready .bar-fill { background: var(--bio); box-shadow: 0 0 8px var(--bio); }

/* ---------- 培養艙 ---------- */
.pods { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.pod {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: linear-gradient(180deg, rgba(79, 216, 255, .07), transparent 60%), var(--bg-2);
}
.pod.empty { border-style: dashed; background: transparent; }
.pod.blocked { border-color: var(--warn); }
.pod.blocked .bar-fill { background: var(--warn); }
.pod-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.pod-state { font-family: var(--mono); color: var(--bio); }
.pod.blocked .pod-state { color: var(--warn); }
.pod-icon {
  display: grid; place-items: center;
  height: 72px; font-size: 44px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124, 242, 154, .14), transparent 65%);
}
.pod.empty .pod-icon { color: var(--muted); font-size: 32px; background: none; }
.bob { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.paused .bob { animation-play-state: paused; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.pod-name { text-align: center; font-weight: 700; }
.pod.starved { border-color: var(--bad); }
.pod.starved .pod-state { color: var(--bad); }
.pod.starved .bar-fill { background: var(--bad); }
.pod.starved .bob { animation-play-state: paused; filter: grayscale(.6); }
.feed {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 8px;
  padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255,255,255,.03); cursor: pointer; font-size: 12px; text-align: left;
}
.feed:hover { border-color: var(--cyan); }
.feed small { color: var(--muted); }
.feed-stock { width: 100%; color: var(--muted); font-family: var(--mono); font-size: 11px; }
.feed.short, .feed.none { border-color: var(--bad); }
.feed.short .feed-stock, .feed.none b { color: var(--bad); }
.feed.free { justify-content: center; cursor: default; color: var(--gold); border-style: dashed; }
.feed.free:hover { border-color: var(--line); }
.pod-meta { text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- 倉庫 ---------- */
.warehouse { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; max-width: 520px; }
.slot {
  position: relative;
  aspect-ratio: 1;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--bg-2);
  overflow: hidden; cursor: pointer;
}
.slot:hover { border-color: var(--bad); }
.slot.empty { border-style: dashed; border-color: rgba(110, 200, 255, .26); cursor: default; background: rgba(255,255,255,.02); }
.slot-icon { font-size: 28px; }
.slot-name {
  position: absolute; left: 4px; right: 4px; top: 3px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  font-size: 10px; color: var(--muted); text-align: left;
}
.slot-name.variant { color: #d9c6ff; }
.slot-qty {
  position: absolute; right: 6px; bottom: 6px;
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  text-shadow: 0 1px 2px #000;
}
.slot-fill { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--cyan); }
.slot.full { border-color: var(--warn); }
.slot.full .slot-fill { background: var(--warn); }
.slot.full .slot-qty { color: var(--warn); }
.totals { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.total b { color: var(--text); font-family: var(--mono); }

/* ---------- 訂單 ---------- */
.orders { display: flex; flex-direction: column; gap: 12px; }
.planet { padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-2); }
.planet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.planet-icon { font-size: 30px; filter: drop-shadow(0 0 10px rgba(255, 90, 60, .5)); }
.planet-info { flex: 1; min-width: 0; }
.planet-name { font-weight: 700; }
.tier-badge {
  margin-left: 4px; padding: 1px 7px; border-radius: 99px;
  font-size: 11px; font-weight: 400; font-family: var(--mono);
  color: var(--gold); border: 1px solid rgba(255, 209, 102, .35); background: rgba(255, 209, 102, .08);
}
.hint { font-size: 12px; color: var(--warn); }
.order { display: flex; flex-direction: column; gap: 8px; }
.order-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.order-label { color: var(--muted); font-size: 12px; }
.order-qty { margin-left: auto; font-family: var(--mono); font-size: 16px; }
.req-tags { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.feature.req { font-size: 12px; }
.order-actions { display: flex; align-items: center; gap: 10px; }
.order-actions .btn { flex: 1; }
.auto { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.auto input { accent-color: var(--bio); cursor: pointer; }
.sp-tag { padding: 2px 8px; border-radius: 99px; background: rgba(124, 242, 154, .1); border: 1px solid rgba(124, 242, 154, .25); }
.reward { font-family: var(--mono); color: var(--gold); font-weight: 700; }

/* ---------- 物種庫 ---------- */
.species-tree { display: flex; flex-direction: column; gap: 10px; }
.species { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; border-radius: 8px; background: var(--bg-2); border: 1px solid transparent; }
.species.variant { border-color: rgba(190, 150, 255, .25); }
.species-icon { font-size: 26px; line-height: 1.2; }
.species-body { flex: 1; min-width: 0; }
.species-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.tree-children {
  display: flex; flex-direction: column; gap: 8px;
  margin: 8px 0 0 20px; padding-left: 14px;
  border-left: 1px dashed rgba(190, 150, 255, .4);
}
.tree-children > .tree-node { position: relative; }
.tree-children > .tree-node::before {
  content: ""; position: absolute; left: -14px; top: 24px; width: 12px;
  border-top: 1px dashed rgba(190, 150, 255, .4);
}
.badge { font-size: 11px; }
.budget-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 8px; }
.budget { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.budget-label { color: var(--muted); }
.budget b { font-family: var(--mono); }
.budget.over b { color: var(--bad); }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(190, 150, 255, .5); }
.pips i.on { background: #b48cff; border-color: #b48cff; }
.pips i.over { background: var(--bad); border-color: var(--bad); }

/* ---------- 研究 ---------- */
.research-current { margin-bottom: 4px; }
.research-now { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--bio); border-radius: 10px; background: rgba(124, 242, 154, .05); }
.research-now .btn { align-self: flex-end; }
h3.sub, h4.sub { margin: 14px 0 8px; font-size: 12px; font-weight: 400; color: var(--muted); letter-spacing: .12em; }
.research-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border-radius: 8px; background: var(--bg-2); }
.research-icon { font-size: 22px; }
.research-body { flex: 1; min-width: 0; }
.lv-tag { font-family: var(--mono); font-size: 11px; color: var(--bio); }

/* ---------- 屬性標籤 ---------- */
.traits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.traits.center { justify-content: center; margin-top: 0; }
.trait { padding: 1px 7px; border-radius: 99px; font-size: 11px; white-space: nowrap; }
.trait.give { color: var(--bio); background: rgba(124, 242, 154, .1); border: 1px solid rgba(124, 242, 154, .28); }
.trait.take { color: var(--warn); background: rgba(255, 171, 92, .1); border: 1px solid rgba(255, 171, 92, .3); }
.trait.trop { color: #d9c6ff; background: rgba(190, 150, 255, .1); border: 1px solid rgba(190, 150, 255, .35); }
.trait.diet { color: var(--text); background: rgba(79, 216, 255, .1); border: 1px solid rgba(79, 216, 255, .35); font-weight: 700; }
.features { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.feature {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 6px; font-size: 11px;
  border: 1px solid rgba(190, 150, 255, .35); background: rgba(190, 150, 255, .08); color: #d9c6ff;
}
.feature b { font-family: var(--mono); }
.feature .cost { color: #b48cff; font-family: var(--mono); font-size: 10px; margin-left: 2px; }
.feature.kind { border-color: rgba(79, 216, 255, .35); background: rgba(79, 216, 255, .06); color: var(--text); }

/* ---------- 日誌 ---------- */
.log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; font-size: 13px; }
.log li { padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,.04); }
.log-date { margin-right: 8px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.log-info { color: var(--cyan); }
.log-good { color: var(--bio); }
.log-warn { color: var(--warn); }

/* ---------- 視窗 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(2, 5, 10, .7);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(440px, 100%);
  padding: 20px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-card { max-height: calc(100vh - 32px); overflow-y: auto; }
.modal-card.wide { width: min(560px, 100%); }
.modal-card h3 { font-size: 16px; margin-bottom: 8px; }
.modal-card p { margin: 0 0 12px; }
.pick-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pick {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; text-align: left;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); cursor: pointer;
}
.pick:hover:not(:disabled) { border-color: var(--cyan); }
.pick:disabled { cursor: default; opacity: .6; }
.pick-icon { font-size: 30px; }
.pick-body { display: flex; flex-direction: column; }
.modal-actions { display: flex; gap: 8px; }
.pick-list.scroll { max-height: 55vh; overflow-y: auto; }

/* ---------- 基因編輯 ---------- */
.editor-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.gene-list { display: flex; flex-direction: column; gap: 6px; }
.gene-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 8px;
  border: 1px solid rgba(190, 150, 255, .3); background: rgba(190, 150, 255, .06);
}
.gene-row.absent { border-style: dashed; background: transparent; }
.gene-name { flex: 1; min-width: 0; }
.gene-lv { min-width: 64px; }
.gene-row .cost { min-width: 36px; text-align: right; font-family: var(--mono); color: #b48cff; }
.gene-mark { padding: 0 6px; border-radius: 4px; font-size: 11px; }
.gene-mark.ins { color: var(--bio); background: rgba(124, 242, 154, .12); }
.gene-mark.lvl { color: var(--gold); background: rgba(255, 209, 102, .12); }
.gene-mark.cut { color: var(--bad); background: rgba(255, 107, 129, .12); }
.lv, .lv-select { font-family: var(--mono); font-size: 12px; }
.lv-select {
  padding: 2px 4px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--text);
}
.changes { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.change { padding: 2px 8px; border-radius: 6px; font-size: 12px; background: rgba(255,255,255,.05); }
.change.cut { color: var(--bad); }
.change.insert { color: var(--bio); }
.change.level { color: var(--gold); }
.errors { margin: 4px 0 8px; padding-left: 18px; color: var(--bad); font-size: 12px; }
.name-field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 14px; font-size: 12px; color: var(--muted); }
.text-input {
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--text); font: inherit;
}
.text-input:focus { outline: none; border-color: var(--cyan); }

/* ---------- 交涉 ---------- */
.tier-card { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.tier-card.current { border-color: var(--line-strong); background: transparent; }
.tier-head { font-weight: 700; }
.tier-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.tier-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

/* ---------- 提示框 ---------- */
.tooltip {
  position: fixed; z-index: 50; top: 0; left: 0;
  max-width: 260px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: #0b1424; color: var(--text);
  font-size: 12px; line-height: 1.5; white-space: pre-line;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  pointer-events: none;
}
.tooltip[hidden] { display: none; }

/* ---------- 設定 ---------- */
.setting { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 16px; }
.setting label { display: flex; justify-content: space-between; }
.setting label b { font-family: var(--mono); color: var(--cyan); }
.setting input[type="range"] { width: 100%; accent-color: var(--cyan); }
.range-ends { display: flex; justify-content: space-between; margin-top: -4px; }
.setting p { margin: 4px 0 0; }
.tip-demo { margin-left: 6px; color: var(--cyan); border-bottom: 1px dashed var(--cyan); cursor: help; }

.paused-badge {
  position: fixed; left: 50%; bottom: 20px; z-index: 15;
  transform: translateX(-50%);
  padding: 6px 18px; border-radius: 99px;
  background: var(--warn); color: #1a0e00; font-weight: 700; letter-spacing: .2em;
  display: none;
}
.paused .paused-badge { display: block; }

/* ---------- 窄螢幕 ---------- */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px 16px 40px;
  }
  .topbar { padding: 10px 16px; }
  .tabs { padding: 10px 16px 0; }
  .stat { min-width: 0; }
}
@media (max-width: 480px) {
  .pods { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .warehouse { gap: 6px; }
  .slot-icon { font-size: 22px; }
  .species { flex-wrap: wrap; }
  .species-actions { flex-direction: row; width: 100%; justify-content: flex-end; }
  .tree-children { margin-left: 8px; padding-left: 10px; }
  .gene-row { flex-wrap: wrap; }
}
