:root {
  --bg: #ffffff;
  --ink: #000000;
  --soft: #d9d9d9;
  --hair: #ececec;
  --muted: #8a8a8a;
  --frame: 1px;
  --gutter: 18px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1a1b1f;
  --ink: #e8e6e2;
  --soft: #3a3a40;
  --hair: #26262a;
  --muted: #9a958d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: .04em;
  -webkit-font-smoothing: antialiased;
}

body { min-width: 280px; }

button { font: inherit; }

button:focus-visible,
.view:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.shell {
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 12px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  border-bottom: var(--frame) solid var(--ink);
  padding-bottom: 12px;
}

.identity { display: flex; align-items: center; min-width: 0; gap: 11px; }
.identity-copy { min-width: 0; }
.mark { font-size: 26px; line-height: 1; }
.brand { font-size: 18px; font-weight: 600; letter-spacing: .18em; text-transform: lowercase; }
.subtitle { color: var(--muted); font-size: 10px; letter-spacing: .13em; text-transform: uppercase; }

.refresh {
  width: 44px;
  height: 44px;
  border: var(--frame) solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  font-size: 18px;
}

.refresh:active { background: var(--ink); color: var(--bg); }
.refresh[aria-busy="true"] { background: var(--ink); color: var(--bg); }

.live-strip {
  min-height: 36px;
  border: var(--frame) solid var(--ink);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
}

.live-strip[data-live="true"] .state-dot { animation: pulse 1.4s ease-in-out infinite; }
.read-only { color: var(--muted); white-space: nowrap; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: var(--frame) solid var(--ink);
}

.tabs button {
  min-width: 0;
  min-height: 44px;
  border: 0;
  border-right: var(--frame) solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  letter-spacing: .08em;
  text-transform: lowercase;
}

.tabs button:last-child { border-right: 0; }
.tabs button[aria-selected="true"] { background: var(--ink); color: var(--bg); }

main { min-width: 0; }
.view { display: grid; gap: 12px; min-width: 0; }
.view[hidden] { display: none; }

.data-window {
  border: var(--frame) solid var(--ink);
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  color: var(--muted);
  font-size: 10px;
}
.data-window b { color: var(--ink); font-weight: 500; text-transform: uppercase; letter-spacing: .14em; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: var(--frame) solid var(--ink);
}

.stat {
  min-width: 0;
  padding: 11px 10px;
  border-right: var(--frame) solid var(--soft);
}
.stat:nth-child(3n) { border-right: 0; }
.stat:nth-child(n+4) { border-top: var(--frame) solid var(--soft); }
.stat-value { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-label { color: var(--muted); font-size: 9px; letter-spacing: .14em; text-transform: uppercase; }

.block {
  border: var(--frame) solid var(--ink);
  padding: 18px 15px 13px;
  position: relative;
}

.num {
  position: absolute;
  top: -11px;
  left: 13px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  font-size: 11px;
  font-weight: 600;
}

.block-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.block-head span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead { margin: 7px 0 10px; font-size: 15px; letter-spacing: .02em; }
.rows { border-top: var(--frame) solid var(--soft); }

.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 6px 0;
  border-bottom: var(--frame) solid var(--hair);
  font-variant-numeric: tabular-nums;
}
.row:last-child { border-bottom: 0; }
.row .key { min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.row .value { text-align: right; white-space: nowrap; }

.list-section { border: var(--frame) solid var(--ink); }
.list-section h2 { margin: 0; padding: 8px 11px; border-bottom: var(--frame) solid var(--ink); font-size: 9px; font-weight: 500; letter-spacing: .18em; }
.list { display: grid; }

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px 12px;
  padding: 10px 11px;
  border-bottom: var(--frame) solid var(--soft);
  min-width: 0;
}
.list-item:last-child { border-bottom: 0; }
.list-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-state { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.list-state.active { background: var(--ink); color: var(--bg); padding: 1px 5px; }
.list-meta { grid-column: 1 / -1; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.empty { padding: 16px 11px; color: var(--muted); }

.graph-frame {
  border: var(--frame) solid var(--ink);
  min-height: 470px;
  overflow: hidden;
  background: var(--bg);
}
.graph-frame svg { display: block; width: 100%; height: auto; min-height: 470px; }
.graph-edge { stroke: var(--ink); stroke-width: 1; fill: none; }
.graph-edge.dashed { stroke: var(--muted); stroke-dasharray: 5 4; }
.graph-node rect { fill: var(--bg); stroke: var(--ink); stroke-width: 1; }
.graph-node.decision rect { fill: var(--ink); }
.graph-node text { fill: var(--ink); font-family: var(--mono); }
.graph-node.decision text { fill: var(--bg); }
.graph-node .node-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.graph-node .node-readout { font-size: 9px; fill: var(--muted); }
.graph-node.decision .node-readout { fill: var(--bg); opacity: .76; }
.graph-node.gate rect { stroke-dasharray: 5 4; }

.legend {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 10px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.system-state {
  min-height: 300px;
  border: var(--frame) dashed var(--ink);
  padding: 30px 20px;
  place-content: center;
  text-align: center;
}
.system-state:not([hidden]) { display: grid; }
.state-glyph { font-size: 30px; }
.system-state h2 { margin: 10px 0 2px; font-size: 13px; letter-spacing: .18em; text-transform: uppercase; }
.system-state p { margin: 0; color: var(--muted); }

footer {
  border-top: var(--frame) solid var(--ink);
  padding-top: 9px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 5px 12px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

@media (max-width: 430px) {
  .shell { --gutter: 14px; gap: 10px; }
  .brand { font-size: 17px; }
  .subtitle { font-size: 9px; }
  .live-strip { grid-template-columns: auto minmax(0, 1fr); }
  .read-only { display: none; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3n) { border-right: var(--frame) solid var(--soft); }
  .stat:nth-child(2n) { border-right: 0; }
  .stat:nth-child(n+3) { border-top: var(--frame) solid var(--soft); }
  .tabs button { font-size: 11px; letter-spacing: .04em; }
  .graph-frame, .graph-frame svg { min-height: 520px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
