:root {
  --dim-bg: #050505;
  --dim-field: #111111;
  --dim-low: #242424;
  --dim-mid-low: #454545;
  --dim-mid: #6b6b6b;
  --dim-high: #9a9a9a;
  --dim-label: #d8d8d8;
  --dim-white: #f4f4f4;
  --dim-muted: #b8b8b8;
  --font: ui-monospace, "IBM Plex Mono", "Roboto Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080808;
  color: var(--dim-label);
  font-family: var(--font);
}

body {
  display: grid;
  place-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.monitor-shell {
  width: min(98vw, 1800px);
  height: min(96vh, 1100px);
  padding: clamp(9px, 1.1vw, 18px);
  padding-bottom: clamp(18px, 2.2vw, 32px);
  border: 1px solid #303030;
  border-radius: clamp(7px, 1vw, 14px);
  background:
    linear-gradient(145deg, #2c2c2c 0%, #111 16%, #050505 60%, #1c1c1c 100%);
  box-shadow:
    0 26px 70px rgba(0,0,0,.65),
    inset 0 1px 0 #494949,
    inset 0 -2px 5px #000;
  position: relative;
}

.monitor-shell::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 7px;
  width: 36%;
  max-width: 380px;
  height: 4px;
  transform: translateX(-50%);
  background: #111;
  border-radius: 999px;
  box-shadow: inset 0 1px 1px #000, 0 1px 0 #333;
}

.viewport {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 48%, #161616 0%, #080808 55%, #030303 100%);
  border: 1px solid #555;
  border-radius: 2px;
  box-shadow: inset 0 0 45px #000;
  cursor: grab;
}

.viewport:active { cursor: grabbing; }

.viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  opacity: .18;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,.025) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 45%, transparent 0 58%, rgba(0,0,0,.38) 100%);
  mix-blend-mode: screen;
}

.title-block {
  position: absolute;
  z-index: 20;
  left: clamp(12px, 1.5vw, 24px);
  top: clamp(11px, 1.4vw, 22px);
  pointer-events: none;
}

.title-block a {
  pointer-events: auto;
  color: inherit;
  font: inherit;
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,.42);
}

.title-block a:hover,
.title-block a:focus-visible {
  border-bottom-color: rgba(255,255,255,.95);
  outline: none;
}

h1 {
  margin: 0;
  color: var(--dim-white);
  font: 500 clamp(11px, 1vw, 14px)/1.25 var(--font);
  letter-spacing: .035em;
  text-transform: none;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  outline: none;
}

#map:focus,
#map:focus-visible {
  outline: none;
  box-shadow: none;
}

.state-soft {
  fill: none;
  stroke: #d8d8d8;
  stroke-width: 6;
  opacity: .16;
  vector-effect: non-scaling-stroke;
  filter: url(#soft-edge);
}

.state {
  fill: #757575;
  fill-opacity: .52;
  stroke: #dedede;
  stroke-opacity: .78;
  stroke-width: .85;
  vector-effect: non-scaling-stroke;
  filter: url(#tissue);
  transition: fill-opacity 160ms linear, stroke-opacity 160ms linear;
}

.state:hover {
  fill-opacity: .68;
  stroke-opacity: 1;
  stroke-width: 1.25;
}

.state,
.state:focus,
.state:focus-visible,
svg path:focus,
svg path:focus-visible {
  outline: none !important;
}

.loading {
  position: absolute;
  z-index: 25;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  color: var(--dim-muted);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  background: #050505;
  transition: opacity 220ms ease;
}

.loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading.is-error {
  color: var(--dim-white);
  padding: 24px;
  text-align: center;
  line-height: 1.7;
}

.loading-mark {
  width: 52px;
  height: 2px;
  justify-self: center;
  background: #9a9a9a;
  box-shadow: 0 0 10px #d8d8d8;
  animation: load 1.1s ease-in-out infinite alternate;
}

@keyframes load {
  from { transform: scaleX(.2); opacity: .35; }
  to { transform: scaleX(1); opacity: 1; }
}

.info-button {
  position: absolute;
  z-index: 10001;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(5,5,5,.72);
  color: #d8d8d8;
  font: 500 16px/1 var(--font);
  cursor: pointer;
}

.info-button:hover,
.info-button:focus-visible {
  color: #fff;
  outline: 1px solid #d8d8d8;
  outline-offset: -5px;
}

.corner-readout {
  position: absolute;
  z-index: 10;
  left: 15px;
  bottom: 13px;
  color: #777;
  font-size: 8px;
  letter-spacing: .12em;
  pointer-events: none;
}

.sources-dialog {
  z-index: 10000;
  width: min(92vw, 520px);
  max-height: min(82vh, 700px);
  margin: auto;
  overflow: auto;
  border: 1px solid #6b6b6b;
  border-radius: 2px;
  background: #080808;
  color: #d8d8d8;
  box-shadow: 0 24px 80px #000;
  padding: 26px;
  font: 11px/1.65 var(--font);
  user-select: text;
}

.sources-dialog::backdrop {
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(2px);
}

.sources-dialog h2 {
  margin: 0 0 18px;
  color: #f4f4f4;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sources-dialog dl { margin: 0; }
.sources-dialog dt { margin-top: 13px; color: #9a9a9a; }
.sources-dialog dd { margin: 2px 0 0; }
.sources-dialog a { color: #f4f4f4; text-decoration-color: #6b6b6b; }
.sources-dialog a:hover { text-decoration-color: #f4f4f4; }

.dialog-close {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #b8b8b8;
  font: 22px/1 var(--font);
  cursor: pointer;
}

.made-with {
  margin: 22px 0 0;
  padding-top: 14px;
  border-top: 1px solid #242424;
  color: #9a9a9a;
}

@media (max-width: 700px) {
  .monitor-shell {
    width: 100vw;
    height: 100dvh;
    padding: 5px;
    border: 0;
    border-radius: 0;
    background: #111;
    box-shadow: inset 0 0 0 1px #333;
  }
  .monitor-shell::after { display: none; }
  .viewport { border-color: #2f2f2f; }
  .corner-readout { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* Robust modal fallback for browsers with incomplete <dialog> support. */
.sources-dialog[open] {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

body.modal-open .monitor-shell {
  pointer-events: none;
}

body.modal-open .sources-dialog,
body.modal-open .sources-dialog * {
  pointer-events: auto;
}
