/* ============================================================
   Project 2029 — Custom Theme
   A Mandate for Restorative + Transformative Democratic Renewal
   ============================================================ */

/* ----- CSS Variables / Color Scheme ----- */
:root {
  --primary: #1a2744;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #dbeafe;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-sidebar: #f1f5f9;
  --border-color: #e2e8f0;
  --highlight: #fef08a;

  /* Section colors */
  --section1-governance: #7c3aed;
  --section2-defense: #dc2626;
  --section3-welfare: #059669;
  --section4-economy: #d97706;
  --section5-regulatory: #0891b2;
  --section6-democracy: #1d4ed8;

  /* Callout colors */
  --callout-info-bg: #eff6ff;
  --callout-info-border: #2563eb;
  --callout-tip-bg: #ecfdf5;
  --callout-tip-border: #059669;
  --callout-warning-bg: #fffbeb;
  --callout-warning-border: #d97706;
  --callout-danger-bg: #fef2f2;
  --callout-danger-border: #dc2626;

  /* Theme override */
  --theme-color: #2563eb;
}

/* ----- Dark Mode ----- */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #0f172a;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --accent-light: #1e3a5f;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-sidebar: #1e293b;
    --border-color: #334155;
    --highlight: #854d0e;

    --callout-info-bg: #1e293b;
    --callout-info-border: #3b82f6;
    --callout-tip-bg: #1e293b;
    --callout-tip-border: #34d399;
    --callout-warning-bg: #1e293b;
    --callout-warning-border: #fbbf24;
    --callout-danger-bg: #1e293b;
    --callout-danger-border: #f87171;

    --theme-color: #3b82f6;
  }

  body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
  }

  .markdown-section {
    color: var(--text-primary);
  }

  .markdown-section h1,
  .markdown-section h2,
  .markdown-section h3,
  .markdown-section h4,
  .markdown-section h5,
  .markdown-section h6 {
    color: var(--text-primary);
  }

  .sidebar {
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
    border-right-color: var(--border-color);
  }

  .sidebar ul li a {
    color: var(--text-secondary);
  }

  .sidebar ul li a:hover,
  .sidebar ul li.active > a {
    color: var(--accent);
  }

  .search input {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
  }

  .search .results-panel {
    background-color: var(--bg-secondary);
  }

  .app-nav {
    background-color: var(--bg-primary);
  }

  table tr:nth-child(even) {
    background-color: var(--bg-secondary);
  }

  table tr:nth-child(odd) {
    background-color: var(--bg-primary);
  }

  code,
  .markdown-section code {
    background-color: var(--bg-secondary);
    color: #e879f9;
  }

  .markdown-section pre > code {
    color: var(--text-primary);
  }

  .docsify-pagination-container {
    border-top-color: var(--border-color);
  }

  blockquote {
    border-left-color: var(--accent);
    color: var(--text-secondary);
  }
}

/* ----- Base Typography ----- */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.markdown-section {
  max-width: 860px;
  padding: 2rem 2.5rem 3rem;
  margin: 0 auto;
}

/* ----- Headings ----- */
.markdown-section h1 {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--primary);
  margin-top: 2rem;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.5rem;
}

.markdown-section h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-color);
}

.markdown-section h3 {
  font-size: 1.375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

.markdown-section h4 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.markdown-section h5,
.markdown-section h6 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

/* ----- Paragraphs and Inline ----- */
.markdown-section p {
  margin: 0 0 1rem;
}

.markdown-section strong {
  font-weight: 700;
  color: var(--text-primary);
}

.markdown-section a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-bottom-color 0.2s ease;
}

.markdown-section a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

/* ----- Code ----- */
.markdown-section code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier,
    monospace;
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background-color: var(--bg-secondary);
  color: #c026d3;
}

.markdown-section pre {
  border-radius: 8px;
  border: 1px solid var(--border-color);
  overflow-x: auto;
}

.markdown-section pre > code {
  padding: 1.25rem;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  display: block;
}

/* ----- Blockquotes ----- */
.markdown-section blockquote {
  border-left: 4px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}

.markdown-section blockquote p {
  margin: 0;
}

/* ----- Lists ----- */
.markdown-section ul,
.markdown-section ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.markdown-section li {
  margin-bottom: 0.35rem;
}

/* ----- Horizontal Rule ----- */
.markdown-section hr {
  border: none;
  border-top: 2px solid var(--border-color);
  margin: 2.5rem 0;
}

/* ----- Tables ----- */
.markdown-section table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.markdown-section table thead {
  background: var(--primary);
  color: #ffffff;
}

.markdown-section table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.markdown-section table td {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-color);
}

.markdown-section table tr:nth-child(even) {
  background-color: var(--bg-secondary);
}

