:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --bg-2: #12151b;
  --line: rgba(232, 213, 163, 0.14);
  --text: #ece7dc;
  --muted: #9a9386;
  --amber: #e8d5a3;
  --danger: #ff6b5a;
  --ok: #9ddeb5;
  --wait: #f0b45a;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  overflow-x: clip;
}

button, input, select {
  font: inherit;
  color: inherit;
}

#app { height: 100%; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.card {
  width: min(420px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
}

.card h1 {
  margin: 0 0 8px;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.card p, .muted { color: var(--muted); }

label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }

input {
  width: 100%;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  min-height: 44px;
}

button.ghost.on {
  background: rgba(232, 213, 163, 0.16);
  color: var(--amber);
}

button.primary, button.ghost, a.ghost, select, .zoom button {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 8px 14px;
  min-height: 44px;
  cursor: pointer;
}

a.ghost {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--amber);
}

.share {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.share input {
  flex: 1;
  min-width: 0;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  padding: 8px 10px;
  min-height: 40px;
}

button.primary {
  background: var(--amber);
  color: #1a1408;
  border-color: transparent;
  margin-top: 18px;
}

.error { color: var(--danger); min-height: 1.2em; }

.shell {
  height: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(112px, 18vh) minmax(0, 1fr);
}

.shell.no-map {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.shell.no-map .stage { display: none; }

.shell > * { min-width: 0; }

.insight {
  margin: 0;
  padding: 8px 16px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  letter-spacing: -0.01em;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
  max-width: 100%;
}

.filters input {
  width: min(280px, 100%);
  min-height: 40px;
  flex: 1 1 180px;
}

.chip {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

.chip.on {
  color: #1a1408;
  background: var(--amber);
  border-color: transparent;
}

.tip {
  position: fixed;
  z-index: 8;
  max-width: min(280px, calc(100vw - 24px));
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #171b22;
  font-size: 12px;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.verdict {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 107, 90, 0.12);
  color: #ffd2cb;
}

.verdict.calm {
  background: rgba(157, 222, 181, 0.1);
  color: var(--ok);
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  letter-spacing: 0.01em;
  background: rgba(240, 180, 90, 0.14);
  color: var(--wait);
}

.pill.bad { background: rgba(255, 107, 90, 0.16); color: #ffb1a8; }
.pill.ok { background: rgba(157, 222, 181, 0.12); color: var(--ok); }

.kicker {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.span-title {
  font-size: 15px;
}

.faults { display: flex; flex-direction: column; gap: 6px; }

.fault {
  text-align: left;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  min-height: 40px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
}

.fault.on { border-color: rgba(255, 107, 90, 0.7); background: rgba(255, 107, 90, 0.08); }

.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 99px;
  display: inline-block;
}

.swatch.bad { background: var(--danger); }
.swatch.run { background: var(--wait); }
.swatch.ok { background: var(--ok); }

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 600;
  letter-spacing: -0.04em;
}

.brand span { color: var(--amber); }

.top .spacer { flex: 1; }

select { background: #0b0d11; padding: 6px 12px; }

.banner {
  background: #2a2114;
  color: var(--amber);
  padding: 6px 16px;
  font-size: 13px;
}

.stage { position: relative; min-height: 0; }

canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }

.timeline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  min-height: 0;
  border-top: 1px solid var(--line);
}

.cascade {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  background: #0e1116;
}

.cascade-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.cascade-head strong {
  letter-spacing: -0.03em;
  margin-right: 4px;
}

.cascade-head span { color: var(--muted); font-size: 13px; }

.cascade-head input {
  width: 168px;
  flex: 0 1 168px;
  min-height: 36px;
  margin-left: auto;
  padding: 6px 10px;
  font-size: 13px;
}

.cascade-context { min-width: 0; }

.brief {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 14px 8px;
  background: #0e1116;
}

.brief-item {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
  cursor: pointer;
}

.brief-item.heavy {
  color: var(--amber);
  border-color: rgba(232, 213, 163, 0.55);
}

.brief-note { color: var(--wait); font-size: 12px; }

.ruler {
  display: grid;
  grid-template-columns: 52px minmax(0, 1.1fr) 72px minmax(80px, 1fr);
  gap: 8px;
  padding: 6px 14px 2px;
}

.ruler-lane { position: relative; height: 14px; }

.ruler-lane i {
  position: absolute;
  top: 0;
  color: var(--muted);
  font-style: normal;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translateX(-50%);
}

.ruler-lane i.end { transform: translateX(-100%); }

.cascade .pad { padding: 16px 14px; }

.rows { overflow: auto; min-height: 0; }

.phase {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 14px 4px;
  color: var(--amber);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: #12151b;
}

.step {
  width: 100%;
  display: grid;
  grid-template-columns: 52px minmax(0, 1.1fr) 72px minmax(80px, 1fr);
  gap: 8px;
  align-items: center;
  padding: 7px 14px;
  border: 0;
  border-bottom: 1px solid rgba(232, 213, 163, 0.06);
  background: transparent;
  text-align: left;
  cursor: pointer;
  min-height: 36px;
}

.step:hover { background: rgba(232, 213, 163, 0.05); }
.step.on { background: rgba(232, 213, 163, 0.1); box-shadow: inset 2px 0 0 var(--amber); }
.step.bad .name, .step.bad .took { color: var(--danger); }
.step.wait .name { color: var(--wait); }

.when, .took {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
}

.name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.name em {
  margin-left: 8px;
  color: var(--wait);
  font-style: normal;
  font-size: 12px;
}

.step.heavy .took { color: var(--amber); }

.lane {
  position: relative;
  height: 8px;
  border-radius: 99px;
  background: rgba(232, 213, 163, 0.08);
}

.lane i {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 99px;
  background: var(--ok);
}

.step.bad .lane i { background: var(--danger); }
.step.wait .lane i { background: var(--wait); }

.duration {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.04em;
}

.share-of {
  margin: -4px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.span-nav {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.text-btn:disabled {
  opacity: 0.35;
  cursor: default;
  text-decoration: none;
}

.command {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #0b0d11;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--amber);
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.labels {
  border-right: 1px solid var(--line);
  padding-top: 28px;
  overflow: hidden;
}

.label {
  height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trace-canvas { position: relative; min-width: 0; min-height: 280px; }

.zoom {
  display: flex;
  gap: 6px;
}

.zoom button {
  width: 44px;
  padding: 0;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-width: 0;
  max-width: 100%;
}

#timeline { touch-action: pan-y; }

.drawer {
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
  background: #10131a;
}

.drawer h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 560;
  letter-spacing: -0.03em;
}

.drawer dl { margin: 0; }
.drawer dt { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; margin-top: 12px; }
.drawer dd { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, monospace; font-size: 12px; }

.stats { display: flex; gap: 14px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stats strong { color: var(--text); font-weight: 560; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

@supports (height: 100dvh) {
  .login, .shell { min-height: 100dvh; }
}

@media (max-width: 960px) {
  .shell {
    height: auto;
    grid-template-rows: auto auto auto minmax(140px, 24vh) auto;
  }

  .shell.no-map { grid-template-rows: auto auto auto auto; }

  .ruler { display: none; }

  .cascade-head input { flex-basis: 100%; width: 100%; margin-left: 0; }

  .top {
    flex-wrap: wrap;
    gap: 10px;
    padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  }

  .stats {
    order: 5;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px 14px;
  }

  .timeline {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(320px, 55vh) auto;
  }

  .cascade { grid-row: 1; }

  .drawer {
    grid-column: 1;
    grid-row: 2;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: none;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .step { grid-template-columns: 48px minmax(0, 1fr) 64px; padding-right: 10px; }
  .lane { display: none; }
}

@media (max-width: 560px) {
  .tools {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .filters input { flex-basis: 100%; }
}

@media (max-width: 420px) {
  .chip, button.ghost, select { padding-left: 10px; padding-right: 10px; }
}
