/* ============================================================
   css/cms-content-theme.css
   Universal reading theme for CMS-rendered content (.cms-content).
   Applied once, automatically, to every blog post AND every CMS
   page rendered through core/page-template.php — no per-post
   styling needed.

   Deliberately reuses the site's existing --font-main / --font-body
   / --sky-deep / --radius / --shadow tokens from css/style.css
   instead of introducing a new webfont — a prior CLS fix already
   tuned font loading sitewide, and pulling in another font family
   here would risk reintroducing that same layout-shift problem.
   ============================================================ */

.cms-content {
  --toc-width: 260px;
  --content-max: 700px;
  --rule: #e5e0d8;
  --code-bg: #1e2430;
  --code-text: #e8ecf3;

  max-width: var(--content-max);
  margin: 0 auto;
  font-family: var(--font-body, 'Hind', sans-serif);
  font-size: 1.125rem;
  line-height: 1.8;
  color: var(--dark, #24292f);
}

[data-theme="dark"] .cms-content {
  --rule: #333c4a;
  --code-bg: #10141c;
  color: #e8ecf3;
}

/* ---------- Layout: content + sticky TOC rail on wide screens ---------- */
.cms-content-wrap {
  display: block;
}

@media (min-width: 1180px) {
  .cms-content-wrap:has(.cms-toc) {
    display: grid;
    grid-template-columns: var(--toc-width) minmax(0, var(--content-max));
    gap: 3rem;
    max-width: calc(var(--content-max) + var(--toc-width) + 3rem);
    margin: 0 auto;
  }
  .cms-content-wrap:has(.cms-toc) .cms-toc {
    order: -1;
    position: sticky;
    top: 1.5rem;
    align-self: start;
    max-height: calc(100vh - 3rem);
    overflow-y: auto;
  }
  .cms-content-wrap:has(.cms-toc) .cms-content { margin: 0; }
}

/* ---------- Typography ---------- */
.cms-content h2,
.cms-content h3,
.cms-content h4 {
  font-family: var(--font-main, 'Baloo 2', cursive);
  line-height: 1.3;
  scroll-margin-top: 1.5rem; /* keeps anchored headings clear of any fixed header */
}
.cms-content h2 { font-size: 1.65rem; margin: 2.6rem 0 1rem; }
.cms-content h3 { font-size: 1.3rem;  margin: 2.1rem 0 0.9rem; }
.cms-content h4 { font-size: 1.1rem;  margin: 1.8rem 0 0.7rem; font-weight: 700; }

.cms-content p { margin: 0 0 1.3rem; }
.cms-content ul,
.cms-content ol { margin: 0 0 1.3rem; padding-left: 1.4rem; }
.cms-content li { margin-bottom: 0.4rem; }
.cms-content a { color: var(--sky-deep, #0a6ebd); text-underline-offset: 3px; }
.cms-content strong { font-weight: 700; }

/* ---------- Blockquote: a quiet signature moment, not a generic box ---------- */
.cms-content blockquote {
  position: relative;
  margin: 2rem 0;
  padding: 0.2rem 0 0.2rem 2rem;
  border-left: 3px solid var(--sky-deep, #0a6ebd);
  font-size: 1.2rem;
  font-style: italic;
  color: inherit;
}
.cms-content blockquote::before {
  content: "\201C";
  position: absolute;
  left: 0.35rem;
  top: -0.3rem;
  font-size: 2.2rem;
  font-style: normal;
  color: var(--sky-deep, #0a6ebd);
  opacity: 0.5;
  font-family: Georgia, serif;
}
.cms-content blockquote p:last-child { margin-bottom: 0; }

/* ---------- Tables ---------- */
.cms-content .cms-table-wrap { overflow-x: auto; margin: 1.6rem 0; }
.cms-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
}
.cms-content th,
.cms-content td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
}
.cms-content th {
  font-family: var(--font-main, 'Baloo 2', cursive);
  font-weight: 700;
  border-bottom: 2px solid var(--sky-deep, #0a6ebd);
}
.cms-content tbody tr:nth-child(even) { background: rgba(10, 110, 189, 0.04); }
[data-theme="dark"] .cms-content tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.03); }

/* ---------- Code ---------- */
.cms-content pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 1.1rem 1.3rem;
  border-radius: var(--radius, 10px);
  overflow-x: auto;
  margin: 1.6rem 0;
  font-size: 0.95rem;
  line-height: 1.6;
}
.cms-content code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}
.cms-content :not(pre) > code {
  background: rgba(10, 110, 189, 0.08);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}
