/* Against Entropy — Unified Stylesheet
   Indian Earth Design System
   One CSS file for all pages. */

/* === Design Tokens === */
:root {
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #f3f4f6;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #c2452d;
  --accent-light: #e06b55;
  --accent-bg: #fef2f0;
  --forest: #1a5c4c;
  --forest-light: #3d9e82;
  --sand: #c4a67d;
  --shadow: rgba(0, 0, 0, 0.06);
  --font-serif: 'Libre Baskerville', Georgia, serif;
  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
  --max-width: 680px;
  --wide-width: 960px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 12px;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* === Skip to content === */
.skip-link {
  position: absolute; top: -40px; left: 0;
  background: var(--forest); color: #fff;
  padding: 8px 16px; z-index: 100;
  font-size: 0.875rem;
}
.skip-link:focus { top: 0; }

/* === Site Header === */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
}
.header-inner {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
}
.logo-mark {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.5rem;
  color: var(--accent);
}
.logo-text {
  font-weight: 500;
  font-size: 0.9375rem;
}
@media (max-width: 480px) {
  .logo-text { display: none; }
}

.site-nav {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  font-size: 0.875rem;
}
.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.25rem 0;
}
.site-nav a:hover { color: var(--accent); }
.site-nav a.active {
  color: var(--accent);
  font-weight: 500;
}

/* === Site Footer === */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: auto;
}
.footer-inner {
  max-width: var(--wide-width);
  margin: 0 auto;
}
.social-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
}
.social-links a { color: var(--text-muted); }
.social-links a:hover { color: var(--accent); }

/* === Page Layouts === */
.page {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  flex: 1;
}
.page-wide {
  max-width: var(--wide-width);
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  flex: 1;
}

/* === Section Hero === */
.hero {
  padding: 2.5rem 0 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.hero-compact {
  padding: 1.5rem 0 1rem;
  margin-bottom: 0.75rem;
}
.hero-tagline {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-top: 0.75rem;
}
.hero-tagline strong {
  color: var(--text);
  font-weight: 600;
}
.hero-tag-link {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
.hero-tag-link:hover {
  text-decoration: underline;
}
.top-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.hero h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 2rem;
  margin-bottom: 0.75rem;
}
.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 580px;
}
.hero-stats {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.hero-stats strong {
  color: var(--text);
  font-weight: 600;
}

/* === Search Widget === */
.search-wrapper {
  position: relative;
  max-width: 480px;
  margin-top: 1.5rem;
}
.search-input {
  width: 100%;
  padding: 0.625rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194, 69, 45, 0.1); }

.search-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-top: 4px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
  box-shadow: 0 4px 16px var(--shadow);
}
.search-results.active { display: block; }
.search-result-item {
  display: block;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg); }
.search-result-title { font-weight: 500; }
.search-result-excerpt {
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* === Card Grid (Browse / Home) === */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}
.card-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 860px) {
  .card-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .card-grid,
  .card-grid-3 { grid-template-columns: 1fr; }
}
.view-all {
  text-align: center;
  margin-top: 2.5rem;
  font-size: 0.9375rem;
}
.view-all a {
  color: var(--accent);
  font-weight: 500;
}
.view-all a:hover {
  color: var(--accent-light);
}

