:root {
  --cream: #f4f0e6;
  --cream-deep: #ebe4d3;
  --paper: #fbf8f1;
  --ink: #2b2a26;
  --ink-soft: #56544c;
  --green: #1f3d2c;
  --green-deep: #14271b;
  --green-soft: #3c5c45;
  --gold: #a9863f;
  --rule: #d8cdb4;
  --shadow: rgba(20, 30, 20, 0.12);
  --radius: 2px;
  --serif: "Source Serif 4", "Noto Serif", Georgia, "Times New Roman", serif;
  --serif-display: "Playfair Display", "Source Serif 4", Georgia, serif;
  --sans: "Inter", "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --cream: #14201a;
  --cream-deep: #0f1813;
  --paper: #182519;
  --ink: #ece6d6;
  --ink-soft: #b9b4a3;
  --green: #cfd9b8;
  --green-deep: #e9ecda;
  --green-soft: #9fae87;
  --gold: #c9a35e;
  --rule: #2c3c2c;
  --shadow: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}

a { color: inherit; text-decoration: none; }

img { max-width: 100%; display: block; }

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--cream);
  border-bottom: 1px solid var(--rule);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 12px;
}

.brand {
  font-family: var(--serif-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.01em;
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand .mark {
  color: var(--gold);
  font-size: 0.95em;
}

nav.primary {
  display: flex;
  gap: 2px;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  flex-wrap: nowrap;
  white-space: nowrap;
}

nav.primary a {
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
}

nav.primary a:hover,
nav.primary a.active {
  color: var(--green);
  border-bottom-color: var(--gold);
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  padding: 0;
}
.theme-toggle:hover { color: var(--green); border-color: var(--gold); }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.nav-toggle {
  display: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--sans);
}

@media (max-width: 880px) {
  nav.primary {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--cream);
    border-bottom: 1px solid var(--rule);
    flex-direction: column;
    flex-wrap: wrap;
    white-space: normal;
    padding: 8px 24px 16px;
  }
  nav.primary.open { display: flex; }
  .nav-toggle { display: inline-block; }
}

@media (max-width: 1040px) and (min-width: 881px) {
  nav.primary { font-size: 0.72rem; gap: 0; }
  nav.primary a { padding: 7px 7px; }
}

/* ---------- Hero ---------- */

.hero {
  background: linear-gradient(180deg, var(--cream-deep), var(--cream));
  border-bottom: 1px solid var(--rule);
}

.hero .wrap {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 56px;
  align-items: center;
  padding-top: 64px;
  padding-bottom: 64px;
}

.eyebrow {
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 18px;
}

.hero h1 {
  font-family: var(--serif-display);
  font-size: clamp(2.4rem, 5vw, 3.6rem);
  line-height: 1.08;
  margin: 0 0 20px;
  color: var(--green);
  font-weight: 700;
}

.hero .lede {
  font-size: 1.18rem;
  font-style: italic;
  color: var(--ink-soft);
  max-width: 36ch;
  margin: 0 0 28px;
  border-left: 3px solid var(--gold);
  padding-left: 16px;
}

.hero-portrait {
  position: relative;
  justify-self: center;
}

.hero-portrait .frame {
  border: 10px solid var(--paper);
  box-shadow: 0 18px 40px var(--shadow);
  background: var(--paper);
  max-width: 320px;
}

.hero-portrait .frame img { display: block; }

.hero-portrait .caption {
  text-align: center;
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 12px;
  letter-spacing: 0.02em;
}

.cta-row { display: flex; gap: 12px; flex-wrap: wrap; }

.btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--green);
  cursor: pointer;
  display: inline-block;
}

.btn.primary { background: var(--green); color: var(--cream); }
.btn.primary:hover { background: var(--green-deep); }
.btn.ghost { background: transparent; color: var(--green); }
.btn.ghost:hover { background: var(--cream-deep); }

@media (max-width: 800px) {
  .hero .wrap { grid-template-columns: 1fr; padding-top: 40px; padding-bottom: 40px; }
  .hero-portrait { order: -1; }
}

/* ---------- Section blocks ---------- */

section.block {
  padding: 64px 0;
  border-bottom: 1px solid var(--rule);
}

section.block:last-of-type { border-bottom: none; }

.section-head { margin-bottom: 36px; max-width: 60ch; }

.section-head .eyebrow { margin-bottom: 10px; }

.section-head h2 {
  font-family: var(--serif-display);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  color: var(--green);
  margin: 0 0 12px;
}

.section-head p { color: var(--ink-soft); margin: 0; }

/* quick links / cards */

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

@media (max-width: 800px) { .card-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 26px 24px;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.card:hover { border-color: var(--gold); transform: translateY(-2px); }

.card .num {
  font-family: var(--serif-display);
  color: var(--gold);
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

.card h3 {
  font-family: var(--serif-display);
  font-size: 1.2rem;
  color: var(--green);
  margin: 8px 0 8px;
}

.card p { color: var(--ink-soft); font-size: 0.95rem; margin: 0 0 14px; }

.card .go {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--green);
}

/* biography copy */

.bio-copy p { margin: 0 0 18px; color: var(--ink); max-width: 70ch; }

/* timeline */

.timeline { position: relative; padding-left: 28px; border-left: 2px solid var(--rule); }

.timeline-item { position: relative; padding-bottom: 36px; }
.timeline-item:last-child { padding-bottom: 0; }

.timeline-item::before {
  content: "";
  position: absolute;
  left: -34px;
  top: 4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--cream);
}

