/* ===========================================
   HeroScape Mastery Series - Main Stylesheet
   Light/Dark Theme with CSS Custom Properties
   =========================================== */

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

html { scroll-behavior: smooth; }

article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section { display: block; }

blockquote, q { quotes: none; }
blockquote::before, blockquote::after,
q::before, q::after { content: ""; }

sup { font-size: x-small; vertical-align: super; }
sub { font-size: x-small; vertical-align: sub; }

/* ---------- Theme Variables ---------- */
:root {
  /* Light theme (default) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-code: #f8fafc;
  --bg-header: #1e3a5f;
  --bg-header-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  --bg-blockquote: #e2e8f0;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-nav: #ffffff;
  --bg-footer: #1e293b;

  --text-primary: #334155;
  --text-secondary: #64748b;
  --text-heading: #1e293b;
  --text-code: #228b22;
  --text-link: #3b82f6;
  --text-link-hover: #2563eb;
  --text-on-header: #ffffff;
  --text-on-footer: #cbd5e1;
  --text-strong: #111827;
  --text-muted: #94a3b8;

  --border-color: #e2e8f0;
  --border-light: #f1f5f9;
  --border-accent: #3b82f6;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-secondary: #4ecdc4;
  --accent-warm: #f59e0b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --content-max: 1100px;
  --nav-height: 56px;

  /* Mermaid overrides */
  --mermaid-bg: #ffffff;
  --mermaid-node: #f8fafc;
  --mermaid-stroke: #94a3b8;
  --mermaid-text: #1f2937;
  --mermaid-edge: #475569;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #1e293b;
  --bg-code: #1e293b;
  --bg-header: #0f172a;
  --bg-header-gradient: linear-gradient(135deg, #0f172a 0%, #1a1a2e 50%, #0f3460 100%);
  --bg-blockquote: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-nav: #1e293b;
  --bg-footer: #0f172a;

  --text-primary: #cbd5e1;
  --text-secondary: #94a3b8;
  --text-heading: #f1f5f9;
  --text-code: #6ee7b7;
  --text-link: #60a5fa;
  --text-link-hover: #93bbfd;
  --text-on-header: #f1f5f9;
  --text-on-footer: #94a3b8;
  --text-strong: #f1f5f9;
  --text-muted: #64748b;

  --border-color: #334155;
  --border-light: #1e293b;
  --border-accent: #3b82f6;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);

  --mermaid-bg: #1e293b;
  --mermaid-node: #334155;
  --mermaid-stroke: #64748b;
  --mermaid-text: #e2e8f0;
  --mermaid-edge: #94a3b8;
}

/* ---------- Base Styles ---------- */
body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Site Navigation Bar ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.3s;
}

.site-nav .nav-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  gap: 0.5rem;
}

.site-nav .nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text-heading);
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}

.site-nav .nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
  list-style: none;
  flex-wrap: nowrap;
}

.site-nav .nav-links a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
  white-space: nowrap;
}

.site-nav .nav-links a:hover {
  color: var(--text-link);
  background: var(--bg-tertiary);
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: var(--border-color);
}

/* Hamburger for mobile */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

@media (max-width: 768px) {
  .nav-hamburger { display: block; }

  .site-nav .nav-links {
    display: none;
    position: absolute;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border-color);
    flex-direction: column;
    padding: 0.75rem 1rem;
    box-shadow: var(--shadow-md);
  }

  .site-nav .nav-links.open { display: flex; }

  .site-nav .nav-links a {
    padding: 0.6rem 0.75rem;
    font-size: 1rem;
  }

  .site-nav .nav-inner {
    flex-wrap: nowrap;
  }
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  font-weight: 700;
  color: var(--text-on-header);
  background: var(--accent);
  margin: 1.5rem 0 1rem;
  padding: 0.75rem 1.25rem;
  line-height: 1.3;
  border-radius: var(--radius-sm);
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  text-align: center;
  background: var(--bg-header-gradient);
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius-md);
}

h2 {
  font-size: clamp(1.2rem, 3vw, 1.6rem);
}

h3 {
  font-size: clamp(1.05rem, 2.5vw, 1.3rem);
}

h4 {
  font-size: 1.1rem;
}

h5 { margin-left: 1rem; font-weight: 600; color: var(--text-heading); }

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

p {
  margin: 0.75rem 0;
  padding: 0 1rem;
}

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

h3 a { color: inherit; }

/* ---------- Code ---------- */
code, pre {
  font-family: var(--font-mono);
  background: var(--bg-code);
  color: var(--text-code);
  border-radius: var(--radius-sm);
}

code {
  padding: 0.15em 0.4em;
  font-size: 0.9em;
}

pre {
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  line-height: 1.6;
}

pre code {
  padding: 0;
  background: transparent;
}

/* ---------- Lists ---------- */
ol, ul {
  margin: 0.5rem 0 0.5rem 2rem;
  padding: 0;
}

ol li { list-style-type: decimal; padding: 0.35rem 0; }
ul li { list-style-type: disc; padding: 0.35rem 0; }
ul li ul li { margin-left: 0; }

dl { margin: 0.5rem 0 0.5rem 1.5rem; }
dd { margin-left: 1.5rem; padding-bottom: 0.5rem; }

/* ---------- Tables ---------- */
table {
  margin: 1rem auto;
  border-collapse: collapse;
  width: auto;
  max-width: 100%;
  overflow-x: auto;
  display: block;
}

@media (min-width: 769px) {
  table { display: table; }
}

