:root {
  --bg: #0a0e13;
  --surface: #0d1117;
  --surface-raised: #161b22;
  --ink: #e6edf3;
  --ink-muted: #8b949e;
  --ink-hint: #484f58;
  --border: #21262d;
  --border-light: #30363d;
  --accent: #a371f7;
  --green: #3fb950;
  --green-dim: rgba(63, 185, 80, 0.08);
  --amber: #d29922;
  --amber-dim: rgba(210, 153, 34, 0.08);
  --red: #f85149;
  --red-dim: rgba(248, 81, 73, 0.08);
  --blue: #58a6ff;
  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --ink: #0e1525;
  --ink-muted: #4b5563;
  --ink-hint: #9ca3af;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --accent: #7c5cbf;
  --green: #2d8a4e;
  --green-dim: rgba(45, 138, 78, 0.06);
  --amber: #b07a1a;
  --amber-dim: rgba(176, 122, 26, 0.06);
  --red: #c53030;
  --red-dim: rgba(197, 48, 48, 0.06);
  --blue: #3d6b8e;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  border-top: 2px solid var(--green);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0 0 0.5rem;
  line-height: 1.2;
}

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

a:hover {
  text-decoration: underline;
}

/* Layout */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#home-link {
  text-decoration: none;
  color: var(--ink);
}

#home-link:hover {
  text-decoration: none;
}

header h1 {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-link {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
  text-decoration: none;
}

.header-link:hover {
  color: var(--ink);
  text-decoration: none;
}

#theme-toggle {
  background: var(--surface-raised);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  cursor: pointer;
}

/* Footer */
footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Main */
main#view {
  padding: 1.5rem 1rem;
  min-height: calc(100vh - 140px);
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 1.5rem;
}

.breadcrumb a {
  color: var(--ink-muted);
}

.breadcrumb a:hover {
  color: var(--ink);
}

.breadcrumb .sep {
  margin: 0 0.35rem;
}

/* Landing */
.landing-intro {
  margin-bottom: 2rem;
}

.landing-intro p {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin: 0.5rem 0;
  max-width: 600px;
}

.landing-headline {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5vw, 3rem);
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.1;
}

.browse-heading {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 2rem 0 0.75rem;
}

/* Index stats card */
.index-stats {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.index-stats .stats-row {
  margin-bottom: 0;
}

/* Nav row */
.nav-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.nav-row a {
  color: var(--ink-muted);
}

.nav-row a:hover {
  color: var(--ink);
}

/* Stats */
.stats-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.stat {
  text-align: center;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-hint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Search */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-width: 600px;
}

.search-bar input {
  flex: 1;
}

.search-bar button {
  flex-shrink: 0;
}

/* Forms */
select, input[type="text"], input[type="search"] {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  width: 100%;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--surface-raised);
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  font-family: var(--font-mono);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h2, .card h3 {
  margin-top: 0;
}

/* Search Results */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.result-card:hover {
  border-color: var(--border-light);
}

.result-municipality {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-hint);
  margin-bottom: 0.25rem;
}

