@font-face {
  font-family: "Phetsarath";
  src:
    url("../assets/fonts/PhetsarathOT.woff2") format("woff2"),
    url("../assets/fonts/PhetsarathOT.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Serif Lao";
  src:
    url("../assets/fonts/NotoSerifLao.woff2") format("woff2"),
    url("../assets/fonts/NotoSerifLao.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

body {
  font-family: "Phetsarath", "Noto Sans Lao", sans-serif;
  background-image: url("../assets/images/wooden_background.jpg");
  background-attachment: fixed;
  background-size: cover;
}

.sutra-content {
  font-family: "Noto Serif Lao", serif;
}

.bg-primary-brown {
  background-color: #795548;
}

.text-primary-brown {
  color: #795548;
}

.bg-soft-brown {
  background-color: #ddcfbc;
}

/* TOC (ສາລະບານ) styling */
.toc-page {
  max-width: 42rem;
  margin-left: auto;
  margin-right: auto;
}
.toc-page .toc-title {
  text-align: center;
  font-size: 1.6em;
  font-weight: 700;
  color: #5d4037;
  margin-bottom: 0.75rem;
  margin-top: 0.25rem;
  letter-spacing: 0.08em;
  position: relative;
  padding-bottom: 0.75rem;
}
.toc-page .toc-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 4rem;
  height: 3px;
  background: linear-gradient(90deg, transparent, #a1887f, transparent);
  border-radius: 2px;
}
.toc-page .toc-entry {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  line-height: 2;
  padding: 0.4rem 0 0.4rem 1.5rem;
  margin: 0;
}
.toc-page .toc-entry::before {
  content: "";
  position: absolute;
  left: 0.5rem;
  top: 0;
  bottom: 0;
  width: 2px;
  background: repeating-linear-gradient(
    to bottom,
    #b8a89a 0px,
    #b8a89a 4px,
    transparent 4px,
    transparent 8px
  );
  opacity: 0.7;
}
.toc-page .toc-entry::after {
  content: "";
  position: absolute;
  left: 0.2rem;
  top: 50%;
  width: 0.85rem;
  height: 2px;
  background: #a1887f;
  opacity: 0.6;
  border-radius: 1px;
}
.toc-page a.toc-entry:first-child::before {
  top: 50%;
}
.toc-page a.toc-entry:last-child::before {
  bottom: 50%;
}
.toc-page .toc-chapter {
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95em;
}
.toc-page .toc-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8em;
  height: 1.5em;
  padding: 0 0.4em;
  font-size: 0.7em;
  font-weight: 700;
  color: #795548;
  background: #efebe9;
  border-radius: 999px;
  line-height: 1;
}
.toc-page .toc-dots {
  flex: 1;
  min-width: 0.5rem;
  border-bottom: 2px dotted #b8a89a;
  align-self: center;
  height: 1px;
}
.toc-page .toc-page-num {
  flex-shrink: 0;
  font-weight: 700;
  color: #5d4037;
  padding-left: 0.25rem;
  min-width: 1.8em;
  text-align: right;
}
.toc-page a.toc-entry {
  color: #4e342e;
  text-decoration: none;
  transition:
    background 0.15s,
    transform 0.15s;
}
.toc-page a.toc-entry:hover {
  background: #efebe9;
  transform: translateX(3px);
}
.toc-page a.toc-entry:nth-child(even) {
  background: rgba(121, 85, 72, 0.04);
}
.toc-page a.toc-entry:nth-child(even):hover {
  background: #efebe9;
}
.toc-page a.toc-entry:not(:last-child) {
  border-bottom: 1px solid rgba(205, 188, 171, 0.25);
}

/* Loading spinner overlay */
#pageLoader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
#pageLoader.active {
  opacity: 1;
  pointer-events: all;
}
#pageLoader .spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #efebe9;
  border-top-color: #795548;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Fade transition for page content swap */
#pageText {
  transition: opacity 0.2s ease;
}
#pageText.swapping {
  opacity: 0.4;
}

/* TTS word highlight */
.tts-w {
  transition:
    background 0.15s,
    color 0.15s;
  border-radius: 2px;
}
.tts-w.tts-active {
  background: #fbbf24;
  color: #1a1a1a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
