*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0e17;
  --bg2: #111827;
  --surface: #1a2235;
  --border: #2a3650;
  --text: #e2e8f0;
  --text2: #94a3b8;
  --accent: #3b82f6;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
  --green: #22c55e;
  --purple: #a855f7;
  --cyan: #06b6d4;
  --pink: #ec4899;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ── Loading overlay ─────────────────── */
#loading {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg);
  transition: opacity 0.5s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
#loading .logo-mark {
  width: 72px; height: 72px; margin-bottom: 1.5rem;
  animation: pulse-logo 2s ease-in-out infinite;
}
@keyframes pulse-logo {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.04); }
}
#loading h1 {
  font-size: 2.2rem; font-weight: 800; margin-bottom: 0.25rem;
  letter-spacing: -0.03em; background: linear-gradient(135deg, var(--text) 0%, var(--accent) 60%, var(--cyan) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
#loading .tagline { color: var(--text2); font-size: 0.85rem; margin-bottom: 1.5rem; letter-spacing: 0.02em; }
#loading .domain { color: var(--accent); font-size: 0.75rem; margin-top: 1.5rem; font-weight: 600; letter-spacing: 0.04em; opacity: 0.7; }
#loading .spinner {
  width: 48px; height: 48px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin-bottom: 1.5rem; display: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
#load-status { color: var(--text2); font-size: 0.875rem; }
#load-bar-outer {
  width: 300px; height: 4px; background: var(--border); border-radius: 2px;
  margin-top: 1rem; overflow: hidden;
}
#load-bar {
  width: 0%; height: 100%; background: var(--accent); border-radius: 2px;
  transition: width 0.3s;
}

/* ── Main layout ─────────────────────── */
#app { display: none; height: 100vh; width: 100vw; position: relative; }
#app.active { display: block; }

/* ── Search bar ──────────────────────── */
#search-container {
  position: absolute; top: 24px; left: 50%; transform: translateX(-50%);
  z-index: 100; width: 560px; max-width: calc(100vw - 48px);
}
#search-box {
  width: 100%; padding: 14px 20px 14px 48px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); font-size: 1rem;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
#search-box:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15), 0 8px 32px rgba(0,0,0,0.4);
}
#search-box::placeholder { color: var(--text2); }
#search-icon {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--text2); pointer-events: none;
}
#search-results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; display: none;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5); max-height: 400px; overflow-y: auto;
}
#search-results.active { display: block; }
.search-item {
  padding: 12px 20px; cursor: pointer; display: flex; align-items: center;
  gap: 12px; border-bottom: 1px solid var(--border); transition: background 0.15s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.selected { background: rgba(59,130,246,0.1); }
.search-item .type-badge {
  padding: 2px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; flex-shrink: 0;
}
.search-item .id { font-weight: 600; font-size: 0.9rem; }
.search-item .epss-pill {
  margin-left: auto; font-size: 0.75rem; padding: 2px 8px; border-radius: 6px;
  font-weight: 600; flex-shrink: 0;
}

/* ── Canvas ──────────────────────────── */
#graph-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none;
}
#graph-canvas:active { cursor: grabbing; }

/* ── Detail panel ────────────────────── */
#detail-panel {
  position: absolute; top: 24px; right: 24px; width: 360px; max-height: calc(100vh - 48px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 24px; overflow-y: auto; display: none; z-index: 90;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}
#detail-panel.active { display: block; }
#detail-panel h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 4px; word-break: break-all; }
#detail-panel .subtitle { color: var(--text2); font-size: 0.8rem; margin-bottom: 16px; }
.detail-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text2); font-size: 0.8rem; }
.detail-value { font-weight: 600; font-size: 0.9rem; }
.epss-gauge {
  width: 100%; height: 8px; background: var(--border); border-radius: 4px;
  margin-top: 8px; overflow: hidden;
}
.epss-gauge-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease-out; }
.edge-list { margin-top: 16px; }
.edge-list h3 { font-size: 0.85rem; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.edge-item {
  padding: 8px 12px; background: rgba(255,255,255,0.03); border-radius: 8px;
  margin-bottom: 6px; cursor: pointer; transition: background 0.15s;
  font-size: 0.85rem; display: flex; align-items: center; gap: 8px;
}
.edge-item:hover { background: rgba(59,130,246,0.1); }
.edge-item .edge-type { color: var(--text2); font-size: 0.7rem; text-transform: uppercase; }
.source-link {
  display: inline-flex; align-items: center; gap: 4px; color: var(--accent);
  text-decoration: none; font-size: 0.75rem; opacity: 0.8; transition: opacity 0.15s;
}
.source-link:hover { opacity: 1; text-decoration: underline; }
.source-link svg { flex-shrink: 0; }
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.detail-title-row h2 { flex: 1; min-width: 0; }
.edge-item .edge-link { margin-left: auto; flex-shrink: 0; color: var(--text2); opacity: 0.5; transition: opacity 0.15s; }
.edge-item:hover .edge-link { opacity: 1; color: var(--accent); }

/* ── Watermark ───────────────────────── */
#watermark {
  position: absolute; bottom: 52px; left: 24px; z-index: 80;
  display: flex; align-items: center; gap: 8px; opacity: 0.35;
  pointer-events: none; user-select: none;
}
#watermark svg { width: 22px; height: 22px; }
#watermark .wm-text { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em; color: var(--text); }
#watermark .wm-domain { font-size: 0.6rem; color: var(--text2); font-weight: 400; }

