
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400;1,700&family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,300;1,8..60,400&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  /* Bakery / Artisan palette */
  --bg:          #FFFBEB;
  --bg-card:     #FFFFFF;
  --text:        #78350F;
  --text-body:   #3D1D08;
  --muted:       #A8A29E;
  --accent:      #92400E;
  --accent-gold: #B45309;
  --border:      #FDE68A;
  --border-soft: #F5E6C8;
  --topbar-bg:   rgba(255,251,235,0.92);

  /* Typography */
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-body:    'Source Serif 4', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  /* Layout */
  --col-w:     680px;
  --topbar-h:  52px;
}

/* ── Base ── */
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.85;
  background: var(--bg);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
}

/* ── Progress bar ── */
#progress-bar {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-gold));
  z-index: 2000;
  transition: width 80ms linear;
}

/* ── Top navigation bar ── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  gap: 12px;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.topbar-center {
  flex: 1;
  text-align: center;
  overflow: hidden;
}
.topbar-chapter {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-chapter strong {
  color: var(--text);
  font-weight: 600;
}
.nav-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
  font-size: 18px;
  border: 1px solid var(--border);
  transition: background 150ms, border-color 150ms;
  line-height: 1;
}
.nav-arrow:hover { background: var(--border); border-color: var(--accent-gold); }
.nav-arrow.disabled { opacity: 0.3; pointer-events: none; }
.toc-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: background 150ms;
  white-space: nowrap;
}
.toc-btn:hover { background: var(--border); }
.toc-btn svg { flex-shrink: 0; }

/* ── TOC Drawer ── */
.toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(120,53,15,.25);
  z-index: 1500;
  animation: fadeIn 200ms ease;
}
.toc-overlay.open { display: block; }
.toc-drawer {
  position: fixed;
  top: 0; right: -360px;
  width: 340px;
  height: 100vh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  z-index: 1600;
  overflow-y: auto;
  transition: right 280ms cubic-bezier(.4,0,.2,1);
  box-shadow: -8px 0 32px rgba(0,0,0,.12);
}
.toc-drawer.open { right: 0; }
.toc-drawer-header {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  padding: 20px 20px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}
.toc-drawer-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
}
.toc-drawer-subtitle {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-style: italic;
}
.toc-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 20px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.toc-close:hover { color: var(--accent); }
.toc-list {
  list-style: none;
  padding: 12px 0 40px;
}
.toc-list a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 20px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--text);
  text-decoration: none;
  line-height: 1.4;
  border-left: 3px solid transparent;
  transition: background 120ms, border-color 120ms;
}
.toc-list a:hover { background: #FEF3C7; border-left-color: var(--accent-gold); }
.toc-list a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  background: #FEF3C7;
}
.toc-num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  min-width: 28px;
  padding-top: 3px;
  flex-shrink: 0;
}

/* ── Main reading area ── */
.page-wrapper {
  animation: fadeInUp 400ms ease both;
}
.chapter-body {
  max-width: var(--col-w);
  margin: 0 auto;
  padding: 56px 24px 100px;
}

/* ── Chapter header ── */
.chapter-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}
.chapter-ornament {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--border);
}
.chapter-ornament::before,
.chapter-ornament::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.chapter-ornament span {
  font-size: 14px;
  color: var(--accent-gold);
  flex-shrink: 0;
}
.chapter-title {
  font-family: var(--font-heading);
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
  margin-bottom: 32px;
  letter-spacing: -.01em;
}
.chapter-divider {
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-gold));
  border-radius: 2px;
  margin-bottom: 40px;
}

/* ── Body typography ── */
.chapter-body p {
  margin-bottom: 1.3em;
  color: var(--text-body);
}

/* Drop cap on first paragraph */
.chapter-body > p:first-of-type::first-letter {
  font-family: var(--font-heading);
  font-size: 4.5em;
  font-weight: 700;
  color: var(--accent);
  float: left;
  line-height: 0.8;
  margin: 0.05em 0.1em 0 0;
  padding-top: 0.05em;
}

.chapter-body h1, .chapter-body h2, .chapter-body h3, .chapter-body h4 {
  font-family: var(--font-heading);
  color: var(--accent);
  margin: 2em 0 .6em;
  line-height: 1.25;
}
.chapter-body h1 { font-size: 1.9rem; }
.chapter-body h2 { font-size: 1.5rem; }
.chapter-body h3 { font-size: 1.2rem; }
.chapter-body h4 { font-size: 1rem; font-weight: 600; }

.chapter-body i, .chapter-body em { font-style: italic; }
.chapter-body b, .chapter-body strong { font-weight: 600; color: var(--text); }

