:root {
  --bg: #f8f8f8;
  --card: #ffffff;
  --fg: #111111;
  --muted: #666666;
  --dim: #9a9a9a;
  --line: #dddddd;
  --line-soft: #eeeeee;
  --accent: #111111;
  --link: #111111;
  --ok: #11936b;
  --warn: #b45309;
  --err: #b91c1c;
  --pill-bg: #f2f2f2;
  --tag-bg: #f2f2f2;
  --tag-fg: #111111;
  --tag-intl-bg: #f2f2f2;
  --tag-intl-fg: #111111;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 0 rgba(0, 0, 0, 0.03);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --card: #111111;
  --fg: #ffffff;
  --muted: #bdbdbd;
  --dim: #777777;
  --line: #333333;
  --line-soft: #222222;
  --accent: #ffffff;
  --link: #ffffff;
  --ok: #36d399;
  --warn: #fbbf24;
  --err: #f87171;
  --pill-bg: #222222;
  --tag-bg: #222222;
  --tag-fg: #ffffff;
  --tag-intl-bg: #222222;
  --tag-intl-fg: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.02);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Top navigation */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in oklab, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topnav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--fg) !important;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: var(--accent);
  color: var(--card);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1;
}
.brand-text { letter-spacing: -0.005em; }

.tabs {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
  position: relative;
}
.tab:hover { color: var(--fg); background: var(--line-soft); }
.tab[aria-selected="true"] {
  color: var(--fg);
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 600;
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 12px; right: 12px;
  bottom: -1px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.topnav-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.iconbtn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color .12s ease, border-color .12s ease;
}
.iconbtn:hover { color: var(--accent); border-color: var(--accent); }

/* One-panel-at-a-time */
.panel { display: none; animation: fadein .18s ease; }
.panel.active { display: block; }
.panel[data-panel="overview"].active {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 14px;
  align-items: stretch;
}
.panel[data-panel="overview"] .card {
  margin-bottom: 0;
}
.panel[data-panel="overview"] .map-card {
  display: flex;
  flex-direction: column;
}
.panel[data-panel="overview"] .map {
  flex: 1;
  min-height: 320px;
}
.panel[data-panel="overview"] .region .kv .row {
  padding: 14px 0;
  font-size: 15px;
}
.panel[data-panel="overview"] .region .kv .note {
  font-size: 12.5px;
}
.panel[data-panel="overview"] .region .kv .value {
  font-size: 14px;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 36px 20px 64px;
}

.hero {
  padding: 8px 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 18px;
  align-items: center;
}
.hero h1 {
  margin: 0 0 6px 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.hero .lede {
  margin: 0;
  color: var(--muted);
  font-size: 14.5px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  grid-column: 2;
  grid-row: 1 / 3;
}
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: 12.5px;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--card);
  border-color: var(--accent);
}
.chip.ghost { color: var(--muted); }

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 10px;
}
.card-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
  min-width: 0;
}
.card-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.card-head .small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.region-tag {
  background: var(--tag-bg);
  color: var(--tag-fg);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.region-tag.intl { background: var(--tag-intl-bg); color: var(--tag-intl-fg); }

.status {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}
.status::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--dim);
  vertical-align: middle;
}
.status.ok::before { background: var(--ok); }
.status.warn::before { background: var(--warn); }
.status.err::before { background: var(--err); }

.kv { display: block; }
.kv .row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 13px;
  align-items: baseline;
}
.kv .row:first-child { border-top: 0; padding-top: 4px; }
.kv .label {
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}
.kv .name {
  color: var(--fg);
  font-weight: 500;
}
.kv .note {
  color: var(--dim);
  font-size: 11.5px;
}
.kv .value {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
  background: var(--pill-bg);
  color: var(--muted);
  text-transform: uppercase;
}
.pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.ok,
.pill.warn,
.pill.err { color: var(--muted); }
.pill.ok .dot { background: var(--ok); }
.pill.warn .dot { background: var(--warn); }
.pill.err .dot { background: var(--err); }
.pill.dim { color: var(--dim); }

