:root {
  --bg: #F8FBF5;
  --surface: #EFF6E9;
  --panel: #ffffff;
  --forest: #2D5A3D;
  --emerald: #059669;
  --sage: #6B9080;
  --mint: #A7C4A0;
  --text: #1B4332;
  --muted: #2D6A4F;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111a14;
    --surface: #18231b;
    --panel: #1e2b22;
    --forest: #7bc49b;
    --emerald: #34d399;
    --sage: #8fb8a2;
    --mint: #3d6b52;
    --text: #d4e8da;
    --muted: #a3c4b0;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(var(--bg), var(--surface));
  color: var(--text);
  line-height: 1.7;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(167, 196, 160, 0.25) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.6;
  pointer-events: none;
  z-index: 0;
}

@media (prefers-color-scheme: dark) {
  body::before { opacity: 0.15; }
}

.wrap { position: relative; z-index: 1; }
.container { max-width: 680px; margin: auto; padding: 2rem; }
.container--wide { max-width: 900px; }

/* ── Nav ── */
nav {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(45, 90, 61, 0.1);
  z-index: 10;
}

@media (prefers-color-scheme: dark) {
  nav { background: rgba(17, 26, 20, 0.88); border-bottom-color: rgba(123, 196, 155, 0.12); }
}

nav .container {
  max-width: 900px;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.nav-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--forest);
  text-decoration: none;
}
.logo:hover { color: var(--emerald); }

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.nav-links a:hover { color: var(--forest); }

.nav-btn {
  padding: 0.5rem 1.2rem;
  border-radius: 12px;
  background: var(--forest);
  color: white !important;
  transition: transform 0.15s, box-shadow 0.15s;
}
.nav-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(45, 90, 61, 0.35);
}

@media (prefers-color-scheme: dark) {
  .nav-btn { background: var(--emerald); color: #111 !important; }
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  color: var(--forest);
}

.nav-toggle svg { display: block; }

@media (max-width: 600px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 1rem 2rem 1.5rem;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(45, 90, 61, 0.1);
    box-shadow: 0 8px 24px rgba(45, 90, 61, 0.1);
  }
  .nav-links.open { display: flex; }
  .nav-links a { font-size: 1.05rem; }

  @media (prefers-color-scheme: dark) {
    .nav-links { background: rgba(17, 26, 20, 0.97); border-bottom-color: rgba(123, 196, 155, 0.12); }
  }
}

/* ── Breadcrumbs ── */
.breadcrumbs {
  font-size: 0.85rem;
  color: var(--sage);
  margin-bottom: 1rem;
}
.breadcrumbs a {
  color: var(--emerald);
  text-decoration: none;
  font-weight: 600;
}
.breadcrumbs a:hover { text-decoration: underline; }
.breadcrumbs .sep { margin: 0 0.4rem; }

/* ── Hero (index pages) ── */
.hero { text-align: center; padding: 3rem 1rem 2rem; }
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}
.hero h1 .accent { color: var(--emerald); }
.hero p { color: var(--muted); margin-top: 0.75rem; font-size: 1.05rem; }

/* ── Post grid (index pages) ── */
.post-grid { display: grid; gap: 1.5rem; margin-top: 2rem; }

.post-card {
  display: block;
  background: var(--panel);
  padding: 1.5rem 1.75rem;
  border-radius: 18px;
  box-shadow: 0 10px 25px rgba(45, 90, 61, 0.08);
  text-decoration: none;
  color: inherit;
  transition: 0.25s ease;
  border: 1px solid transparent;
}
.post-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 32px rgba(45, 90, 61, 0.12);
  border-color: var(--mint);
}
.post-card .date {
  font-size: 0.8rem;
  color: var(--sage);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}
.post-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}
.post-card p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--forest);
  margin: 2rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--mint);
}
.section-title:first-of-type { margin-top: 0; }
.section-desc { color: var(--muted); font-size: 0.95rem; margin-bottom: 1rem; }

