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

:root,
[data-theme="dark"] {
  --bg: #0d0f14;
  --bg-raised: #1e2435;
  --bg-drawer: #151a26;
  --border: #252a38;
  --text: #c8cdd8;
  --text-muted: #6b7280;
  --text-dim: #4b5263;
  --accent: #60a5fa;
  --accent-dim: #3b82f6;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  --col-width: 720px;
  --line-height: 1.72;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-raised: #f0f0f0;
  --bg-drawer: #f5f5f5;
  --border: #cccccc;
  --text: #000000;
  --text-muted: #666666;
  --text-dim: #999999;
  --accent: #0077cc;
  --accent-dim: #005fa3;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: var(--line-height);
  min-height: 100vh;
  padding: 0 1.5rem 6rem;
  transition: background 0.2s, color 0.2s;
}

.container {
  max-width: var(--col-width);
  margin: 0 auto;
}

.hidden {
  display: none !important;
}

/* ── Nav ── */

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 0;
  margin-bottom: 2.5rem;
  display: flex;
  gap: 1.5rem;
}

.nav-link {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-decoration: none;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.nav-link:hover {
  color: var(--text-muted);
}

.nav-link.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ── Header / Project Info ── */

.project-header {
  margin-bottom: 0;
}

.project-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.project-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.architecture-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.architecture-steps {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.arch-step {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  padding: 0.3rem 0.65rem;
  border-radius: 3px;
}

.arch-arrow {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.example-queries {
  margin-bottom: 0.5rem;
}

.example-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}

.example-query {
  display: block;
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.88rem;
  padding: 0.35rem 0.5rem;
  margin-bottom: 0.15rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  border-radius: 3px;
  transition: color 0.15s, border-color 0.15s;
}

.example-query:hover {
  color: var(--text);
  border-color: var(--border);
}

/* ── Search ── */

.search-area {
  margin-bottom: 2.5rem;
}

.search-box {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: 3px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.search-box:focus-within {
  border-color: var(--accent-dim);
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 0.85rem 1rem;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-btn {
  background: none;
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.search-btn:hover {
  color: var(--text);
  background: var(--bg-drawer);
}

.search-btn:disabled {
  cursor: default;
  opacity: 0.4;
}

/* ── Backend Status ── */

.backend-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.6rem;
  min-height: 1.1em;
}

.backend-status .dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
}

.dot-waking { background: var(--accent-dim); }
.dot-ready  { background: #5a8a5a; }
.dot-error  { background: #8a4444; }

/* ── Loading ── */

.loading-area {
  display: none;
  margin-bottom: 2rem;
}

.loading-area.visible {
  display: block;
}

.loading-bar-track {
  width: 100%;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  overflow: hidden;
  margin-bottom: 0.6rem;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: var(--accent-dim);
  border-radius: 1px;
  transition: width 0.4s ease-out;
}

.loading-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.loading-text {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.loading-elapsed {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ── Answer ── */

.results-area {
  display: none;
}

.results-area.visible {
  display: block;
}

.answer-block {
  margin-bottom: 2.5rem;
}

.answer-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.answer-text {
  font-size: 0.95rem;
  line-height: var(--line-height);
  color: var(--text);
}

.answer-text p {
  margin-bottom: 1rem;
}

.answer-text p:last-child {
  margin-bottom: 0;
}

.answer-text ol,
.answer-text ul {
  margin: 0 0 1rem 1.25rem;
  padding: 0;
}

.answer-text li {
  margin-bottom: 0.5rem;
  line-height: var(--line-height);
}

.answer-text li:last-child {
  margin-bottom: 0;
}

.answer-text strong {
  color: var(--text);
  font-weight: 600;
}

.answer-text code {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--bg-raised);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  color: var(--accent);
}

/* ── Sources ── */

.sources-block {
  margin-bottom: 2.5rem;
}

.sources-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.source-item {
  border-left: 2px solid var(--border);
  padding: 0.5rem 0 0.5rem 0.85rem;
  margin-bottom: 0.6rem;
}

.source-title {
  font-size: 0.88rem;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.source-meta {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* ── Drawers ── */

.drawers {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.drawer {
  border-top: 1px solid var(--border);
}

.drawer:last-child {
  border-bottom: 1px solid var(--border);
}

.drawer-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  padding: 0.75rem 0;
  cursor: pointer;
  transition: color 0.15s;
}

.drawer-toggle:hover {
  color: var(--text);
}

.drawer-chevron {
  transition: transform 0.2s;
  font-size: 0.65rem;
}

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

.drawer-body {
  display: none;
  padding: 0 0 1rem;
}

.drawer.open .drawer-body {
  display: block;
}

.drawer-badge {
  font-size: 0.7rem;
  color: var(--accent-dim);
  margin-left: 0.5rem;
}

/* ── Drawer: Sub-queries ── */

.subquery-item {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

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

.subquery-index {
  color: var(--text-dim);
  margin-right: 0.5rem;
}

/* ── Drawer: Chunks ── */

.chunk-item {
  background: var(--bg-drawer);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
}

.chunk-item:last-child {
  margin-bottom: 0;
}

.chunk-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.chunk-source {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.chunk-score {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
}

.chunk-text {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.55;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Drawer: Telemetry ── */

.telemetry-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.telemetry-row:last-child {
  border-bottom: none;
}

.telemetry-key {
  color: var(--text-dim);
}

.telemetry-val {
  color: var(--text-muted);
}

/* ── Error ── */

.error-block {
  display: none;
  background: var(--bg-raised);
  border: 1px solid #7a3a3a;
  border-radius: 3px;
  padding: 0.85rem 1rem;
  margin-bottom: 2rem;
}

.error-block.visible {
  display: block;
}

.error-text {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: #c27070;
}

/* ══════════════════════════════════════ */
/*  ARCHITECTURE VIEW                    */
/* ══════════════════════════════════════ */

.arch-view {
  padding-bottom: 4rem;
}

.arch-title {
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 0.3rem;
}

.arch-updated {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 3rem;
}

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

.arch-link:hover {
  text-decoration: underline;
}

.arch-section {
  margin-bottom: 3rem;
}

.arch-heading {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
  color: var(--text);
}

.arch-subheading {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
}

.arch-body {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  line-height: var(--line-height);
}

.arch-body code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--bg-raised);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  color: var(--accent);
}

.arch-body strong {
  color: var(--text);
  font-weight: 600;
}

.arch-code {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin-bottom: 1rem;
  white-space: pre;
}

.arch-list {
  list-style: none;
  margin-bottom: 1rem;
}

.arch-list li {
  font-size: 0.88rem;
  color: var(--text-muted);
  padding: 0.35rem 0 0.35rem 1rem;
  position: relative;
  line-height: var(--line-height);
}

.arch-list li::before {
  content: "—";
  position: absolute;
  left: 0;
  color: var(--text-dim);
}

.arch-list li code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--bg-raised);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  color: var(--accent);
}

/* ── Tier Cards ── */

.tier-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
}

.tier-label {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.tier-count {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent-dim);
  margin-bottom: 0.5rem;
}

.tier-body {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: var(--line-height);
}

.tier-body code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg-drawer);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
  color: var(--accent);
}

/* ── Level Callouts ── */

.level-problem {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent);
  background: var(--bg-raised);
  border-left: 2px solid var(--accent-dim);
  padding: 0.6rem 0.85rem;
  margin-bottom: 1.25rem;
}

.level-failure {
  font-size: 0.85rem;
  color: var(--text-dim);
  border-left: 2px solid var(--border);
  padding: 0.5rem 0.85rem;
  margin-top: 1.25rem;
}

.failure-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

/* ── Component List ── */

.component-list {
  margin-bottom: 1rem;
}

.component {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  line-height: var(--line-height);
}

.component:last-child {
  border-bottom: none;
}

.component-name {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  font-weight: 600;
  margin-right: 0.5rem;
}

.component code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg-raised);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
  color: var(--accent);
}

/* ── Tables ── */

.arch-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 1rem;
  font-size: 0.82rem;
}

