:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #16202a;
  --muted: #5b6876;
  --border: #d9e0e7;
  --accent: #0e7c86;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2f3;
  --pass: #1b7f3b;
  --pass-bg: #e3f4e8;
  --fail: #b42318;
  --fail-bg: #fde7e5;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --neutral-bg: #eceff2;
  --origin: #d9480f;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1218;
    --surface: #151c24;
    --surface-2: #1c2530;
    --text: #e6edf3;
    --muted: #93a1b0;
    --border: #2a3542;
    --accent: #3cc3cf;
    --accent-ink: #062226;
    --accent-soft: #11313a;
    --pass: #5fd38a;
    --pass-bg: #12301f;
    --fail: #ff8a80;
    --fail-bg: #3a1714;
    --warn: #ffc261;
    --warn-bg: #352710;
    --neutral-bg: #232d38;
    --origin: #ff8c4b;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1218;
  --surface: #151c24;
  --surface-2: #1c2530;
  --text: #e6edf3;
  --muted: #93a1b0;
  --border: #2a3542;
  --accent: #3cc3cf;
  --accent-ink: #062226;
  --accent-soft: #11313a;
  --pass: #5fd38a;
  --pass-bg: #12301f;
  --fail: #ff8a80;
  --fail-bg: #3a1714;
  --warn: #ffc261;
  --warn-bg: #352710;
  --neutral-bg: #232d38;
  --origin: #ff8c4b;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; gap: 14px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.2rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.logo { width: 30px; height: 30px; fill: var(--accent); }
.logo .iris { fill: var(--surface); }
.logo .pupil { fill: var(--text); }
.tagline { color: var(--muted); font-size: .9rem; }
.icon-btn { margin-left: auto; background: none; border: 1px solid var(--border); color: var(--text); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 1.05rem; }

main { padding: 24px 16px 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card h3 { margin: 0 0 12px; font-size: 1rem; }

h1 { font-size: 1.6rem; margin: 0 0 6px; letter-spacing: -.02em; }
h2 { margin: 0; font-size: 1.3rem; }
.lead { color: var(--muted); margin: 0 0 18px; max-width: 70ch; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Intake */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 40px 16px; border: 2px dashed var(--border); border-radius: 12px; background: var(--surface-2); cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.dz-icon { font-size: 2.2rem; color: var(--accent); line-height: 1; }
.dz-title { font-weight: 600; font-size: 1.05rem; }
.dz-sub { color: var(--muted); font-size: .88rem; }

.paste { margin-top: 14px; }
.paste summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.paste textarea { width: 100%; margin: 10px 0; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: .85rem/1.4 ui-monospace, Menlo, monospace; resize: vertical; }

.howto { margin-top: 16px; font-size: .86rem; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }

.error { color: var(--fail); background: var(--fail-bg); padding: 10px 12px; border-radius: 8px; margin: 14px 0 0; }

.btn { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn:hover { filter: brightness(1.08); }

/* Results */
.results-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.grid > .card { margin-bottom: 16px; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .86rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.origin-ip { font-size: 1.5rem; font-weight: 700; font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
.origin-loc { font-size: 1.05rem; margin: 4px 0 10px; }
.origin-src { display: inline-block; font-size: .78rem; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 2px 10px; margin-bottom: 10px; }

.auth { display: flex; flex-wrap: wrap; gap: 10px; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 12px; font-size: .86rem; font-weight: 600; background: var(--neutral-bg); color: var(--muted); }
.badge.pass { background: var(--pass-bg); color: var(--pass); }
.badge.fail { background: var(--fail-bg); color: var(--fail); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; border-radius: 4px; padding: 1px 6px; background: var(--neutral-bg); color: var(--muted); white-space: nowrap; }
.tag.origin { background: var(--origin); color: #fff; }

.warnings { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.warnings li { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 8px; font-size: .9rem; }
.warnings li.ok { background: var(--pass-bg); color: var(--pass); }

#map { height: 380px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.hop-pin { background: var(--accent); color: var(--accent-ink); border: 2px solid #fff; border-radius: 50%; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.hop-pin.origin { background: var(--origin); color: #fff; width: 34px; height: 34px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
td.host { overflow-wrap: anywhere; min-width: 140px; }
td.ip { font-family: ui-monospace, Menlo, monospace; white-space: nowrap; }
tr.is-origin td { background: color-mix(in srgb, var(--origin) 10%, transparent); }

.raw summary { cursor: pointer; font-weight: 600; }
.raw pre { margin: 12px 0 0; max-height: 420px; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8rem; }

.notice ul { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.footer { padding: 8px 16px 32px; }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; gap: 0; }
  .tagline { display: none; }
  h1 { font-size: 1.35rem; }
  #map { height: 300px; }
  .card { padding: 16px; }
}

/* Darken OSM tiles in dark mode */
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
}

.tag.ok { background: var(--pass-bg); color: var(--pass); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--fail-bg); color: var(--fail); }
.warn-text { color: var(--warn); }
.origin-hidden { font-size: 1.15rem; font-weight: 700; margin: 6px 0 8px; }
.auth-details { margin-top: 14px; font-size: .9rem; }
#links .tag { margin: 2px 0; }
#links details summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; }
