:root {
  --bg: #0a0c0e;
  --bg-soft: #0f1114;
  --surface: #131519;
  --surface-2: #191c21;
  --border: #23272d;
  --border-strong: #2f353d;
  --text: #e7eaee;
  --text-muted: #9aa1a9;
  --text-faint: #636b74;
  --accent: #4ade80;
  --accent-dim: rgba(74, 222, 128, 0.12);
  --accent-hover: #22c55e;
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, "Cascadia Code", Consolas, monospace;
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.32);
  --ring: 0 0 0 3px rgba(74, 222, 128, 0.22);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 20px 72px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 26px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 11.5px; color: var(--text-faint); letter-spacing: 0.04em; }
.topbar-note { font-size: 12px; color: var(--text-faint); }

/* ---- command ---- */
.command {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field-host { flex: 1 1 auto; }
.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.field input {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 11px 13px;
  font-family: var(--mono);
  width: 100%;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.field-port input { width: 92px; }

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #06120a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 650;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  min-height: 44px;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.65; cursor: progress; }
.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(6, 18, 10, 0.35);
  border-top-color: #06120a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn.loading .btn-label { opacity: 0.6; }
.btn.loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- results ---- */
.results { display: grid; gap: 16px; margin-top: 24px; }

.hidden { display: none !important; }

/* ---- verdict ---- */
.verdict {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  background: var(--surface);
  animation: rise 0.24s ease;
}
.verdict-icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.verdict-icon svg { width: 18px; height: 18px; }
.verdict-ok .verdict-icon { background: rgba(74, 222, 128, 0.14); color: var(--green); }
.verdict-warn .verdict-icon { background: rgba(251, 191, 36, 0.14); color: var(--amber); }
.verdict-err .verdict-icon { background: rgba(248, 113, 113, 0.14); color: var(--red); }
.verdict-body { min-width: 0; }
.verdict-title { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.verdict-ok .verdict-title { color: var(--green); }
.verdict-warn .verdict-title { color: var(--amber); }
.verdict-err .verdict-title { color: var(--red); }
.verdict-facts {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.verdict-facts .sep { color: var(--text-faint); }
.verdict-detail {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  animation: rise 0.24s ease;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

/* ---- certificate ---- */
.cert-subject { font-size: 19px; font-weight: 650; letter-spacing: -0.02em; font-family: var(--mono); overflow-wrap: anywhere; }
.cert-issuer { margin-top: 3px; font-size: 13px; color: var(--text-muted); }
.cert-issuer b { color: var(--text); font-weight: 550; }

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 20px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.kv .k {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  margin-bottom: 3px;
}
.kv .v {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.san-block { margin-top: 16px; }
.san-label { font-size: 11px; color: var(--text-faint); letter-spacing: 0.03em; margin-bottom: 8px; }
.san-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.san-tag {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ---- validity ---- */
.bar {
  height: 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-fill.ok { background: var(--green); }
.bar-fill.warn { background: var(--amber); }
.bar-fill.bad { background: var(--red); }
.validity-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.validity-dates { font-family: var(--mono); font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.validity-days { font-family: var(--mono); font-size: 13px; font-weight: 600; }

/* ---- badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.badge.valid { background: rgba(74, 222, 128, 0.14); color: var(--green); }
.badge.expiring_soon { background: rgba(251, 191, 36, 0.14); color: var(--amber); }
.badge.expired, .badge.not_yet_valid { background: rgba(248, 113, 113, 0.14); color: var(--red); }

/* ---- chain ---- */
.chain { list-style: none; margin: 0; padding: 0; }
.chain-node {
  display: flex;
  gap: 14px;
  position: relative;
}
.chain-node:not(:last-child) { padding-bottom: 16px; }
.chain-rail { position: relative; width: 14px; flex: 0 0 auto; }
.chain-rail::before {
  content: "";
  position: absolute;
  top: 16px;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  background: var(--border-strong);
}
.chain-node:last-child .chain-rail::before { display: none; }
.chain-dot {
  position: relative;
  z-index: 1;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  margin-top: 5px;
}
.chain-dot.valid { background: var(--green); }
.chain-dot.expiring_soon { background: var(--amber); }
.chain-dot.expired, .chain-dot.not_yet_valid { background: var(--red); }

.chain-body { flex: 1 1 auto; min-width: 0; }
.chain-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.chain-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.chain-head-title { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.chain-role {
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.chain-cn { font-family: var(--mono); font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.chain-download {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 550;
  font-family: var(--sans);
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.chain-download:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

.chain-kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px 18px;
  margin-top: 13px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.chain-pem-toggle {
  margin-top: 13px;
  font-size: 12px;
  font-weight: 550;
  font-family: var(--sans);
  color: var(--accent);
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
.chain-pem-toggle:hover { text-decoration: underline; }

.chain-pem { margin-top: 10px; }
.chain-pem textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  padding: 12px;
  outline: none;
  white-space: pre;
  overflow: auto;
}
.chain-pem-bar { display: flex; justify-content: flex-end; margin-top: 8px; }
.chain-pem-copy {
  font-size: 12px;
  font-weight: 550;
  font-family: var(--sans);
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.chain-pem-copy:hover { color: var(--accent); border-color: var(--accent); }

.chain-desc {
  margin: -6px 0 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.chain-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* ---- footer ---- */
.foot {
  margin-top: auto;
  padding-top: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-faint);
}
.foot-label { color: var(--text-faint); }
.foot a { color: var(--text-muted); text-decoration: none; border-bottom: 1px solid var(--border); padding-bottom: 1px; transition: color 0.15s ease, border-color 0.15s ease; }
.foot a:hover { color: var(--accent); border-color: var(--accent); }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---- challenge modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease;
}
.modal-title { margin: 0 0 8px; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.modal-text { margin: 0 0 16px; font-size: 13px; color: var(--text-muted); }
.challenge-question {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  padding: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  letter-spacing: 0.02em;
}
.modal input {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 11px 13px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.modal input:focus { border-color: var(--accent); box-shadow: var(--ring); }
.challenge-error { margin-top: 10px; font-size: 12.5px; color: var(--red); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

@media (max-width: 560px) {
  .command { flex-wrap: wrap; }
  .field-host { flex: 1 1 100%; }
  .field-port { flex: 1; }
  .btn { flex: 1; }
  .verdict { flex-direction: column; gap: 10px; }
}

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