:root {
  --ink: #1d2b25;
  --muted: #5f6f68;
  --line: #dfe6e2;
  --primary: #154c3c;
  --primary-soft: #e7f0ec;
  --accent: #e5484d;
  --note: #fff7e8;
  --note-line: #f0c36d;
  --bg: #f4f6f5;
  --paper: #ffffff;
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Athiti", "Thonburi", "Tahoma", sans-serif;
  font-weight: 500;
  line-height: 1.7;
}

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

a { color: var(--primary); }

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

/* ---------- cover ---------- */
.cover {
  position: relative;
  min-height: 92vh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 48px 40px;
  border-radius: 20px;
  overflow: hidden;
  color: #fff;
  background: var(--primary) url("../photos/event-chalung-cup.jpg") 65% 35% / cover no-repeat;
}
.cover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(21, 76, 60, 0.15) 0%, rgba(13, 46, 36, 0.92) 70%);
}
.cover > * { position: relative; }
.cover .brand { font-size: 1rem; letter-spacing: 0.3em; text-transform: uppercase; opacity: 0.85; }
.cover h1 { margin: 8px 0 4px; font-size: 3rem; line-height: 1.2; }
.cover p { margin: 0; font-size: 1.25rem; opacity: 0.92; }
.cover .meta { margin-top: 28px; font-size: 0.95rem; opacity: 0.8; }
.cover .pdf-link {
  align-self: flex-start;
  margin-top: 18px;
  padding: 10px 20px;
  border-radius: 999px;
  background: #fff;
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}
.cover .pdf-link:hover { background: var(--primary-soft); }

/* ---------- toc ---------- */
.toc { background: var(--paper); border-radius: 16px; padding: 32px 36px; margin-top: 32px; }
.toc h2 { margin-top: 0; }
.toc ol { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 40px; counter-reset: chapter; }
.toc li { display: flex; gap: 8px; break-inside: avoid; margin-bottom: 4px; }
.toc li:not(.part):not(.extra) { counter-increment: chapter; }
.toc li:not(.part):not(.extra)::before { content: counter(chapter) "."; min-width: 1.6em; color: var(--muted); }
.toc li > a { flex: 1; }
.toc .part { font-weight: 700; color: var(--primary); margin: 12px 0 4px; }

/* ---------- chapters ---------- */
.part-title {
  margin: 56px 0 0;
  padding: 28px 32px;
  border-radius: 16px;
  background: var(--primary);
  color: #fff;
}
.part-title h2 { margin: 0; font-size: 2rem; }
.part-title p { margin: 4px 0 0; opacity: 0.85; }

.chapter { background: var(--paper); border-radius: 16px; padding: 32px 36px; margin-top: 32px; }
.chapter > h2 { margin: 0 0 4px; font-size: 1.7rem; color: var(--primary); }
.chapter > h2 .no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  margin-right: 10px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
  vertical-align: 4px;
}
.chapter > .lead { margin: 0 0 8px; color: var(--muted); }

