/* 细胞觉醒 —— 暗色海洋主题 */
:root {
  --bg: #05121f;
  --bg2: #0a1d30;
  --panel: rgba(9, 24, 40, 0.85);
  --panel-line: #1c3a55;
  --ink: #d6ecff;
  --ink-dim: #7fa6c4;
  --food: #5dff8f;      /* 荧光绿营养 */
  --purple: #c07cff;    /* 紫色谱系 */
  --toxin: #ff5d5d;     /* 红毒素 */
  --accent: #4cc3ff;
  --barrier: #7fd8ff;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #0b2947 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, #03101e 100%);
  color: var(--ink);
  overflow: hidden;
}
#app { height: 100vh; display: flex; flex-direction: column; }

/* 顶栏 */
#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--panel-line);
  background: linear-gradient(180deg, rgba(10,25,43,.9), rgba(6,17,30,.6));
  flex: 0 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 2px; font-weight: 700; }
.world-tag { font-size: 11px; color: var(--food); border: 1px solid rgba(93,255,143,.4); border-radius: 20px; padding: 2px 8px; white-space: nowrap; }
.status-strip { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--ink-dim); margin-left: auto; }
.status-strip span { background: rgba(255,255,255,.03); padding: 3px 8px; border-radius: 10px; white-space: nowrap; }
.top-actions { display: flex; gap: 6px; }
button, .ghost {
  border: 1px solid var(--panel-line); background: rgba(255,255,255,.03); color: var(--ink);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
button:hover { border-color: var(--accent); }
.ghost { font-size: 12px; color: var(--ink-dim); }
.primary { background: var(--accent); color: #04121e; border-color: transparent; font-weight: 600; }

/* 主布局 */
#layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 250px 1fr 260px;
  gap: 0;
}
.side { padding: 12px; overflow-y: auto; background: var(--panel); }
.side h2 { margin: 0 0 4px; font-size: 13px; letter-spacing: 1px; color: var(--food); }
.side h3 { margin: 12px 0 6px; font-size: 12px; color: var(--ink-dim); }
.hint { color: var(--ink-dim); font-size: 11px; line-height: 1.5; margin: 2px 0 10px; }
.note { color: var(--ink-dim); font-size: 10.5px; line-height: 1.5; margin-top: 8px; }
.left { border-right: 1px solid var(--panel-line); }
.right { border-left: 1px solid var(--panel-line); }

.ctl { display: block; margin-bottom: 10px; }
.ctl > span { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 2px; }
.ctl b { color: var(--accent); font-weight: 600; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.ctl select { width: 100%; background: #0a1d30; color: var(--ink); border: 1px solid var(--panel-line); border-radius: 6px; padding: 5px; }

.toggle-row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-bottom: 10px; }
.switch { width: 46px; font-size: 11px; padding: 3px 0; border-radius: 12px; }
.switch[data-state="on"] { background: var(--food); color: #03120a; border-color: transparent; }
.switch[data-state="off"] { background: var(--danger); color: #1c0303; border-color: transparent; }

/* 画布区 */
#stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#canvas-wrap { flex: 1 1 auto; position: relative; min-height: 0; background: #03101d; }
#world { width: 100%; height: 100%; display: block; touch-action: none; }
#legend { position: absolute; left: 10px; top: 10px; display: flex; gap: 10px; font-size: 10px; color: var(--ink-dim); pointer-events: none; }
#legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.lg.seed::before { background: var(--purple); }
.lg.food::before { background: var(--food); }
.lg.tox::before { background: var(--toxin); }
.lg.bar::before { background: var(--barrier); border-radius: 2px; }

#toolbar { display: flex; gap: 4px; padding: 6px 8px; background: var(--panel); border-top: 1px solid var(--panel-line); flex-wrap: wrap; justify-content: center; flex: 0 0 auto; }
.tool { display: flex; align-items: center; gap: 4px; font-size: 12px; padding: 5px 9px; }
.tool span { font-size: 13px; }
.tool.active { background: var(--accent); color: #04121e; border-color: transparent; }
#toolbar-hint { text-align: center; font-size: 10.5px; color: var(--ink-dim); padding: 3px; background: rgba(255,255,255,.02); }

/* 观察面板 */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: rgba(255,255,255,.04); border-radius: 8px; padding: 6px 8px; }
.stat .k { font-size: 10px; color: var(--ink-dim); }
.stat .v { font-size: 15px; font-weight: 700; }
.cell-card { margin-top: 8px; }
.empty { color: var(--ink-dim); font-size: 11px; line-height: 1.5; }
#cell-body { font-size: 12px; }
#cell-body .kv { display: flex; justify-content: space-between; padding: 2px 0; border-bottom: 1px dashed rgba(255,255,255,.05); }
#cell-body .kv b { color: var(--ink); font-weight: 500; }
#cell-body .kv .val { color: var(--accent); }
.bar-w { background: rgba(255,255,255,.06); height: 6px; border-radius: 4px; margin: 2px 0 8px; overflow: hidden; }
.bar-w i { display: block; height: 100%; background: linear-gradient(90deg, var(--food), var(--accent)); }
.mini { font-size: 10px; padding: 1px 6px; margin-left: 6px; }

.history ul { list-style: none; margin: 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 11px; color: var(--ink-dim); }
.history li { display: flex; gap: 6px; padding: 2px 0; border-bottom: 1px dashed rgba(255,255,255,.04); }
.history li .t { color: var(--accent); white-space: nowrap; }

/* 弹窗/提示 */
.modal { position: fixed; inset: 0; background: rgba(2,8,15,.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal .card { background: var(--bg2); border: 1px solid var(--panel-line); border-radius: 14px; padding: 20px; width: min(320px, 90vw); }
.modal input { display: block; width: 100%; margin: 8px 0; padding: 8px; background: #0a1d30; border: 1px solid var(--panel-line); border-radius: 8px; color: var(--ink); }
.row-end { display: flex; justify-content: flex-end; gap: 6px; margin-top: 10px; }
.err { color: var(--danger); font-size: 12px; min-height: 16px; margin-top: 6px; }
#toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: #06203a; border: 1px solid var(--panel-line); color: var(--ink); padding: 8px 16px; border-radius: 10px; font-size: 13px; z-index: 60; }

/* 响应式：窄屏改为单列滚动 */
@media (max-width: 980px) {
  body { overflow: auto; }
  #app { height: auto; }
  #layout { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; }
  #rules { order: 2; border-right: 0; border-top: 1px solid var(--panel-line); }
  #inspect { order: 3; border-left: 0; border-top: 1px solid var(--panel-line); }
  #stage { order: 1; }
  .status-strip { display: none; }
}
