:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #14181d;
  --muted: #66717f;
  --line: #dce1e7;
  --soft: #edf1f4;
  --accent: #0b6e69;
  --accent-2: #7a3f12;
  --hot: #d94b29;
  --cool: #3568b8;
  --shadow: 0 18px 55px rgba(30, 40, 50, 0.08);
  --hover-tint: rgba(11, 110, 105, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --ink: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --soft: #1e2430;
  --accent: #58a6ff;
  --accent-2: #d4924a;
  --hot: #f66;
  --cool: #6b9eff;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
  --hover-tint: rgba(88, 166, 255, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
}

.search-pane {
  padding: 22px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  max-height: 100vh;
}

.detail-pane {
  padding: 26px;
  overflow-y: auto;
  max-height: 100vh;
}

.brand-row,
.detail-header,
.panel-head,
.mode-row,
.summary-strip {
  display: flex;
  align-items: center;
}

.brand-row,
.detail-header,
.panel-head {
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 12ch;
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1.03;
}

h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.icon-button,
.seg-button,
.concept-row,
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.icon-button:hover,
.concept-row:hover,
.seg-button:hover,
.chip:hover {
  border-color: var(--accent);
}

.search-box {
  display: grid;
  gap: 8px;
  margin-top: 26px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  color: var(--ink);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 110, 105, 0.14);
}

.mode-row {
  gap: 6px;
  margin-top: 14px;
}

.seg-button {
  flex: 1;
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
}

.seg-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.seg-button:disabled,
.upload-panel input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.summary-strip {
  justify-content: stretch;
  gap: 8px;
  margin: 22px 0;
}

