/* Design tokens: dark NOC theme by default, clean daylight theme in light mode. */
:root {
  --bg-base: rgba(6, 9, 14, 0.9);
  --bg-card: rgba(13, 20, 31, 0.75);
  --border-card: rgba(30, 58, 86, 0.6);
  --accent-best: #00ff88;
  --accent-backup: #00e5ff;
  --accent-local: #ff5722;
  --accent-transit: #c084fc;
  --accent-invalid: #ff4d4d;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --bg-input: rgba(6, 9, 14, 0.8);
  --bg-pre: rgba(6, 9, 14, 0.85);
  --bg-topbar: rgba(6, 9, 14, 0.9);
  --bg-grid: rgba(30, 58, 86, 0.25);
  --bg-community: rgba(192, 132, 252, 0.15);
  --btn-submit-text: #04110a;
  --btn-clear-bg: rgba(255, 255, 255, 0.06);
  --btn-clear-hover: rgba(255, 255, 255, 0.12);
  --captcha-bg: #06090e;
  --captcha-modal-bg: rgba(13, 20, 31, 0.95);
  --captcha-modal-shadow: 0 12px 36px rgba(0, 0, 0, 0.6), 0 0 20px rgba(0, 229, 255, 0.2);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, "SFMono-Regular", monospace;
  --logo-height: 76px;
  --bg-blur: 1px;
  --bg-opacity: 0.35;
  --graph-node-bg: rgba(13, 20, 31, 0.95);
  --graph-node-text: var(--text-main);
  --graph-node-border: var(--border-card);
  --graph-shadow: rgba(0, 0, 0, 0.5);
  --notice-error-bg: rgba(255, 77, 77, 0.12);
  --notice-error-border: rgba(255, 77, 77, 0.6);
  --notice-error-text: #ffd0d0;
  --notice-mock-bg: rgba(255, 87, 34, 0.12);
  --notice-mock-border: rgba(255, 87, 34, 0.5);
  --notice-mock-text: #ffccbc;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg-base: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.90);
  --border-card: rgba(203, 213, 225, 0.85);
  --accent-best: #059669;
  --accent-backup: #0284c7;
  --accent-local: #ea580c;
  --accent-transit: #7c3aed;
  --accent-invalid: #dc2626;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --bg-input: #ffffff;
  --bg-pre: #ffffff;
  --bg-topbar: rgba(255, 255, 255, 0.92);
  --bg-grid: rgba(148, 163, 184, 0.25);
  --bg-community: rgba(124, 58, 237, 0.12);
  --btn-submit-text: #ffffff;
  --btn-clear-bg: rgba(0, 0, 0, 0.05);
  --btn-clear-hover: rgba(0, 0, 0, 0.1);
  --captcha-bg: #f8fafc;
  --captcha-modal-bg: rgba(255, 255, 255, 0.98);
  --captcha-modal-shadow: 0 12px 36px rgba(0, 0, 0, 0.12), 0 0 20px rgba(2, 132, 199, 0.12);
  --graph-node-bg: #ffffff;
  --graph-node-text: #0f172a;
  --graph-node-border: #cbd5e1;
  --graph-shadow: rgba(0, 0, 0, 0.08);
  --notice-error-bg: #fee2e2;
  --notice-error-border: #ef4444;
  --notice-error-text: #991b1b;
  --notice-mock-bg: #fff7ed;
  --notice-mock-border: #fb923c;
  --notice-mock-text: #9a3412;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  background: var(--bg-base);
  color: var(--text-main);
  font: 15px/1.5 var(--font-sans);
  min-height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  /* background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    url("/assets/nogglass.png"); */
  background-size: 48px 48px, 48px 48px, cover;
  background-position: center, center, center;
  background-repeat: repeat, repeat, no-repeat;
  filter: blur(var(--bg-blur, 1px));
  transform: scale(1.005);
  opacity: var(--bg-opacity, 0.35);
  pointer-events: none;
  z-index: -1;
}

