:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-muted: #5c6470;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --accent-soft: #d8f0ec;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --rail: #c9ced6;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #2b323c;
    --text: #e6e9ee;
    --text-muted: #98a2b3;
    --accent: #2dd4bf;
    --accent-contrast: #062421;
    --accent-soft: #123b37;
    --ok: #4ade80;
    --ok-soft: #14351f;
    --warn: #fbbf24;
    --warn-soft: #3d2c0a;
    --bad: #f87171;
    --bad-soft: #3f1515;
    --info: #60a5fa;
    --info-soft: #14284a;
    --rail: #3a424d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

.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;
}

/* ---- hero ---- */
.hero { margin-bottom: 28px; }
.hero-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 14px;
}
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.01em; }
.lede { margin: 0; color: var(--text-muted); max-width: 60ch; }

/* ---- lookup form ---- */
.lookup { margin-bottom: 20px; }
.lookup-row { display: flex; gap: 10px; }
.lookup-row input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  transition: border-color 120ms, box-shadow 120ms;
}
.lookup-row input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.option {
  display: flex; gap: 8px; align-items: flex-start;
  margin-top: 10px; font-size: 13px; color: var(--text-muted); cursor: pointer;
}
.option input { margin: 3px 0 0; accent-color: var(--accent); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 12px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap; position: relative;
  transition: filter 120ms, transform 60ms;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary[disabled] { cursor: progress; opacity: 0.85; }
.btn-download { background: var(--text); color: var(--bg); }
.btn-download:hover { filter: brightness(1.15); }
.btn-ghost {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
  padding: 5px 10px; font-size: 12px; font-weight: 500;
}
.btn-ghost:hover { filter: brightness(0.97); }

.btn-spinner {
  display: none; width: 16px; height: 16px;
  border: 2px solid color-mix(in srgb, var(--accent-contrast) 40%, transparent);
  border-top-color: var(--accent-contrast); border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.btn.is-loading .btn-label { visibility: hidden; }
.btn.is-loading .btn-spinner { display: block; position: absolute; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- error ---- */
.error {
  padding: 14px 16px; border-radius: 10px; margin-bottom: 20px;
  background: var(--bad-soft); color: var(--bad);
  border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent);
  font-weight: 500;
}

/* ---- summary ---- */
.summary {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.summary-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.summary-target { font-size: 20px; font-weight: 700; word-break: break-all; }
.summary-meta { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-info { background: var(--info-soft); color: var(--info); }

/* ---- notes ---- */
.notes {
  margin: 0 0 20px; padding: 12px 16px 12px 34px;
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: 10px; font-size: 13.5px;
}
.notes li + li { margin-top: 4px; }

/* ---- chain ---- */
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 24px 0 10px; }
.count { font-weight: 400; }
.chain { list-style: none; margin: 0; padding: 0; }
.cert { display: grid; grid-template-columns: 28px 1fr; gap: 0 8px; }
.cert-rail { position: relative; display: flex; justify-content: center; }
.cert-rail::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 2px; background: var(--rail);
}
.cert:first-child .cert-rail::before { top: 26px; }
.cert:last-child .cert-rail::before { bottom: calc(100% - 26px); }
.cert-dot {
  position: relative; z-index: 1; margin-top: 20px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
}
.cert.is-expired .cert-dot { border-color: var(--bad); }
.cert.is-aia .cert-dot { border-color: var(--info); border-style: dashed; }
.cert-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow);
  min-width: 0;
}
.cert-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.role {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
}
.role-root { background: var(--surface-2); color: var(--text-muted); }
.cert-cn { font-weight: 600; font-size: 16px; word-break: break-word; }
.tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; }
.tag-aia { background: var(--info-soft); color: var(--info); }
.tag-expired { background: var(--bad-soft); color: var(--bad); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }

.cert-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 0; font-size: 13.5px;
}
.cert-grid .wide { grid-column: 1 / -1; }
.cert-grid dt { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; }
.cert-grid dd { margin: 1px 0 0; word-break: break-all; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.f-sans span {
  display: inline-block; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 7px; margin: 2px 4px 2px 0; font-family: var(--mono); font-size: 12px;
}
.f-sans .more { color: var(--text-muted); border: 0; background: none; cursor: pointer; }

.pem { margin-top: 10px; font-size: 13px; }
.pem summary { cursor: pointer; color: var(--text-muted); user-select: none; }
.pem-box { position: relative; margin-top: 8px; }
.pem-box .btn-copy { position: absolute; top: 8px; right: 8px; }
.pem pre {
  margin: 0; padding: 12px; overflow-x: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.4;
}

/* ---- misc ---- */
.contents {
  margin-top: 24px; padding: 14px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); font-size: 13.5px;
}
.contents summary { cursor: pointer; font-weight: 600; }
.contents ul { padding-left: 20px; margin: 10px 0; }
.contents li + li { margin-top: 4px; }
.contents code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--text-muted); margin: 6px 0 0; }
.foot { margin-top: 40px; color: var(--text-muted); font-size: 12.5px; }
.foot p { margin: 0; }

@media (max-width: 560px) {
  .page { padding-top: 28px; }
  .lookup-row { flex-direction: column; }
  .cert-grid { grid-template-columns: 1fr; }
  .summary-head .btn-download { width: 100%; }
}