.arch-table th {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg-raised);
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.arch-table td {
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: var(--line-height);
}

.arch-table tr:last-child td {
  border-bottom: none;
}

.arch-table code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg-raised);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
  color: var(--accent);
}

.arch-table em {
  font-style: italic;
}

/* ── Arch Note ── */

.arch-note {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: var(--bg-raised);
  border-left: 2px solid var(--border);
  padding: 0.6rem 0.85rem;
  margin: 1rem 0;
  line-height: var(--line-height);
}

/* ── Responsive ── */

@media (max-width: 600px) {
  body {
    padding: 0 1rem 4rem;
  }

  .architecture-steps {
    gap: 0.3rem;
  }

  .arch-step {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
  }
}

/* ── Source links ── */

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

.source-link:hover {
  text-decoration: underline;
}

.source-arxiv {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--text-dim);
}

/* ── Papers tab ── */

.papers-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.papers-search {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-family: var(--font);
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  outline: none;
}

.papers-search:focus {
  border-color: var(--accent);
}

.papers-field-filter {
  padding: 0.5rem 0.75rem;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  outline: none;
  min-width: 10rem;
}

.paper-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

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

.paper-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  display: block;
  margin-bottom: 0.25rem;
}

.paper-title:hover {
  text-decoration: underline;
}

.paper-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.paper-arxiv {
  font-family: var(--mono);
  font-size: 0.92em;
  color: var(--text-dim);
}

.paper-field {
  color: var(--accent-dim);
}

/* ── Timeline ── */

.timeline {
  position: relative;
  padding-left: 2rem;
  border-left: 2px solid var(--border);
  margin-left: 0.5rem;
}

.timeline-entry {
  position: relative;
  padding-bottom: 1.5rem;
}

.timeline-entry:last-child {
  padding-bottom: 0;
}

.timeline-marker {
  position: absolute;
  left: -2.65rem;
  top: 0.1rem;
  width: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--accent);
  background: var(--bg);
  padding: 0.15rem 0;
}

.timeline-marker::before {
  content: "●";
}

.timeline-content strong {
  font-size: 0.88rem;
  color: var(--text);
  display: block;
  margin-bottom: 0.25rem;
}

.timeline-content p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.timeline-content code {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--bg-raised);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* ── Theme Toggle ── */

.theme-toggle {
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  z-index: 100;
  padding: 0;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

[data-theme="dark"] .icon-sun,
.icon-moon { display: none; }

[data-theme="dark"] .icon-moon { display: block; }
[data-theme="light"] .icon-sun { display: block; }