main {
  padding: 24px 16px 48px;
  max-width: 1280px;
  margin: 0 auto;
  flex: 1;
  width: 100%;
}

/* --- top bar --- */
.topbar {
  border-bottom: 1px solid var(--border-card);
  background: linear-gradient(180deg, rgba(13, 20, 31, 0.95) 0%, rgba(6, 9, 14, 0.90) 100%);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(14px);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
}

html[data-theme="light"] .topbar {
  background: var(--bg-topbar);
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.05);
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-logo {
  height: var(--logo-height, 56px);
  width: auto;
  max-width: min(70vw, 420px);
  display: block;
  object-fit: contain;
  filter: brightness(1.35) drop-shadow(0 2px 8px rgba(0, 0, 0, 0.35));
}

html[data-theme="light"] .brand-logo {
  filter: none;
}

.brand-divider {
  width: 1px;
  height: 36px;
  background: linear-gradient(180deg, transparent, var(--border-card), transparent);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  color: var(--text-main);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-tagline,
.meta {
  color: var(--text-muted);
  font-size: 15px;
}

.locales {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: rgba(6, 9, 14, 0.65);
  border: 1px solid var(--border-card);
  border-radius: 8px;
}

html[data-theme="light"] .locales {
  background: rgba(241, 245, 249, 0.9);
}

.locales a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
  transition: all 0.15s ease;
}

.locales a:hover {
  color: var(--text-main);
}

.locales a[aria-current="true"] {
  color: var(--text-main);
  border-color: var(--border-card);
  background: var(--bg-card);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* --- form --- */
.query {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--bg-card);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.field-grow {
  flex: 1 1 260px;
}

[hidden],
.field[hidden] {
  display: none !important;
}

select,
input {
  font: 14px var(--font-mono);
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--accent-backup);
  outline-offset: 1px;
}

input:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button {
  font: 600 14px var(--font-sans);
  color: var(--btn-submit-text, #04110a);
  background: var(--accent-best);
  border: 0;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.15s ease;
}

button[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-clear {
  background: var(--btn-clear-bg);
  color: var(--text-muted);
  border: 1px solid var(--border-card);
}

.btn-clear:hover {
  background: var(--btn-clear-hover);
  color: var(--text-main);
  border-color: var(--border-card);
}

/* --- notices --- */
.notice {
  margin: 16px 0 0;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  font-size: 14px;
}

.notice-mock {
  background: var(--notice-mock-bg);
  border-color: var(--notice-mock-border);
  color: var(--notice-mock-text);
  font-weight: 500;
}

.notice-error {
  background: var(--notice-error-bg);
  border-color: var(--notice-error-border);
  color: var(--notice-error-text);
  font-weight: 600;
}

html[data-theme="light"] .notice-error,
html[data-theme="light"] #error {
  background: #fee2e2 !important;
  border-color: #ef4444 !important;
  color: #991b1b !important;
  font-weight: 600 !important;
}

html[data-theme="light"] .notice-mock,
html[data-theme="light"] #mock-warning {
  background: #fff7ed !important;
  border-color: #fb923c !important;
  color: #9a3412 !important;
  font-weight: 600 !important;
}

/* --- panels --- */
.panel {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--bg-card);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#graph {
  width: 100%;
  overflow-x: auto;
}

#graph svg {
  display: block;
  min-width: 520px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  font: 13px var(--font-mono);
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-card);
  white-space: nowrap;
}

th {
  color: var(--text-muted);
  font: 600 12px var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tr[data-best="true"] td {
  color: var(--accent-best);
}

td.unknown {
  color: var(--text-muted);
  font-style: italic;
}

td.cell-communities {
  white-space: normal;
  min-width: 260px;
}

.communities-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid currentColor;
}

.badge-valid {
  color: var(--accent-best);
}

.badge-invalid {
  color: var(--accent-invalid);
}

.badge-not_found,
.badge-not_checked {
  color: var(--text-muted);
}