/* Full-bleed images — slightly overflow column for impact */
.chapter-body img:not([width]) {
  display: block;
  width: min(900px, calc(100% + 48px));
  margin-left: max(-24px, calc((var(--col-w) - 900px) / 2));
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(120,53,15,.15);
  margin-top: 2em;
  margin-bottom: 2em;
}

/* Inline icon images (small, have explicit width attr from EPUB stylesheet) */
.chapter-body img[width] {
  display: inline;
  vertical-align: middle;
  height: auto;
  max-width: 100%;
  border-radius: 4px;
  margin: 0 4px;
}

/* Caption under image */
.chapter-body img + p {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: -1.5em;
  font-style: italic;
}

/* Tables — recipe vitals */
.chapter-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 2em 0;
  font-size: 15px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.chapter-body th {
  background: #FEF3C7;
  color: var(--accent);
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.chapter-body td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-body);
  font-size: 14px;
}
.chapter-body tr:last-child td { border-bottom: none; }

/* ── Recipe Vitals card ── */
.vitals-card {
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 20px 24px;
  margin: 2.5em 0;
  background: var(--bg-card);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px 24px;
}
.vitals-card-title {
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 8px;
}
.vitals-item { display: flex; flex-direction: column; gap: 2px; }
.vitals-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.vitals-value {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Section divider ── */
.section-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 3em 0;
  color: var(--border);
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.section-divider span { font-size: 16px; color: var(--accent-gold); flex-shrink: 0; }

/* ── Chapter navigation ── */
.chapter-nav {
  display: flex;
  gap: 16px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border-soft);
}
.nav-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  transition: border-color 200ms, box-shadow 200ms, transform 150ms;
}
.nav-card:hover {
  border-color: var(--accent-gold);
  box-shadow: 0 4px 16px rgba(180,83,9,.12);
  transform: translateY(-1px);
}
.nav-card.next { text-align: right; }
.nav-dir {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-title {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}

/* ── Index page ── */
.index-hero {
  max-width: 640px;
  margin: 0 auto;
  padding: 64px 24px 48px;
  text-align: center;
}
.index-cover {
  width: min(240px, 70%);
  border-radius: 10px;
  box-shadow: 0 12px 48px rgba(120,53,15,.25);
  display: block;
  margin: 0 auto 36px;
}
.index-title {
  font-family: var(--font-heading);
  font-size: clamp(2rem, 7vw, 3.2rem);
  font-weight: 900;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 10px;
}
.index-subtitle {
  font-family: var(--font-body);
  font-size: 1.05rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 6px;
}
.index-author {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent-gold);
  margin-bottom: 36px;
}
.index-divider {
  width: 48px;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-gold));
  border-radius: 2px;
  margin: 0 auto 36px;
}
.start-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 14px 32px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background 200ms, transform 150ms;
}
.start-btn:hover { background: var(--accent-gold); transform: translateY(-1px); }

/* ── TOC grid on index ── */
.toc-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px 80px;
}
.toc-section-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}
.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}
.toc-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--bg-card);
  text-decoration: none;
  color: var(--text-body);
  transition: border-color 150ms, box-shadow 150ms;
}
.toc-card:hover {
  border-color: var(--accent-gold);
  box-shadow: 0 2px 12px rgba(180,83,9,.08);
}
.toc-card-num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  min-width: 28px;
  padding-top: 3px;
  flex-shrink: 0;
}
.toc-card-title {
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.45;
}

/* ── Language toggle ── */
.lang-toggle {
  display: flex;
  align-items: center;
  background: var(--border-soft);
  border-radius: 20px;
  padding: 3px;
  gap: 0;
  border: 1px solid var(--border);
}
.lang-btn {
  padding: 4px 12px;
  border-radius: 16px;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
  cursor: pointer;
  color: var(--muted);
  transition: background 150ms, color 150ms;
  white-space: nowrap;
}
.lang-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Show/hide language content */
body.lang-vi .content-en { display: none; }
body.lang-en .content-vi { display: none; }

/* Bilingual title — show matching language */
body.lang-vi .title-en { display: none; }
body.lang-en .title-vi { display: none; }
body.lang-vi .topbar-title-en { display: none; }
body.lang-en .topbar-title-vi { display: none; }

/* ── Animations ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ── Mobile ── */
@media (max-width: 640px) {
  :root { --topbar-h: 48px; }
  body { font-size: 17px; }
  .chapter-body { padding: 40px 18px 80px; }
  .chapter-title { font-size: 1.6rem; }
  .chapter-body img { width: 100%; margin-left: 0; }
  .chapter-nav { flex-direction: column; }
  .toc-drawer { width: min(320px, 92vw); }
  .vitals-card { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
