:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1d1e20; --mute: #5a5d62; --line: #dcdad4;
  --link: #0d6b63; --link-bg: #dff1ee;
  --ins: #8a4b00; --ins-bg: #fbe9d2;
  --bad: #a3262a; --bad-bg: #fbe3e3;
  --focus: #1c5fd6;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b; --panel: #1f2226; --ink: #ecebe8; --mute: #a4a8ae; --line: #33373d;
    --link: #62d3c6; --link-bg: #17403c;
    --ins: #f2b25c; --ins-bg: #44301a;
    --bad: #ff8b8f; --bad-bg: #432324;
    --focus: #8ab4ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }   /* chừa chỗ cho thanh dính khi cuộn tới ô / dùng Tab */
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: 0 16px 56px; max-width: 760px; margin-inline: auto;
}
h1, h2 { line-height: 1.2; text-wrap: balance; }
h1 { font-size: 2rem; margin: 4px 0 8px; }
h2 { font-size: 1.3rem; margin: 40px 0 12px; }
.kicker { margin: 28px 0 0; color: var(--mute); font-size: .95rem; }
.lead, .sub { color: var(--mute); margin: 0 0 12px; }
b { font-weight: 700; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

/* chọn giọng đọc */
.voice { display: grid; grid-template-columns: max-content 1fr; gap: 8px 12px; align-items: center; margin-top: 16px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.voice label { font-weight: 600; }
.voice select { font: inherit; min-height: 44px; padding: 0 10px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-width: 0; width: 100%; }
.voice .btn { grid-column: 1 / -1; justify-self: start; }
.voice .hint { grid-column: 1 / -1; margin: 0; color: var(--mute); font-size: .92rem; }
.voice select:disabled { opacity: .55; }

/* thanh điều khiển dính đầu trang */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-top: 12px;
}
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 10px 18px; min-height: 44px; line-height: 24px; cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--link); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
}
.btn.primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: .95rem; }
.btn.good { border-color: var(--link); color: var(--link); }
.btn.wrong { border-color: var(--bad); color: var(--bad); }
.btn[aria-pressed="true"], .btn.playing { box-shadow: inset 0 0 0 2px currentColor; }
.ic { width: 18px; height: 18px; fill: currentColor; flex: none; }
.msg { min-height: 1.4em; margin: 6px 0 0; color: var(--bad); font-size: .95rem; }

/* chú thích */
.legend ul { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.legend li { display: flex; gap: 12px; align-items: baseline; }
.legend .demo { flex: none; width: 92px; text-align: center; }
.legend .txt { flex: 1; min-width: 0; }
.legend .st, .legend .arr { background: none; box-shadow: none; }
main > section:first-child h2 { margin-top: 24px; }
.tie { font-size: 1.3em; line-height: 0; font-weight: 400; }
details.more { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
details.more summary { cursor: pointer; font-weight: 600; min-height: 28px; }
details.more label { display: block; padding: 8px 0 0; }
details.more input { width: 20px; height: 20px; vertical-align: -4px; margin-right: 8px; }

/* chữ đặc biệt trong bài */
.demo, .chip { font-weight: 700; border-radius: 6px; padding: 1px 6px; }
.link, .k-l, .k-c { color: var(--link); background: var(--link-bg); box-shadow: inset 0 -3px 0 var(--link); }
.ins, .k-i { color: var(--ins); background: var(--ins-bg); box-shadow: inset 0 -3px 0 var(--ins); }
.st, .k-st { font-weight: 800; letter-spacing: .02em; }
.k-e, .k-a, .k-s, .k-k { text-decoration: underline dotted 2px; text-underline-offset: 5px; }
.chip {
  font: inherit; font-weight: 700; border: 0; cursor: pointer; margin: 2px 0; padding: 4px 8px; min-height: 36px;
}
.chip[aria-expanded="true"] { outline: 2px solid currentColor; outline-offset: 1px; }
.chip.playing { animation: pulse .9s ease-in-out infinite alternate; }
.k-e, .k-a, .k-s, .k-k { background: none; color: inherit; font-weight: 600; padding: 4px 3px; }
.sup { font-size: .8em; opacity: .85; }
.arr, .arrow { font-weight: 800; font-size: 1.1em; }
.arr.down, .arrow.down { color: var(--bad); }
.arr.up, .arrow.up { color: var(--link); }
.arrow small { font-size: .6em; vertical-align: sub; margin-left: 1px; font-weight: 600; }
@keyframes pulse { to { filter: brightness(.88); } }

/* các câu thoại */
.lines { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.line { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.line.playing { border-color: var(--link); box-shadow: 0 0 0 2px var(--link); }
.line .who { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-weight: 700; color: var(--mute); }
.line .text { font-size: 1.15rem; line-height: 2.1; overflow-wrap: anywhere; }
.detail { margin-top: 10px; padding: 12px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.detail h3 { margin: 0 0 4px; font-size: 1.15rem; }
.detail p { margin: 4px 0; }
.detail .ipa, .card .ipa { font-family: "Charis SIL", "Gentium Plus", "Doulos SIL", "Segoe UI", "Noto Sans", system-ui, sans-serif; font-size: 1.1rem; }
.tag { color: var(--mute); font-size: .92rem; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* thẻ học từng chỗ */
.cards { display: grid; gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card h3 { margin: 0 0 2px; font-size: 1.3rem; }
.card p { margin: 4px 0; }

.others { display: grid; gap: 6px 14px; grid-template-columns: max-content 1fr; margin: 0; }
.others dt { font-weight: 700; }
.others dd { margin: 0; }
.steps { padding-left: 1.3em; display: grid; gap: 8px; }
footer { margin-top: 40px; color: var(--mute); font-size: .95rem; border-top: 1px solid var(--line); padding-top: 14px; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  h1 { font-size: 1.7rem; }
  .others { grid-template-columns: 1fr; }
  .others dd { margin-bottom: 6px; }
  .btn.primary span { white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  .chip.playing { animation: none; filter: brightness(.88); }
  html { scroll-behavior: auto; }
}
