:root {
  --bg: #0d1117;
  --fg: #c9d1d9;
  --accent: #58a6ff;
  --border: #30363d;
  --surface: #161b22;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
  --purple: #bc8cff;
  --muted: #8b949e;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Top bar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 20px;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.topbar-home:hover {
  color: var(--fg);
  background: rgba(255,255,255,0.06);
}

.topbar-home svg {
  width: 16px;
  height: 16px;
}

.topbar-sep {
  color: var(--border);
  font-size: 18px;
  font-weight: 300;
  user-select: none;
}

.topbar-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Custom select wrapper (cross-browser) ── */
.select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.select-wrap select {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 28px 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  line-height: 1.3;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
  pointer-events: none;
}

.select-wrap select:hover {
  border-color: var(--accent);
}

.topbar-controls button {
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  line-height: 1.3;
}

.topbar-controls button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--fg);
}

.topbar-controls button:disabled {
  opacity: 0.3;
  cursor: default;
}

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

/* ── Document content ── */
.doc-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 32px 80px;
  color: var(--fg);
  line-height: 1.65;
}

.doc-content h1 {
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 4px;
}

.doc-content h2 {
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  margin-top: 48px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.doc-content h3 {
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  margin-top: 28px;
  margin-bottom: 8px;
}

.doc-content h4 {
  color: var(--purple);
  font-size: 13px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.doc-content p,
.doc-content li {
  font-size: 14px;
  margin-bottom: 6px;
}

.doc-content ul,
.doc-content ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13px;
}

.doc-content th {
  background: var(--surface);
  color: var(--accent);
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.doc-content td {
  padding: 7px 12px;
  border: 1px solid var(--border);
  vertical-align: top;
}

.doc-content tr:nth-child(even) td {
  background: rgba(22, 27, 34, 0.5);
}

.doc-content code {
  background: var(--surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--green);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
}

.doc-content pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  margin: 14px 0;
  line-height: 1.5;
  color: var(--fg);
}

.doc-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.doc-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.doc-content a {
  color: var(--accent);
  text-decoration: none;
}

.doc-content a:hover {
  text-decoration: underline;
}

.doc-content strong {
  color: #e6edf3;
}

/* ── Custom classes from source docs ── */
.meta {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 32px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}

.tag-green  { background: #0c2016; color: var(--green); border: 1px solid #10a35b; }
.tag-red    { background: #2d0a0a; color: var(--red);   border: 1px solid #da3633; }
.tag-yellow { background: #2d1a0a; color: var(--yellow); border: 1px solid #f59e0b; }
.tag-blue   { background: #0a1929; color: var(--accent); border: 1px solid #1f6feb; }
.tag-purple { background: #1a0a2e; color: var(--purple); border: 1px solid #8957e5; }

.callout {
  background: var(--surface);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin: 14px 0;
  border-radius: 0 8px 8px 0;
}

.callout-warn  { border-left-color: var(--yellow); }
.callout-danger { border-left-color: var(--red); }

.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 20px 0;
}

.toc a {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}

.toc a:hover { text-decoration: underline; }

.toc ol {
  counter-reset: toc-counter;
  list-style: none;
  padding-left: 0;
}

.toc li {
  counter-increment: toc-counter;
  margin-bottom: 4px;
}

.toc li::before {
  content: counter(toc-counter) ". ";
  color: var(--muted);
}

.figma-ref {
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
}

.ascii-diagram {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
  white-space: pre;
  line-height: 1.4;
}

/* ── Diff view ── */
.diff-line {
  font-family: 'SF Mono', 'Fira Code', ui-monospace, monospace;
  font-size: 13px;
  padding: 1px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-add {
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
}

.diff-remove {
  background: rgba(248, 81, 73, 0.15);
  color: var(--red);
}

.diff-header {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

/* ── Index / root page ── */
.index-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 80px 24px;
  text-transform: lowercase;
}

.index-brand {
  margin-bottom: 48px;
}

.index-brand h1 {
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.index-brand p {
  font-size: 14px;
  color: var(--muted);
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
  transition: background 0.15s;
}

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

.doc-item-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.doc-item-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.doc-item-icon svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.doc-item-info {
  min-width: 0;
}

.doc-item-title {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-item-meta {
  font-size: 12px;
  color: var(--muted);
}

.doc-item-arrow {
  color: var(--border);
  flex-shrink: 0;
  transition: color 0.15s;
}

.doc-item:hover .doc-item-arrow {
  color: var(--muted);
}

.doc-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 500;
  padding: 0px 5px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 6px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', ui-monospace, monospace;
}

.doc-item-title .doc-badge {
  position: relative;
  top: -2px;
}

.doc-badge-shared {
  background: rgba(88, 166, 255, 0.1);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.25);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Responsive ── */
@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .topbar-title { font-size: 12px; }
  .doc-content { padding: 28px 18px 60px; }
  .index-page { padding: 48px 18px; }
}