.timeline-item .era {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 4px;
}

.timeline-item h3 {
  font-family: var(--serif-display);
  font-size: 1.25rem;
  color: var(--green);
  margin: 0 0 8px;
}

.timeline-item p { color: var(--ink-soft); margin: 0; max-width: 64ch; }

/* footer */

footer.site-footer {
  border-top: 1px solid var(--rule);
  padding: 36px 0 48px;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

footer.site-footer .wrap {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ---------- Reading page (Riwayat) ---------- */

.reader {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 48px;
  padding: 40px 0 80px;
  align-items: start;
}

@media (max-width: 880px) { .reader { grid-template-columns: 1fr; } }

.toc {
  position: sticky;
  top: 88px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.toc h4 {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 12px;
}

.toc-search {
  width: 100%;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 8px 10px;
  margin-bottom: 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink);
}

.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: chap; }

.toc li { counter-increment: chap; margin-bottom: 4px; }

.toc a {
  display: block;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 7px 9px;
  border-radius: var(--radius);
  color: var(--ink-soft);
}

.toc a::before {
  content: counter(chap, decimal-leading-zero) "  ";
  color: var(--gold);
  font-family: var(--serif-display);
}

.toc a:hover, .toc a.active {
  background: var(--cream-deep);
  color: var(--green);
}

.reader-main { max-width: 70ch; }

.reader-main .chap-eyebrow {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.reader-main h1 {
  font-family: var(--serif-display);
  font-size: clamp(1.8rem, 3.4vw, 2.5rem);
  color: var(--green);
  margin: 10px 0 6px;
}

.reader-main .chap-desc {
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 28px;
}

.reader-main p.para { margin: 0 0 20px; text-align: justify; hyphens: auto; }

mark.hit { background: var(--gold); color: var(--green-deep); padding: 0 2px; }

.chap-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.82rem;
}

.chap-nav a {
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.chap-nav a:hover { color: var(--gold); }
.chap-nav .disabled { color: var(--rule); pointer-events: none; }

/* ---------- Silsilah (family tree) ---------- */

.tree-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.tree-tools input {
  flex: 1;
  min-width: 220px;
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

#tree {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 22px;
}

.tnode { margin: 0; padding-left: 22px; list-style: none; }
.tnode.root-list { padding-left: 0; }

.tnode > li {
  margin: 2px 0;
  border-left: 1px solid var(--rule);
  padding-left: 14px;
}

.tlabel {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.93rem;
}

.tlabel:hover { color: var(--gold); }

.tlabel .twist {
  width: 14px;
  display: inline-block;
  color: var(--gold);
  font-size: 0.75rem;
  transition: transform 0.15s ease;
}

.tlabel.open .twist { transform: rotate(90deg); }

.tlabel .leaf-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rule);
  display: inline-block;
  margin: 0 4px;
}

.tchildren { display: none; }
.tchildren.open { display: block; }

.tlabel.match { background: var(--cream-deep); border-radius: var(--radius); }

/* ---------- Syair manuscript ---------- */

.manuscript {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 48px;
  font-family: var(--serif);
}

@media (max-width: 700px) { .manuscript { padding: 28px 20px; } }

.manuscript .verse { margin: 0 0 22px; text-align: center; }
.manuscript .verse-line { margin: 0; line-height: 1.9; }

.child-name-tag {
  background: var(--cream-deep);
  border-bottom: 2px solid var(--gold);
  padding: 1px 4px;
  color: var(--green);
  font-weight: 600;
}

.children-index {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 40px;
}

.child-card {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.child-card .no {
  font-family: var(--serif-display);
  color: var(--gold);
  font-size: 0.8rem;
}

.child-card h4 {
  margin: 4px 0 6px;
  font-family: var(--serif-display);
  color: var(--green);
}

.child-card p { margin: 0; font-size: 0.85rem; color: var(--ink-soft); }

/* ---------- Galeri ---------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 28px;
}

@media (max-width: 760px) { .gallery-grid { grid-template-columns: 1fr; } }

.gallery-item {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.gallery-item img { width: 100%; }

.gallery-item .meta { padding: 18px 20px; }

.gallery-item h3 {
  font-family: var(--serif-display);
  color: var(--green);
  margin: 0 0 8px;
}

.gallery-item p { color: var(--ink-soft); margin: 0; font-size: 0.92rem; }

/* generic page hero (non-home) */

.page-hero {
  padding: 48px 0 8px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--cream-deep), var(--cream));
}

.page-hero h1 {
  font-family: var(--serif-display);
  font-size: clamp(2rem, 4vw, 2.8rem);
  color: var(--green);
  margin: 8px 0 14px;
}

.page-hero p { color: var(--ink-soft); max-width: 60ch; margin: 0 0 36px; }