.step { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.step h3 { margin: 0 0 6px; font-size: 1.25rem; }
.step p { margin: 0 0 8px; }

/* phone screenshots sit beside their text */
.step.phone { display: grid; grid-template-columns: 250px 1fr; gap: 28px; align-items: start; }
.step.phone figure { margin: 0; }
.step.phone img { border-radius: 22px; border: 6px solid #1f2a25; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12); }

/* desktop screenshots run full width above their text */
.step.desk figure { margin: 10px 0 14px; }
.step.desk img { border-radius: 10px; border: 1px solid var(--line); box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08); }

figcaption { margin-top: 6px; font-size: 0.85rem; color: var(--muted); text-align: center; }

ol.marks { margin: 8px 0; padding: 0; list-style: none; counter-reset: mark; }
ol.marks li { position: relative; margin: 0 0 8px; padding-left: 36px; counter-increment: mark; }
ol.marks li::before {
  content: counter(mark);
  position: absolute;
  left: 0;
  top: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font: 700 0.85rem/24px system-ui, sans-serif;
  text-align: center;
}

ol.steps { margin: 8px 0; padding-left: 1.3em; }
ol.steps li { margin-bottom: 4px; }

.note {
  margin: 12px 0 0;
  padding: 10px 14px;
  border-left: 4px solid var(--note-line);
  border-radius: 8px;
  background: var(--note);
  font-size: 0.95rem;
}
.note.warn { border-color: var(--accent); background: #fdecec; }

table.terms { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.95rem; }
table.terms th, table.terms td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.terms th { background: var(--primary-soft); }

.chip {
  display: inline-block;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

kbd {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fafafa;
  font-family: inherit;
  font-size: 0.9em;
}

@media (max-width: 720px) {
  .cover { min-height: 70vh; padding: 32px 20px; }
  .cover h1 { font-size: 2.1rem; }
  .toc, .chapter { padding: 22px 18px; }
  .toc ol { columns: 1; }
  .step.phone { grid-template-columns: 1fr; }
  .step.phone figure { max-width: 260px; margin: 0 auto; }
}

/* ---------- paged A4 (built by scripts/build-pdf.ts) ----------
   The PDF script moves every block into fixed A4 sheets so the print keeps the
   screen look: grey page, white rounded cards, large phone shots. */
@page { size: A4; margin: 0; }

html.paged { font-size: 14.5px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
html.paged body { background: #fff; }
html.paged .page { display: none; }
html.paged .pdf-link { display: none; }

.sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 210mm;
  height: 297mm;
  padding: 12mm 12mm 0;
  overflow: hidden;
  background: var(--bg);
  break-after: page;
}
.sheet:last-child { break-after: auto; }
.sheet-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6mm; overflow: hidden; }
.sheet-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7mm 8mm;
  align-content: start;
  padding: 9mm 9mm;
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.sheet-card > * { grid-column: 1 / -1; margin: 0; }
.sheet-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 13mm;
  font-size: 8.5pt;
  color: var(--muted);
}
.sheet-foot .pg { font-weight: 700; color: var(--primary); }

/* cover fills the whole first sheet */
.sheet.is-cover { padding: 0; }
.sheet.is-cover .sheet-body { gap: 0; }
.sheet.is-cover .cover { flex: 1; min-height: 0; margin: 0; border-radius: 0; padding: 30mm 22mm; background-position: 65% 35%; }
.sheet.is-cover .cover h1 { font-size: 3.4rem; }

/* toc */
.sheet .toc { margin: 0; padding: 12mm 14mm; }
.sheet .toc ol { columns: 1; }
.sheet .toc li a { display: flex; justify-content: space-between; gap: 8px; text-decoration: none; color: var(--ink); }
.sheet .toc li a .toc-pg { color: var(--primary); font-weight: 700; }
.sheet .toc li { padding: 1px 0; border-bottom: 1px dotted var(--line); }
.sheet .toc li.part { border: 0; margin-top: 10px; }

.sheet .part-title { margin: 0; }

/* chapter heading at the top of a card */
.chapter-head > h2 { margin: 0 0 4px; font-size: 1.7rem; color: var(--primary); }
.chapter-head > .lead { margin: 0; color: var(--muted); }
.chapter-head .no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  margin-right: 10px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1.1rem;
  vertical-align: 4px;
}

/* steps inside sheets: no rule lines, phone steps take one column each */
.sheet .step { margin: 0; padding: 0; border: 0; }
.sheet-card > .step.phone { grid-column: auto; display: block; }
.sheet .step.phone figure { width: 58mm; max-width: 100%; margin: 0 auto 5mm; }
.sheet .step.phone img { border-width: 5px; border-radius: 18px; margin: 0 auto; }
.sheet .step.desk figure { margin: 0 0 4mm; }
.sheet .step.desk img { width: auto; max-width: 100%; max-height: 165mm; margin: 0 auto; }
.sheet .step h3 { font-size: 1.15rem; }
.sheet .appendix-block h3 { margin: 0 0 6px; color: var(--primary); }
