/* ===== WH40K Wrath & Glory — Modern Responsive Stylesheet ===== */

/* --- CSS Custom Properties (Light/Dark) --- */
:root {
  --bg: #f4f4f5;
  --bg-surface: #ffffff;
  --bg-surface-alt: #e8e8ec;
  --text: #1c1917;
  --text-muted: #57534e;
  --heading-bg: #1e293b;
  --heading-text: #f8fafc;
  --accent: #b91c1c;
  --accent-light: #fecaca;
  --link: #1d4ed8;
  --link-hover: #b91c1c;
  --border: #d4d4d8;
  --code-bg: #1e1e2e;
  --code-text: #a6e3a1;
  --blockquote-bg: #fef9c3;
  --blockquote-border: #ca8a04;
  --table-header-bg: #1e293b;
  --table-header-text: #f8fafc;
  --table-stripe: #f4f4f5;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --radius: 8px;
  --nav-bg: #111827;
  --nav-text: #f9fafb;
  --nav-accent: #ef4444;
  --transition: .25s ease;
}

[data-theme="dark"] {
  --bg: #0c0a09;
  --bg-surface: #1c1917;
  --bg-surface-alt: #292524;
  --text: #e7e5e4;
  --text-muted: #a8a29e;
  --heading-bg: #991b1b;
  --heading-text: #fef2f2;
  --accent: #ef4444;
  --accent-light: #450a0a;
  --link: #60a5fa;
  --link-hover: #f87171;
  --border: #44403c;
  --code-bg: #1a1a2e;
  --code-text: #a6e3a1;
  --blockquote-bg: #292524;
  --blockquote-border: #b91c1c;
  --table-header-bg: #450a0a;
  --table-header-text: #fef2f2;
  --table-stripe: #1c1917;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --nav-bg: #0c0a09;
}

/* --- Reset (minimal) --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- Base --- */
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  transition: background var(--transition), color var(--transition);
  padding-bottom: 2rem;
}

/* --- Top Nav (injected by nav.js) --- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nav-bg);
  color: var(--nav-text);
  padding: .6rem 1.2rem;
  font-size: .85rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.site-nav a { color: var(--nav-text); text-decoration: none; transition: color var(--transition); }
.site-nav a:hover { color: var(--nav-accent); }
.site-nav .nav-brand { font-weight: 700; font-size: 1rem; letter-spacing: .5px; white-space: nowrap; }
.site-nav .nav-links { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.site-nav .nav-links a { padding: .25rem 0; }

/* hamburger */
.nav-toggle { display: none; background: none; border: none; color: var(--nav-text); font-size: 1.5rem; cursor: pointer; line-height: 1; }

/* dark mode toggle */
.theme-toggle {
  background: none; border: 1px solid rgba(255,255,255,.2); border-radius: 6px;
  color: var(--nav-text); cursor: pointer; padding: .3rem .6rem; font-size: .85rem;
  transition: background var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,.1); }

/* mobile nav */
@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .site-nav .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: .5rem;
    padding-top: .75rem;
  }
  .site-nav .nav-links.open { display: flex; }
  .site-nav { flex-wrap: wrap; }
}

/* --- Page Header --- */
header {
  text-align: center;
  padding: 2.5rem 1.5rem 1.5rem;
  background: var(--heading-bg);
  color: var(--heading-text);
  margin-bottom: 2rem;
}
header h1 {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 800;
  background: none;
  color: inherit;
  margin: 0;
  padding: 0;
  line-height: 1.2;
}
header h2 {
  font-size: clamp(1rem, 2.5vw, 1.3rem);
  font-weight: 400;
  opacity: .85;
  margin: .5rem 0 0;
  background: none;
  color: inherit;
  padding: 0;
}

/* --- Main Content --- */
main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* --- Typography --- */
h1, h2, h3, h4, h5 { font-weight: 700; line-height: 1.3; }

h2 {
  font-size: 1.5rem;
  color: var(--heading-text);
  background: var(--heading-bg);
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin: 2rem 0 1rem;
}
h3 {
  font-size: 1.2rem;
  color: var(--accent);
  background: none;
  padding: 0;
  margin: 1.5rem 0 .75rem;
}
h4 {
  font-size: 1.05rem;
  color: var(--text);
  background: none;
  padding: 0;
  margin: 1.25rem 0 .5rem;
}

