*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #faf6f0;
  --bg-secondary: #f3ece1;
  --bg-card: #fffdf9;
  --text-primary: #2c2417;
  --text-secondary: #5a4d3e;
  --text-muted: #8a7e6e;
  --accent: #b8923e;
  --accent-hover: #9a7a2e;
  --accent-light: #dbc68e;
  --border: #d9ccb4;
  --border-light: #e8dece;
  --shadow: rgba(44, 36, 23, 0.08);
  --shadow-deep: rgba(44, 36, 23, 0.15);
  --font-zh: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-en: "Cormorant Garamond", "Georgia", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --max-width: 780px;
  --transition: 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(184, 146, 62, 0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(184, 146, 62, 0.04) 0%, transparent 60%);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 3rem 1.5rem 2rem;
  opacity: 0;
  animation: fadeInPage 0.8s ease-out 0.2s forwards;
}

@keyframes fadeInPage {
  to { opacity: 1; }
}

/* ──────────────── Header ──────────────── */

.header {
  text-align: center;
  margin-bottom: 3rem;
}

.ornament {
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 1rem;
  opacity: 0.7;
  letter-spacing: 0.5em;
}

.sutra-title {
  font-weight: 400;
  margin-bottom: 0.5rem;
}

.title-zh {
  display: block;
  font-family: var(--font-zh);
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-primary);
}

.title-en {
  display: block;
  font-family: var(--font-en);
  font-size: 1.15rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  margin-top: 0.3rem;
}

.sutra-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 0.75rem;
}

.subtitle-zh {
  font-family: var(--font-zh);
  display: block;
  letter-spacing: 0.08em;
}

.subtitle-en {
  font-family: var(--font-en);
  font-style: italic;
  display: block;
  margin-top: 0.15rem;
}

/* ──────────────── Chapter ──────────────── */

.chapter {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 2.5rem 2rem;
  box-shadow:
    0 2px 20px var(--shadow),
    0 0 0 1px rgba(255, 255, 255, 0.6) inset;
  transition: opacity var(--transition), transform var(--transition);
}

.chapter.fade-out {
  opacity: 0;
  transform: translateY(8px);
}

.chapter.fade-in {
  opacity: 1;
  transform: translateY(0);
}

.chapter-header {
  text-align: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-light);
  position: relative;
}

.chapter-header::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 2px;
  background: var(--accent-light);
}

.chapter-number {
  display: inline-block;
  font-family: var(--font-en);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  margin-bottom: 0.5rem;
}

.chapter-title {
  font-weight: 400;
}

.chapter-title-zh {
  display: block;
  font-family: var(--font-zh);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-primary);
}

.chapter-title-en {
  display: block;
  font-family: var(--font-en);
  font-size: 1.05rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ──────────────── Text ──────────────── */

.chapter-body {
  line-height: 2;
}

.text-block {
  white-space: pre-line;
}

.text-zh {
  font-family: var(--font-zh);
  font-size: 1.1rem;
  line-height: 2;
  color: var(--text-primary);
  letter-spacing: 0.04em;
  text-align: justify;
}

.text-en {
  font-family: var(--font-en);
  font-size: 1.1rem;
  line-height: 1.9;
  color: var(--text-secondary);
  text-align: justify;
}

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1.8rem 0;
}

.divider span {
  display: block;
  width: 60px;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--border) 20%,
    var(--border) 80%,
    transparent
  );
}

/* ──────────────── Controls ──────────────── */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 2.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 0.65rem 1.6rem;
  cursor: pointer;
  transition: all 0.25s ease;
  user-select: none;
}

.btn:hover {
  color: var(--bg-card);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(184, 146, 62, 0.25);
}

.btn:active {
  transform: scale(0.97);
}

.btn-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.btn-small {
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  min-width: 2.4rem;
  justify-content: center;
}

.chapter-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chapter-indicator {
  font-family: var(--font-en);
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 4rem;
  text-align: center;
}

/* ──────────────── Footer ──────────────── */

.footer {
  text-align: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-light);
}

.footer p {
  font-family: var(--font-zh);
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  line-height: 2;
}

/* ──────────────── Responsive ──────────────── */

@media (max-width: 600px) {
  .container {
    padding: 1.75rem 1rem 1.5rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .header {
    margin-top: 2rem;
    padding-top: 1.5rem;
  }

  .ornament {
    letter-spacing: 0.25em;
  }

  .title-zh {
    font-size: 1.45rem;
  }

  .title-en {
    font-size: 1rem;
  }

  .chapter {
    padding: 1.5rem 1.1rem;
  }

  .chapter-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1.1rem;
  }

  .chapter-title-zh {
    font-size: 1.2rem;
  }

  .chapter-title-en {
    font-size: 0.95rem;
  }

  /* Justify looks poor on narrow columns — left-align English, keep Chinese */
  .text-en {
    text-align: left;
    font-size: 1.05rem;
  }

  .text-zh {
    font-size: 1rem;
  }

  /* Larger tap targets (≥ 44px) */
  .btn {
    padding: 0.8rem 1.6rem;
    font-size: 0.95rem;
    min-height: 44px;
  }

  .btn-small {
    padding: 0.6rem 1rem;
    min-width: 44px;
    min-height: 44px;
    font-size: 0.9rem;
  }

  .controls {
    gap: 0.85rem;
    margin-top: 2rem;
  }

  .chapter-nav {
    gap: 0.6rem;
  }

  .footer {
    margin-top: 2rem;
    padding-top: 1.25rem;
  }

  .footer p {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    line-height: 2.2;
  }
}

@media (min-width: 900px) {
  :root {
    --max-width: 820px;
  }

  .container {
    padding: 4rem 2rem 3rem;
  }

  .chapter {
    padding: 3rem 2.5rem;
  }
}

/* ──────────────── Print ──────────────── */

@media print {
  .controls,
  .ornament {
    display: none;
  }

  .chapter {
    box-shadow: none;
    border: none;
  }

  body {
    background: white;
  }
}
