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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #1c2230;
  --bg-input: #0d1117;
  --border-color: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-blue: #1a9fd4;
  --accent-blue-hover: #1589b8;
  --accent-link: #58a6ff;
  --error-bg: #2d1b1b;
  --error-text: #f85149;
  --success: #3fb950;
  --node-pillar: #1a9fd4;
  --node-cluster: #3fb950;
  --node-article: #d29922;
  --node-pillar-bg: #0d2d3f;
  --node-cluster-bg: #0d2d1a;
  --node-article-bg: #2d220d;
  --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─────────────────────────────────────────── */

.site-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.logo-icon {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.logo-icon svg {
  width: 100%;
  height: 100%;
}

.logo-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

.menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background-color: var(--text-primary);
  border-radius: 2px;
  transition: background-color 0.2s;
}

.menu-toggle:hover span {
  background-color: var(--accent-blue);
}

/* ─── Main ────────────────────────────────────────────── */

.site-main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 20px 64px;
  position: relative;
}

/* ─── Hero ────────────────────────────────────────────── */

.tool-hero {
  margin-bottom: 40px;
}

.tool-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.2;
}

.tool-description {
  font-size: 1rem;
  color: var(--text-secondary);
  max-width: 680px;
  line-height: 1.7;
}

/* ─── Input Card ──────────────────────────────────────── */

.tool-input-section {
  margin-bottom: 24px;
}

.input-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 28px 28px 24px;
}

.input-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.keyword-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font-body);
  padding: 11px 16px;
  outline: none;
  transition: border-color 0.2s;
}

.keyword-input::placeholder {
  color: var(--text-muted);
}

.keyword-input:focus {
  border-color: var(--accent-blue);
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font-body);
  padding: 11px 24px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover {
  background: var(--accent-blue-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-hint {
  margin-top: 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ─── Error ───────────────────────────────────────────── */

.error-banner {
  background: var(--error-bg);
  border: 1px solid var(--error-text);
  border-radius: 6px;
  padding: 12px 18px;
  color: var(--error-text);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ─── Results ─────────────────────────────────────────── */

.results-section {
  margin-top: 8px;
}

.results-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-family: var(--font-body);
  font-weight: 500;
  padding: 10px 18px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ─── Tree Panel ──────────────────────────────────────── */

.tree-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.tree-controls {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
}

.ctrl-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-family: var(--font-body);
  padding: 6px 14px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.ctrl-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent-blue);
}

.svg-wrapper {
  overflow: auto;
  min-height: 420px;
  cursor: grab;
  user-select: none;
}

.svg-wrapper:active {
  cursor: grabbing;
}

#blueprintTree {
  display: block;
}

/* ─── Tooltip ─────────────────────────────────────────── */

.node-tooltip {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px 16px;
  min-width: 220px;
  max-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 200;
  pointer-events: none;
}

.tooltip-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  line-height: 1.4;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.tooltip-row {
  display: flex;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 6px;
  align-items: flex-start;
}

.tt-label {
  color: var(--text-muted);
  min-width: 75px;
  flex-shrink: 0;
}

/* ─── Publish Order ───────────────────────────────────── */

.order-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.order-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 16px 20px 10px;
  border-bottom: 1px solid var(--border-color);
}

.order-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s;
}

.order-item:last-child {
  border-bottom: none;
}

.order-item:hover {
  background: var(--bg-secondary);
}

.order-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.order-num.pillar {
  background: var(--node-pillar-bg);
  color: var(--node-pillar);
  border: 1px solid var(--node-pillar);
}

.order-num.cluster {
  background: var(--node-cluster-bg);
  color: var(--node-cluster);
  border: 1px solid var(--node-cluster);
}

.order-num.article {
  background: var(--node-article-bg);
  color: var(--node-article);
  border: 1px solid var(--node-article);
}

.order-content {
  flex: 1;
}

.order-item-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.order-item-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.order-meta-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.order-meta-tag .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-pillar { background: var(--node-pillar); }
.dot-cluster { background: var(--node-cluster); }
.dot-article { background: var(--node-article); }

/* ─── Link Map ────────────────────────────────────────── */

.linking-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

.link-group {
  border-bottom: 1px solid var(--border-color);
}

.link-group:last-child {
  border-bottom: none;
}

.link-group-header {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.link-group-header:hover {
  background: var(--bg-secondary);
}

.link-group-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

.badge-pillar {
  background: var(--node-pillar-bg);
  color: var(--node-pillar);
  border: 1px solid var(--node-pillar);
}

.badge-cluster {
  background: var(--node-cluster-bg);
  color: var(--node-cluster);
  border: 1px solid var(--node-cluster);
}

.link-group-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.link-group-chevron {
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.link-group.open .link-group-chevron {
  transform: rotate(90deg);
}

.link-group-body {
  display: none;
  padding: 4px 20px 16px 52px;
}

.link-group.open .link-group-body {
  display: block;
}

.link-row {
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 5px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-arrow {
  color: var(--accent-blue);
  font-size: 0.8rem;
}

.link-target {
  color: var(--text-primary);
}

.link-type {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
  font-style: italic;
}

/* ─── Export Row ──────────────────────────────────────── */

.export-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-body);
  font-weight: 500;
  padding: 10px 20px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.btn-export svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-export:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: var(--bg-secondary);
}

/* ─── Loading ─────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 17, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}

.loading-inner {
  text-align: center;
}

.loader-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-text {
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* ─── Utility ─────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ─── Footer ──────────────────────────────────────────── */

.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 20px 40px;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 48px;
}

.footer-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.footer-desc {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 400px;
}

.footer-links-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.footer-links ul {
  list-style: none;
}

.footer-links li {
  margin-bottom: 12px;
}

.footer-links a {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--text-primary);
}

.footer-link-accent {
  color: var(--accent-link) !important;
}

.footer-bottom {
  border-top: 1px solid var(--border-color);
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 20px;
}

.footer-bottom p {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.heart {
  color: #e05252;
}

.footer-dev-link {
  color: var(--accent-link);
  text-decoration: none;
}

.footer-dev-link:hover {
  text-decoration: underline;
}

/* ─── SVG Tree Nodes ──────────────────────────────────── */

.tree-node {
  cursor: pointer;
}

.tree-node rect {
  transition: filter 0.15s;
}

.tree-node:hover rect {
  filter: brightness(1.2);
}

.tree-edge {
  fill: none;
  stroke: var(--border-color);
  stroke-width: 1.5;
}

.tree-edge-pillar {
  stroke: #1a9fd455;
}

.tree-edge-cluster {
  stroke: #3fb95055;
}

/* ─── Responsive ──────────────────────────────────────── */

@media (max-width: 640px) {
  .tool-title {
    font-size: 1.5rem;
  }

  .input-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-primary {
    width: 100%;
    text-align: center;
  }

  .footer-inner {
    grid-template-columns: 1fr;
    gap: 32px;
  }

  .export-row {
    flex-direction: column;
  }

  .btn-export {
    justify-content: center;
  }
}

/* ─── Ad Slots ────────────────────────────────────────── */

.ad-slot {
  width: 100%;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.ad-slot-top {
  margin: 0 0 24px;
  min-height: 0;
}

.ad-slot-bottom {
  margin: 24px 0 0;
  min-height: 0;
}

.ad-slot:empty {
  display: none;
}

/* ─── Focus Visible ───────────────────────────────────── */

.btn-primary:focus-visible,
.btn-export:focus-visible,
.ctrl-btn:focus-visible,
.tab-btn:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}
