@font-face {
  font-family: "Space Grotesk";
  src: url("./fonts/space-grotesk.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #102033;
  --dim: #3d5166;
  --line: rgba(16, 32, 51, 0.22);
  --panel: rgba(255, 250, 242, 0.94);
  --paper: #fffaf2;
  --sand: #f4ead4;
  --violet: #5b4fd6;
  --cyan: #0c6478;
  --gold: #8a5a08;
  --bad: #b4233a;
  --ok: #0d7a32;
  --serving: #1fbf4a;
  --syncing: #e39b12;
  --lagging: #d4a800;
  --down: #e23b3b;
  --fenced: #8b939c;
  --updating: #2f6dff;
  --starting: #b7c3ce;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  background: #7ec8e0;
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
}
button, input { font: inherit; color: inherit; }
button, .skip, a { cursor: pointer; }
a { color: var(--cyan); }
.skip {
  position: absolute;
  left: 8px;
  top: -48px;
  background: #fff;
  color: #041018;
  padding: 6px 10px;
  z-index: 20;
}
.skip:focus { top: 8px; }
#stage { position: fixed; inset: 0; width: 100dvw; height: 100dvh; }
#stage[hidden] { display: none; }
#view { display: block; width: 100dvw; height: 100dvh; touch-action: none; }
#labels {
  position: fixed;
  left: 0;
  top: 0;
  width: 100dvw;
  height: 100dvh;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}
