:root {
  --bg: #0d1117;
  --bg-sidebar: #161b22;
  --bg-card: #1c2128;
  --bg-terminal: #0d1117;
  --border: #30363d;
  --border-subtle: #21262d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --text-dim: #484f58;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
  --sidebar-w: 264px;
}

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

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

/* ---- layout ---- */

.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- sidebar ---- */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-top h1 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.filter-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.filter {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 3px 7px;
  transition: color 0.1s, border-color 0.1s, background 0.1s;
}

.filter:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.filter.active {
  background: var(--bg-card);
  border-color: var(--text-muted);
  color: var(--text);
}

.search {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.1s;
}

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

.search:focus {
  border-color: #58a6ff;
}

/* code list */

.code-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0;
}

.code-list::-webkit-scrollbar { width: 4px; }
.code-list::-webkit-scrollbar-track { background: transparent; }
.code-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.cat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 16px 4px;
  opacity: 0.7;
}

.cat-label:first-child {
  padding-top: 4px;
}

.code-item {
  width: 100%;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 16px 5px 13px;
  text-align: left;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  font: inherit;
}

.code-item:hover {
  background: var(--bg-card);
  color: var(--text);
}

.code-item.active {
  background: var(--bg-card);
  border-left-color: var(--cat);
  color: var(--text);
}

.ci-num {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--cat);
  flex-shrink: 0;
  width: 30px;
}

.code-item.active .ci-num {
  opacity: 1;
}

.ci-name {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  padding: 24px 16px;
  color: var(--text-dim);
  font-size: 12px;
}

/* ---- detail panel ---- */

.detail {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  min-width: 0;
}

.detail::-webkit-scrollbar { width: 6px; }
.detail::-webkit-scrollbar-track { background: transparent; }
.detail::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.detail-inner {
  max-width: 720px;
}

.detail-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 60vh;
  color: var(--text-dim);
  gap: 8px;
}

.detail-placeholder p {
  font-size: 14px;
}

.placeholder-hint {
  font-size: 11px;
  font-family: var(--font-mono);
}

/* header */

.detail-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 8px;
}

.detail-code {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}

.detail-name-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-name {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.2;
}

.detail-cat {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.75;
}

.detail-tagline {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 24px;
  line-height: 1.6;
}

/* terminal */

.terminal-wrap {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 28px;
}

.terminal-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
}

.tb-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.85;
}

.tb-label {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 8px;
  transition: color 0.1s, border-color 0.1s;
}

.copy-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.terminal-body {
  padding: 16px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre;
}

.terminal-body::-webkit-scrollbar { height: 4px; }
.terminal-body::-webkit-scrollbar-track { background: transparent; }
.terminal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* syntax tokens */

.l-req-line  { color: #79c0ff; }
.l-req-hdr   { color: #4d91d8; }
.l-req-sep   { color: #2f5a80; }
.l-res-status { color: #e6edf3; font-weight: 600; }
.l-res-hdr   { color: #4ca86e; }
.l-res-sep   { color: #2f6b45; }
.l-narrator  { color: var(--text-dim); font-style: italic; }
.l-body      { color: #b0bec5; }

.h-name  { color: inherit; opacity: 0.8; }
.h-colon { color: inherit; opacity: 0.55; }

/* notes */

.notes-section {
  margin-bottom: 24px;
}

.notes-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.notes-body {
  color: var(--text-muted);
  line-height: 1.7;
  font-size: 13.5px;
}

.notes-body code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  padding: 0 4px;
  color: #e3b341;
}

.notes-body em {
  color: var(--text);
  font-style: italic;
}

/* see also */

.see-also {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.see-also-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-right: 4px;
}

.see-also-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--cat);
  cursor: pointer;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 10px;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.see-also-chip:hover {
  background: var(--bg-sidebar);
  border-color: var(--cat);
}

/* back button (mobile only) */

.back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 0;
  margin-bottom: 20px;
}

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

/* footer */

.site-footer {
  padding: 40px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}

.site-footer a {
  color: var(--text-dim);
  text-decoration: none;
}

.site-footer a:hover { color: var(--text-muted); }

/* ---- mobile ---- */

@media (max-width: 700px) {
  .layout {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .code-list {
    max-height: 260px;
    overflow-y: auto;
  }

  .detail {
    padding: 24px 20px;
    overflow: visible;
  }

  .detail-code {
    font-size: 40px;
  }

  .detail-name {
    font-size: 18px;
  }

  .back-btn {
    display: inline-block;
  }

  body.show-detail .sidebar {
    display: none;
  }

  body.show-detail .back-btn {
    display: inline-block;
  }
}

@media (min-width: 701px) {
  body.show-detail .sidebar {
    display: flex;
  }
}

@media (max-width: 500px) {
  .detail {
    padding: 20px 16px;
  }
  .terminal-body {
    font-size: 11px;
  }
}
