/* ─────────────────────────────────────────────────────────────
   Papers — design tokens
   ───────────────────────────────────────────────────────────── */

:root {
  --bg:            #f7f7f8;
  --surface:       #ffffff;
  --surface-2:     #f2f2f4;
  --line:          #e4e4e8;
  --line-strong:   #d4d4da;
  --text:          #17171a;
  --text-dim:      #6c6c78;
  --text-faint:    #9a9aa6;
  --accent:        #4f46e5;
  --accent-soft:   #eeecfe;
  --accent-text:   #ffffff;
  --ok:            #10834a;
  --ok-soft:       #e3f5ec;
  --warn:          #92600a;
  --warn-soft:     #fdf1dc;
  --err:           #bb2124;
  --err-soft:      #fdeaea;
  --shadow-sm:     0 1px 2px rgba(16,16,24,.05);
  --shadow-md:     0 4px 16px -4px rgba(16,16,24,.10), 0 1px 3px rgba(16,16,24,.05);
  --shadow-lg:     0 24px 60px -20px rgba(16,16,24,.28);
  --radius:        14px;
  --radius-sm:     9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { color-scheme: dark; }
}

/* Dark palette — applied for explicit dark, or auto + OS dark */
:root[data-theme="dark"] {
  --bg:            #0e0e11;
  --surface:       #17171b;
  --surface-2:     #1e1e24;
  --line:          #28282f;
  --line-strong:   #3a3a44;
  --text:          #ededf0;
  --text-dim:      #a0a0ad;
  --text-faint:    #70707e;
  --accent:        #8b85ff;
  --accent-soft:   #22203a;
  --accent-text:   #12121a;
  --ok:            #4ade80;
  --ok-soft:       #112a1d;
  --warn:          #fbbf24;
  --warn-soft:     #2b2110;
  --err:           #f87171;
  --err-soft:      #2c1618;
  --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
  --shadow-md:     0 4px 16px -4px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.7);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg:            #0e0e11;
    --surface:       #17171b;
    --surface-2:     #1e1e24;
    --line:          #28282f;
    --line-strong:   #3a3a44;
    --text:          #ededf0;
    --text-dim:      #a0a0ad;
    --text-faint:    #70707e;
    --accent:        #8b85ff;
    --accent-soft:   #22203a;
    --accent-text:   #12121a;
    --ok:            #4ade80;
    --ok-soft:       #112a1d;
    --warn:          #fbbf24;
    --warn-soft:     #2b2110;
    --err:           #f87171;
    --err-soft:      #2c1618;
    --shadow-sm:     0 1px 2px rgba(0,0,0,.4);
    --shadow-md:     0 4px 16px -4px rgba(0,0,0,.5), 0 1px 3px rgba(0,0,0,.4);
    --shadow-lg:     0 24px 60px -20px rgba(0,0,0,.7);
  }
}

/* ───────────────────────── base ───────────────────────── */

* { box-sizing: border-box; }

/* An author `display` rule beats the UA stylesheet's [hidden] — don't let it. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor;
      stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.shell {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  padding-inline: 20px;
}

/* ───────────────────────── topbar ───────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
}

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

.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ff7ab6));
  box-shadow: var(--shadow-sm);
}

.brand-name { font-weight: 600; letter-spacing: -.01em; }

.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ───────────────────────── hero ───────────────────────── */

.hero { padding: 54px 0 26px; text-align: center; }

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(26px, 4.4vw, 34px);
  font-weight: 650;
  letter-spacing: -.028em;
}

.hero p { margin: 0; color: var(--text-dim); font-size: 15px; }

/* ───────────────────────── search card ───────────────────────── */

.search-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 8px 8px 14px;
}

.tabs {
  position: relative;
  display: flex;
  gap: 2px;
  padding: 4px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border-radius: 10px;
  width: max-content;
}

.tab {
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  padding: 6px 18px;
  border-radius: 7px;
  cursor: pointer;
  transition: color .15s;
}
.tab.is-active { color: var(--text); }

.tab-indicator {
  position: absolute;
  top: 4px; left: 4px;
  height: calc(100% - 8px);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform .26s cubic-bezier(.3,.9,.3,1), width .26s cubic-bezier(.3,.9,.3,1);
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 16%, transparent);
}

.field-icon { color: var(--text-faint); flex: none; }

#queryInput {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 8px 0;
}
#queryInput::placeholder { color: var(--text-faint); }

.btn-primary {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 560;
  font-size: 14px;
  padding: 9px 18px;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .62; cursor: default; filter: none; }

