/* ═══════════ 九寨沟 · 引力调度沙盘 ═══════════ */
:root {
  --bg: #050810;
  --panel: #0c1220;
  --panel2: #111a2b;
  --line: #1a2540;
  --cyan: #22d3ee;
  --mint: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --text: #e5edf7;
  --dim: #7f8ca3;
  --mono: 'JetBrains Mono', ui-monospace, 'PingFang SC', 'Microsoft YaHei', monospace;
  --sans: -apple-system, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 扫描线质感 */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.014) 0 1px, transparent 1px 3px);
  pointer-events: none;
  z-index: 60;
}

/* ═══════════ 顶栏 ═══════════ */
.topbar {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  background: linear-gradient(180deg, #0c1220 0%, #080d18 100%);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 9px;
  display: grid; place-items: center; background: var(--panel);
  box-shadow: 0 0 18px rgba(34, 211, 238, .12);
}
.brand-text h1 { font-size: 16px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; }
.brand-text p { font-size: 10px; color: var(--dim); letter-spacing: .12em; margin-top: 2px; white-space: nowrap; }

.clock-box { margin-left: auto; text-align: center; }
.clock { font-family: var(--mono); font-size: 26px; font-weight: 700; color: var(--cyan); text-shadow: 0 0 16px rgba(34,211,238,.45); line-height: 1; }
.clock-sub { font-family: var(--mono); font-size: 8px; letter-spacing: .28em; color: var(--dim); margin-top: 3px; }

.top-actions { display: flex; align-items: center; gap: 10px; }

.speed-ctrl { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.spd {
  font-family: var(--mono); font-size: 11px; padding: 6px 10px;
  background: var(--panel); color: var(--dim); border: none; cursor: pointer;
  border-right: 1px solid var(--line);
}
.spd:last-child { border-right: none; }
.spd.on { background: rgba(34,211,238,.14); color: var(--cyan); }

.ghost-btn {
  font-size: 12px; padding: 7px 14px; border-radius: 7px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); cursor: pointer; transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.ghost-btn.accent { border-color: rgba(251,191,36,.4); color: var(--amber); }
.ghost-btn.accent:hover { border-color: var(--amber); }

.live-badge {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .22em; color: var(--mint);
  border: 1px solid rgba(52,211,153,.35); border-radius: 999px; padding: 6px 12px;
  background: rgba(52,211,153,.07);
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 rgba(52,211,153,.5);} 50% { opacity: .55; box-shadow: 0 0 0 5px rgba(52,211,153,0);} }

/* ═══════════ 布局 ═══════════ */
.layout { flex: 1; display: flex; min-height: 0; }

.map-wrap {
  flex: 1; position: relative; min-width: 0;
  background:
    radial-gradient(ellipse 90% 70% at 45% 40%, rgba(34,211,238,.05), transparent 60%),
    var(--bg);
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.map-overlay {
  position: absolute; z-index: 5;
  background: rgba(12, 18, 32, .82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.legend { left: 14px; bottom: 14px; font-size: 11px; color: var(--dim); }
.legend-title, .formula-title {
  font-family: var(--mono); font-size: 9px; letter-spacing: .26em;
  color: var(--dim); margin-bottom: 8px;
}
.legend-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.bus { border-radius: 2px; width: 12px; height: 7px; }
.arc-demo {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block;
  border: 2px solid var(--amber); border-bottom-color: transparent; border-left-color: transparent;
  transform: rotate(-45deg);
}

.formula { right: 14px; bottom: 14px; text-align: left; max-width: 260px; }
.formula-eq { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--cyan); text-shadow: 0 0 14px rgba(34,211,238,.4); }
.formula-note { font-size: 10px; color: var(--dim); line-height: 1.7; margin-top: 6px; }

/* ═══════════ 右侧面板 ═══════════ */
.panel {
  width: 380px; flex: none;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.sec { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sec.grow { flex: 1; min-height: 180px; border-bottom: none; }
.sec-title {
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 9px;
}
.sec-title span { font-family: var(--mono); font-size: 8px; letter-spacing: .24em; color: var(--dim); font-weight: 400; }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.metric {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px;
}
.m-val { font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.1; }
.m-val.cyan { color: var(--cyan); }
.m-val.amber { color: var(--amber); }
.m-label { font-size: 10px; color: var(--dim); margin-top: 4px; letter-spacing: .06em; }

.peak-line { font-size: 11px; color: var(--dim); margin-top: 10px; }
.peak-line b { color: var(--red); font-weight: 600; }
.peak-line .phase-tag { color: var(--cyan); font-weight: 600; }
.mono { font-family: var(--mono); }

.tag {
  font-family: var(--mono); font-size: 9px !important; letter-spacing: .2em;
  color: var(--amber) !important; border: 1px solid rgba(251,191,36,.35);
  padding: 2px 8px; border-radius: 999px;
}

/* 分段控件 */
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn {
  flex: 1; padding: 9px 0; font-size: 13px; font-weight: 600;
  background: var(--panel2); color: var(--dim); border: none; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-btn.on { background: rgba(34,211,238,.15); color: var(--cyan); }
.hint { font-size: 11px; color: var(--dim); line-height: 1.7; margin-top: 9px; }

/* 滑杆 */
.slider { width: 100%; appearance: none; height: 4px; border-radius: 2px; background: var(--line); outline: none; }
.slider::-webkit-slider-thumb {
  appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--cyan); border: 2px solid #062430;
  box-shadow: 0 0 10px rgba(34,211,238,.6); cursor: pointer;
}
.slider-scale { display: flex; justify-content: space-between; font-size: 9px; color: var(--dim); margin-top: 6px; font-family: var(--mono); }

.btn-row { display: flex; gap: 8px; margin-top: 14px; }
.act-btn {
  flex: 1; padding: 9px 0; font-size: 12px; font-weight: 600;
  border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); cursor: pointer;
  transition: transform .12s, border-color .15s;
}
.act-btn:hover { border-color: var(--cyan); }
.act-btn:active { transform: scale(.96); }
.act-btn.warn { border-color: rgba(248,113,113,.45); color: var(--red); }
.act-btn.warn:hover { border-color: var(--red); background: rgba(248,113,113,.08); }

/* 负荷排行 */
.rank-list { display: flex; flex-direction: column; gap: 7px; }
.rank-row { display: grid; grid-template-columns: 58px 1fr 52px; align-items: center; gap: 9px; font-size: 11px; }
.rank-name { color: var(--text); white-space: nowrap; overflow: hidden; }
.rank-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.rank-fill { height: 100%; border-radius: 3px; transition: width .3s ease, background .3s ease; }
.rank-val { font-family: var(--mono); font-size: 10px; color: var(--dim); text-align: right; }

/* 日志 */
.log-list { display: flex; flex-direction: column; gap: 5px; }
.log-item {
  font-family: var(--mono); font-size: 10.5px; line-height: 1.55;
  color: var(--dim); padding: 6px 9px;
  background: var(--panel2); border-left: 2px solid var(--line); border-radius: 0 6px 6px 0;
  animation: logIn .3s ease;
}
.log-item .lt { color: var(--cyan); margin-right: 6px; }
.log-item.grav { border-left-color: var(--cyan); color: #bfe9f2; }
.log-item.alert { border-left-color: var(--red); color: #f5c1c1; }
@keyframes logIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ═══════════ 弹窗 ═══════════ */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3, 6, 12, .72); backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center;
}
.modal-mask.show { display: flex; }
.modal {
  width: min(620px, 92vw); max-height: 84vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px 34px; position: relative;
  box-shadow: 0 24px 80px rgba(0,0,0,.6), 0 0 0 1px rgba(34,211,238,.08);
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--panel2); border: 1px solid var(--line);
  color: var(--dim); font-size: 17px; cursor: pointer;
}
.modal-close:hover { color: var(--red); border-color: var(--red); }
.modal h3 { font-size: 19px; letter-spacing: .04em; margin-bottom: 4px; }
.modal h3 .mono { font-size: 10px; color: var(--dim); letter-spacing: .22em; margin-left: 8px; }
.modal-lead { font-size: 13px; color: var(--amber); line-height: 1.8; margin: 14px 0 18px; padding: 12px 14px; background: rgba(251,191,36,.06); border-left: 2px solid var(--amber); border-radius: 0 8px 8px 0; }
.steps { list-style: none; counter-reset: st; }
.steps li {
  counter-increment: st; font-size: 13px; color: var(--text);
  line-height: 1.9; padding: 9px 0 9px 40px; position: relative;
  border-bottom: 1px dashed var(--line);
}
.steps li::before {
  content: counter(st, decimal-leading-zero);
  position: absolute; left: 2px; top: 12px;
  font-family: var(--mono); font-size: 11px; font-weight: 700; color: var(--cyan);
}
.steps li .mono { color: var(--cyan); font-size: 12px; }
.modal-foot { font-size: 11px; color: var(--dim); line-height: 1.9; margin-top: 16px; }

/* 结算面板 */
.settle { text-align: left; }
.settle-sub { font-family: var(--mono); font-size: 11px; color: var(--dim); letter-spacing: .12em; margin: 6px 0 18px; }
.settle-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.settle-item {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 12px; text-align: center;
}
.s-val { font-family: var(--mono); font-size: 24px; font-weight: 700; color: var(--text); }
.s-val.cyan { color: var(--cyan); }
.s-val.amber { color: var(--amber); }
.s-val.red { color: var(--red); font-size: 19px; }
.s-label { font-size: 10px; color: var(--dim); margin-top: 6px; letter-spacing: .05em; }
.settle-note { font-size: 12px; color: var(--dim); line-height: 1.8; margin: 16px 0 4px; }
.settle .btn-row { margin-top: 14px; }

/* 闭园后的 LIVE 徽章 */
.live-badge.ended { color: var(--dim); border-color: var(--line); background: transparent; }
.live-badge.ended .live-dot { background: var(--dim); animation: none; }

@media (max-width: 640px) {
  .settle-grid { grid-template-columns: 1fr 1fr; }
}

/* 窄屏适配 */
@media (max-width: 980px) {
  body { overflow: auto; }

  /* 顶栏两行：第一行品牌+LIVE，第二行时钟+控制 */
  .topbar {
    height: auto; flex-wrap: wrap;
    gap: 8px 10px; padding: 10px 12px;
  }
  .brand { flex: 1 1 auto; min-width: 0; gap: 9px; }
  .brand-mark { width: 34px; height: 34px; flex: none; }
  .brand-text h1 { font-size: 14px; white-space: normal; line-height: 1.3; }
  .brand-text p { display: none; }
  .clock-box { order: 3; margin-left: 0; display: flex; align-items: baseline; gap: 8px; }
  .clock { font-size: 20px; }
  .clock-sub { margin-top: 0; }
  .top-actions {
    order: 4; flex: 1 1 100%; justify-content: flex-start;
    gap: 6px; overflow: visible;
  }
  .speed-ctrl { margin-right: auto; }
  .live-badge { order: 2; margin-left: auto; padding: 4px 9px; }
  .ghost-btn { padding: 6px 10px; font-size: 11px; white-space: nowrap; }
  .spd { padding: 5px 8px; font-size: 10px; }

  .layout { flex-direction: column; }
  .map-wrap { height: 58vh; flex: none; }
  .panel { width: 100%; border-left: none; border-top: 1px solid var(--line); }

  /* 地图覆盖层：图例去左上、公式留右下，紧凑化 */
  .legend {
    top: 8px; left: 8px; bottom: auto;
    padding: 8px 10px; font-size: 9px; max-width: 46%;
  }
  .legend-title { font-size: 8px; margin-bottom: 5px; }
  .legend-row { margin-top: 3px; gap: 6px; }
  .formula {
    right: 8px; bottom: 8px;
    padding: 8px 10px; max-width: 48%;
  }
  .formula-title { font-size: 8px; margin-bottom: 4px; }
  .formula-eq { font-size: 15px; }
  .formula-note { font-size: 9px; line-height: 1.6; margin-top: 4px; }
}