table, td, tr, th {
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.75rem;
  text-align: center;
}

th {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

td {
  background: var(--bg-secondary);
}

/* ---------- Blockquote ---------- */
blockquote {
  margin: 1.25rem auto;
  max-width: 85%;
  background: var(--bg-blockquote);
  color: var(--text-primary);
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ---------- Images ---------- */
img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

div img { max-width: 45%; }
@media (max-width: 600px) { div img { max-width: 100%; } }

.center { text-align: center; }

/* ---------- SVG / Canvas ---------- */
svg, canvas {
  display: block;
  margin: 1rem auto;
  max-width: 100%;
}

.svg-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ---------- Mermaid ---------- */
.mermaid_container, .mermaid-diagram, .mermaid {
  margin: 1.5rem auto;
  padding: 1.25rem;
  background: var(--mermaid-bg);
  color: var(--mermaid-text);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-width: 90%;
  text-align: center;
}

.mermaid svg { margin: 0 auto; display: block; }

.mermaid .node rect,
.mermaid .node circle,
.mermaid .node ellipse,
.mermaid .node polygon,
.mermaid .node path {
  fill: var(--mermaid-node);
  stroke: var(--mermaid-stroke);
}

.mermaid .edgePath .path { stroke: var(--mermaid-edge); }

.mermaid .label,
.mermaid .label text,
.mermaid text,
.mermaid .flowchart-label text,
.mermaid .mindmap-node text,
.mermaid .mindmap-node .nodeText,
.mermaid .nodeLabel {
  fill: var(--mermaid-text) !important;
  color: var(--mermaid-text) !important;
}

.mermaid .cluster rect {
  fill: var(--bg-tertiary);
  stroke: var(--mermaid-stroke);
}

/* ---------- Utility Classes ---------- */
.comment-block {
  border-left: 4px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--bg-tertiary);
}

.code-comment {
  color: #0891b2;
  font-style: italic;
}

.analogy-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-warm);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}

.analogy-box h3 {
  background: transparent;
  color: var(--text-heading);
  padding: 0 0 0.5rem;
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

/* ---------- Content Page Layout ---------- */
body > header {
  background: var(--bg-header-gradient);
  color: var(--text-on-header);
  padding: 2.5rem 1.5rem 2rem;
  text-align: center;
}

body > header h1 {
  background: transparent;
  margin: 0;
  padding: 0;
}

body > header .subtitle {
  color: rgba(255,255,255,0.85);
  font-size: 1.15rem;
  margin-top: 0.5rem;
}

body > main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

body > main section {
  margin-bottom: 2.5rem;
}

/* ---------- Prev / Next Navigation ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  max-width: var(--content-max);
  margin: 2rem auto;
  padding: 0 1.25rem;
}

.page-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  text-decoration: none;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
  flex: 1;
  min-width: 0;
}

.page-nav a:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  background: var(--bg-card-hover);
}

.page-nav a.next { text-align: right; }

.page-nav .nav-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.page-nav .nav-title {
  font-weight: 600;
  color: var(--text-link);
  font-size: 0.95rem;
}

@media (max-width: 550px) {
  .page-nav { flex-direction: column; }
}

/* ---------- Footer ---------- */
body > footer,
.main-footer {
  background: var(--bg-footer);
  color: var(--text-on-footer);
  padding: 2rem 1.5rem 1rem;
  margin-top: 2rem;
}

.main-footer .container {
  max-width: var(--content-max);
  margin: 0 auto;
}

.footer-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 2rem;
  margin-bottom: 2rem;
}

.footer-section h3 {
  background: transparent;
  color: var(--accent-secondary);
  padding: 0;
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.footer-section ul { list-style: none; margin: 0; }
.footer-section ul li { margin-bottom: 0.4rem; padding: 0; }

.footer-section ul li a {
  color: var(--text-on-footer);
  text-decoration: none;
  font-size: 0.9rem;
}
.footer-section ul li a:hover { color: var(--accent-secondary); }

.footer-bottom {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 1.25rem;
  text-align: center;
  font-size: 0.85rem;
}

.footer-tagline {
  color: var(--accent-secondary);
  font-style: italic;
  margin-top: 0.3rem;
}

/* Simple content-page footer */
.content-footer {
  background: var(--bg-footer);
  color: var(--text-on-footer);
  padding: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  margin-top: 2rem;
}

.content-footer a {
  color: var(--accent-secondary);
}

/* ---------- Feature / Topic Grids (content pages) ---------- */
.feature-grid, .topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin: 1.25rem 0;
}

.feature, .topic, .application {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: box-shadow 0.2s;
}

.feature:hover, .topic:hover, .application:hover {
  box-shadow: var(--shadow-md);
}

.feature h3, .topic h3, .application h3 {
  background: transparent;
  color: var(--text-heading);
  padding: 0 0 0.4rem;
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
}

/* ---------- Example armies, tips, etc ---------- */
.example-armies, .beginner-tips, .community-aspect {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.army-example {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.army-example:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.call-to-action {
  background: var(--bg-tertiary);
  border: 2px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  margin: 2rem 0;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  body > main {
    padding: 1rem 0.75rem 2rem;
  }

  h1 { font-size: 1.4rem; padding: 1rem; }
  h2 { font-size: 1.15rem; }
  h3 { font-size: 1.05rem; }

  p { padding: 0 0.5rem; }

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

  blockquote { max-width: 95%; margin: 1rem auto; }
}
