:root {
  --lift: #16a34a;
  --drag: #f97316;
  --hot: #ef4444;
  --cold: #2563eb;
  --ink: #10243e;
  --ink-2: #3c5a7d;
  --muted: #5b7290;
  --line: #d5e3f2;
  --card: #ffffff;
  --bg: #eef5fd;
  --bg-2: #dcebfb;
  --r-md: 14px;
  --r-lg: 22px;
  --shadow: 0 2px 4px rgba(16, 36, 62, .06), 0 10px 26px rgba(16, 36, 62, .09);
  --font: "Nunito", "Segoe UI Rounded", "SF Pro Rounded", system-ui, -apple-system,
          "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 78% -8%, #ffffff 0%, rgba(255, 255, 255, 0) 62%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { color: var(--cold); display: flex; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.15rem; letter-spacing: .2px; }
.brand-text em { font-style: normal; font-size: .78rem; color: var(--muted); }

/* ---------------------------------------------------------------- layout */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(290px, 30vw, 380px);
  gap: clamp(12px, 2vw, 22px);
  padding: clamp(12px, 2vw, 22px);
  align-items: stretch;
}

.stagewrap {
  position: relative;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #f7fbff, #e9f2fc);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
  min-height: 340px;
}
#stage { display: block; width: 100%; height: 100%; }

/* ------------------------------------------------------------------- hud */
.hud {
  position: absolute; top: 12px; left: 12px;
  display: flex; align-items: center; gap: 8px;
}
.hud-badge {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 5px 10px;
  font-size: .82rem; font-weight: 700; color: var(--ink-2);
  box-shadow: 0 2px 6px rgba(16, 36, 62, .08);
}
.hud-badge .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--lift);
  transition: background .25s;
}
.hud-badge.warn .dot { background: #eab308; }
.hud-badge.bad .dot { background: var(--hot); }
.hud-stall {
  background: var(--hot); color: #fff; font-weight: 900; letter-spacing: .5px;
  padding: 5px 12px; border-radius: 999px; font-size: .9rem;
  box-shadow: 0 0 0 0 rgba(239,68,68,.6);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70%  { box-shadow: 0 0 0 12px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

/* ---------------------------------------------------------------- legend */
.legend {
  position: absolute; top: 12px; right: 12px;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 10px;
  box-shadow: 0 2px 6px rgba(16, 36, 62, .08);
  text-align: center;
}
.legend-label { font-size: .68rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.legend-bar {
  height: 10px; width: 130px; border-radius: 5px; margin: 5px 0 3px;
  background: linear-gradient(90deg, #2563eb, #16a34a, #facc15, #ef4444);
}
.legend-ends { display: flex; justify-content: space-between; font-size: .62rem; color: var(--muted); }
.legend-note { margin: 4px 0 0; font-size: .68rem; color: var(--ink-2); }
.legend-note b { color: var(--ink); }

/* ----------------------------------------------------------------- panel */
.panel {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: clamp(14px, 2vw, 20px);
  display: flex; flex-direction: column; gap: 14px;
  overflow: auto;
}
.panel h1 { margin: 0; font-size: 1.3rem; }
.lead { margin: 0; font-size: .85rem; line-height: 1.45; color: var(--ink-2); }

.viewsw { display: flex; gap: 6px; background: #eef5fd; border-radius: 12px; padding: 4px; }
.viewsw button {
  flex: 1; font: inherit; font-size: .78rem; font-weight: 800; cursor: pointer;
  border: 0; border-radius: 9px; padding: 8px 6px; color: var(--ink-2);
  background: transparent; transition: background .15s, color .15s, box-shadow .15s;
}
.viewsw button:hover { color: var(--cold); }
.viewsw button.active { background: #fff; color: var(--cold); box-shadow: 0 1px 4px rgba(16,36,62,.14); }

.control { display: flex; flex-direction: column; gap: 6px; }
.control label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: .82rem; font-weight: 800; color: var(--ink-2);
}
.control output {
  font-variant-numeric: tabular-nums;
  background: #eef5fd; color: var(--cold);
  border-radius: 8px; padding: 1px 8px; font-weight: 800;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; border-radius: 4px; outline: none;
  background: linear-gradient(90deg, #cfe3fa, #7fb2ec);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 3px solid var(--cold);
  box-shadow: 0 2px 6px rgba(16, 36, 62, .25);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 3px solid var(--cold);
}
.ticks { display: flex; justify-content: space-between; font-size: .62rem; color: var(--muted); }

/* -------------------------------------------------------------- readouts */
.readouts { display: flex; flex-direction: column; gap: 10px; }
.readout .ro-head { display: flex; justify-content: space-between; font-size: .8rem; font-weight: 800; }
.readout.lift .ro-head span { color: var(--lift); }
.readout.drag .ro-head span { color: var(--drag); }
.readout .ro-head b { font-variant-numeric: tabular-nums; }
.bar { height: 12px; border-radius: 6px; background: #eef2f7; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; width: 0%; border-radius: 6px; transition: width .18s ease; }
.readout.lift .bar i { background: linear-gradient(90deg, #4ade80, var(--lift)); }
.readout.drag .bar i { background: linear-gradient(90deg, #fdba74, var(--drag)); }
.ratio { font-size: .78rem; color: var(--muted); text-align: right; }
.ratio b { color: var(--ink); }

/* --------------------------------------------------------------- presets */
.presets { display: flex; gap: 8px; flex-wrap: wrap; }
.presets button {
  flex: 1 1 auto;
  font: inherit; font-size: .8rem; font-weight: 800;
  padding: 9px 10px; border-radius: 11px; cursor: pointer;
  border: 1.5px solid var(--line); background: #f6faff; color: var(--ink-2);
  transition: transform .1s, border-color .15s, background .15s;
}
.presets button:hover { border-color: var(--cold); background: #eaf3ff; }
.presets button:active { transform: scale(.97); }
.presets button[data-preset="stall"]:hover { border-color: var(--hot); background: #fff0f0; color: #b91c1c; }

.tipline { margin: auto 0 0; font-size: .76rem; color: var(--muted); line-height: 1.4; border-top: 1px dashed var(--line); padding-top: 10px; }
.tipline b { color: var(--hot); }

/* ---------------------------------------------------------------- footer */
.sitefoot {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; font-size: .8rem; color: var(--muted);
  border-top: 1px solid var(--line); background: rgba(255,255,255,.7);
}
.sitefoot b { color: var(--ink-2); }
.sitefoot a { color: var(--cold); text-decoration: none; font-weight: 700; }
.sitefoot a:hover { text-decoration: underline; }
.sitefoot .sep { opacity: .5; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .stagewrap { min-height: 300px; }
  .legend { top: auto; bottom: 12px; right: 12px; }
}