.cms-content pre code { background: none; padding: 0; }

/* ---------- Images / figures / gallery ---------- */
.cms-content figure { margin: 1.8rem 0; }
.cms-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius, 10px);
  display: block;
}
.cms-content figcaption {
  font-size: 0.9rem;
  color: #6b7280;
  margin-top: 0.5rem;
  text-align: center;
}
.cms-content .cms-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.8rem 0;
}
.cms-content .cms-gallery figure { margin: 0; }

/* Responsive video embeds, if ever pasted in */
.cms-content .cms-video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  margin: 1.8rem 0;
  border-radius: var(--radius, 10px);
  overflow: hidden;
}
.cms-content .cms-video-wrap iframe,
.cms-content .cms-video-wrap video {
  width: 100%; height: 100%; border: 0;
}

/* ---------- FAQ: native <details>, zero extra JS ---------- */
.cms-content details {
  border: 1px solid var(--rule);
  border-radius: var(--radius, 10px);
  margin: 0.8rem 0;
  padding: 0.9rem 1.1rem;
}
.cms-content summary {
  font-family: var(--font-main, 'Baloo 2', cursive);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.cms-content summary::-webkit-details-marker { display: none; }
.cms-content summary::after {
  content: "+";
  font-size: 1.3rem;
  line-height: 1;
  color: var(--sky-deep, #0a6ebd);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.cms-content details[open] summary::after { transform: rotate(45deg); }
.cms-content details p:last-child { margin-bottom: 0; margin-top: 0.7rem; }

@media (prefers-reduced-motion: reduce) {
  .cms-content summary::after { transition: none; }
}

/* ---------- Table of contents ---------- */
.cms-toc {
  background: rgba(10, 110, 189, 0.05);
  border: 1px solid var(--rule);
  border-radius: var(--radius, 10px);
  padding: 1.1rem 1.3rem;
  margin: 0 0 2rem;
  font-size: 0.95rem;
}
[data-theme="dark"] .cms-toc { background: rgba(255, 255, 255, 0.04); }
.cms-toc-title {
  font-family: var(--font-main, 'Baloo 2', cursive);
  font-weight: 700;
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sky-deep, #0a6ebd);
}
.cms-toc ol { list-style: none; margin: 0; padding: 0; }
.cms-toc ol ol { padding-left: 1.1rem; margin-top: 0.3rem; }
.cms-toc li { margin-bottom: 0.45rem; }
.cms-toc a {
  color: inherit;
  text-decoration: none;
  display: block;
  border-left: 2px solid transparent;
  padding-left: 0.6rem;
  margin-left: -0.6rem;
}
.cms-toc a:hover,
.cms-toc a.is-active {
  color: var(--sky-deep, #0a6ebd);
  border-left-color: var(--sky-deep, #0a6ebd);
}

/* ---------- Dark mode toggle button ---------- */
.cms-theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: inherit;
}
.cms-theme-toggle:focus-visible,
.cms-content a:focus-visible,
.cms-content summary:focus-visible {
  outline: 2px solid var(--sky-deep, #0a6ebd);
  outline-offset: 2px;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .cms-content { font-size: 1.05rem; }
  .cms-content h2 { font-size: 1.4rem; }
  .cms-content h3 { font-size: 1.2rem; }
}
