/* Ngữ pháp Lào — reader độc lập, mobile-first */

:root {
  --bg: #eef2f7;
  --bg-header: #ffffff;
  --surface: #ffffff;
  --text: #1a2332;
  --text-muted: #5c6b7f;
  --text-soft: #7b8a9a;
  --border: #dde4ed;
  --border-strong: #c5d0de;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-muted: #e6fffa;
  --lao: #0c4a6e;
  --example-bg: #f8fafc;
  --example-border: #14b8a6;
  --heading: #0f172a;
  --bar-bg: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-header: 0 1px 0 var(--border), 0 4px 20px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --font-vi: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-lao: "Phetsarath OT", "Saysettha OT", "Noto Sans Lao", sans-serif;
  --line: 1.55;
  --page-pad-x: 1rem;
  --page-pad-y: 1.15rem;
  --header-h: auto;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-vi);
  font-size: 16px;
  line-height: var(--line);
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  padding-bottom: calc(1.5rem + var(--safe-bottom));
}

/* ── Header cố định ── */
.book-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  box-shadow: var(--shadow-header);
  padding-top: var(--safe-top);
}

.book-header__inner {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.85rem var(--page-pad-x) 0.75rem;
  padding-left: calc(var(--page-pad-x) + var(--safe-left));
  padding-right: calc(var(--page-pad-x) + var(--safe-right));
}

.book-header__title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--heading);
  letter-spacing: -0.02em;
  margin: 0;
}

.book-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

/* ── Nội dung sách ── */
.book {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.85rem var(--page-pad-x) 2rem;
  padding-left: calc(var(--page-pad-x) + var(--safe-left));
  padding-right: calc(var(--page-pad-x) + var(--safe-right));
}

.page {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--page-pad-y) 1rem;
  margin-bottom: 0.85rem;
}

.page:last-child {
  margin-bottom: 0;
}

/* ── Phần mở / chia mục ── */
.main-title {
  text-align: center;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 2px solid var(--accent-soft);
}

.main-title h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--heading);
  margin: 0 0 0.35rem;
  line-height: 1.35;
}

.main-title .lao {
  font-size: 1rem;
  color: var(--accent);
  font-weight: 600;
}

.section-title {
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.75rem;
  background: var(--accent-muted);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
}

.section-title .vi {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--heading);
}

.section-title .lao {
  font-size: 0.88rem;
  color: var(--accent);
  margin-top: 0.15rem;
  font-weight: 600;
}

.word-bar {
  display: inline-block;
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.45rem 0.85rem;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: var(--bar-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

/* ── Mục từ / giải thích ── */
.entry-block {
  margin-bottom: 1.15rem;
}

.entry-block:last-child {
  margin-bottom: 0;
}

.entry-heading {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 0.5rem;
  line-height: 1.45;
}

.entry-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0.55rem;
  line-height: 1.5;
}

.note {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-soft);
  margin-bottom: 0.55rem;
  padding: 0.45rem 0.65rem;
  background: #fffbeb;
  border-radius: 8px;
  border-left: 3px solid #fbbf24;
  line-height: 1.45;
}

/* ── Ví dụ Việt – Lào ── */
.examples {
  margin-top: 0.35rem;
}

.example {
  margin-bottom: 0.55rem;
  padding: 0.6rem 0.75rem;
  background: var(--example-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--example-border);
}

.example:last-child {
  margin-bottom: 0;
}

.example .vi {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 0.2rem;
}

.example .lao {
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--lao);
  padding-left: 0;
  font-weight: 500;
}

/* Ví dụ không bọc .examples */
.page > .example,
.entry-block > .example {
  margin-bottom: 0.55rem;
}

/* ── Chữ Lào ── */
.lao {
  font-family: var(--font-lao);
}

span.lao {
  color: var(--lao);
  font-weight: 600;
}

.entry-heading .lao {
  color: var(--accent);
}

/* ── Bảng (cuộn ngang trên mobile) ── */
.entry-block:has(table),
.page > section:has(table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-left: -0.25rem;
  margin-right: -0.25rem;
  padding-left: 0.25rem;
  padding-right: 0.25rem;
}

.compare-table,
.word-table {
  width: 100%;
  min-width: 280px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
  margin: 0.5rem 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.compare-table th,
.compare-table td,
.word-table th,
.word-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  vertical-align: top;
  text-align: left;
}

.compare-table tr:last-child td,
.word-table tr:last-child td {
  border-bottom: none;
}

.compare-table th:last-child,
.compare-table td:last-child,
.word-table th:last-child,
.word-table td:last-child {
  border-right: none;
}

.compare-table th,
.word-table th {
  background: #f1f5f9;
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--heading);
  white-space: nowrap;
}

.compare-table td.lao,
.word-table td.lao {
  color: var(--lao);
  font-weight: 600;
  white-space: nowrap;
}

/* ── Danh sách ── */
.word-list {
  font-size: 0.88rem;
  margin: 0.35rem 0 0.65rem;
  padding-left: 1.15rem;
  color: var(--text);
  line-height: 1.55;
}

.word-list li {
  margin-bottom: 0.3rem;
}

.word-list .lao {
  color: var(--lao);
}

/* ── Chân trang / trống ── */
.footnote {
  margin-top: 1.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
  font-size: 0.75rem;
  color: var(--text-soft);
  line-height: 1.45;
}

.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ── Nút lên đầu (mobile) ── */
.scroll-top {
  position: fixed;
  right: calc(0.85rem + var(--safe-right));
  bottom: calc(0.85rem + var(--safe-bottom));
  z-index: 90;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s, visibility 0.2s, transform 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.scroll-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ── Tablet / desktop ── */
@media (min-width: 640px) {
  :root {
    --page-pad-x: 1.25rem;
    --page-pad-y: 1.35rem;
  }

  .book-header__title {
    font-size: 1.2rem;
  }

  .page {
    padding: var(--page-pad-y) 1.25rem;
    margin-bottom: 1rem;
  }

  .main-title h1 {
    font-size: 1.3rem;
  }

  .example .lao {
    font-size: 1.05rem;
  }
}

@media (min-width: 900px) {
  body {
    background: linear-gradient(180deg, #e2e8f0 0%, var(--bg) 120px);
  }

  .book {
    padding-top: 1.25rem;
  }

  .page {
    box-shadow: var(--shadow-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .scroll-top {
    transition: none;
  }
}