p {
  margin: .75rem 0;
}

strong { font-weight: 700; color: var(--text); }
em { font-style: italic; }

a { color: var(--link); transition: color var(--transition); }
a:hover { color: var(--link-hover); }

/* --- Lists --- */
ul, ol { margin: .75rem 0 .75rem 1.5rem; }
ul { list-style: disc; }
ol { list-style: decimal; }
li { padding: .25rem 0; }
li ul, li ol { margin: .25rem 0 .25rem 1.25rem; }
dd { margin-left: 1.5rem; padding-bottom: .5rem; }

/* --- Code --- */
code, pre {
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: .9rem;
}
code {
  background: var(--code-bg);
  color: var(--code-text);
  padding: .15rem .4rem;
  border-radius: 4px;
}
pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1rem 0;
  line-height: 1.6;
}
pre code { background: none; padding: 0; }

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem auto;
  font-size: .9rem;
  overflow-x: auto;
  display: block;
  max-width: 100%;
}
@media (min-width: 640px) { table { display: table; } }
th, td {
  border: 1px solid var(--border);
  padding: .6rem .75rem;
  text-align: left;
}
th {
  background: var(--table-header-bg);
  color: var(--table-header-text);
  font-weight: 600;
}
tr:nth-child(even) td { background: var(--table-stripe); }

/* --- Blockquote --- */
blockquote {
  background: var(--blockquote-bg);
  border-left: 4px solid var(--blockquote-border);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text);
}

/* --- Images & SVG --- */
img { max-width: 100%; height: auto; border-radius: var(--radius); }
svg { display: block; max-width: 100%; margin: 1rem auto; }

/* --- Section Cards --- */
section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  transition: background var(--transition), border-color var(--transition);
}

/* --- Utility boxes --- */
.analogy-box, .example-box, .character-example, .takeaway-box, .tier-comparison, .comment-block {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

/* --- Mermaid --- */
.mermaid, .mermaid_container, .mermaid-diagram {
  margin: 1.5rem auto;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 100%;
  overflow-x: auto;
  text-align: center;
}
[data-theme="dark"] .mermaid,
[data-theme="dark"] .mermaid_container,
[data-theme="dark"] .mermaid-diagram {
  background: #1e1e2e;
}

/* --- Prev / Next Footer Nav (injected by nav.js) --- */
.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  max-width: 52rem;
  margin: 2rem auto 1rem;
  padding: 1rem 1.25rem;
  border-top: 2px solid var(--border);
  font-size: .9rem;
}
.page-nav a {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--link);
  transition: background var(--transition), box-shadow var(--transition);
}
.page-nav a:hover { background: var(--bg-surface-alt); box-shadow: var(--shadow); }
.page-nav .spacer { flex: 1; }

/* --- Site Footer --- */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--text-muted);
  font-size: .85rem;
  max-width: 52rem;
  margin: 0 auto;
}

/* --- Canvas elements --- */
canvas { max-width: 100%; height: auto; border-radius: var(--radius); }

/* --- Sup / Sub --- */
sup { font-size: .75em; vertical-align: super; }
sub { font-size: .75em; vertical-align: sub; }

/* --- Index Page Specific --- */
.index-hero {
  text-align: center;
  padding: 3rem 1.5rem 2rem;
  background: linear-gradient(135deg, #1e293b 0%, #450a0a 100%);
  color: #f8fafc;
}
.index-hero h1 { font-size: clamp(1.8rem, 5vw, 3rem); margin-bottom: .5rem; }
.index-hero p { font-size: 1.1rem; opacity: .85; max-width: 36rem; margin: .5rem auto 0; }

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  max-width: 56rem;
  margin: 2rem auto;
  padding: 0 1.25rem;
}
.chapter-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
  box-shadow: var(--shadow);
}
.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  border-color: var(--accent);
}
.chapter-card .card-num {
  flex-shrink: 0;
  width: 2.2rem; height: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--heading-bg);
  color: var(--heading-text);
  border-radius: 50%;
  font-weight: 700;
  font-size: .85rem;
}
.chapter-card .card-title { font-weight: 600; font-size: .95rem; }

/* --- Print --- */
@media print {
  .site-nav, .page-nav, .theme-toggle, .nav-toggle { display: none !important; }
  body { background: #fff; color: #000; }
  section { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
}
