:root {
  --bg: #080d1a;
  --bg-soft: #0d1426;
  --panel: #121b30;
  --panel-2: #17223a;
  --line: #263553;
  --line-soft: #1d2942;
  --text: #e9eefb;
  --muted: #8b9bbd;
  --dim: #5f7196;
  --accent: #5eead4;
  --primary: #7c8cff;
  --gold: #f7c66b;
  --danger: #ff7b8a;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(0, 0, 0, .42);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1100px 620px at 12% -10%, rgba(94, 234, 212, .09), transparent 60%),
    radial-gradient(900px 560px at 92% 4%, rgba(124, 140, 255, .12), transparent 62%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding: 22px 22px 40px;
}

.app { max-width: 1240px; margin: 0 auto; }

/* ---------- header ---------- */
.header {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 16px 20px; margin-bottom: 20px;
  background: linear-gradient(120deg, rgba(23, 34, 58, .95), rgba(13, 20, 38, .9));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 16px; }
.logo-mark {
  display: grid; grid-template-columns: repeat(2, 13px); grid-template-rows: repeat(2, 13px);
  gap: 3px; padding: 10px; border-radius: 12px;
  background: rgba(94, 234, 212, .08); border: 1px solid rgba(94, 234, 212, .25);
}
.logo-mark i { display: block; border-radius: 3px; background: var(--accent); box-shadow: 0 0 10px rgba(94, 234, 212, .55); }
.logo-mark i:nth-child(2) { background: var(--primary); box-shadow: 0 0 10px rgba(124, 140, 255, .55); }
.logo-mark i:nth-child(3) { background: var(--gold); box-shadow: 0 0 10px rgba(247, 198, 107, .5); }
.logo-mark i:nth-child(4) { background: #ff8fa3; box-shadow: 0 0 10px rgba(255, 143, 163, .5); }
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: 2px; font-weight: 750; }
.brand-text h1 span { font-size: 12px; letter-spacing: 1px; color: var(--accent); margin-left: 8px; font-weight: 600; }
.brand-text p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.header-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 11px; padding: 6px 11px; border-radius: 999px;
  background: rgba(94, 234, 212, .12); color: var(--accent);
  border: 1px solid rgba(94, 234, 212, .28); white-space: nowrap;
}
.badge-ghost { background: rgba(124, 140, 255, .1); color: #aab5ff; border-color: rgba(124, 140, 255, .25); }
.badge.warn { background: rgba(247, 198, 107, .12); color: var(--gold); border-color: rgba(247, 198, 107, .3); }

/* ---------- layout ---------- */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 372px; gap: 20px; align-items: start; }
.stage {
  background: linear-gradient(160deg, rgba(23, 34, 58, .82), rgba(10, 16, 31, .92));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.stage-inner { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.board-frame {
  position: relative; padding: 10px; border-radius: 18px;
  background: linear-gradient(145deg, #1b2742, #0c1426);
  border: 1px solid #2c3d60;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 20px 50px rgba(0, 0, 0, .55), 0 0 60px rgba(94, 234, 212, .06);
}
#board { display: block; width: 320px; height: auto; aspect-ratio: 1 / 2; max-width: 100%; border-radius: 8px; }
.board-overlay {
  position: absolute; inset: 10px; display: grid; place-items: center;
  background: rgba(6, 11, 23, .78); backdrop-filter: blur(4px); border-radius: 8px;
}
.overlay-card { text-align: center; padding: 26px; }
.overlay-title { font-size: 26px; font-weight: 800; letter-spacing: 3px; color: var(--danger); }
.overlay-sub { color: var(--muted); font-size: 13px; margin: 10px 0 20px; line-height: 1.8; }
.stage-caption {
  width: 100%; max-width: 344px; display: flex; align-items: center; gap: 9px;
  font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line-soft); padding-top: 12px;
}
.stage-caption-right { margin-left: auto; color: var(--dim); font-family: ui-monospace, Consolas, monospace; font-size: 11px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.live-dot.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.live-dot.busy { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

/* ---------- cards ---------- */
.sidebar { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: linear-gradient(160deg, rgba(23, 34, 58, .9), rgba(13, 20, 38, .94));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 12px; letter-spacing: 2.4px; color: var(--accent); font-weight: 700; }
.card-sub { font-size: 11px; color: var(--dim); }

/* next preview */
.next-list { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.next-item {
  flex: 1; min-width: 0; padding: 7px 2px 5px; border-radius: 9px;
  background: rgba(255, 255, 255, .025); border: 1px solid var(--line-soft);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.next-item:first-child { border-color: rgba(94, 234, 212, .35); background: rgba(94, 234, 212, .06); }
.mini-grid { display: grid; grid-template-columns: repeat(4, 10px); grid-template-rows: repeat(2, 10px); gap: 1px; }
.mini-cell { width: 10px; height: 10px; border-radius: 2px; }
.mini-cell.filled { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 0 7px currentColor; }
.next-name { font-size: 10px; color: var(--dim); letter-spacing: 1px; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat {
  background: rgba(255, 255, 255, .025); border: 1px solid var(--line-soft);
  border-radius: 9px; padding: 9px 11px; display: flex; align-items: baseline; justify-content: space-between;
}
.stat span { font-size: 11px; color: var(--muted); }
.stat strong { font-size: 17px; font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.metric-row { display: flex; gap: 8px; margin-top: 9px; }
.metric-row > div {
  flex: 1; text-align: center; padding: 6px 4px; border-radius: 8px;
  background: rgba(124, 140, 255, .06); border: 1px solid rgba(124, 140, 255, .12);
}
.metric-row span { display: block; font-size: 10px; color: var(--dim); }
.metric-row b { font-size: 13px; color: #b7c2ff; font-variant-numeric: tabular-nums; }

/* decision */
.decision-main { font-size: 12px; color: var(--text); line-height: 1.7; min-height: 22px; }
.decision-main em { color: var(--gold); font-style: normal; font-weight: 700; }
.candidates { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.candidate { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.cand-label { width: 92px; color: var(--muted); font-family: ui-monospace, Consolas, monospace; white-space: nowrap; }
.cand-track { flex: 1; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, .06); overflow: hidden; }
.cand-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.candidate:first-child .cand-fill { background: linear-gradient(90deg, var(--gold), var(--accent)); }
.cand-value { width: 46px; text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* controls */
.btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.btn {
  flex: 1; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  font-size: 12px; font-weight: 600; transition: .16s ease; white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); border-color: #3c517d; background: #1e2c49; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #4f60d8, #6f7ff0); border-color: #6f7ff0; }
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, #5a6ce6, #8290ff); }
.btn-accent { background: linear-gradient(135deg, #168a78, #23b39b); border-color: #23b39b; }
.btn-accent.running { background: linear-gradient(135deg, #a05a1f, #d18a35); border-color: #d18a35; }
.btn-ghost { flex: none; background: transparent; }
.field { margin-top: 10px; }
.field label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.field .hint { color: var(--dim); }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field select, .field input[type="number"] {
  width: 100%; padding: 8px 10px; border-radius: 8px; color: var(--text);
  background: #0e1729; border: 1px solid var(--line); font-size: 12px; outline: none;
}
.field select:focus, .field input[type="number"]:focus { border-color: var(--accent); }
.switch-row { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--muted); cursor: pointer; }
.switch-row input { accent-color: var(--accent); width: 15px; height: 15px; }
.manual-help { margin-top: 9px; font-size: 11px; color: var(--gold); line-height: 1.7; background: rgba(247, 198, 107, .07); border: 1px solid rgba(247, 198, 107, .18); border-radius: 8px; padding: 8px; }

/* log */
.event-log { display: flex; flex-direction: column; gap: 5px; max-height: 150px; overflow: auto; font-size: 11px; font-family: ui-monospace, Consolas, monospace; }
.event-log div { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-log b { color: var(--accent); font-weight: 600; }
.event-log .clear b { color: var(--gold); }

/* ---------- overlays ---------- */
.hidden { display: none !important; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #2a1c2b; border: 1px solid var(--danger); color: #ffd9e0;
  padding: 11px 18px; border-radius: 10px; font-size: 12px; z-index: 50;
  box-shadow: var(--shadow);
}
.modal { position: fixed; inset: 0; background: rgba(4, 8, 18, .76); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal-card { width: min(620px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-head h2 { margin: 0; font-size: 15px; letter-spacing: 1px; }
.modal-body { padding: 18px 22px 24px; font-size: 13px; line-height: 1.9; color: var(--muted); }
.modal-body p { margin: 0 0 12px; }
.modal-body b { color: var(--text); }
.modal-body code { background: rgba(94, 234, 212, .09); color: var(--accent); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

@media (max-width: 980px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header { flex-direction: column; align-items: flex-start; }
  .header-meta { justify-content: flex-start; }
}
@media (max-width: 620px) {
  body { padding: 12px; }
  .sidebar { grid-template-columns: 1fr; }
  #board { width: 280px; }
}
