:root {
  --primary: #2563eb;
  --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --primary-border: color-mix(in srgb, var(--primary) 55%, transparent);
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4e9;
  --text: #111827;
  --muted: #667085;
  --error: #d92d20;
  --error-soft: color-mix(in srgb, var(--error) 10%, transparent);
  --ok: #12925b;
  --code-bg: #f7f8fa;
  --code-text: #1f2937;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 4px 16px rgb(16 24 40 / 6%);
  --radius: 12px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232d;
    --border: #2a323d;
    --text: #e6edf3;
    --muted: #8b949e;
    --error: #f97066;
    --ok: #3fb950;
    --code-bg: #0b0f14;
    --code-text: #d6dde6;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --error: #f97066;
  --ok: #3fb950;
  --code-bg: #0b0f14;
  --code-text: #d6dde6;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }

svg { display: block; }

.muted { color: var(--muted); }

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 48px 16px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

/* Header */
.site-header { text-align: center; margin-bottom: 32px; }
.logo-wrap { margin: 0 auto; }
.logo { display: block; margin: 0 auto 16px; max-width: 100%; height: auto; }

/* Show the logo that matches the current theme. */
.logo-dark { display: none; }
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.site-header h1 { margin: 0; font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { margin: 8px auto 0; color: var(--muted); max-width: 640px; }

.theme-toggle { position: fixed; top: 14px; right: 14px; z-index: 5; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.field { margin-bottom: 20px; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.field-label {
  display: block;
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Router buttons */
.group + .group { margin-top: 16px; }
.group-name { margin: 0 0 8px; font-size: 0.95rem; font-weight: 600; }
.router-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.router {
  position: relative;
  text-align: left;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 38px 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, transform 0.05s;
  min-height: 62px;
}
.router:hover { border-color: var(--primary-border); }
.router:active { transform: scale(0.99); }
.router:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.router[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); }
.router-name { display: block; font-weight: 600; line-height: 1.3; }
.router-desc { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; line-height: 1.3; }
.router-check {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--surface);
}
.router[aria-pressed="true"] .router-check { background: var(--primary); border-color: var(--primary); }
.router-check svg { width: 12px; height: 12px; opacity: 0; }
.router[aria-pressed="true"] .router-check svg { opacity: 1; }

/* Form row */
.row { display: grid; grid-template-columns: minmax(180px, 260px) 1fr; gap: 16px; }
.row .field { margin-bottom: 0; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select, input[type="text"] {
  width: 100%;
  height: 44px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 0 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select { appearance: none; padding-right: 36px; cursor: pointer; }
input[type="text"] { font-family: var(--mono); font-size: 0.95rem; }
select:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input[aria-invalid="true"] { border-color: var(--error); }
.target-row { display: flex; gap: 10px; }
.target-row input { flex: 1; min-width: 0; }

.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.primary-button:hover { filter: brightness(1.08); }
.primary-button:disabled { opacity: 0.6; cursor: progress; }
.primary-button svg { width: 18px; height: 18px; }

.help { margin: 14px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.35em; }
.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--error-soft);
  color: var(--error);
  font-size: 0.92rem;
}

.link-button, .ghost-button, .icon-button {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--muted);
}
.link-button { padding: 0; font-size: 0.85rem; color: var(--primary); }
.link-button:hover { text-decoration: underline; }
.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
}
.ghost-button:hover { background: var(--surface-2); }
.ghost-button svg { width: 16px; height: 16px; }
.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.icon-button:hover { background: var(--surface-2); }
.icon-button svg { width: 18px; height: 18px; }

/* Results */
.results-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.results-title h2 { margin: 0; font-size: 1.25rem; }
.results-title h2 .target { font-family: var(--mono); font-weight: 600; }
.results-title p { margin: 2px 0 0; font-size: 0.9rem; }

.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.result-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
}
.result-head:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.status { width: 20px; height: 20px; flex: none; display: grid; place-items: center; }
.status svg { width: 20px; height: 20px; }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.status.loading { color: var(--primary); }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.result-names { flex: 1; min-width: 0; }
.result-name { font-weight: 600; }
.result-desc { color: var(--muted); font-size: 0.85rem; margin-left: 8px; }
.result-meta { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  margin-right: 6px;
}
.chevron { width: 18px; height: 18px; color: var(--muted); transition: transform 0.15s; flex: none; }
.result-head[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.result-body { border-top: 1px solid var(--border); padding: 12px 16px 16px; }
.result-head[aria-expanded="false"] + .result-body { display: none; }
.result-actions { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 8px; }
.section + .section { margin-top: 14px; }
.section-label { margin: 0 0 6px; font-size: 0.8rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.command { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); margin: 0 0 6px; }
pre.output {
  margin: 0;
  padding: 14px;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: 0.82rem/1.45 var(--mono);
  overflow-x: auto;
  white-space: pre;
  tab-size: 8;
}
.error-text { color: var(--error); margin: 0; }
.note { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; }
.cache-note { text-align: center; font-size: 0.85rem; margin-top: 16px; }

/* Resolve dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
}
dialog::backdrop { background: rgb(15 23 42 / 45%); }
dialog h3 { margin: 0 0 4px; font-size: 1.1rem; }
dialog p { margin: 0 0 16px; }
#resolve-options { display: grid; gap: 8px; }
.address-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
}
.address-option:hover, .address-option:focus-visible { border-color: var(--primary); outline: none; }
.address-family {
  flex: none;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
}
.address-value { font-family: var(--mono); font-size: 0.9rem; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

/* Footer */
.site-footer { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 40px; }
.site-footer p { margin: 4px 0; }
#footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0; }
#footer-links a { color: var(--muted); }
#footer-links a:hover { color: var(--text); }

@media (max-width: 640px) {
  .page { padding-top: 56px; }
  .site-header h1 { font-size: 1.6rem; }
  .card { padding: 16px; }
  .row { grid-template-columns: 1fr; gap: 16px; }
  .router-grid { grid-template-columns: 1fr 1fr; }
  .submit-text { display: none; }
  .primary-button { padding: 0 14px; }
  .results-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .result-desc { display: block; margin-left: 0; }
}

@media (max-width: 380px) {
  .router-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
