:root {
  --bg: #FAFAF8;
  --fg: #111827;
  --fg-muted: #6B7280;
  --accent: #1E3A8A;
  --accent-hover: #1D4ED8;
  --accent-bg: #EFF6FF;
  --border: #E5E7EB;
  --code-bg: #18181B;
  --code-fg: #E4E4E7;
  --inline-code-bg: #F3F4F6;
  --method-bg: #FFFFFF;
  --sidebar-bg: #F9F9F7;
  --nav-bg: #FFFFFF;
  --sidebar-w: 272px;
  --nav-h: 60px;
  --shadow: 0 1px 3px rgba(0,0,0,0.07);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 8px;
  --badge-abstract-bg: #EFF6FF;
  --badge-abstract-fg: #1E3A8A;
  /* Syntax highlighting — tuned for dark code blocks */
  --hl-keyword: #C084FC;
  --hl-string: #86EFAC;
  --hl-number: #FCA5A5;
  --hl-comment: #71717A;
  --hl-selector: #93C5FD;
  --hl-symbol: #FCD34D;
  --hl-class: #F9A8D4;
  --hl-self: #F87171;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0A0A09;
    --fg: #FAFAF8;
    --fg-muted: #9CA3AF;
    --accent: #60A5FA;
    --accent-hover: #93C5FD;
    --accent-bg: #1E3A8A;
    --border: #27272A;
    --code-bg: #111110;
    --code-fg: #E4E4E7;
    --inline-code-bg: #27272A;
    --method-bg: #18181B;
    --sidebar-bg: #111110;
    --nav-bg: #0A0A09;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
    --badge-abstract-bg: #1E3A8A;
    --badge-abstract-fg: #93C5FD;
  }
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.7;
}

/* --- Top navigation bar --- */
.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  z-index: 100;
  gap: 1.5rem;
}

.nav-logo {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
  text-decoration: none;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.nav-logo:hover { color: var(--fg); text-decoration: none; }
.nav-logo img { display: block; height: 32px; width: auto; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}

.nav-links a {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg-muted);
  text-decoration: none;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.nav-links a:hover {
  background: var(--accent-bg);
  color: var(--accent);
  text-decoration: none;
}
.nav-links a.nav-github {
  margin-left: auto;
  border: 1px solid var(--border);
}
.nav-links a.nav-github:hover { border-color: var(--accent); }

/* --- Layout --- */
.page-wrapper {
  display: flex;
  min-height: 100vh;
  padding-top: var(--nav-h);
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--nav-h);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  padding: 1.25rem 0;
  z-index: 10;
  transition: transform 0.2s;
}

.sidebar-search-wrap {
  padding: 0 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.sidebar-search {
  display: block;
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.83rem;
  background: var(--bg);
  color: var(--fg);
  outline: none;
  font-family: inherit;
}
.sidebar-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.sidebar-section-label {
  padding: 0.75rem 1.25rem 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.sidebar-nav { list-style: none; }
.sidebar-nav li { margin: 0; }
.sidebar-nav a {
  display: block;
  padding: 0.55rem 1.25rem;
  font-size: 0.875rem;
  color: var(--fg-muted);
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
  overflow-wrap: break-word;
  word-break: break-word;
}
.sidebar-nav a:hover {
  background: var(--accent-bg);
  color: var(--accent);
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  max-width: 860px;
  padding: 2.5rem 3rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(var(--nav-h) + 10px);
  left: 12px;
  z-index: 20;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  color: var(--fg);
  min-width: 44px;
  min-height: 44px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar-toggle { display: block; }
  .main-content { margin-left: 0; padding: 2rem 1.25rem; padding-top: 3.5rem; }
  .nav-links a:not(.nav-github) { display: none; }

  /* Collapse TOC to single column */
  .toc ul { column-count: 1; }

  /* Make tables scroll horizontally */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Scale page headings */
  h1 { font-size: 1.5rem; }

  /* Stack method header on narrow screens */
  .method-header { flex-direction: column; gap: 0.4rem; }
  .source-link { margin-left: 0; }

  /* Code block horizontal scroll with tighter padding */
  pre { padding: 1rem; font-size: 0.82rem; }
}

@media (max-width: 480px) {
  /* Very small screens: tighter padding */
  .main-content { padding: 1.25rem 0.875rem; padding-top: 3.5rem; }
  .landing-content { padding: 1.5rem 1rem 1.5rem; }

  /* Tighter nav padding */
  .top-nav { padding: 0 1rem; }

  /* Full-width CTAs with adequate tap targets */
  .landing-cta { flex-direction: column; }
  .btn-primary, .btn-secondary { width: 100%; text-align: center; padding: 0.75rem 1.25rem; min-height: 44px; }

  /* Landing hero: tighter gap and smaller logo */
  .landing-hero { gap: 1.5rem; }
  .landing-logo img { height: 36px; }

  /* Reduce method card padding */
  .method { padding: 1rem; }

  /* Code blocks: smaller font on tiny screens */
  pre { font-size: 0.78rem; padding: 0.75rem 1rem; }

  /* Code window tighter layout */
  .code-window-bar { padding: 0.5rem 0.75rem; }
  .code-window-body { padding: 0.75rem 1rem; }
  .code-window-body pre { font-size: 0.75rem; }
}

/* --- Typography --- */
a { color: inherit; text-decoration: none; }
a:hover { color: inherit; }
img { max-width: 100%; height: auto; }

/* Underline links in running prose text, tables, and lists */
.main-content p a,
.method-doc p a,
.class-doc p a,
.readme p a,
.main-content table a,
.prose-content table a,
.prose-content li a { text-decoration: underline; }

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.025em;
  line-height: 1.2;
}
h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
h3 { font-size: 1.05rem; font-weight: 600; margin-top: 1.75rem; margin-bottom: 0.4rem; }
h4 {
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.3rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
p { margin-bottom: 0.875rem; }

code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--inline-code-bg);
  color: var(--fg);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.25rem;
  line-height: 1.6;
}
pre code { background: none; color: inherit; padding: 0; font-size: 0.875rem; }

