/* Shared styles for topic pages (พื้นฐานพุทธธรรม articles) */
:root {
  --blue: #1E7AE6;
  --blue-dark: #1864C2;
  --blue-soft: #E8F1FC;
  --red: #F04E23;
  --red-dark: #D43F18;
  --red-soft: #FDE8E2;
  --yellow: #FFD93D;
  --yellow-soft: #FFF6CC;
  --green: #1F9D55;
  --green-soft: #DCFCE7;
  --purple: #8B5CF6;
  --purple-soft: #EDE7FE;
  --ink: #1A1A1A;
  --ink-2: #4A4A4A;
  --ink-3: #7A7A7A;
  --line: #E6E8EC;
  --paper: #FFFFFF;
  --bg: #F7F8FA;

  --font: "Noto Sans Thai", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --radius-pill: 999px;
  --radius-card: 20px;
  --radius-lg: 28px;
  --header-h: 64px;

  --accent: var(--blue);
  --accent-dark: var(--blue-dark);
  --accent-soft: var(--blue-soft);
}
body[data-accent="red"]    { --accent: var(--red);    --accent-dark: var(--red-dark);  --accent-soft: var(--red-soft); }
body[data-accent="yellow"] { --accent: #B89200;       --accent-dark: #8A6A00;          --accent-soft: var(--yellow-soft); }
body[data-accent="green"]  { --accent: var(--green);  --accent-dark: #157040;           --accent-soft: var(--green-soft); }
body[data-accent="purple"] { --accent: var(--purple); --accent-dark: #6B3FE0;          --accent-soft: var(--purple-soft); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }

/* ─── Topbar (same pattern as index) ──────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  max-width: 1400px; margin: 0 auto;
  min-height: var(--header-h);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  font-size: 15px; font-weight: 700;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: transparent;
  display: grid; place-items: center;
  color: transparent; font-weight: 800; font-size: 14px;
  overflow: hidden;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.brand-text { display:flex; flex-direction: column; line-height: 1.15; }
.brand-text small {
  font-weight: 500; font-size: 11px; color: var(--ink-3);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.brand-spacer { flex: 1; }
.top-nav { display: flex; gap: 8px; }
.top-nav a {
  padding: 8px 14px; font-size: 14px; font-weight: 600;
  color: var(--ink-2); border-radius: 10px;
}
.top-nav a:hover { background: var(--bg); color: var(--ink); }
.topbar-actions { display: flex; gap: 8px; }
.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line);
  background: white; color: var(--ink);
  padding: 8px 14px; border-radius: 10px;
  font: inherit; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s;
}
.btn:hover { background: var(--bg); }
.progress-rail { height: 3px; background: var(--line); }
.progress-fill {
  height: 100%; background: var(--accent);
  width: 0%;
  transition: width .15s linear;
}

/* ─── Breadcrumb ──────────────────────────────────────────────── */
.crumbs {
  background: white; border-bottom: 1px solid var(--line);
}
.crumbs-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 10px 28px;
  font-size: 13px; color: var(--ink-3);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.crumbs-inner a:hover { color: var(--ink); }
.crumbs-inner strong { color: var(--ink); font-weight: 700; }
.crumbs-inner .sep { color: var(--line); }

/* ─── Hero ────────────────────────────────────────────────────── */
.topic-hero {
  background: white;
  border-bottom: 1px solid var(--line);
}
.hero-inner {
  max-width: 1100px; margin: 0 auto;
  padding: 56px 28px 48px;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 40px;
  align-items: center;
}
@media (max-width: 860px) { .hero-inner { grid-template-columns: 1fr; } }

.hero-badges {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-bottom: 18px;
}
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
}
.badge.cat { background: var(--accent-soft); color: var(--accent-dark); }
.badge.meta { background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }

.hero-text h1 {
  margin: 0 0 12px;
  font-size: clamp(40px, 5vw, 56px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.hero-jp {
  font-family: var(--mono);
  font-size: 16px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  margin-bottom: 22px;
}
.lede {
  font-size: 20px;
  color: var(--ink-2);
  line-height: 1.55;
  margin: 0;
  text-wrap: pretty;
  max-width: 50ch;
}

.hero-art {
  aspect-ratio: 1 / 1;
  background-color: var(--accent);
  background-image:
    linear-gradient(180deg, rgba(0,0,0,0) 50%, rgba(0,0,0,0.25) 100%),
    var(--hero-image, url('https://images.unsplash.com/photo-1518173946687-a4c8892bbd9f?auto=format&fit=crop&w=900&q=80'));
  background-size: cover;
  background-position: center;
  border-radius: var(--radius-lg);
  color: white;
  box-shadow:
    0 1px 2px rgba(0,0,0,0.05),
    0 18px 42px -10px rgba(0,0,0,0.18);
  position: relative;
  overflow: hidden;
}
.hero-art .hero-photo {
  position: absolute; inset: 0;
}
body[data-accent="yellow"] .hero-art {
  background-color: var(--yellow);
  color: var(--ink);
}

/* ─── Reader layout ───────────────────────────────────────────── */
.reader {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 28px 80px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 56px;
  align-items: start;
}
@media (max-width: 860px) {
  .reader { grid-template-columns: 1fr; gap: 24px; padding-top: 32px; }
  .toc { order: 2; }
}

/* TOC */
.toc { font-size: 14px; }
.toc-sticky {
  position: sticky;
  top: calc(var(--header-h) + 20px);
  display: flex; flex-direction: column;
}
.toc-head {
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
#toc-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 2px;
}
#toc-list a {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  border-left: 2px solid transparent;
  margin-left: -12px; padding-left: 14px;
  transition: background .15s, color .15s, border-color .15s;
}
#toc-list a:hover { color: var(--ink); background: var(--bg); }
#toc-list a.active {
  color: var(--accent-dark);
  border-left-color: var(--accent);
  font-weight: 700;
}
@media (max-width: 860px) {
  .toc-sticky { position: static; }
  .toc-head { margin-top: 8px; }
  #toc-list a { padding-left: 12px; margin-left: 0; }
}

/* Article */
.article > section {
  scroll-margin-top: calc(var(--header-h) + 24px);
  padding: 8px 0 32px;
}
.article > section + section {
  border-top: 1px solid var(--line);
  padding-top: 36px;
}
.article h2 {
  margin: 0 0 16px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.005em;
  line-height: 1.2;
  text-wrap: balance;
}
.article h2::before {
  content: "";
  display: inline-block;
  width: 28px; height: 4px;
  background: var(--accent);
  vertical-align: middle;
  margin-right: 14px;
  border-radius: 2px;
  transform: translateY(-6px);
}
.article h3 {
  margin: 28px 0 10px;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.003em;
  line-height: 1.3;
}
.article p {
  margin: 0 0 16px;
  text-wrap: pretty;
}
.article .lead-p {
  font-size: 19px;
  color: var(--ink);
  font-weight: 500;
  line-height: 1.65;
}
.article strong { font-weight: 700; color: var(--ink); }
.article em { font-style: normal; background: var(--yellow); padding: 0 4px; border-radius: 3px; }

.bullet-list, .ref-list {
  margin: 14px 0 18px;
  padding-left: 24px;
}
.bullet-list li, .ref-list li {
  margin-bottom: 8px;
  line-height: 1.6;
}
.bullet-list li::marker { color: var(--accent); }
.ref-list { font-size: 14px; color: var(--ink-2); }

/* Callouts */
.callout {
  display: flex; gap: 16px;
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 20px 22px;
  margin: 20px 0 24px;
  border-left: 4px solid var(--accent);
}
.callout[data-c="blue"]   { background: var(--blue-soft);   border-color: var(--blue); }
.callout[data-c="red"]    { background: var(--red-soft);    border-color: var(--red); }
.callout[data-c="yellow"] { background: var(--yellow-soft); border-color: var(--yellow); }
.callout[data-c="green"]  { background: var(--green-soft);  border-color: var(--green); }
.callout[data-c="purple"] { background: var(--purple-soft); border-color: var(--purple); }
.callout-icon {
  font-size: 24px;
  flex-shrink: 0;
}
.callout strong {
  display: block;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--ink-2);
}
.callout p {
  margin: 0;
  font-size: 17px;
  line-height: 1.6;
}

/* Comparison tables (e.g. ten worlds list) */
.compare-table {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin: 18px 0 24px;
  background: white;
}
.compare-row {
  display: grid;
  grid-template-columns: 56px 1fr 2fr;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.compare-row:first-child { border-top: 0; }
.compare-row .n {
  font-family: var(--mono);
  font-size: 13px; color: var(--ink-3); font-weight: 600;
  text-align: center;
}
.compare-row .label {
  font-weight: 700;
  display: flex; flex-direction: column;
}
.compare-row .label .jp {
  font-size: 12px; font-family: var(--mono); color: var(--ink-3);
  font-weight: 500; margin-top: 2px;
}
.compare-row .desc {
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.55;
}
.compare-row[data-tone="dark"]  { background: #fff5f5; }
.compare-row[data-tone="light"] { background: #f0f9ff; }

/* Related */
.related h2 { margin-bottom: 18px; }
.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 860px) { .related-grid { grid-template-columns: 1fr; } }
.related-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex; align-items: center; gap: 14px;
  transition: transform .2s, border-color .2s, box-shadow .2s;
}
.related-card:hover {
  transform: translateY(-2px);
  border-color: var(--ink);
  box-shadow: 0 6px 18px -6px rgba(0,0,0,0.12);
}
.r-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.r-icon[data-c="blue"]   { background: var(--blue-soft);   color: var(--blue-dark); }
.r-icon[data-c="red"]    { background: var(--red-soft);    color: var(--red-dark); }
.r-icon[data-c="yellow"] { background: var(--yellow-soft); color: #8A6A00; }
.r-icon[data-c="green"]  { background: var(--green-soft);  color: var(--green); }
.r-icon[data-c="purple"] { background: var(--purple-soft); color: var(--purple); }
.r-title { font-weight: 700; font-size: 15px; line-height: 1.3; }
.r-jp { font-size: 12px; color: var(--ink-3); font-family: var(--mono); margin-top: 2px; }

.page-foot {
  max-width: 1100px; margin: 0 auto;
  padding: 24px 28px 64px;
  border-top: 1px solid var(--line);
}
.back-link {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; color: var(--ink-2);
}
.back-link:hover { color: var(--ink); }

/* ─── Print ──────────────────────────────────────────────────── */
@media print {
  @page { size: A4; margin: 16mm; }
  body { background: white; font-size: 12pt; }
  .topbar, .crumbs, .toc, .progress-rail, .topbar-actions,
  .related, .page-foot, .hero-art { display: none !important; }
  .reader { grid-template-columns: 1fr; padding: 0; }
  .topic-hero { border: 0; padding: 0; }
  .hero-inner { grid-template-columns: 1fr; padding: 0 0 16px; }
  .hero-text h1 { font-size: 28pt; }
  .article h2 { font-size: 18pt; }
  .article h3 { font-size: 14pt; }
  .article > section { break-inside: avoid; padding: 8pt 0 16pt; }
  .callout { break-inside: avoid; }
}