.tag {
  pointer-events: auto;
  font: 600 12px/1.2 "Space Grotesk", system-ui, sans-serif;
  color: #102033;
  background: rgba(255, 250, 242, 0.94);
  border: 1px solid rgba(16, 32, 51, 0.45);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag.region {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 3px 10px;
  background: rgba(255, 248, 230, 0.96);
  border-color: #102033;
}
.tag.hq, .tag.buoy { font-size: 13px; }
.tag.gw { font-weight: 700; border-color: #8a2a2a; }
.tag.dim { opacity: 0.28; }
.tag.hot { box-shadow: 0 0 0 2px #102033; }
.topbar {
  position: fixed;
  z-index: 6;
  top: 0;
  left: 0;
  right: 0;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: var(--panel);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.res, .tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
}
.stat, .meta {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.meta { font-weight: 500; color: var(--dim); font-size: 12px; }
.badge {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
}
.badge.live { color: var(--ok); border-color: var(--ok); background: #e7f8ee; }
.badge.demo { color: var(--gold); border-color: var(--gold); background: #fff6df; }
.reconnect { color: var(--gold); font-size: 12px; font-weight: 600; }
.lives { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.life {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.life-name, .life-pct, .life-clock {
  font-size: 11px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.life-name { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
.life-bar {
  width: 54px;
  height: 8px;
  border: 1px solid #102033;
  border-radius: 99px;
  background: #fff;
  overflow: hidden;
}
.life-bar > span {
  display: block;
  height: 100%;
  background: var(--ok);
}
.life.warn .life-bar > span { background: var(--lagging); }
.life.hot .life-bar > span { background: var(--bad); }
.topbar button, #inspector button, #legend button {
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(16, 32, 51, 0.45);
  border-radius: 999px;
  padding: 4px 10px;
}
.topbar button[aria-pressed="true"], #live-btn.hot {
  border-color: var(--cyan);
  color: var(--cyan);
  background: #e7f6f8;
}
#search-form { display: flex; gap: 6px; }
#search {
  width: 9.5rem;
  background: #fff;
  border: 1px solid rgba(16, 32, 51, 0.45);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 16px;
  color: var(--ink);
}
#scrub { width: 110px; }
#replay-clock { font-size: 12px; color: var(--dim); }
.hint {
  position: fixed;
  z-index: 5;
  left: max(10px, env(safe-area-inset-left));
  top: 158px;
  margin: 0;
  max-width: min(420px, 70vw);
  color: var(--ink);
  background: rgba(255, 250, 242, 0.92);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 13px;
  pointer-events: none;
}
.hint:empty { display: none; }
#feed {
  position: fixed;
  z-index: 5;
  top: 158px;
  right: max(8px, env(safe-area-inset-right));
  width: min(240px, 42vw);
  max-height: calc(100dvh - 168px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
#feed:empty { display: none; }
.card {
  pointer-events: auto;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--cyan);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.35;
}
.card time { display: block; color: var(--dim); font-variant-numeric: tabular-nums; font-size: 11px; }
.card p { margin: 2px 0 0; }
.card.outage { border-left-color: var(--down); }
.card.delist { border-left-color: var(--syncing); }
.card.merge { border-left-color: var(--ok); }
.card.placement { border-left-color: var(--updating); }
.card.hardfork { border-left-color: var(--violet); }
#state-key {
  position: fixed;
  z-index: 5;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(52px, calc(env(safe-area-inset-bottom) + 46px));
  margin: 0;
  padding: 6px 8px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  max-width: min(440px, calc(100dvw - 16px));
  background: rgba(255, 250, 242, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}
#state-key li { display: flex; align-items: center; gap: 4px; }
.sw {
  width: 12px;
  height: 12px;
  display: inline-block;
  border: 1px solid #102033;
  flex: none;
}
.s-serving { background: var(--serving); border-radius: 99px; }
.s-syncing { background: var(--syncing); border-radius: 99px; box-shadow: 0 0 0 2px var(--syncing); }
.s-lagging { background: var(--lagging); border-radius: 2px; height: 8px; }
.s-down { background: var(--down); border-radius: 2px 8px; transform: rotate(180deg); }
.s-fenced { background: var(--fenced); border-style: dashed; }
.s-updating { background: var(--updating); transform: rotate(45deg); border-radius: 2px; }
.s-starting { background: var(--starting); border-radius: 99px; width: 8px; height: 8px; }
.foot {
  position: fixed;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 4px 10px max(4px, env(safe-area-inset-bottom));
  background: rgba(255, 250, 242, 0.94);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--ink);
  font-size: 12px;
}
.foot p { margin: 0; }
.legal { color: var(--dim); }
#inspector {
  position: fixed;
  z-index: 6;
  top: 158px;
  left: max(10px, env(safe-area-inset-left));
  width: min(320px, calc(100dvw - 20px));
  max-height: min(52dvh, 460px);
  overflow: auto;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid rgba(16, 32, 51, 0.35);
  border-radius: 14px;
  padding: 10px 12px;
}
#inspector h2 { font-size: 16px; margin: 0 0 6px; }
#inspector h3 { font-size: 13px; margin: 10px 0 4px; }
#inspector p, #inspector li { font-size: 14px; line-height: 1.4; }
#inspector ol { margin: 0; padding-left: 18px; }
#inspector time { color: var(--dim); }
#boot-error {
  position: fixed;
  z-index: 7;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(64px, env(safe-area-inset-bottom));
  max-width: min(480px, calc(100dvw - 20px));
  background: #3c1420;
  color: #ffd5dc;
  border-radius: 10px;
  padding: 8px 10px;
}
#tables {
  position: fixed;
  inset: 0;
  width: 100dvw;
  height: 100dvh;
  overflow: auto;
  z-index: 4;
  background: var(--paper);
  color: var(--ink);
  padding: 120px 12px 72px;
}
#tables[hidden] { display: none; }
#tables h2 { font-size: 16px; margin: 18px 0 6px; }
.table-wrap { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #e4d8c4; vertical-align: top; }
.quiet, .table-note { color: var(--dim); }
#legend {
  width: min(560px, calc(100dvw - 24px));
  max-height: min(80dvh, 720px);
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid rgba(16, 32, 51, 0.35);
  border-radius: 16px;
  padding: 16px;
}
#legend::backdrop { background: rgba(16, 32, 51, 0.35); }
#legend h2 { margin: 0 0 8px; font-size: 20px; }
#legend dt { font-weight: 700; margin-top: 8px; }
#legend dd { margin: 0 0 4px; color: var(--dim); }
.legend-states { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
.legend-states li { display: flex; align-items: center; gap: 8px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
@media (max-width: 700px) {
  .tools { flex-wrap: nowrap; overflow-x: auto; }
  .tag.region { font-size: 16px; }
  .hint { top: auto; bottom: 108px; }
  #inspector {
    top: auto;
    bottom: 78px;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    width: auto;
    max-height: 38dvh;
  }
  #feed { top: auto; bottom: 78px; max-height: 24dvh; width: min(168px, 46vw); }
  #state-key { bottom: 78px; max-width: 50vw; }
  #tables { padding-top: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
