/* ── Design tokens ──────────────────────────────────────────────────── */
:root {
  --bg:         #fbfbfa;
  --surface:    #f4f4f2;
  --surface-2:  #eaeae7;
  --surface-3:  #dededa;
  --border:     #e3e3df;
  --border-2:   #cfcfc9;
  --text:       #18181b;
  --text-2:     #52525b;
  --text-3:     #8a8a95;
  --accent:     #b45309;
  --accent-dim: rgba(180, 83, 9, 0.10);
  --ds-color:   #1d4ed8;
  --ds-bg:      rgba(29, 78, 216, 0.10);
  --alg-color:  #c2410c;
  --alg-bg:     rgba(194, 65, 12, 0.10);
  --mark-bg:    rgba(180, 83, 9, 0.20);
  --font-sans:  -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-mono:  ui-monospace, 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'Menlo', monospace;
  --panel-w:    360px;
  --radius:     4px;
}

:root[data-theme="dark"] {
  --bg:         #0c0c0f;
  --surface:    #111116;
  --surface-2:  #1a1a22;
  --surface-3:  #222230;
  --border:     #252530;
  --border-2:   #32324a;
  --text:       #e6e4e0;
  --text-2:     #9a98a8;
  --text-3:     #6a6878;
  --accent:     #e8a049;
  --accent-dim: rgba(232, 160, 73, 0.12);
  --ds-color:   #4d9fff;
  --ds-bg:      rgba(77, 159, 255, 0.1);
  --alg-color:  #ff7b3f;
  --alg-bg:     rgba(255, 123, 63, 0.1);
  --mark-bg:    rgba(232, 160, 73, 0.22);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App grid ───────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Search panel ───────────────────────────────────────────────────── */
#search-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#site-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 20px 16px;
  flex-shrink: 0;
}

.site-brand {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-transform: uppercase;
}

.site-subtitle {
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-3);
  text-transform: uppercase;
}

.theme-toggle {
  margin-left: auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Search input */
.search-wrap {
  position: relative;
  margin: 0 12px 10px;
  flex-shrink: 0;
}

.search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  font-size: 15px;
  pointer-events: none;
  user-select: none;
  line-height: 1;
}

#search {
  width: 100%;
  padding: 8px 10px 8px 30px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  -webkit-appearance: none;
  appearance: none;
}

#search::-webkit-search-cancel-button,
#search::-webkit-search-decoration { display: none; }

#search::placeholder { color: var(--text-3); }

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Results list */
#results-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  padding-bottom: 8px;
  min-height: 0;
}

#results-list::-webkit-scrollbar { width: 3px; }
#results-list::-webkit-scrollbar-track { background: transparent; }
#results-list::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 2px; }

/* List section label */
.results-label {
  padding: 10px 16px 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  user-select: none;
}

/* Result item */
.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  cursor: pointer;
  border-left: 1px solid transparent;
  transition: background 0.07s;
  outline: none;
}

.result-item:hover { background: var(--surface-2); }

.result-item.active {
  background: var(--accent-dim);
  border-left-color: var(--accent);
}

.result-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.result-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.result-name mark {
  background: var(--mark-bg);
  color: var(--accent);
  border-radius: 2px;
  padding: 0 1px;
}

/* Badge */
.badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 2px;
  white-space: nowrap;
}

.badge-ds  { color: var(--ds-color);  background: var(--ds-bg); }
.badge-alg { color: var(--alg-color); background: var(--alg-bg); }

/* Empty / no-result states */
.state-message {
  padding: 24px 16px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.6;
}

.state-message strong {
  color: var(--text);
  font-weight: 500;
}

/* ── Entry panel ────────────────────────────────────────────────────── */
#entry-panel {
  overflow-y: auto;
  background: var(--bg);
  min-height: 0;
}

#entry-panel::-webkit-scrollbar { width: 5px; }
#entry-panel::-webkit-scrollbar-track { background: transparent; }
#entry-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.entry-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 56px 96px;
}

/* Entry header */
.entry-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.entry-title-group { flex: 1; min-width: 0; }

.entry-title {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: 10px;
  letter-spacing: -0.02em;
  word-break: break-word;
}

.entry-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.entry-source {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.entry-source:hover { color: var(--text-2); }

.entry-source:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Back button */
.btn-back {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 11px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.1s, color 0.1s;
  line-height: 1.4;
}

.btn-back:hover { background: var(--surface-3); color: var(--text); }

.btn-back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Entry sections */
.entry-description {
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-2);
  margin-bottom: 32px;
}

.entry-description p { margin-bottom: 10px; }
.entry-description p:last-child { margin-bottom: 0; }

.entry-description code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

.entry-section { margin-bottom: 32px; overflow-x: auto; }

.entry-section-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 12px;
}

/* Tables */
.entry-section table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.entry-section th {
  padding: 5px 14px 5px 0;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}

.entry-section td {
  padding: 8px 14px 8px 0;
  color: var(--text-2);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.5;
}

.entry-section td:first-child { color: var(--text); }

.entry-section td code,
.entry-section th code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--accent);
}

/* Lists */
.entry-section ul,
.entry-section ol {
  padding-left: 18px;
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.7;
}

.entry-section li { margin-bottom: 5px; }

.entry-section p {
  color: var(--text-2);
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 8px;
}

.entry-section p:last-child { margin-bottom: 0; }

.entry-section p code,
.entry-section li code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text);
}

/* Code samples */
.code-sample { margin-bottom: 28px; }

.code-sample:last-child { margin-bottom: 0; }

.code-sample-heading {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

/* Visually hidden -- screen readers only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Code block wrapper -- relative container so copy button can anchor top-right */
.code-block-wrap { position: relative; }

/* Copy button */
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  color: var(--text-3);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.1s, color 0.1s, border-color 0.1s;
  z-index: 1;
  line-height: 1;
}

.code-block-wrap:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }

.copy-btn:hover {
  background: var(--surface-2);
  color: var(--text-2);
  border-color: var(--accent);
}

.copy-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
  opacity: 1;
}

/* Related entries section */
.entry-related { margin-bottom: 32px; }

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

.related-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  text-align: left;
}

.related-chip:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  color: var(--text);
}

.related-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.related-chip-name {
  font-weight: 500;
}

/* Code hero block -- sits immediately after the entry header */
.code-samples-hero {
  margin-bottom: 36px;
}

/* Chroma pre override -- inline styles from catppuccin-mocha */
#entry-panel pre {
  overflow-x: auto !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  font-family: var(--font-mono) !important;
  font-size: 15px !important;
  line-height: 1.75 !important;
  padding: 20px 22px !important;
  margin: 0 !important;
  tab-size: 4;
}

#entry-panel code {
  font-family: var(--font-mono);
  tab-size: 4;
}

/* ── Global focus visible ───────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Responsive: single column at 640px ────────────────────────────── */
@media (max-width: 640px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
    height: 100vh; /* fallback */
  }

  #search-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 45vh;
  }

  #entry-panel {
    overflow-y: auto;
  }

  .entry-inner { padding: 24px 20px 56px; }

  .entry-title { font-size: 20px; }

  .entry-header { flex-direction: column; gap: 12px; }

  /* Larger touch targets on mobile */
  .result-item { padding: 11px 16px; }
}

@media (max-width: 400px) {
  .entry-inner { padding: 16px 14px 40px; }
}