.skeleton {
  display: inline-block;
  min-width: 110px;
  height: 11px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--line-soft), color-mix(in oklab, var(--line-soft) 40%, var(--line)), var(--line-soft));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  vertical-align: middle;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.more-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.more {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 12px;
  color: var(--fg) !important;
  text-decoration: none;
  transition: border-color .12s ease, transform .12s ease;
  box-shadow: var(--shadow);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.more:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.more-title { font-weight: 600; font-size: 13.5px; }
.more-sub { grid-column: 1 / 2; color: var(--muted); font-size: 12px; }
.more-arrow { grid-row: 1 / 3; font-size: 18px; color: var(--accent); }

.conn-group + .conn-group { margin-top: 12px; }
.conn-title {
  margin: 0 0 8px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.conn-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 8px;
}
.conn-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  font-size: 12.5px;
  position: relative;
  min-width: 0;
}
.conn-cell .conn-icon {
  width: 18px; height: 18px;
  border-radius: 4px;
  background: var(--line-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.conn-cell .conn-icon img { width: 18px; height: 18px; object-fit: contain; }
.conn-cell .conn-name { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-cell .conn-latency { font-family: var(--mono); font-size: 11px; color: var(--muted); flex-shrink: 0; }.conn-cell .conn-latency.fast { color: var(--ok); }
.conn-cell .conn-latency.medium { color: var(--warn); }
.conn-cell .conn-latency.slow,
.conn-cell .conn-latency.blocked { color: var(--err); }
.conn-cell.ok { border-color: var(--line); }
.conn-cell.err { border-color: var(--line); opacity: .75; }
.conn-cell.err .conn-latency { color: var(--err); }

body[data-hide~="ip"] .kv .value { filter: blur(6px); transition: filter .15s ease; }
body[data-hide~="ip"] .kv .value:hover { filter: none; }
body[data-hide~="location"] #map,
body[data-hide~="location"] #location-summary { filter: blur(10px); transition: filter .15s ease; }
body[data-hide~="location"] #map:hover,
body[data-hide~="location"] #location-summary:hover { filter: none; }

.map-card { padding-bottom: 14px; }
.map {
  width: 100%;
  height: 320px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--line-soft);
}
.map-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--muted);
  font-size: 13px;
}
.map-foot { margin: 10px 0 0 0; }
.map-card .card-head #location-summary { flex: 1; min-width: 0; }
.map-provider {
  margin-left: auto;
  font: inherit;
  font-size: 12px;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 24px 4px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 12px) 50%,
    calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.map-provider:hover { border-color: var(--fg); }
.map-provider:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
:root[data-theme="dark"] .leaflet-tile { filter: brightness(0.85) saturate(0.9); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

@media (max-width: 720px) {
  .page { padding: 24px 14px 48px; }
  .hero { grid-template-columns: 1fr; }
  .hero h1 { font-size: 24px; }
  .toolbar { grid-column: 1; grid-row: auto; justify-content: flex-start; padding-top: 8px; }
  .grid.two, .more-links { grid-template-columns: 1fr; }
  .card { padding: 14px 14px; }
  .card-head { align-items: flex-start; gap: 2px 10px; }
  .card-head .small { flex-basis: 100%; }
  .panel[data-panel="overview"].active { grid-template-columns: 1fr; }
  .panel[data-panel="overview"] .card { margin-bottom: 0; }
  .kv .row { grid-template-columns: max-content minmax(0, 1fr); gap: 10px; padding: 9px 0; }
  .conn-grid { grid-template-columns: 1fr; }
  .more { grid-template-columns: 1fr; }
  .more-arrow { display: none; }
}

.credit {
  position: fixed;
  right: 0;
  bottom: 0;
  padding: 2px 5px;
  font-size: 10px;
  line-height: 1;
  color: var(--muted, #888);
  text-decoration: none;
  opacity: 0.6;
  z-index: 1000;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.credit:hover { opacity: 1; color: var(--accent, #fff); text-decoration: underline; }
