:root {
  color-scheme: dark;
  --bg: #121419;
  --panel: #1a1d24;
  --sector: #22252d;
  --ind: #2a2e38;
  --line: #2f333e;
  --text: #e8eaef;
  --muted: #9ba2ae;
  --accent: #5b93ff;
  --brand: #22c55e;
  --up: #3fcf78;
  --down: #ff6b6e;
  --warn: #ffb84d;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

a { color: inherit; }

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.boards { display: flex; flex-wrap: wrap; gap: 4px; }
.boards a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  text-decoration: none;
}
.boards a b { color: var(--text); font-weight: 700; margin-right: 4px; }
.boards a:hover { background: #242936; color: var(--text); }
.boards a[aria-current="page"] { background: #2e3646; color: var(--text); box-shadow: inset 0 -2px 0 var(--brand); }
.boards a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: #2e3646; color: var(--text); }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

#map {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 8px 16px 0;
  overflow: hidden;
  background: var(--bg);
}

.sector { position: absolute; background: var(--sector); }

.sector-h, .ind-h {
  position: absolute;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-transform: uppercase;
  pointer-events: none;
}
.sector-h { padding: 0 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; line-height: 16px; color: var(--text); }
.ind-h { padding: 0 3px; font-size: 9.5px; font-weight: 600; letter-spacing: 0.03em; line-height: 13px; color: var(--muted); background: var(--ind); }

.tile {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  cursor: default;
  transition: background-color 0.6s ease;
}
.tile .t { font-weight: 700; line-height: 1; letter-spacing: 0.01em; white-space: nowrap; }
.tile .c { margin-top: 0.2em; font-weight: 600; line-height: 1.1; white-space: nowrap; font-variant-numeric: tabular-nums; opacity: 0.95; }
.tile:hover { outline: 2px solid rgba(255, 255, 255, 0.85); outline-offset: -2px; z-index: 1; }

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  padding: 8px 16px 4px;
}
.caption { display: none; white-space: nowrap; }
.caption .dim { color: var(--muted); margin-left: 4px; }

.status { display: flex; flex-wrap: wrap; gap: 2px 12px; min-width: 0; color: var(--muted); font-size: 12.5px; }
.status .src { color: var(--text); }
.status .warn { color: var(--warn); }
.status .err { color: var(--down); overflow-wrap: anywhere; }

.legend { display: flex; gap: 2px; }
.legend span {
  min-width: 40px;
  padding: 3px 6px;
  border-radius: 3px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.fine { margin: 0; padding: 0 16px 10px; color: var(--muted); font-size: 12px; }
.fine a { color: var(--text); }
.fine code { font-size: 11.5px; color: var(--text); }

.tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10;
  width: max-content;
  max-width: min(340px, calc(100vw - 16px));
  padding: 10px 12px;
  background: #1b1e26;
  border: 1px solid #3a404d;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  pointer-events: none;
}
.tip[hidden] { display: none; }
.tip-h { display: flex; align-items: baseline; gap: 8px; }
.tip-h b { font-size: 16px; }
.tip-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-sub { margin-top: 2px; color: var(--muted); font-size: 12px; }
.tip-kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0 0; }
.tip-kv dt { color: var(--muted); }
.tip-kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.tip-kv dd.up { color: var(--up); }
.tip-kv dd.down { color: var(--down); }
.tip-peers { list-style: none; margin: 10px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: grid; gap: 2px; }
.tip-peers li { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 1px 4px; border-radius: 4px; }
.tip-peers li.on { background: #2b3140; }
.tip-peers .ps { font-weight: 700; }
.tip-peers .pn { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-peers .chip { min-width: 62px; padding: 1px 5px; border-radius: 3px; color: #fff; font-size: 12px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Full screen (?style=fullscreen): the map and one caption line, sized
   to the screen; no transitions or shadows, which a Pi pays for on every
   repaint. ---- */
.fs body { cursor: none; font-size: clamp(12px, 1.5vh, 24px); }
.fs .bar, .fs .fine, .fs .tip { display: none; }
.fs #map { margin: 0.4vh 0.4vh 0; }
.fs .tile { transition: none; text-shadow: none; }
.fs .tile:hover { outline: none; }
.fs .foot { flex-wrap: nowrap; gap: 0 1.5em; padding: 0.5vh 0.8vh; }
.fs .caption { display: block; font-size: 1em; }
.fs .status { flex: 1; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; font-size: 0.9em; }
.fs .legend span { min-width: 3.2em; padding: 0.15em 0.4em; font-size: 0.85em; }

@media (max-width: 600px) {
  .bar, .foot, .fine { padding-left: 12px; padding-right: 12px; }
  #map { margin: 6px 12px 0; }
  .legend { width: 100%; }
  .legend span { flex: 1; min-width: 0; padding: 2px 0; font-size: 11px; }
  .boards a { padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