.spinner {
  display: none;
  width: 13px; height: 13px;
  border: 2px solid color-mix(in srgb, var(--accent-text) 35%, transparent);
  border-top-color: var(--accent-text);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
body.is-busy .spinner { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.hint {
  margin: 10px 4px 0;
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ───────────────────────── results ───────────────────────── */

.results { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }

.item, .cve {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 15px 17px;
  animation: rise .3s cubic-bezier(.2,.8,.3,1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
}

.item-head { display: flex; align-items: flex-start; gap: 11px; }

.status-dot {
  flex: none;
  width: 8px; height: 8px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--text-faint);
}

.item[data-state="searching"]  .status-dot,
.item[data-state="downloading"] .status-dot {
  background: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}
.item[data-state="saved"]    .status-dot { background: var(--ok); }
.item[data-state="error"]    .status-dot,
.item[data-state="notfound"] .status-dot { background: var(--err); }

@keyframes pulse {
  50% { opacity: .3; transform: scale(.78); }
}

.item-title { flex: 1 1 auto; min-width: 0; }

.item-query {
  margin: 0;
  font-size: 14.5px;
  font-weight: 560;
  letter-spacing: -.008em;
  word-break: break-word;
}

.item-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  word-break: break-word;
}

.badge {
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.item[data-state="saved"]    .badge { background: var(--ok-soft);   color: var(--ok); }
.item[data-state="error"]    .badge,
.item[data-state="notfound"] .badge { background: var(--err-soft);  color: var(--err); }
.item[data-state="downloading"] .badge,
.item[data-state="searching"]   .badge { background: var(--accent-soft); color: var(--accent); }

.progress {
  height: 4px;
  margin-top: 13px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width .2s ease-out;
}

.progress.is-indeterminate .progress-bar {
  width: 35%;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(300%); }
}

.item-actions { display: flex; gap: 8px; margin-top: 13px; }

.btn-ghost {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 520;
  padding: 6px 13px;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--text-faint); }

.log { margin-top: 12px; }

.log summary {
  font-size: 12.5px;
  color: var(--text-faint);
  cursor: pointer;
  width: max-content;
  list-style: none;
  user-select: none;
}
.log summary::-webkit-details-marker { display: none; }
.log summary::before { content: "▸"; display: inline-block; margin-right: 6px; }
.log[open] summary::before { content: "▾"; }
.log summary:hover { color: var(--text-dim); }

.log-body {
  margin: 9px 0 0;
  max-height: 190px;
  overflow: auto;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ───────────────────────── CVE card ───────────────────────── */

.cve { border-left: 3px solid var(--accent); }

.cve-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.cve-id { margin: 0; font-size: 17px; font-weight: 640; letter-spacing: -.01em; }

.cve-score {
  font-size: 12px; font-weight: 650;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim);
}
.cve-score[data-sev="CRITICAL"] { background: var(--err-soft);  color: var(--err); }
.cve-score[data-sev="HIGH"]     { background: var(--err-soft);  color: var(--err); }
.cve-score[data-sev="MEDIUM"]   { background: var(--warn-soft); color: var(--warn); }
.cve-score[data-sev="LOW"]      { background: var(--ok-soft);   color: var(--ok); }

.cve-date { margin-left: auto; font-size: 12.5px; color: var(--text-faint); }

.cve-vector {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  word-break: break-all;
}

.cve-desc { margin: 12px 0 0; font-size: 14px; color: var(--text-dim); }

.cve-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }

.cve-section h4 {
  margin: 0 0 9px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

details.cve-refs > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  width: max-content;
}
details.cve-refs > summary::-webkit-details-marker { display: none; }
details.cve-refs > summary h4 { display: inline; }
details.cve-refs > summary::after {
  content: "▸";
  margin-left: 7px;
  font-size: 10px;
  color: var(--text-faint);
}
details.cve-refs[open] > summary::after { content: "▾"; }
details.cve-refs[open] > summary h4 { margin-bottom: 0; }
details.cve-refs > summary:hover h4,
details.cve-refs > summary:hover::after { color: var(--text-dim); }
details.cve-refs .ref-groups { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font-size: 12.5px;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  text-decoration: none;
}
a.chip:hover { border-color: var(--accent); color: var(--accent); }

