/* ============================================================
   Battu — Lá số Bát tự
   Palet: giấy ngà #faf7f0 · mực #2b2822 · một điểm son #a33c2f
   ============================================================ */

:root {
  --paper: #faf7f0;
  --paper-2: #fcf9f1;
  --ink: #2b2822;
  --ink-2: #6d6455;          /* chữ phụ — đủ tương phản AA trên giấy ngà */
  --line: #e6dfcd;           /* hairline */
  --line-2: #cfc4a9;         /* hairline đậm hơn */
  --accent: #a33c2f;         /* đỏ son — dùng rất tiết chế */
  --accent-deep: #8f3125;
  --pos-bg: #f3ead2;         /* chip dương tính (hợp/hội) — vàng đất ấm */
  --pos-line: #dccd9f;
  --pos-ink: #6e5313;
  --warn-bg: #f6e2da;        /* chip cảnh báo (xung/hình/hại/pha) — hồng đất */
  --warn-line: #e5c3b6;
  --warn-ink: #8c2f1f;

  /* Font hệ thống đủ dấu tiếng Việt 100% (ADR-0009: UI không còn chữ Hán
     nên không cần font SC — SimSun/Noto SC là nguyên nhân vỡ dấu trước đây;
     Georgia thiếu Latin Extended Additional nên phải đứng sau Palatino) */
  /* Webfont tự host đi theo app (web/fonts/) — mọi máy/VPS hiển thị giống hệt nhau;
     font hệ thống phía sau chỉ là fallback khi file font không tải được */
  --serif: "Noto Serif", "Palatino Linotype", "Book Antiqua", Cambria, "Times New Roman", Georgia, serif;
  --sans: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

/* ---------- Nền móng ---------- */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: #eddcc2; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 22px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.muted { color: var(--ink-2); font-size: .85rem; }
.han { font-family: var(--serif); }

/* ---------- Masthead: khối giới thiệu / trạng thái rỗng ---------- */

.masthead {
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--line-2);
  background: linear-gradient(180deg, #fbf8f1 0%, var(--paper) 100%);
}

/* Neo thị giác: hai chữ Hán lớn mờ phía phải, thay ảnh minh họa */
.masthead::before {
  content: "Bát tự";
  position: absolute;
  right: -1%;
  top: 50%;
  transform: translateY(-52%);
  font-family: var(--serif);
  font-size: clamp(10rem, 24vw, 17rem);
  line-height: 1;
  letter-spacing: -.04em;
  color: rgba(43, 40, 34, .05);
  pointer-events: none;
  user-select: none;
}

.masthead-in { position: relative; padding: 52px 22px 30px; }

.brand {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.9rem, 4.6vw, 3rem);
  letter-spacing: .1em;
  line-height: 1.2;
}

.brand-sub {
  margin: 12px 0 0;
  max-width: 58ch;
  color: var(--ink-2);
  font-size: .98rem;
  line-height: 1.65;
}

.brand-sub strong { color: var(--accent); font-weight: 600; }

/* ---------- Section chung: ngăn dọc bằng hairline, không card ---------- */

.composer { padding: 26px 0 30px; }

#stage .sec { padding: 30px 0 34px; }
#stage .sec + .sec { border-top: 1px solid var(--line); }

.sec-title {
  margin: 0 0 18px;
  display: flex;
  align-items: baseline;
  gap: .55em;
  font-size: 1.14rem;
  font-weight: 600;
  letter-spacing: .05em;
}

/* Motion 1: kết quả hiện lên tuần tự sau khi an số */
.reveal { animation: rise .55s cubic-bezier(.22, .61, .36, 1) both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Form ---------- */

.fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 18px;
  align-items: start;
}

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; border: 0; padding: 0; min-width: 0; }

.field > label, .field > legend {
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 0;
}

input[type="text"], input[type="number"], select {
  width: 100%;
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  background: #fffdf7;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 9px 11px;
  color-scheme: light;
}

input[type="text"]:focus-visible,
input[type="number"]:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.tz-num { margin-top: 8px; }

