:root {
  --bg: #101614;
  --surface: #18211e;
  --surface-2: #212c28;
  --line: #31403a;
  --text: #e8f2ec;
  --muted: #93a69c;
  --accent: #e2f36a;
  --accent-ink: #1a2208;
  --live: #143528;
  --live-ink: #d8ffe8;
  --live-line: #3ddc97;
  --down: #3a161c;
  --down-ink: #ffd9de;
  --down-line: #ff5a6a;
  --font: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", "Segoe UI Mono", monospace;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.mark {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
}
.brand h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: -0.04em; }
.top-status { display: flex; gap: 8px; align-items: center; }
#key-state, .lamp {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--surface);
}
#key-state[data-ready="no"] { color: var(--down-ink); border-color: var(--down-line); }
#key-state[data-ready="yes"] { color: var(--live-ink); border-color: var(--live-line); }
.lamp[data-phase="idle"] { background: var(--down); color: var(--down-ink); border-color: var(--down-line); }
.lamp[data-phase="live"] { background: var(--live); color: var(--live-ink); border-color: var(--live-line); }
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  flex: 0 0 auto;
  min-height: 44px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0 14px;
}
.tabs button[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.panel { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.sheet { max-width: 1100px; }
.sheet-head h1 { margin: 0 0 8px; font-size: 32px; letter-spacing: -0.04em; }
.kicker, .endpoint, .meta, .muted, .empty { color: var(--muted); }
.kicker { margin: 0 0 4px; text-transform: uppercase; letter-spacing: 0.14em; font-size: 12px; }
.lede { margin: 0 0 8px; max-width: 68ch; }
.endpoint { margin: 0; font-family: var(--mono); font-size: 13px; }
.filters, .row-actions, .rule-grid { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 16px 0; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); min-width: 140px; }
input, select {
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 0 12px;
}
button.primary, .filters button, .row-actions button, .rule-buttons button, .sim button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.ghost, .rule-buttons button[aria-pressed="false"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.rule-buttons { display: grid; gap: 8px; }
.rule-buttons button { text-align: left; }
.rule-buttons button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.banner, .note {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
}
.banner { border-color: var(--down-line); color: var(--down-ink); background: var(--down); }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; background: var(--surface); }
pre {
  overflow: auto;
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}
.live-window {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid var(--down-line);
  background: var(--down);
  color: var(--down-ink);
  border-radius: 16px;
  padding: 16px;
  margin: 8px 0 16px;
}
.live-window[data-phase="ringing"],
.live-window[data-phase="active"] {
  background: var(--live);
  color: var(--live-ink);
  border-color: var(--live-line);
}
.live-lamp {
  width: 16px;
  height: 16px;
  margin-top: 4px;
  border-radius: 99px;
  background: currentColor;
  flex: 0 0 auto;
}
.live-window[data-phase="ringing"] .live-lamp,
.live-window[data-phase="active"] .live-lamp {
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.live-kicker { margin: 0; text-transform: uppercase; letter-spacing: 0.14em; font-size: 12px; }
.live-title { margin: 2px 0; font-size: 22px; letter-spacing: -0.03em; }
.live-detail, .log-item { margin: 0; }
.log { display: grid; gap: 8px; margin-top: 8px; }
.log-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.log-item strong { font-weight: 600; }
.tree { display: grid; gap: 8px; margin: 8px 0 16px; }
.tree-step {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 12px 12px 0;
}
.step-no {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 99px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
}
.split { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .split { grid-template-columns: 1.1fr 0.9fr; align-items: start; }
}
@media (max-width: 720px) {
  .top { align-items: flex-start; flex-direction: column; }
  .brand h1, .sheet-head h1 { font-size: 26px; }
  .panel { padding: 12px; }
}
.event-log {
  min-height: 62vh;
  max-height: 72vh;
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0c1210;
  padding: 4px 14px 14px;
}
.event-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.event-row pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}
@media (prefers-reduced-motion: reduce) {
  .live-lamp { animation: none; }
}