.community {
  display: inline-block;
  margin: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-community);
  color: var(--accent-transit);
  font-size: 12px;
}

pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  background: var(--bg-pre);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  font: 12.5px/1.5 var(--font-mono);
  color: var(--text-main);
}

.raw-best-route {
  color: var(--accent-best);
  font-weight: 500;
}

.raw-best-badge {
  display: inline-block;
  background: var(--accent-best);
  color: var(--btn-submit-text);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

footer {
  padding: 16px;
  border-top: 1px solid var(--border-card);
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  position: relative;
}

footer a {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

footer a:hover {
  color: var(--text-main);
  background: var(--btn-clear-bg, rgba(255, 255, 255, 0.06));
  text-decoration: none;
}

.footer-terms-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  width: auto;
}

.footer-terms-btn:hover {
  color: var(--text-main);
  background: var(--btn-clear-bg, rgba(255, 255, 255, 0.06));
}

.footer-terms-btn[aria-expanded="true"] {
  color: var(--text-main);
  background: var(--btn-clear-hover, rgba(255, 255, 255, 0.12));
}

.terms-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(8px) scale(0.98);
  width: min(960px, calc(100vw - 32px));
  z-index: 50;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0.2s;
}

.terms-popup.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0) scale(1);
}

.terms-popup-box {
  background: var(--captcha-modal-bg, rgba(13, 20, 31, 0.98));
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 20px 24px;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.terms-popup-box p {
  margin: 0;
}

.terms-popup-box p+p {
  margin-top: 14px;
}

/* Animation is decoration: a visitor who asked for less motion gets a solid
   line instead of a pulsing one. */
@media (prefers-reduced-motion: no-preference) {
  .edge-best {
    animation: pulse 2.4s ease-in-out infinite;
  }

  @keyframes pulse {

    0%,
    100% {
      opacity: 1;
    }

    50% {
      opacity: 0.55;
    }
  }
}

@media (max-width: 640px) {
  .query {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .footer-terms-btn {
    width: auto;
  }
}

/* --- global view --- */
.verdict {
  margin: 0 0 12px;
  font-size: 14px;
}

.verdict-agrees {
  color: var(--accent-best);
}

.verdict-mismatch,
.verdict-not_seen_by_router {
  color: var(--accent-invalid);
}

.verdict-not_announced_globally {
  color: var(--accent-local);
}

.verdict-unknown {
  color: var(--text-muted);
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 13px;
}

.facts dt {
  color: var(--text-muted);
}

.facts dd {
  margin: 0;
  font-family: var(--font-mono);
}

/* A session that is not established is the reason someone opened the page. */
tr[data-established="false"] td {
  color: var(--accent-invalid);
}

/* --- captcha modal --- */
.captcha-modal {
  border: 1px solid var(--border-card);
  border-radius: 12px;
  background: var(--captcha-modal-bg);
  backdrop-filter: blur(16px);
  color: var(--text-main);
  padding: 0;
  max-width: 360px;
  width: 90vw;
  box-shadow: var(--captcha-modal-shadow);
}

.captcha-modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.captcha-box {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.captcha-box h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main);
}

.captcha-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.captcha-visual {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--captcha-bg);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  justify-content: center;
}

.captcha-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 4px;
}

.captcha-svg svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.btn-refresh {
  background: transparent;
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  font-size: 18px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.btn-refresh:hover {
  color: var(--accent-backup);
  border-color: var(--accent-backup);
  background: rgba(0, 229, 255, 0.1);
}

.captcha-input-row {
  display: flex;
  gap: 8px;
}

#captcha-input {
  flex: 1;
  text-align: center;
  letter-spacing: 4px;
  font-family: var(--font-mono);
  font-size: 18px;
  text-transform: uppercase;
}

.btn-submit {
  padding: 8px 16px;
}

.captcha-error-text {
  color: var(--accent-invalid);
  font-size: 12px;
  margin: 0;
}