/* Design token + bố cục chung. Sáng mặc định; tối theo hệ thống hoặc data-theme="dark" */
:root {
  --paper: #f8f4ec;
  --paper-2: #f0e9dc;
  --card: #fffdf8;
  --ink: #2a251e;
  --ink-2: #5d554a;
  --line: #e2d8c6;
  --accent: #2f6b4f;
  --accent-ink: #ffffff;
  --gold: #b8862b;
  --marker: #ffe9a8;
  --marker-ink: #3a2e10;
  --hl-bg: #fff7dc;
  --hl-line: #e8c766;
  --story-bg: #eef4ef;
  --ask-bg: #f3eef9;
  --ask-line: #8a6bb8;
  --shadow: 0 1px 2px rgb(60 40 10 / 6%), 0 8px 24px rgb(60 40 10 / 8%);
  --font-step: 0;
  --fs-body: calc(17px + var(--font-step) * 1.5px);
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --sans: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --gutter: 16px;
  --measure: 680px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #17150f; --paper-2: #211e16; --card: #1f1c15;
    --ink: #ece5d6; --ink-2: #b3aa99; --line: #3a3427;
    --accent: #7cc39c; --accent-ink: #10231a; --gold: #e0b45a;
    --marker: #5b4a12; --marker-ink: #fff3cc;
    --hl-bg: #2b2513; --hl-line: #a58a35;
    --story-bg: #1b261f; --ask-bg: #241f2d; --ask-line: #a98bd6;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #17150f; --paper-2: #211e16; --card: #1f1c15;
  --ink: #ece5d6; --ink-2: #b3aa99; --line: #3a3427;
  --accent: #7cc39c; --accent-ink: #10231a; --gold: #e0b45a;
  --marker: #5b4a12; --marker-ink: #fff3cc;
  --hl-bg: #2b2513; --hl-line: #a58a35;
  --story-bg: #1b261f; --ask-bg: #241f2d; --ask-line: #a98bd6;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  overflow-x: hidden;
}
a { color: var(--accent); }
img { max-width: 100%; }
#app { outline: none; max-width: 1040px; margin: 0 auto; padding: 8px var(--gutter) 64px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; text-wrap: balance; }
h1 { font-size: clamp(28px, 6vw, 40px); margin: 0 0 12px; letter-spacing: -0.01em; }

.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.center { text-align: center; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
.eyebrow a { color: inherit; text-decoration: none; }
.lead { font-family: var(--serif); font-size: 20px; color: var(--ink-2); margin: 0 0 12px; }

/* Thanh trên cùng */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px var(--gutter);
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; font-family: var(--serif); font-size: 18px; white-space: nowrap; }
.brand-mark { color: var(--accent); font-size: 22px; }
.tools { display: flex; gap: 4px; }
.tool {
  min-width: 40px; height: 40px; padding: 0 8px;
  display: inline-grid; place-items: center;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--ink); font: 600 15px var(--sans);
  text-decoration: none; cursor: pointer;
}
.tool:hover { background: var(--paper-2); }
.tool:disabled { opacity: .35; cursor: default; }
.tool:focus-visible, .btn:focus-visible, a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.scroll-bar { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 20; background: var(--gold); transition: width .1s linear; }

/* Nút */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 18px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font: 600 15px var(--sans); text-decoration: none; border: 1px solid var(--accent);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--accent); }

/* Thanh tiến độ */
.meter { height: 6px; border-radius: 99px; background: var(--paper-2); overflow: hidden; margin: 14px 0 6px; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: inherit; }

.page-head { padding: 24px 0 8px; max-width: var(--measure); }
.empty { text-align: center; padding: 48px 0; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper); font-size: 14px; font-weight: 500;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .brand span:last-child { font-size: 16px; }
  .tool { min-width: 36px; padding: 0 6px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