.markdown-section table tr:hover {
  background-color: var(--accent-light);
}

/* ----- Sidebar ----- */
.sidebar {
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  padding-top: 1rem;
}

.sidebar > h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  padding: 0 1rem;
  margin-bottom: 0.5rem;
}

.sidebar ul li a {
  font-size: 0.925rem;
  color: var(--text-secondary);
  padding: 0.3rem 0.5rem;
  display: block;
  transition: color 0.15s ease, background-color 0.15s ease;
  border-radius: 4px;
}

.sidebar ul li a:hover {
  color: var(--accent);
  background-color: rgba(37, 99, 235, 0.06);
}

.sidebar ul li.active > a {
  color: var(--accent);
  font-weight: 600;
  background-color: rgba(37, 99, 235, 0.08);
}

/* Section color indicators in sidebar */
.sidebar-nav > ul > li:nth-child(n+3):nth-child(-n+5) > a {
  border-left: 3px solid var(--section1-governance);
  padding-left: 0.75rem;
}

.sidebar-nav > ul > li:nth-child(n+6):nth-child(-n+11) > a {
  border-left: 3px solid var(--section2-defense);
  padding-left: 0.75rem;
}

.sidebar-nav > ul > li:nth-child(n+12):nth-child(-n+22) > a {
  border-left: 3px solid var(--section3-welfare);
  padding-left: 0.75rem;
}

.sidebar-nav > ul > li:nth-child(n+23):nth-child(-n+28) > a {
  border-left: 3px solid var(--section4-economy);
  padding-left: 0.75rem;
}

.sidebar-nav > ul > li:nth-child(n+29):nth-child(-n+29) > a {
  border-left: 3px solid var(--section5-regulatory);
  padding-left: 0.75rem;
}

.sidebar-nav > ul > li:nth-child(n+30):nth-child(-n+33) > a {
  border-left: 3px solid var(--section6-democracy);
  padding-left: 0.75rem;
}

/* Sidebar search styling */
.sidebar .search {
  margin-bottom: 1rem;
  padding: 0 0.75rem;
}

.sidebar .search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.2s ease;
}

.sidebar .search input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.sidebar .search .results-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ----- Cover Page ----- */
section.cover {
  background: linear-gradient(135deg, var(--primary) 0%, #0f172a 100%) !important;
  color: #ffffff;
}

section.cover h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}

section.cover h2 {
  font-weight: 400;
  font-size: 1.35rem;
  opacity: 0.9;
  margin-bottom: 1.5rem;
}

section.cover p:last-of-type a {
  border-radius: 6px;
  padding: 0.65rem 1.75rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

section.cover p:last-of-type a:first-child {
  background: var(--accent) !important;
  color: #ffffff !important;
  border: none;
}

section.cover p:last-of-type a:first-child:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

section.cover p:last-of-type a:last-child {
  color: #ffffff !important;
  border: 2px solid rgba(255, 255, 255, 0.5) !important;
  background: transparent !important;
}

section.cover p:last-of-type a:last-child:hover {
  border-color: #ffffff !important;
  transform: translateY(-1px);
}

section.cover .cover-main {
  max-width: 700px;
  margin: 0 auto;
}

/* ----- Callout Boxes ----- */
.callout,
.tip,
.warning,
.danger {
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
  border-radius: 0 6px 6px 0;
  font-size: 0.95rem;
}

.callout {
  background: var(--callout-info-bg);
  border-left-color: var(--callout-info-border);
}

.tip {
  background: var(--callout-tip-bg);
  border-left-color: var(--callout-tip-border);
}

.warning {
  background: var(--callout-warning-bg);
  border-left-color: var(--callout-warning-border);
}

.danger {
  background: var(--callout-danger-bg);
  border-left-color: var(--callout-danger-border);
}

.callout p:last-child,
.tip p:last-child,
.warning p:last-child,
.danger p:last-child {
  margin-bottom: 0;
}

/* ----- Stats Grid ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stats-grid .stat {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
}

.stats-grid .stat .number {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}

.stats-grid .stat .label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- Reform Card ----- */
.reform-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s ease;
}

.reform-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.reform-card h4 {
  margin-top: 0;
  color: var(--accent);
  font-size: 1.1rem;
}

.reform-card p:last-child {
  margin-bottom: 0;
}

/* Section-colored reform cards */
.reform-card.governance { border-top: 3px solid var(--section1-governance); }
.reform-card.defense { border-top: 3px solid var(--section2-defense); }
.reform-card.welfare { border-top: 3px solid var(--section3-welfare); }
.reform-card.economy { border-top: 3px solid var(--section4-economy); }
.reform-card.regulatory { border-top: 3px solid var(--section5-regulatory); }
.reform-card.democracy { border-top: 3px solid var(--section6-democracy); }