/* ── Article ── */
article { padding: 2rem 0; }
article .date {
  font-size: 0.85rem;
  color: var(--sage);
  font-weight: 600;
  margin-bottom: 0.5rem;
}
article h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
  color: var(--text);
  margin-bottom: 1.5rem;
  line-height: 1.3;
}
article h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.5rem 0 0.75rem;
}
article h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin: 1.25rem 0 0.5rem;
}
article p { color: var(--muted); margin-bottom: 1rem; }
article ul, article ol { margin: 0 0 1rem 1.5rem; color: var(--muted); }
article li { margin-bottom: 0.4rem; }

article .example {
  background: var(--panel);
  padding: 1rem 1.25rem;
  border-radius: 12px;
  margin: 1rem 0;
  border-left: 4px solid var(--emerald);
  font-family: 'Courier New', monospace;
  color: var(--text);
  overflow-x: auto;
}

.formula {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--forest);
  text-align: center;
  padding: 1rem;
  background: var(--panel);
  border-radius: 12px;
  margin: 1rem 0;
}

/* ── Tables ── */
article table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}
article th, article td {
  border: 1px solid var(--mint);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
article th {
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
}
article td { color: var(--muted); }

/* ── References (research posts) ── */
.references { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--mint); }
.references h2 { margin-bottom: 1rem; }
.references ol { margin-left: 1.5rem; color: var(--muted); font-size: 0.9rem; line-height: 1.8; }
.references a { color: var(--emerald); }

article .ref { font-size: 0.85rem; color: var(--sage); margin-top: 0.25rem; }
article .ref a { color: var(--emerald); }

/* ── Related posts / tutorials ── */
.related-posts {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(45, 90, 61, 0.15);
}
.related-posts h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--forest);
  margin-bottom: 0.75rem;
}
.related-posts ul { list-style: none; margin: 0; padding: 0; }
.related-posts li { margin-bottom: 0.5rem; }
.related-posts a { color: var(--emerald); text-decoration: none; font-weight: 600; }
.related-posts a:hover { text-decoration: underline; }

/* ── Practice problems ── */
.practice {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(45, 90, 61, 0.15);
}
.practice h2 { margin-bottom: 0.75rem; }
.practice-item { margin-bottom: 1rem; }
.practice-item p { font-weight: 600; color: var(--text); margin-bottom: 0.25rem; }
.practice-answer {
  background: var(--surface);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  color: var(--muted);
}
details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--emerald);
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}
details summary:hover { text-decoration: underline; }

/* ── Buttons / CTA ── */
.button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--forest), var(--sage));
  color: white !important;
  text-decoration: none;
  font-weight: 700;
  transition: 0.2s ease;
  font-size: 0.95rem;
}
.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(45, 90, 61, 0.3);
}

@media (prefers-color-scheme: dark) {
  .button { background: linear-gradient(135deg, var(--emerald), var(--sage)); color: #111 !important; }
}

.back-link {
  display: inline-block;
  color: var(--emerald);
  text-decoration: none;
  font-weight: 600;
  margin-bottom: 1rem;
}
.back-link:hover { text-decoration: underline; }

/* ── CTA box ── */
.cta-box {
  text-align: center;
  margin-top: 3rem;
  padding: 2rem;
  background: var(--panel);
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(45, 90, 61, 0.08);
}
.cta-box h3 { font-size: 1.2rem; margin-bottom: 0.5rem; color: var(--text); }
.cta-box p { color: var(--muted); margin-bottom: 1rem; }

/* ── Footer ── */
footer {
  text-align: center;
  color: var(--muted);
  padding: 2.5rem 1rem 1.5rem;
  font-size: 0.85rem;
}
footer a { color: var(--emerald); text-decoration: none; }
footer a:hover { text-decoration: underline; }
.footer-inner { max-width: 680px; margin: auto; }
.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.25rem;
  margin-bottom: 0.75rem;
}
.footer-links a { font-weight: 600; }
.footer-about {
  font-size: 0.8rem;
  color: var(--sage);
  margin-top: 0.75rem;
}

/* ── SVG diagrams ── */
.diagram {
  text-align: center;
  margin: 1.5rem 0;
}
.diagram svg {
  max-width: 100%;
  height: auto;
}