.result-section {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.result-section a {
  color: var(--ink);
}

.result-section a:hover {
  color: var(--accent);
}

.result-section .section-number {
  font-family: var(--font-mono);
  color: var(--ink-muted);
  margin-right: 0.5rem;
}

.result-snippet {
  font-size: 0.875rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.result-snippet mark {
  background: var(--amber-dim);
  color: var(--amber);
  padding: 0 0.125rem;
}

.results-meta {
  font-size: 0.85rem;
  color: var(--ink-hint);
  margin-bottom: 1rem;
}

.no-results {
  color: var(--ink-muted);
  padding: 2rem 0;
}

/* Section detail */
.section-body {
  line-height: 1.8;
  max-width: 700px;
  font-size: 0.95rem;
  margin: 1.5rem 0;
  border-left: 2px solid var(--border-light);
  padding-left: 1.25rem;
}

.section-meta {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 1.5rem;
}

.section-meta span {
  margin-right: 1.5rem;
}

/* Section context card */
.section-context {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* Source attribution */
.source-line {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin: 0.25rem 0 0.75rem;
}

.source-line a {
  color: var(--ink-muted);
}

.source-line a:hover {
  color: var(--accent);
}

/* Municipality header card */
.muni-card {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.muni-card h2 {
  margin-bottom: 0.5rem;
}

.muni-details {
  font-size: 0.9rem;
  color: var(--ink-muted);
}

.muni-details p {
  margin: 0.25rem 0;
}

.muni-card-map {
  min-height: 200px;
  height: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

/* Muni stats inside card */
.muni-stats {
  display: flex;
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.muni-stats .stat-value {
  font-size: 1.25rem;
}

.muni-stats .stat-label {
  font-size: 0.65rem;
}

/* Accordion: title and chapter toggles */
.title-group {
  margin-bottom: 1.5rem;
  border-left: 2px solid var(--accent);
  padding-left: 0.75rem;
}

.title-group h3.title-toggle {
  font-size: 1rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.title-toggle .toggle-icon::after {
  content: '\25BC';
  font-size: 0.6rem;
  color: var(--ink-hint);
}

.title-group.collapsed .toggle-icon::after {
  content: '\25B6';
}

.title-group.collapsed .title-content {
  display: none;
}

.chapter-group {
  margin-bottom: 1rem;
  margin-left: 1rem;
}

.chapter-group h4.chapter-toggle {
  font-size: 0.875rem;
  color: var(--ink-muted);
  font-weight: 600;
  margin-bottom: 0.375rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.chapter-toggle .toggle-icon::after {
  content: '\25BC';
  font-size: 0.5rem;
  color: var(--ink-hint);
}

.chapter-group.collapsed .toggle-icon::after {
  content: '\25B6';
}

.chapter-group.collapsed .section-list {
  display: none;
}

.section-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0 0.5rem;
}

.section-list li {
  padding: 0.375rem 0;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.section-list li:last-child {
  border-bottom: none;
}

.section-list .section-num {
  font-family: var(--font-mono);
  color: var(--ink-muted);
  margin-right: 0.5rem;
  font-size: 0.8rem;
}

/* Compare layout */
.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.compare-column {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem;
}

.compare-column h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.compare-column .result-card {
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  margin-bottom: 0;
}

.compare-column .result-card:last-child {
  border-bottom: none;
}

/* Topic tags */
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  padding: 0.125rem 0.5rem;
  text-decoration: none;
}

.tag:hover {
  color: var(--ink);
  border-color: var(--border-light);
  text-decoration: none;
}

/* Topic index grid */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.topic-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--ink);
}

.topic-card:hover {
  border-color: var(--border-light);
  text-decoration: none;
}

.topic-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.topic-count {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
}

/* Quote highlight */
.quote-highlight {
  background: var(--amber-dim);
  padding: 0.125rem 0;
}

.copy-link-btn {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  cursor: pointer;
  white-space: nowrap;
}

.copy-link-btn:hover {
  color: var(--ink);
  border-color: var(--accent);
}

/* Prev/next section navigation */
.section-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  max-width: 700px;
}

.section-nav a {
  color: var(--ink-muted);
  max-width: 45%;
}

.section-nav a:hover {
  color: var(--accent);
}

/* Similar sections */
.similar-sections {
  margin-top: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1rem;
  max-width: 700px;
}

.similar-sections h4 {
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.similar-section-name {
  color: var(--ink-muted);
  font-size: 0.8rem;
  margin-left: 0.25rem;
}

.similar-sections ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.similar-sections li {
  padding: 0.25rem 0;
  font-size: 0.85rem;
}

/* Coverage map */
.coverage-map {
  width: 100%;
  height: calc(100vh - 220px);
  min-height: 400px;
  border: 1px solid var(--border);
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--ink-muted);
  white-space: nowrap;
}

td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

tr:hover {
  background: var(--surface-raised);
}

tr.clickable {
  cursor: pointer;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* Links */
.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--ink-muted);
}

.back-link:hover {
  color: var(--ink);
}

/* Loading */
.loading {
  color: var(--ink-muted);
  font-family: var(--font-mono);
  padding: 2rem 0;
}

/* Responsive */
@media (max-width: 768px) {
  .stat-value {
    font-size: 1.5rem;
  }

  .section-body {
    max-width: 100%;
  }

  .muni-card {
    grid-template-columns: 1fr;
  }

  .muni-card-map {
    height: 200px;
    min-height: 200px;
  }

  .section-context {
    flex-direction: column;
  }

  .section-nav {
    flex-direction: column;
    gap: 0.5rem;
  }

  .section-nav a {
    max-width: 100%;
  }

  .compare-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 0.8125rem;
  }

  .stats-row {
    flex-direction: column;
    gap: 0.75rem;
  }

  main#view {
    padding: 1rem 0.5rem;
  }

  .search-bar {
    flex-direction: column;
  }

  .topic-grid {
    grid-template-columns: 1fr;
  }
}