.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 1px 3px var(--shadow);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px var(--shadow);
}
.card-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.125rem;
  margin-bottom: 0.375rem;
  line-height: 1.4;
  color: var(--text);
  transition: color 0.15s ease;
}
.card:hover .card-title { color: var(--accent); }
.card-source-byline {
  font-size: 0.8125rem;
  color: var(--accent);
  margin-bottom: 0.375rem;
  font-weight: 500;
}
.card-excerpt {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.card-badges {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.card-topic {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sand);
  margin-bottom: 0.25rem;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
}
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-type { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.wip-note {
  font-size: 0.8125rem;
  font-style: italic;
  color: #92400e;
  margin-bottom: 0.5rem;
}

/* === Tags === */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tag {
  display: inline-block;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.tag:hover { background: #fde8e4; color: var(--accent); }
.tag.active {
  background: var(--accent);
  color: #fff;
}

/* === Tag Filter Bar === */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

/* === Article Page === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
}
.back-link:hover { color: var(--text); }

.article-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 400;
  line-height: 1.3;
  color: var(--text);
  margin-bottom: 1rem;
}
@media (min-width: 640px) {
  .article-title { font-size: 2.5rem; }
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.article-tags {
  margin-bottom: 2.5rem;
}

/* === Enrichment Panel (AI's Take) === */
.enrichment {
  margin-bottom: 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.enrichment summary {
  cursor: pointer;
  padding: 1rem 1.5rem;
  background: #fffbeb;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.enrichment summary::-webkit-details-marker { display: none; }
.enrichment summary::after {
  content: '\25BC';
  font-size: 0.75rem;
  color: var(--accent);
  transition: transform 0.2s;
}
.enrichment[open] summary::after { transform: rotate(180deg); }
.enrichment-insight {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  font-style: italic;
  color: var(--text-muted);
}
.enrichment-body {
  padding: 1.5rem;
  background: #fffbeb;
}
.enrichment-section { margin-bottom: 1rem; }
.enrichment-section:last-child { margin-bottom: 0; }
.enrichment-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.enrichment-text {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: #374151;
}
.enrichment-list {
  list-style: none;
  padding: 0;
}
.enrichment-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
  color: #374151;
}
.enrichment-list li::before {
  content: '\2022';
  color: var(--accent);
  font-weight: bold;
  margin-top: 2px;
}
.enrichment-grid {
  display: grid;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
@media (min-width: 640px) {
  .enrichment-grid { grid-template-columns: 1fr 1fr; }
}
.enrichment-grid .label-good { color: var(--forest); font-weight: 600; font-size: 0.8125rem; margin-bottom: 0.25rem; }
.enrichment-grid .label-bad { color: #b91c1c; font-weight: 600; font-size: 0.8125rem; margin-bottom: 0.25rem; }
.enrichment-grid p { font-size: 0.8125rem; color: var(--text-muted); }
.enrichment-concepts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}
.concept-tag {
  font-size: 0.75rem;
  padding: 4px 8px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: var(--radius-sm);
}

/* === Prose (Article Body) === */
.prose h1 { font-family: var(--font-serif); font-size: 1.875rem; font-weight: 400; margin: 2rem 0 1rem; }
.prose h2 { font-family: var(--font-serif); font-size: 1.5rem; font-weight: 400; margin: 2rem 0 1rem; }
.prose h3 { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 400; margin: 1.5rem 0 0.75rem; color: var(--accent); }
.prose p { margin-bottom: 1rem; line-height: 1.8; }
.prose a { color: var(--accent); text-decoration: underline; }
.prose a:hover { color: var(--accent-light); }
.prose ul, .prose ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: 0.5rem; }
.prose ul li { list-style-type: disc; }
.prose ol li { list-style-type: decimal; }
.prose blockquote {
  border-left: 4px solid var(--sand);
  padding-left: 1rem;
  font-style: italic;
  color: var(--text-muted);
  margin: 1rem 0;
}
.prose strong { font-weight: 600; }
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 3px;
}
.prose pre {
  background: #1f2937;
  color: #f3f4f6;
  padding: 1rem;
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin: 1rem 0;
  font-size: 0.875rem;
  line-height: 1.6;
}
.prose pre code { background: none; padding: 0; color: inherit; }
.prose img { max-width: 100%; border-radius: var(--radius-lg); margin: 1rem 0; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.prose table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: 0.9375rem; }
.prose th { text-align: left; padding: 0.5rem; border-bottom: 2px solid var(--border); font-weight: 600; }
.prose td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
.prose tr:last-child td { border-bottom: none; }

/* === Callouts === */
.callout {
  margin: 1.5rem 0;
  border-radius: var(--radius-lg);
  border-left: 4px solid;
  overflow: hidden;
}
.callout-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.callout-content {
  padding: 0 1rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.7;
  color: #374151;
}
.callout-content p:last-child { margin-bottom: 0; }

.callout-highlight { border-color: #f59e0b; background: #fffbeb; }
.callout-highlight .callout-title { background: #fef3c7; color: #92400e; }
.callout-note { border-color: #3b82f6; background: #eff6ff; }
.callout-note .callout-title { background: #dbeafe; color: #1e40af; }
.callout-question { border-color: var(--accent); background: var(--accent-bg); }
.callout-question .callout-title { background: #fee2e2; color: #991b1b; }
.callout-insight { border-color: #22c55e; background: #f0fdf4; }
.callout-insight .callout-title { background: #dcfce7; color: #166534; }
.callout-warning { border-color: #ef4444; background: #fef2f2; }
.callout-warning .callout-title { background: #fee2e2; color: #991b1b; }
.callout-tip { border-color: #14b8a6; background: #f0fdfa; }
.callout-tip .callout-title { background: #ccfbf1; color: #115e59; }

/* === WIP Notes === */
.wip-notes {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
}
.wip-notes strong { color: #92400e; }
.wip-notes span { color: #78350f; }

/* === Article Footer Nav === */
.article-footer {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.article-footer a {
  color: var(--accent);
  font-size: 0.9375rem;
}

/* === Source Link === */
.source-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.625rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--forest);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--forest);
  font-weight: 500;
}
.source-link:hover { background: var(--forest); color: #fff; }

/* === Related Articles === */
.related-articles {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.related-articles h3 {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  margin-bottom: 1rem;
}
.related-list {
  list-style: none;
  padding: 0;
}
.related-list li {
  margin-bottom: 0.75rem;
}
.related-list a {
  font-size: 0.9375rem;
}
.related-list .shared-concepts {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

/* === Concepts Page === */
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.concept-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s;
}
.concept-card:hover { border-color: var(--accent); }
.concept-name {
  font-weight: 500;
  margin-bottom: 0.25rem;
}
.concept-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* === Sort / Filter Controls === */
.controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.controls label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.controls select {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.page-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

/* === Loading skeleton (optional, for search JSON fetch) === */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-lg);
  height: 120px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* === Utilities === */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); border: 0;
}
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