.summary-strip div {
  flex: 1;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.summary-strip strong,
.summary-strip span {
  display: block;
}

.summary-strip span,
.panel-head span,
.compact-list,
.relation-list,
.card-meta,
.stat-label,
.empty-state p {
  color: var(--muted);
  font-size: 0.83rem;
}

.upload-panel,
.activation-section,
.wordcloud-section,
.relation-section {
  margin-top: 22px;
}

.upload-panel input {
  width: 100%;
  margin-top: 12px;
}

.upload-preview {
  margin-top: 12px;
}

.upload-preview img {
  width: 100%;
  max-height: 210px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.compact-list,
.result-list,
.relation-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.result-list {
  display: grid;
  gap: 8px;
}

.empty-list-row {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 12px 2px;
}

.concept-row {
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  text-align: left;
}

.concept-row.active {
  border-color: var(--accent);
  background: rgba(11, 110, 105, 0.08);
}

.rank {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
  font-weight: 800;
}

.row-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.row-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.score {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.empty-state {
  min-height: calc(100vh - 52px);
  display: grid;
  place-content: center;
  text-align: center;
}

.empty-state h2 {
  margin-bottom: 8px;
  font-size: 2rem;
}

.concept-detail {
  max-width: 1180px;
  margin: 0 auto;
}

.hidden {
  display: none;
}

.detail-header {
  margin-bottom: 18px;
}

#concept-name {
  font-size: 2rem;
  line-height: 1.1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.stat-value {
  display: block;
  margin-top: 6px;
  font-size: 1.35rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.activation-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.combined-plot-card {
  grid-column: 1 / -1;
  margin: 0;
}

.combined-plot-card img {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.activation-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.activation-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.activation-pair div {
  position: relative;
  background: var(--panel);
}

.activation-pair span {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
}

.activation-card img {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  object-fit: cover;
  background: var(--soft);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  font-variant-numeric: tabular-nums;
}

.wordcloud-image {
  width: 100%;
  display: block;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

#graph {
  width: 100%;
  min-height: 420px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
  cursor: grab;
}
#graph:active { cursor: grabbing; }

.open-network-btn {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
.open-network-btn:hover { background: var(--hover-tint); }

.graph-edge {
  stroke: #6f7f8f;
  stroke-linecap: round;
}

/* Circular image nodes */
.graph-node {
  cursor: pointer;
}

.graph-node .node-bg {
  fill: var(--panel);
}

.graph-node .node-ring {
  fill: none;
  stroke: var(--cool);
  stroke-width: 2;
  transition: stroke 0.15s, stroke-width 0.15s;
}

.graph-node.selected .node-ring {
  stroke: var(--accent);
  stroke-width: 3.5;
}

.graph-node:hover .node-ring,
.graph-node:focus-visible .node-ring {
  stroke: var(--accent);
  stroke-width: 2.5;
  outline: none;
}

/* Network button in brand-row */
.network-btn {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  align-self: flex-start;
}

/* Network link in detail panel */
.network-link {
  display: inline-block;
  margin-top: 10px;
  padding: 7px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
}

.network-link:hover {
  background: var(--hover-tint);
}

.network-btn:hover {
  background: var(--hover-tint);
}

.relation-list {
  display: grid;
  gap: 8px;
}

.chip {
  width: 100%;
  min-height: 42px;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .search-pane,
  .detail-pane {
    max-height: none;
  }

  .search-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .search-pane  { padding: 14px; }
  .detail-pane  { padding: 14px; overflow-x: hidden; }

  /* Stack brand row vertically so Network button doesn't crowd the title */
  .brand-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .network-btn { align-self: stretch; text-align: center; justify-content: center; }

  /* Stack detail header */
  .detail-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .network-link { align-self: stretch; text-align: center; }

  /* Larger touch targets for result rows */
  .result-list li button,
  .result-list li a { min-height: 52px; font-size: 0.9rem; }

  /* Open-in-network button full width */
  .open-network-btn { display: block; text-align: center; }

  /* Hide theme toggle label on very small screens */
  #atlas-theme-toggle { bottom: 10px; right: 10px; }

  /* SVG ancestor graph: shorter on phone */
  #graph { min-height: 240px; }

  /* Activation gallery: single column on phone */
  .activation-gallery {
    grid-template-columns: 1fr;
  }

  /* Cap combined plot height so it doesn't dominate the screen */
  .combined-plot-card img { max-height: 50vw; object-fit: contain; }
}

/* ── Dark mode: image containers get a dark background ── */
[data-theme="dark"] .wordcloud-image,
[data-theme="dark"] .activation-gallery { background: var(--soft); }

/* ── Theme toggle button (bottom-right) ── */
#atlas-theme-toggle {
  position: fixed; bottom: 18px; right: 20px;
  display: flex; gap: 4px; z-index: 30;
}
.atlas-tmode-btn {
  padding: 4px 10px; font-size: 0.7rem; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--muted); font-family: inherit;
}
.atlas-tmode-btn.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.atlas-tmode-btn:hover:not(.active) {
  border-color: var(--accent); color: var(--ink);
}

/* ── About-CFM dropdown (top-center, shared with the Network page) ── */
#model-dropdown {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  z-index: 30; font-size: 0.86rem;
}
#model-dropdown summary {
  list-style: none; padding: 9px 22px;
  background: var(--accent); border: 1px solid var(--accent);
  border-top: none; border-radius: 0 0 8px 8px;
  cursor: pointer; color: #fff; font-weight: 800;
  display: flex; align-items: center; gap: 8px; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}
#model-dropdown summary::-webkit-details-marker { display: none; }
#model-dropdown summary::marker { content: ""; }
#model-dropdown summary .chevron { font-size: 0.65rem; transition: transform 0.15s; }
#model-dropdown[open] summary .chevron { transform: rotate(180deg); }
#model-dropdown summary:hover { filter: brightness(1.08); }
#dropdown-panel {
  background: var(--panel); border: 1px solid var(--line);
  border-top: none; border-radius: 0 0 8px 8px;
  padding: 14px 18px; min-width: 520px; max-width: 700px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
#dropdown-panel .about-text {
  font-size: 0.8rem; color: var(--ink); line-height: 1.6;
  font-weight: 400; margin-bottom: 12px;
}
#dropdown-panel .model-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
#dropdown-panel .model-label { color: var(--muted); font-size: 0.72rem; }
#dropdown-panel .model-name { font-weight: 800; color: var(--ink); }
#dropdown-panel .hf-link {
  font-size: 0.72rem; color: var(--accent); text-decoration: none; font-weight: 700;
  border: 1px solid var(--accent); padding: 3px 8px; border-radius: 5px;
  white-space: nowrap;
}
#dropdown-panel .hf-link:hover { background: var(--hover-tint); }
#dropdown-panel img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; }
#dropdown-panel .cite-block { margin-top: 12px; }
#dropdown-panel .cite-label {
  display: block; font-size: 0.74rem; color: var(--muted);
  font-weight: 700; margin-bottom: 6px;
}
#dropdown-panel .cite-bibtex {
  font-size: 0.68rem; line-height: 1.5; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px;
  overflow-x: auto; margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#dropdown-panel .about-disclaimer {
  font-size: 0.74rem; color: var(--muted); line-height: 1.55; font-weight: 400;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; margin-top: 12px; margin-bottom: 0;
}

@media (max-width: 640px) {
  #model-dropdown { left: 10px; right: 10px; transform: none; }
  #model-dropdown summary { padding: 7px 12px; }
  #dropdown-panel { min-width: unset; width: 100%; max-height: 75vh; overflow-y: auto; }
}