.link-btn {
  margin-top: 9px;
  border: 0; padding: 0;
  background: none;
  color: var(--accent);
  font: inherit; font-size: 12.5px;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.ref-group { margin-bottom: 13px; }
.ref-group:last-child { margin-bottom: 0; }

.ref-group-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.ref-link {
  display: block;
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
  padding: 1px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-link:hover { text-decoration: underline; }

/* ───────────────────────── empty state ───────────────────────── */

.empty {
  margin-top: 46px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}
.empty[hidden] { display: none; }

.empty-art {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin-bottom: 14px;
}
.empty-art span {
  width: 34px; height: 44px;
  border: 1.5px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
}
.empty-art span:nth-child(1) { transform: rotate(-7deg) translateY(3px); }
.empty-art span:nth-child(3) { transform: rotate(7deg)  translateY(3px); }

/* ───────────────────────── footer ───────────────────────── */

.foot {
  margin-top: auto;
  padding-block: 28px 24px;
  display: flex;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.foot-dot { opacity: .5; }

/* ───────────────────────── settings drawer ───────────────────────── */

.overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(10,10,14,.38);
  backdrop-filter: blur(2px);
  animation: fade .18s ease both;
}
.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.drawer {
  position: fixed;
  z-index: 31;
  top: 0; right: 0;
  width: min(380px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: slide-in .24s cubic-bezier(.2,.8,.3,1) both;
}
.drawer[hidden] { display: none; }

@keyframes slide-in { from { transform: translateX(100%); } }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 16px 22px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 620; }

.drawer-body { padding: 22px; display: flex; flex-direction: column; gap: 26px; }

.setting { display: flex; flex-direction: column; gap: 3px; }

.setting-name { font-size: 14px; font-weight: 550; }

.setting-note { font-size: 12.5px; color: var(--text-faint); }

#dirInput {
  margin-top: 8px;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: 0;
}
#dirInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--accent) 16%, transparent);
}

.setting-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 16px; }
.setting-row > div { display: flex; flex-direction: column; gap: 3px; }

.switch {
  flex: none;
  position: relative;
  width: 44px; height: 26px;
  border: 0; border-radius: 999px;
  background: var(--line-strong);
  cursor: pointer;
  transition: background .18s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch:disabled { opacity: .45; cursor: default; }

.switch-knob {
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform .18s cubic-bezier(.3,.9,.3,1);
}
.switch[aria-checked="true"] .switch-knob { transform: translateX(18px); }

.drawer-msg { margin: 0; font-size: 12.5px; min-height: 1em; color: var(--text-faint); }
.drawer-msg[data-kind="error"] { color: var(--err); }
.drawer-msg[data-kind="ok"]    { color: var(--ok); }

/* ───────────────────────── small screens ───────────────────────── */

@media (max-width: 560px) {
  .hero { padding-top: 36px; }
  .field { flex-wrap: wrap; padding: 10px; gap: 8px; }
  .field-icon { display: none; }
  #queryInput { flex-basis: 100%; padding: 4px 2px; }
  .btn-primary { width: 100%; justify-content: center; }
  .cve-date { margin-left: 0; flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ─────────────────────────────────────────────────────────────
   Static site additions
   ───────────────────────────────────────────────────────────── */

a.btn-primary { text-decoration: none; }

.item[data-state="found"] .status-dot { background: var(--ok); }
.item[data-state="found"] .badge { background: var(--ok-soft); color: var(--ok); }

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 16px;
  padding-inline: 4px;
  font-size: 12.5px;
  color: var(--text-faint);
}
.examples .chip { cursor: pointer; font: inherit; }
.examples .chip:hover { border-color: var(--accent); color: var(--accent); }

.item-authors {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-authors:empty { display: none; }

/* Other copies */

.alts { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }

.alts h4 {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.alt-list { display: flex; flex-direction: column; gap: 2px; }

.alt {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 6px 9px;
  margin-inline: -9px;
  border-radius: 8px;
  text-decoration: none;
  transition: background .13s;
}
.alt:hover { background: var(--surface-2); }

.alt-host {
  flex: none;
  font-size: 12.5px;
  font-weight: 560;
  color: var(--text);
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alt-url {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.alt-note {
  flex: none;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Source trace */

.source-grid {
  margin-top: 10px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.source-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 10px;
  font-size: 12px;
}

.source-row::before {
  content: "";
  flex: none;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ok);
}
.source-row[data-ok="false"]::before { background: var(--line-strong); }

.source-name { flex: none; width: 128px; color: var(--text); }
.source-note {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-time { flex: none; color: var(--text-faint); font-variant-numeric: tabular-nums; }

/* About drawer prose */

.prose { font-size: 13.5px; color: var(--text-dim); line-height: 1.65; }
.prose p { margin: 0 0 14px; }
.prose h3 {
  margin: 20px 0 6px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
}

@media (max-width: 560px) {
  .source-name { width: 96px; }
  .alt { flex-wrap: wrap; gap: 4px; }
  .alt-host { max-width: 100%; }
}

.item[data-state="unsure"] .status-dot { background: var(--warn); }
.item[data-state="unsure"] .badge { background: var(--warn-soft); color: var(--warn); }
.alt-note { background: var(--warn-soft); color: var(--warn); }
