:root {
  --bg: #0b1020;
  --panel: #131b30;
  --panel-2: #1a2440;
  --line: #26314f;
  --text: #eef2fa;
  --muted: #98a3bd;
  --calm: #2dd4bf;
  --warn: #f5a524;
  --danger: #f04444;
  --lock: #a78bfa;
  --motion: #60a5fa;
  --stage: var(--calm);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: 16px 24px 88px;
  min-height: 100vh;
}
body[data-stage="armed"] { --stage: var(--warn); }
body[data-stage="alerted"] { --stage: var(--danger); }
body[data-stage="locked"] { --stage: var(--lock); }

h1, h2 { margin: 0; font-weight: 650; }
h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 24px; font-weight: 750; letter-spacing: .02em; }
.brand .sub { color: var(--muted); font-size: 16px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted); }
.pill.env { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill.conn.live { color: var(--calm); }
.pill.conn.down { color: var(--danger); }
.pill.conn.replay { color: var(--lock); }

.stages { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0; margin: 20px 0; }
.stages li {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px;
  background: var(--panel); color: var(--muted); font-weight: 600; border: 1px solid transparent;
  transition: background .3s, color .3s, border-color .3s;
}
.stages .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); flex: none; }
.stages li.done { color: var(--text); }
.stages li.done .dot { background: var(--muted); }
.stages li.current { color: var(--text); border-color: var(--stage); background: color-mix(in srgb, var(--stage) 16%, var(--panel)); }
.stages li.current .dot { background: var(--stage); box-shadow: 0 0 0 4px color-mix(in srgb, var(--stage) 30%, transparent); }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas:
    "hero hero ai"
    "hero hero evidence"
    "charts charts hr"
    "charts charts timeline";
}
.card { background: var(--panel); border-radius: 14px; padding: 18px 20px; border: 1px solid var(--line); min-width: 0; }
.hero { grid-area: hero; display: flex; align-items: center; justify-content: space-between; gap: 24px;
        border-color: var(--stage); background: color-mix(in srgb, var(--stage) 10%, var(--panel)); transition: background .4s, border-color .4s; }
.ai { grid-area: ai; }
.evidence { grid-area: evidence; }
.hr { grid-area: hr; }
.charts { grid-area: charts; }
.timeline { grid-area: timeline; }

.hero h1 { font-size: clamp(32px, 4.4vw, 56px); line-height: 1.05; color: var(--stage); transition: color .4s; }
.hero p { font-size: clamp(16px, 1.5vw, 21px); margin: 12px 0 0; max-width: 40ch; }
.hero .hero-note { color: var(--muted); font-size: 15px; }

.ring { position: relative; width: clamp(130px, 14vw, 190px); aspect-ratio: 1; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-track { stroke: var(--line); }
.ring-fill { stroke: var(--stage); stroke-linecap: round; stroke-dasharray: 326.73; transition: stroke-dashoffset .2s linear; }
.ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-label span { font-size: clamp(38px, 4.5vw, 60px); font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.ring-label small { color: var(--muted); }

.activity { font-size: 30px; font-weight: 700; margin: 10px 0 14px; }
.activity.attack { color: var(--danger); }
.meter-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.meter-label strong { color: var(--text); font-variant-numeric: tabular-nums; font-size: 18px; }
.meter { height: 14px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--calm), var(--warn) 55%, var(--danger)); transition: width .4s; }

.evidence-bar { position: relative; height: 26px; background: var(--panel-2); border-radius: 8px; margin: 34px 0 6px; }
.evidence-fill { height: 100%; width: 0; border-radius: 8px; background: var(--stage); transition: width .4s, background .4s; }
.mark { position: absolute; top: -6px; bottom: -6px; width: 2px; background: var(--warn); }
.mark.alert { background: var(--danger); }
.mark span { position: absolute; bottom: 100%; transform: translateX(-50%); white-space: nowrap; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.mark.alert span { transform: translateX(-90%); }

.hr-value { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; }
.hr-value span { font-size: 54px; font-weight: 750; font-variant-numeric: tabular-nums; }
.hr-value small { color: var(--muted); font-size: 16px; }

.chart-head { display: flex; justify-content: space-between; align-items: baseline; margin: 2px 0 6px; }
.chart-head + canvas + .chart-head { margin-top: 16px; }
canvas { width: 100%; height: 150px; display: block; }
.legend { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.lg-ev { background: var(--text); }
.lg-p { background: color-mix(in srgb, var(--danger) 60%, transparent); height: 10px !important; margin-left: 8px; }

.timeline ol { list-style: none; margin: 10px 0 0; padding: 0; max-height: 360px; overflow: auto; }
.timeline li { display: grid; grid-template-columns: 74px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline time { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .k-prompt { color: var(--warn); }
.timeline .k-alert, .timeline .k-status-attack, .timeline .k-status-panic { color: var(--danger); }
.timeline .k-lock { color: var(--lock); }
.timeline .k-user-cleared, .timeline .k-disarm, .timeline .k-prompt-cancelled { color: var(--calm); }
.timeline .src { display: block; color: var(--muted); font-size: 12px; }
.timeline .empty { display: block; color: var(--muted); }

.controls {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line);
}
button, .button, select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 14px; cursor: pointer;
}
button:hover, .button:hover { border-color: var(--muted); }
.button input { display: none; }
.replay { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 260px; }
.replay[hidden] { display: none; }
.replay input[type=range] { flex: 1; accent-color: var(--lock); }

@media (max-width: 980px) {
  body { padding: 16px 16px 140px; }
  .grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "hero" "ai" "evidence" "charts" "hr" "timeline"; }
  .hero { flex-direction: column; align-items: flex-start; }
  .stages { grid-template-columns: repeat(2, 1fr); }
}