/* --- Tables --- */
table { border-collapse: collapse; width: 100%; margin-bottom: 1.25rem; font-size: 0.9rem; }
th, td { border: 1px solid var(--border); padding: 0.5rem 0.875rem; text-align: left; overflow-wrap: break-word; word-break: break-word; }
td.adr-num { white-space: nowrap; }
.prose-content td:first-child { white-space: nowrap; }
th {
  background: var(--accent-bg);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
tbody tr:hover { background: var(--sidebar-bg); }

/* --- Lists --- */
.class-doc ul, .class-doc ol, .method-doc ul, .method-doc ol, .readme ul, .readme ol,
.prose-content ul, .prose-content ol {
  margin-bottom: 0.875rem;
  padding-left: 1.5rem;
}
.class-doc li, .method-doc li, .readme li,
.prose-content li { margin-bottom: 0.3rem; }

/* --- Breadcrumb --- */
.breadcrumb {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.breadcrumb a { color: var(--fg-muted); }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }

/* --- Chapter navigation --- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  margin: 1.5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  gap: 1rem;
}
.chapter-nav a { color: var(--accent); text-decoration: none; }
.chapter-nav a:hover { text-decoration: underline; }
.chapter-nav-prev { text-align: left; flex: 1; }
.chapter-nav-up { text-align: center; flex: 0; white-space: nowrap; color: var(--fg-muted); }
.chapter-nav-up:hover { color: var(--accent) !important; }
.chapter-nav-next { text-align: right; flex: 1; }
.chapter-nav-placeholder { flex: 1; }

/* --- Class page --- */
.class-doc { margin-bottom: 2.5rem; }

.superclass {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--fg-muted);
  margin-bottom: 1.25rem;
  background: var(--accent-bg);
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-sealed { background: var(--inline-code-bg); color: var(--fg-muted); }
.badge-abstract { background: var(--badge-abstract-bg); color: var(--badge-abstract-fg); }

/* --- Methods --- */
.method {
  background: var(--method-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  transition: box-shadow 0.15s;
}
.method:hover { box-shadow: var(--shadow-md); }
.method:target { border-left: 3px solid var(--accent); }

.method-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.method-signature {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  overflow-wrap: break-word;
  word-break: break-all;
  min-width: 0;
}
.source-link { font-size: 0.75rem; color: var(--fg-muted); margin-left: auto; }
.method-doc { margin-top: 0.6rem; }
.method-doc p { margin-bottom: 0.5rem; }

/* --- TOC --- */
.toc { margin-bottom: 2rem; }
.toc ul { list-style: none; column-count: 2; column-gap: 2rem; }
.toc li { margin-bottom: 0.3rem; font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }
.toc .label {
  display: inline-block;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--fg-muted);
  background: var(--inline-code-bg);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  margin-right: 0.3rem;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Class list (index) --- */
.class-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 0.75rem;
}
.class-list li {
  background: var(--method-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.class-list li:hover { box-shadow: var(--shadow-md); border-color: var(--accent); }
.class-list li a { font-weight: 600; }
.class-list .class-summary {
  display: block;
  font-size: 0.82rem;
  color: var(--fg-muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* --- Hierarchy tree --- */
.hierarchy-tree { margin-bottom: 2.5rem; }
.hierarchy-tree ul {
  list-style: none;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
}
.hierarchy-tree > ul { border-left: none; padding-left: 0; }
.hierarchy-tree li { margin: 0.25rem 0; font-size: 0.9rem; }
.hierarchy-tree a { font-weight: 500; }
.hierarchy-tree .class-summary {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-left: 0.4rem;
}

/* --- ADR list --- */
.adr-list { list-style: none; padding: 0; margin: 1.5rem 0; }
.adr-list li { margin: 0.4rem 0; font-size: 0.95rem; }
.adr-list a { text-decoration: none; }
.adr-list a:hover { text-decoration: underline; }

/* --- Inherited methods --- */
.inherited-section { margin-top: 2.5rem; }
.inherited-section .method { background: transparent; border-style: dashed; opacity: 0.8; }

/* --- Search results --- */
.search-results { display: none; margin-bottom: 2rem; }
.search-results.active { display: block; }
.search-results h2 { border-bottom: none; margin-top: 0; }
.search-result-item { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.search-result-item:last-child { border-bottom: none; }
.search-result-class { font-weight: 600; }
.search-result-method { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; }

/* --- Syntax highlighting (on dark code blocks) --- */
.hl-keyword { color: var(--hl-keyword); font-weight: 600; }
.hl-string { color: var(--hl-string); }
.hl-number { color: var(--hl-number); }
.hl-comment { color: var(--hl-comment); font-style: italic; }
.hl-selector { color: var(--hl-selector); }
.hl-symbol { color: var(--hl-symbol); }
.hl-class { color: var(--hl-class); }
.hl-self { color: var(--hl-self); font-weight: 600; }

/* --- Footer --- */
footer {
  margin-top: 4rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--fg-muted);
}

/* --- Landing page --- */
.landing-wrapper {
  flex-direction: column;
}
.landing-wrapper .sidebar-toggle { display: none; }

.landing-content {
  max-width: 1020px;
  margin: 0 auto;
  padding: 4rem 2.5rem 3rem;
  width: 100%;
}

.landing-hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
  margin-bottom: 5rem;
}
@media (max-width: 860px) {
  .landing-hero { grid-template-columns: 1fr; gap: 2.5rem; }
  .landing-content { padding: 2.5rem 1.5rem 2rem; }
  .landing-logo img { height: 44px; }
}

.landing-logo {
  display: block;
  margin-bottom: 1.25rem;
}
.landing-logo img { height: 56px; width: auto; }

.landing-hero-text h1 {
  font-size: 2.75rem;
  line-height: 1.1;
  letter-spacing: -0.04em;
  margin-bottom: 1rem;
}
.landing-tagline {
  font-size: 1.05rem;
  color: var(--fg-muted);
  line-height: 1.65;
  margin-bottom: 1.75rem;
}
.landing-cta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }

.btn-secondary {
  display: inline-block;
  background: transparent;
  color: var(--fg-muted);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.6rem 1.25rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.landing-code-window {
  background: var(--code-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.code-window-bar {
  background: #27272A;
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.code-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.code-dot-r { background: #EF4444; }
.code-dot-y { background: #F59E0B; }
.code-dot-g { background: #10B981; }
.code-window-title {
  margin-left: 0.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: #A1A1AA;
}
.code-window-body { padding: 1.25rem 1.5rem; }
.code-window-body pre {
  margin: 0; padding: 0; background: none;
  font-size: 0.82rem;
  line-height: 1.75;
}
.code-window-body pre code { background: none; color: var(--code-fg); padding: 0; }

.landing-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}
.landing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.landing-card {
  display: block;
  background: var(--method-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--fg);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}
.landing-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
  transform: translateY(-1px);
  text-decoration: none;
}
.landing-card h2 {
  font-size: 0.95rem;
  margin-top: 0; margin-bottom: 0.4rem;
  border-bottom: none; padding-bottom: 0;
  color: var(--fg); font-weight: 600;
}
.landing-card p {
  font-size: 0.875rem;
  color: var(--fg-muted);
  margin-bottom: 0;
  line-height: 1.5;
}
.landing-links {
  text-align: center;
  margin-top: 2rem;
  font-size: 0.875rem;
  color: var(--fg-muted);
}
.landing-links a:hover { text-decoration: underline; }

/* --- Prose pages --- */
.prose-content { max-width: 760px; min-width: 0; overflow-wrap: break-word; word-break: break-word; }