/* ── Stats bar ───────────────────────── */
#stats-bar {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 24px; padding: 8px 20px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; z-index: 90;
  font-size: 0.75rem; color: var(--text2);
}
#stats-bar strong { color: var(--text); }

/* ── Node type colors ────────────────── */
.type-cve { background: rgba(239,68,68,0.15); color: var(--red); }
.type-package { background: rgba(59,130,246,0.15); color: var(--accent); }
.type-exploit { background: rgba(249,115,22,0.15); color: var(--orange); }
.type-cwe { background: rgba(168,85,247,0.15); color: var(--purple); }
.type-technique { background: rgba(6,182,212,0.15); color: var(--cyan); }
.type-actor { background: rgba(236,72,153,0.15); color: var(--pink); }
.type-software { background: rgba(20,184,166,0.15); color: #14b8a6; }
.type-advisory { background: rgba(34,197,94,0.15); color: var(--green); }

.epss-critical { background: rgba(239,68,68,0.15); color: var(--red); }
.epss-high { background: rgba(249,115,22,0.15); color: var(--orange); }
.epss-medium { background: rgba(234,179,8,0.15); color: var(--yellow); }
.epss-low { background: rgba(34,197,94,0.15); color: var(--green); }

.cvss-critical { background: rgba(239,68,68,0.15); color: var(--red); }
.cvss-high { background: rgba(249,115,22,0.15); color: var(--orange); }
.cvss-medium { background: rgba(234,179,8,0.15); color: var(--yellow); }
.cvss-low { background: rgba(34,197,94,0.15); color: var(--green); }
.cvss-none { background: rgba(148,163,184,0.1); color: var(--text2); }

.detail-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.detail-section h3 { font-size: 0.8rem; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.score-bar { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.score-bar .bar { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.score-bar .bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease-out; }
.severity-badge { padding: 2px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.meta-timestamp { font-size: 0.75rem; color: var(--text2); }

#freshness-panel {
  position: absolute; bottom: 48px; right: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; z-index: 90; display: none; min-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
#freshness-panel.active { display: block; }
#freshness-panel h3 { font-size: 0.8rem; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 12px; }
.freshness-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 0.8rem; }
.freshness-name { color: var(--text2); }
.freshness-count { color: var(--text); font-weight: 600; margin: 0 8px; }
.freshness-date { color: var(--text2); font-size: 0.75rem; }
.freshness-indicator { width: 6px; height: 6px; border-radius: 50%; margin-right: 8px; flex-shrink: 0; }
.fresh-good { background: var(--green); }
.fresh-warn { background: var(--yellow); }
.fresh-stale { background: var(--red); }

/* ── CVE description ─────────────────── */
.cve-description {
  color: var(--text2); font-size: 0.82rem; line-height: 1.5;
  margin: 0; padding: 0;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.cve-description:hover {
  -webkit-line-clamp: unset;
}

/* ── Drag handle (mobile bottom sheet) ── */
.drag-handle {
  display: none; width: 36px; height: 4px; border-radius: 2px;
  background: var(--border); margin: 0 auto 12px;
}

/* ── Close button ────────────────────── */
.close-btn {
  position: absolute; top: 12px; right: 12px; width: 28px; height: 28px;
  border: none; background: rgba(255,255,255,0.05); border-radius: 8px;
  color: var(--text2); cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.close-btn:hover { background: rgba(255,255,255,0.1); }

/* ── Type filter bar ────────────────── */
#type-filter {
  position: absolute; top: 24px; left: 24px; z-index: 95;
  display: none; flex-direction: column; gap: 6px;
}
#type-filter.active { display: flex; }
.type-chip {
  display: flex; align-items: center; gap: 6px; padding: 5px 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; transition: opacity 0.2s, border-color 0.2s;
  user-select: none; white-space: nowrap;
}
.type-chip .chip-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.type-chip .chip-count { margin-left: auto; color: var(--text2); font-weight: 400; }
.type-chip.hidden { opacity: 0.3; border-color: transparent; }
.type-chip:hover { border-color: var(--accent); }

/* ── Context menu ───────────────────── */
#context-menu {
  position: fixed; z-index: 200; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 4px 0; min-width: 180px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
#context-menu.active { display: block; }
.ctx-item {
  padding: 8px 14px; cursor: pointer; font-size: 0.8rem;
  display: flex; align-items: center; gap: 10px; transition: background 0.1s;
  color: var(--text);
}
.ctx-item:first-child { border-radius: 6px 6px 0 0; }
.ctx-item:last-child { border-radius: 0 0 6px 6px; }
.ctx-item:hover { background: rgba(59,130,246,0.12); }
.ctx-item .ctx-key { margin-left: auto; color: var(--text2); font-size: 0.65rem; font-family: monospace; }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Layout controls ────────────────── */
#layout-controls {
  position: absolute; bottom: 48px; left: 24px; z-index: 90;
  display: none; flex-direction: column; gap: 4px;
}
#layout-controls.active { display: flex; }
.layout-btn {
  width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.layout-btn:hover { border-color: var(--accent); color: var(--text); }
.layout-btn.active-btn { background: rgba(59,130,246,0.15); border-color: var(--accent); color: var(--accent); }
.layout-btn[title]::after { content: none; }

/* ── Tooltip ────────────────────────── */
#tooltip {
  position: fixed; z-index: 150; display: none; pointer-events: none;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 0.75rem; color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4); max-width: 280px;
  white-space: nowrap;
}
#tooltip.active { display: block; }

/* ─────────────────────────────────────── */
/* Mobile responsive                       */
/* ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Search bar: full width, smaller text */
  #search-container {
    top: 12px; left: 12px; right: 12px;
    width: auto; max-width: none; transform: none;
  }
  #search-box {
    padding: 12px 16px 12px 40px; font-size: 0.9rem; border-radius: 10px;
  }
  #search-icon { left: 12px; }
  #search-results { max-height: 50vh; border-radius: 10px; }

  /* Detail panel: bottom sheet, full width */
  #detail-panel {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; max-height: 60vh;
    border-radius: 16px 16px 0 0;
    padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
  }
  #detail-panel h2 { font-size: 1.1rem; }
  .close-btn { top: 8px; right: 8px; }
  .drag-handle { display: block; }

  /* Type filter: horizontal scrollable row under search */
  #type-filter {
    top: 64px; left: 12px; right: 12px;
    flex-direction: row; overflow-x: auto; gap: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #type-filter::-webkit-scrollbar { display: none; }
  .type-chip { padding: 4px 8px; font-size: 0.6rem; border-radius: 6px; }
  .type-chip .chip-count { display: none; }

  /* Layout controls: horizontal row, bottom-left */
  #layout-controls {
    bottom: 52px; left: 12px;
    flex-direction: row; gap: 4px;
  }
  .layout-btn { width: 32px; height: 32px; font-size: 0.85rem; border-radius: 8px; }

  /* Stats bar: compact, scrollable */
  #stats-bar {
    bottom: 8px; left: 8px; right: 8px;
    transform: none; gap: 12px;
    padding: 6px 12px; border-radius: 8px;
    font-size: 0.65rem; overflow-x: auto;
    white-space: nowrap; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #stats-bar::-webkit-scrollbar { display: none; }

  /* Watermark: smaller */
  #watermark { bottom: 44px; left: 12px; opacity: 0.2; }
  #watermark svg { width: 16px; height: 16px; }
  #watermark .wm-text { font-size: 0.6rem; }
  #watermark .wm-domain { display: none; }

  /* Freshness panel: bottom sheet */
  #freshness-panel {
    position: fixed; bottom: 0; left: 0; right: 0;
    border-radius: 12px 12px 0 0; min-width: auto;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  }

  /* Loading screen: smaller elements */
  #loading .logo-mark { width: 56px; height: 56px; }
  #loading h1 { font-size: 1.6rem; }
  #load-bar-outer { width: 240px; }

  /* Context menu: wider on mobile */
  #context-menu { min-width: 200px; }

  /* Tooltip: hide on touch devices (no hover) */
  #tooltip { display: none !important; }

}

/* Very small phones (iPhone SE, etc.) */
@media (max-width: 380px) {
  #search-box { font-size: 0.8rem; padding: 10px 14px 10px 36px; }
  #detail-panel { max-height: 55vh; padding: 16px 12px; }
  #detail-panel h2 { font-size: 1rem; }
  .edge-item { font-size: 0.75rem; padding: 6px 8px; }
  .type-chip { font-size: 0.55rem; }
}