/* ----- Pagination (Prev/Next Chapter) ----- */
.docsify-pagination-container {
  border-top: 2px solid var(--border-color);
  margin-top: 3rem;
  padding-top: 1.5rem;
}

.pagination-item-title {
  font-weight: 600;
  color: var(--accent);
}

.pagination-item-label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- Back to Top ----- */
.app-nav {
  position: fixed;
  right: 0;
  top: 0;
  z-index: 10;
}

/* ----- Scroll bar ----- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ----- Responsive / Mobile ----- */
@media screen and (max-width: 768px) {
  .markdown-section {
    padding: 1rem 1.25rem 2rem;
    max-width: 100%;
  }

  .markdown-section h1 {
    font-size: 1.75rem;
  }

  .markdown-section h2 {
    font-size: 1.4rem;
  }

  .markdown-section h3 {
    font-size: 1.15rem;
  }

  body {
    font-size: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .stats-grid .stat .number {
    font-size: 1.5rem;
  }

  section.cover h1 {
    font-size: 2rem;
  }

  section.cover h2 {
    font-size: 1.1rem;
  }

  .markdown-section table {
    font-size: 0.85rem;
  }

  .markdown-section table th,
  .markdown-section table td {
    padding: 0.4rem 0.6rem;
  }
}

@media screen and (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* ----- Print Styles ----- */
@media print {
  .sidebar,
  .sidebar-toggle,
  .app-nav,
  .docsify-pagination-container,
  .github-corner {
    display: none !important;
  }

  body {
    font-size: 11pt;
    line-height: 1.5;
    color: #000000;
  }

  .content {
    margin-left: 0 !important;
    max-width: 100% !important;
  }

  .markdown-section {
    max-width: 100%;
    padding: 0;
  }

  .markdown-section h1 {
    font-size: 22pt;
    border-bottom: 2px solid #000000;
    color: #000000;
  }

  .markdown-section h2 {
    font-size: 16pt;
    border-bottom: 1px solid #666666;
    color: #000000;
  }

  .markdown-section h3 {
    font-size: 13pt;
    color: #000000;
  }

  .markdown-section a {
    color: #000000;
    text-decoration: underline;
  }

  .markdown-section a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666666;
  }

  .markdown-section a[href^="#"]::after,
  .markdown-section a[href^="javascript"]::after {
    content: "";
  }

  .callout,
  .tip,
  .warning,
  .danger {
    border: 1px solid #cccccc;
    border-left-width: 4px;
    page-break-inside: avoid;
  }

  .reform-card {
    border: 1px solid #cccccc;
    box-shadow: none;
    page-break-inside: avoid;
  }

  table {
    page-break-inside: avoid;
  }

  h2, h3 {
    page-break-after: avoid;
  }

  img {
    max-width: 100% !important;
  }
}

/* ----- Homepage: Stats Grid ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-top: 3px solid var(--accent);
  border-radius: 8px;
  padding: 1.25rem 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ----- Homepage: Section Navigation Cards ----- */
.section-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}

.reform-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.reform-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.reform-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-color);
}

.reform-card ul {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.875rem;
}

.reform-card li {
  margin-bottom: 0.2rem;
}

/* Section color borders */
.reform-card.section1 { border-top: 3px solid var(--section1-governance); }
.reform-card.section1 h3 { color: var(--section1-governance); border-bottom-color: var(--section1-governance); }

.reform-card.section2 { border-top: 3px solid var(--section2-defense); }
.reform-card.section2 h3 { color: var(--section2-defense); border-bottom-color: var(--section2-defense); }

.reform-card.section3 { border-top: 3px solid var(--section3-welfare); }
.reform-card.section3 h3 { color: var(--section3-welfare); border-bottom-color: var(--section3-welfare); }

.reform-card.section4 { border-top: 3px solid var(--section4-economy); }
.reform-card.section4 h3 { color: var(--section4-economy); border-bottom-color: var(--section4-economy); }

.reform-card.section5 { border-top: 3px solid var(--section5-regulatory); }
.reform-card.section5 h3 { color: var(--section5-regulatory); border-bottom-color: var(--section5-regulatory); }

.reform-card.section6 { border-top: 3px solid var(--section6-democracy); }
.reform-card.section6 h3 { color: var(--section6-democracy); border-bottom-color: var(--section6-democracy); }

/* Dark mode adjustments for cards */
@media (prefers-color-scheme: dark) {
  .stat-card,
  .reform-card {
    background: var(--bg-secondary);
    border-color: var(--border-color);
  }
}

/* Mobile: single column cards */
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .section-nav {
    grid-template-columns: 1fr;
  }
}