/* Chú giải UI (ADR-0011): chip "?" + popover giải thích thuật ngữ */
.hint-wrap { position: relative; display: inline-block; margin-left: 4px; }
.hint-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: #fffdf7;
  color: var(--ink-2);
  font: inherit;
  font-size: .68rem;
  font-weight: 600;
  line-height: 1;
  padding: 0;
  cursor: help;
  vertical-align: middle;
}
.hint-chip:hover, .hint-chip:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.hint-pop {
  position: fixed;
  z-index: 60;
  width: min(300px, 78vw);
  background: #fffdf7;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(40, 30, 20, .16);
  color: var(--ink);
  font-size: .84rem;
  line-height: 1.55;
  padding: 10px 12px;
  text-align: left;
  white-space: normal;
  cursor: auto;
}
.hint-pop::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 10px;
  width: 8px;
  height: 8px;
  background: #fffdf7;
  border-left: 1px solid var(--line-2);
  border-top: 1px solid var(--line-2);
  transform: rotate(45deg);
}

/* Đối chiếu chọn (segmented) cho giới tính / loại lịch */
.seg { display: flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; background: #fffdf7; }
.seg-opt { flex: 1; position: relative; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span {
  display: block;
  text-align: center;
  padding: 9px 10px;
  font-size: .88rem;
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.seg-opt + .seg-opt span { border-left: 1px solid var(--line); }
.seg-opt input:checked + span { background: #f1e9d6; color: var(--ink); font-weight: 600; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Ô "Tháng nhuận" — chỉ hiện khi chọn Âm lịch */
.leap-row { display: none; align-items: center; gap: 7px; margin-top: 8px; font-size: .86rem; color: var(--ink); cursor: pointer; }
.is-lunar .leap-row { display: inline-flex; }
.leap-row input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }

.field--submit { justify-content: flex-end; }

.submit-row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.btn-primary {
  font: inherit;
  font-weight: 600;
  letter-spacing: .03em;
  color: #fff8ef;
  background: var(--accent);
  border: 1px solid var(--accent-deep);
  border-radius: 8px;
  padding: 10px 26px;
  cursor: pointer;
  transition: background .18s ease, transform .1s ease;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-deep); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: progress; }

/* Nút phụ (Xuất dữ liệu) */
.btn-secondary {
  font: inherit;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease;
}
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-2); background: #f5f0e2; }
.btn-secondary:disabled { opacity: .45; cursor: not-allowed; }

/* Khối lỗi API */
.form-error {
  margin-top: 16px;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: .9rem;
  line-height: 1.55;
}
.form-error strong { font-weight: 700; }

/* ---------- Tổng quan lá số ---------- */

.chart-gender {
  margin: 0 0 2px;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: .05em;
  border-left: 3px solid var(--accent);
  padding-left: 12px;
}

.chart-dates { margin: 6px 0 14px; color: var(--ink-2); font-size: .92rem; }

.meta {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 6px 24px;
}

.kv { display: flex; gap: 10px; align-items: baseline; }
.kv dt {
  flex: 0 0 auto;
  min-width: 78px;
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.kv dd { margin: 0; font-size: .93rem; }

/* ---------- Tứ trụ dạng bảng (bố cục đã duyệt 2026-09-27) ---------- */

/* Không bọc khung riêng — bảng nằm trực tiếp trong thẻ mục; chỉ cuộn ngang khi hẹp */
.ttwrap { overflow-x: auto; }
table.tt { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 640px; }
.tt th, .tt td {
  padding: 10px 13px;
  border-bottom: 1px solid var(--line-2);
  border-right: 1px solid var(--line-2);
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}
.tt tr > *:last-child { border-right: none; }
.tt tbody tr:last-child > * { border-bottom: none; }
.tt thead th { border-bottom: 2px solid var(--line-2); text-align: center; }
.tt th.tt-lbl {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
  width: 136px;
  vertical-align: middle;
}
.tt thead th.tt-lbl { text-align: left; vertical-align: bottom; }
.tt .tt-pos {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 2px;
}
.tt .tt-god { font-weight: 600; font-size: .95rem; }
.tt .tt-gz {
  font-family: var(--serif);
  font-size: 1.65rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
}
.tt .tt-day { background: #fbf3ea; }
.tt thead th.tt-day .tt-pos { color: var(--accent); }
.tt .tt-mut { color: var(--ink-2); font-size: .86em; }

.tt-value {
  display: inline;
  border: 0;
  border-bottom: 1px dotted var(--line-2);
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: inherit;
  cursor: help;
}
.tt-value:hover, .tt-value[aria-expanded="true"] { border-bottom-color: var(--accent); }
.tt-value:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.tt-value-pop {
  position: fixed;
  z-index: 80;
  width: min(360px, calc(100vw - 16px));
  max-height: min(65vh, calc(100dvh - 16px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fffdf7;
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(40, 30, 20, .2);
  padding: 13px 15px;
  font-size: .87rem;
  line-height: 1.5;
  text-align: left;
}
.tt-value-pop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tt-value-pop-title { display: block; font-size: 1rem; margin-bottom: 7px; }
.tt-value-pop h4 { font-size: .75rem; color: var(--accent-deep); margin: 10px 0 4px; }
.tt-value-pop p { margin: 0 0 5px; }

/* Đại vận giữ hiệu ứng hover của bố cục thẻ cũ */
.dayun:hover { transform: translateY(-2px); border-color: var(--line-2); }

/* Thần sát — gạch chấm gợi tooltip */
.ss-row { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.ss {
  font-size: .8rem;
  color: var(--ink);
  border-bottom: 1px dotted var(--line-2);
  cursor: help;
}

/* ---------- Ngũ hành ---------- */

.elems { display: grid; gap: 10px; max-width: 640px; }

.elem { display: grid; grid-template-columns: 84px 1fr 44px; align-items: center; gap: 12px; }
.elem-label { font-size: .9rem; }
.elem-label .han { color: var(--ink-2); margin-left: .3em; }

.elem-bar { height: 8px; background: #ece4d0; border-radius: 99px; overflow: hidden; }
.elem-fill {
  display: block;
  height: 100%;
  width: 0;                      /* Motion 2: JS set width sau khi gắn DOM */
  border-radius: 99px;
  transition: width .7s cubic-bezier(.22, .61, .36, 1);
}

.elem-val { font-size: .88rem; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }

.elem-note { margin: 16px 0 0; font-size: .9rem; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }

/* ---------- Quan hệ chi ---------- */

.rels { display: grid; gap: 10px; }
.rel { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
.rel p { margin: 0; font-size: .92rem; }

.chip {
  display: inline-block;
  font-size: .76rem;
  line-height: 1.25;
  padding: 3px 9px 4px;
  border-radius: 99px;
  border: 1px solid #ddd3ba;
  background: #f1ebdc;
  color: #5f5747;
  white-space: normal;
  overflow-wrap: anywhere;
}
.chip--pos  { background: var(--pos-bg);  border-color: var(--pos-line);  color: var(--pos-ink); }
.chip--warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; }

/* ---------- Điều hậu · Kim bất hoán · Cách cục ---------- */

.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 28px; }

.sub-title { margin: 0 0 9px; font-size: .96rem; font-weight: 600; letter-spacing: .03em; }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li {
  padding: 5px 0;
  font-size: .9rem;
  border-bottom: 1px dashed var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
}
ul.plain li:last-child { border-bottom: 0; }

ul.cach li { justify-content: space-between; gap: 12px; }
.cc-val { color: var(--ink-2); font-weight: 400; }
.ky { color: var(--warn-ink); }

/* ---------- Bảng (Lục thân, Lưu niên) ---------- */

.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.grid-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.grid-table th {
  text-align: left;
  font-size: .73rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}
.grid-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid-table tbody tr:hover td { background: #f5f0e2; }

/* Bảng Lục thân — dòng phụ tàng can, thụt lề và nhạt hơn hàng chính */
.lq-tang td { padding: 4px 10px; color: var(--ink-2); font-size: .85rem; }
.lq-tang td:first-child { padding-left: 26px; font-style: italic; white-space: nowrap; }

.td-year { font-weight: 600; font-variant-numeric: tabular-nums; }
.td-gz .han { font-size: 1.05rem; }

/* Bảng Lưu niên — cuộn ngang khi hẹp */
.lt { min-width: 800px; }

/* ---------- Đại vận ---------- */

/* Tám Đại vận: hai hàng bốn cột đều trên desktop. */
.dayuns {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.dayun {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--paper-2);
  transition: border-color .18s ease, transform .18s ease;
}

.dayun-age { font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.dayun-god { font-size: .86rem; }
.dayun-gz { display: flex; flex-direction: column; }
.dayun-gz .han { font-size: 1.7rem; line-height: 1.25; }
.dayun-meta { font-size: .78rem; color: var(--ink-2); }

/* ---------- Luận giải ---------- */

.reading { display: grid; gap: 34px; }

.reading-duo { gap: 38px; }

.duo-row {
  display: grid;
  grid-template-columns: minmax(0, 1.48fr) minmax(0, 1fr);
  gap: clamp(20px, 3vw, 32px);
  align-items: start;
}

.duo-row > .rsec { grid-column: 1; grid-row: 1; }
.duo-row > .guide-card { grid-column: 2; grid-row: 1; }

.duo-row > .rsec,
.duo-row > .guide-card { min-inline-size: 0; }

.guide-card {
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  background: #f7f1e5;
  padding: 17px 18px 15px;
  color: var(--ink);
  box-shadow: 0 8px 22px rgba(63, 54, 40, .07);
}

.guide-card-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin: 0 0 12px;
  color: var(--accent-deep);
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: .025em;
}

.guide-card-title::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.guide-card p {
  max-width: none;
  margin: 0 0 9px;
  font-size: .9rem;
  line-height: 1.75;
}

.guide-card .guide-flow { margin: 5px 0 11px; max-width: none; }
.guide-card .guide-flow li { font-size: .9rem; line-height: 1.68; }
.guide-card .guide-example { margin: 10px 0 12px; background: var(--paper); }

.guide-note {
  margin-top: 12px !important;
  margin-bottom: 0 !important;
  border-top: 1px solid var(--line-2);
  padding-top: 10px;
  color: var(--accent-deep);
  font-weight: 600;
}

/* Đầu mục: số thứ tự son + tiêu đề + hairline kéo ngang */
.rsec-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}
.rsec-num {
  font-family: var(--serif);
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: .08em;
  font-variant-numeric: tabular-nums;
}
.rsec-head h3 { margin: 0; font-size: 1.06rem; font-weight: 600; letter-spacing: .04em; }

.rsec p { margin: 0 0 8px; max-width: 72ch; line-height: 1.78; font-size: .94rem; }

/* Dòng dữ kiện nhấn ("Tứ trụ: …") */
.rsec p.rkey {
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--ink);
}

/* Đề mục phụ trong section (dòng [ … ]) */
.rsub {
  margin: 18px 0 7px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent-deep);
}

/* Khối trích cổ thư — viền trái, nền giấy đậm hơn, chữ hơi nhỏ */
.rquote {
  margin: 0 0 4px;
  max-width: 72ch;
  border-left: 2px solid var(--line-2);
  background: var(--paper-2);
  border-radius: 0 8px 8px 0;
  padding: 10px 16px 8px;
}
.rquote p { font-size: .9rem; line-height: 1.8; color: #454037; margin: 0 0 7px; }
.rquote p:last-child { margin-bottom: 2px; }

/* Danh sách gạch đầu dòng (Điều hậu…) */
.rlist { margin: 0 0 10px; padding: 0 0 0 6px; list-style: none; max-width: 72ch; }
.rlist li {
  position: relative;
  padding: 3px 0 3px 20px;
  font-size: .92rem;
  line-height: 1.7;
}
.rlist li::before {
  content: "•";
  position: absolute;
  left: 4px;
  color: var(--accent);
}

@media (max-width: 440px) {
  .rquote { padding: 9px 12px 7px; }
}

@media (max-width: 760px) {
  .dayuns { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .dayun { padding: 12px; }
}

@media (max-width: 360px) {
  .dayuns { grid-template-columns: 1fr; }
}

/* ---------- Hộp thoại dữ kiện lá số ---------- */

.modal {
  width: min(720px, 94vw);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border: 1px solid var(--line-2);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  padding: 20px 22px 18px;
  box-shadow: 0 24px 60px rgba(43, 40, 34, .28);
}
.modal::backdrop { background: rgba(43, 40, 34, .45); }

.modal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.modal-head h2 { margin: 0; font-size: 1.06rem; font-weight: 600; letter-spacing: .03em; }
.modal-close {
  font: inherit;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink-2);
  border-radius: 7px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { border-color: var(--ink-2); color: var(--ink); }

.modal-sub { margin: 8px 0 12px; color: var(--ink-2); font-size: .86rem; line-height: 1.6; }

.export-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.export-group { min-width: 0; margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.export-group legend { padding: 0 5px; font-size: .88rem; font-weight: 600; }
.export-list { max-height: 156px; overflow-y: auto; overscroll-behavior: contain; }
.export-choice { display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 6px; cursor: pointer; font-size: .86rem; }
.export-choice input { width: 18px; height: 18px; margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.export-choice:has(input:checked) { background: var(--paper-2); border-radius: 5px; }
.export-choice:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 5px; }
.export-empty { margin: 6px; color: var(--ink-2); font-size: .86rem; line-height: 1.6; }
.export-summary { margin: 10px 0; color: var(--ink-2); font-size: .84rem; }
@media (max-width: 520px) {
  .export-options { grid-template-columns: 1fr; }
  .modal { padding: 16px; }
  .modal-foot { flex-wrap: wrap; }
}

.export-pre {
  margin: 0;
  max-height: 34vh;
  overflow: auto;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: .8rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  tab-size: 2;
}

.modal-foot { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.copied-note { color: #3f6d3f; font-weight: 600; font-size: .88rem; }

/* ---------- Footer / noscript ---------- */

.foot { border-top: 1px solid var(--line); margin-top: 10px; }
.foot .wrap { padding: 20px 22px 42px; color: var(--ink-2); font-size: .84rem; }

.noscript {
  margin: 0;
  padding: 10px 22px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: .9rem;
  text-align: center;
}

/* ---------- Thành phần nội dung dùng trong thẻ cẩm nang ---------- */

.guide-flow {
  list-style: none;
  margin: 6px 0 10px;
  padding: 0;
  max-width: 72ch;
  counter-reset: step;
}
.guide-flow li {
  counter-increment: step;
  position: relative;
  padding: 7px 0 7px 38px;
  border-bottom: 1px dashed var(--line);
  font-size: .94rem;
  line-height: 1.68;
}
.guide-flow li:last-child { border-bottom: 0; }
.guide-flow li::before {
  content: counter(step);
  position: absolute;
  left: 4px;
  top: 10px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  font-family: var(--serif);
  font-size: .76rem;
  color: var(--accent-deep);
}

/* Khối ví dụ trong cẩm nang — dữ kiện lấy từ engine, tách khỏi lời giải thích */
.guide-example {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  background: var(--paper-2);
  padding: 11px 15px;
  margin: 10px 0;
  max-width: 76ch;
}
.guide-example p { margin: 0 0 6px; max-width: none; }
.guide-example p:last-child { margin-bottom: 0; }

/* Link điều hướng trong masthead/footer */
.brand-sub a, .foot a {
  color: var(--accent-deep);
  text-decoration: none;
  border-bottom: 1px dotted var(--line-2);
}
.brand-sub a:hover, .brand-sub a:focus-visible,
.foot a:hover, .foot a:focus-visible { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .duo-row { grid-template-columns: 1fr; gap: 18px; }
  .duo-row > .guide-card, .duo-row > .rsec { grid-column: auto; grid-row: auto; }
}

@media (max-width: 880px) {
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trio { grid-template-columns: 1fr; gap: 24px; }
  .masthead-in { padding: 40px 22px 26px; }
}

@media (max-width: 440px) {
  .fields { grid-template-columns: 1fr; }
  .submit-row .btn-primary, .submit-row .btn-secondary { width: 100%; }
  .meta { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .duo-row { grid-template-columns: 1fr; }
  .duo-row > .guide-card, .duo-row > .rsec { grid-column: auto; grid-row: auto; }
  .guide-card { break-inside: avoid; box-shadow: none; }
  .foot a { display: none; }
  .masthead { padding: 20px 0 8px; }
}

/* ---------- Tôn trọng tùy chọn giảm chuyển động ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  html { scroll-behavior: auto; }
}

/* Hướng dẫn theo ngữ cảnh (ADR-0013). */
.section-help { margin: -6px 0 18px; max-width: 76ch; }
.help-summary { margin: 0 0 8px; color: var(--ink-2); font-size: .9rem; line-height: 1.7; }
.help-details > summary { cursor: pointer; color: var(--accent-deep); font-size: .9rem; padding: 5px 0; }
.help-details > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.help-details[open] > summary { margin-bottom: 9px; }
.hint-wrap[hidden] { display: none; }

/* Khối "Đọc các nhận định cùng nhau" — hộp "Căn cứ và nguồn" đã bỏ khỏi UI (2026-09-29),
   dữ kiện claims/nguồn vẫn trả đầy đủ trong /api/chart. */
.reading-context { border-left: 3px solid var(--accent); padding: 4px 0 4px 16px; margin: 18px 0 24px; }
.reading-context h4 { font-family: var(--sans); font-size: .95rem; margin: 4px 0 10px; }
.reading-context p { font-family: var(--sans); font-size: .9rem; line-height: 1.8; overflow-wrap: anywhere; }
.reading-comparison + .reading-comparison { margin-top: 22px; }
