/* ---- biến màu ---- */
:root { --bg: #fbf7ee; --paper: #fffdf8; --ink: #2b2118; --dim: #6f6255; --line: #e6dcc8; --brand: #9d2a25; --brand-ink: #fff; --accent: #b7791f; --jade: #276749; --soft: #f4ecdb; --ok: #1f7a43; --bad: #b3261e; --shadow: 0 2px 10px rgb(70 45 15 / .08);
  --serif: "Noto Serif", "Source Serif 4", Cambria, Georgia, "Times New Roman", serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif; }
:root[data-theme="dark"] { --bg: #171310; --paper: #211c17; --ink: #efe7da; --dim: #b3a695; --line: #3a3128; --brand: #d9635c; --brand-ink: #1b0f0d; --accent: #e0a84a; --jade: #6fcf97; --soft: #2a241d; --ok: #6fcf97; --bad: #ff8a80; --shadow: 0 2px 10px rgb(0 0 0 / .35); }

/* ---- nền tảng ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.65 var(--sans); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.3; margin: 1.4em 0 .5em; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); margin-top: .4em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.12rem; }
a { color: var(--brand); }
img { max-width: 100%; }
main { max-width: 1120px; margin: 0 auto; padding: 12px 18px 60px; min-height: 60vh; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--paper); padding: 8px; z-index: 20; }
.center { text-align: center; }
.hint-text, .fine { color: var(--dim); font-size: .88rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-width: 100%; }
textarea { width: 100%; line-height: 1.7; resize: vertical; }

/* ---- đầu và chân trang ---- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 8px 18px; background: var(--paper); border-bottom: 3px double var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.brand b { display: block; font-family: var(--serif); color: var(--brand); line-height: 1.15; }
.brand small { display: block; font-size: .72rem; color: var(--dim); line-height: 1.2; }
.menu { margin-left: auto; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.menu > a:not(.btn), .drop summary { padding: 6px 8px; text-decoration: none; color: var(--ink); border-radius: 6px; font-size: .93rem; cursor: pointer; }
.menu > a:not(.btn):hover, .menu > a[aria-current], .drop summary:hover { background: var(--soft); color: var(--brand); }
.drop { position: relative; }
.drop summary { list-style: none; }
.drop summary::after { content: " ▾"; }
.drop-grid { position: absolute; top: 110%; left: 0; display: grid; grid-template-columns: repeat(3, 76px); gap: 6px; padding: 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.drop-grid a, .grade-switch a { text-align: center; padding: 6px; background: var(--soft); border-radius: 6px; text-decoration: none; }
.search input { width: 150px; padding: 5px 10px; font-size: .9rem; border-radius: 99px; }
.icon { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.menu-btn { display: none; margin-left: auto; }
.foot { display: grid; grid-template-columns: 2fr 1.2fr 1fr 1fr; gap: 24px; padding: 30px max(18px, calc((100% - 1084px) / 2)); background: var(--soft); border-top: 3px double var(--line); font-size: .94rem; }
.foot a { display: block; text-decoration: none; padding: 2px 0; }
.foot-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1100px) {
  .menu-btn { display: block; }
  .menu { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--paper); border-bottom: 2px solid var(--line); padding: 12px 18px; justify-content: flex-start; max-height: 80vh; overflow: auto; }
  .menu.open { display: flex; }
  .drop-grid { position: static; box-shadow: none; }
}
@media (max-width: 760px) { .foot { grid-template-columns: 1fr; } }

/* ---- nút, thẻ, khối ---- */
.btn { display: inline-block; background: var(--brand); color: var(--brand-ink); border: 2px solid var(--brand); border-radius: 99px; padding: 8px 20px; text-decoration: none; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { padding: 4px 14px; font-size: .9rem; }
.btn.big { font-size: 1.15rem; padding: 12px 34px; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 4px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); text-align: left; cursor: pointer; }
.card:hover { border-color: var(--brand); transform: translateY(-2px); }
.card b { font-family: var(--serif); }
.card span { font-size: .9rem; color: var(--dim); }
.card .card-icon { font-size: 1.8rem; }
.tag { align-self: flex-start; margin-top: auto; font-style: normal; font-size: .76rem; background: var(--soft); border-radius: 99px; padding: 1px 10px; color: var(--accent); font-weight: 600; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 18px; }
.tabs a, .chips a, .chips span, .quick a { padding: 4px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--paper); text-decoration: none; font-size: .92rem; }
.tabs a.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chips, .quick { display: flex; flex-wrap: wrap; gap: 8px; }
.dim { color: var(--dim); }
.crumbs { font-size: .85rem; color: var(--dim); display: flex; gap: 6px; flex-wrap: wrap; }
.page-head p { color: var(--dim); margin-top: 0; }
.note { background: var(--soft); border-left: 4px solid var(--accent); padding: 8px 14px; border-radius: 6px; font-size: .92rem; }
.empty { color: var(--dim); font-style: italic; }
.error { background: color-mix(in srgb, var(--bad) 14%, transparent); border-radius: 8px; padding: 8px 12px; }
table { width: 100%; border-collapse: collapse; background: var(--paper); font-size: .95rem; }
th, td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; }
.filter { width: 100%; max-width: 440px; margin-bottom: 8px; }

/* ---- trang chủ ---- */
.hero { text-align: center; padding: 34px 10px 18px; background: radial-gradient(ellipse at top, var(--soft), transparent 70%); border-radius: 20px; }
.hero h1 { color: var(--brand); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; color: var(--accent); font-weight: 700; margin: 0; }
.stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; list-style: none; padding: 0; }
.stats li { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 18px; }
.stats b { font-size: 1.3rem; color: var(--brand); font-family: var(--serif); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.level { background: var(--paper); border: 1px solid var(--line); border-top: 5px solid var(--brand); border-radius: 14px; padding: 4px 18px 18px; }
.level-th { border-top-color: var(--jade); }
.level-thcs { border-top-color: var(--accent); }
.level h3 { margin-bottom: 0; }
.level p { margin: 0 0 10px; color: var(--dim); }
.grade-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.grade-grid a { width: 50px; height: 50px; display: grid; place-items: center; font: 700 1.3rem var(--serif); border: 2px solid var(--line); border-radius: 12px; text-decoration: none; }
.grade-grid a:hover { background: var(--brand); color: var(--brand-ink); }
.grade-switch { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; font-size: .88rem; }

/* ---- mục lục, bài đọc ---- */
.unit { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; margin-bottom: 8px; }
.unit summary { cursor: pointer; }
.unit summary span { margin-left: 10px; color: var(--dim); font-size: .9rem; }
.unit ul { padding-left: 20px; }
.kind { font-style: normal; font-size: .72rem; font-weight: 700; display: inline-block; min-width: 92px; text-align: center; border-radius: 5px; background: var(--soft); color: var(--dim); margin-right: 4px; }
.kind-doc { color: var(--brand); }
.kind-tv { color: var(--jade); }
.kind-viet { color: var(--accent); }
.reading { max-width: 760px; margin: 0 auto; }
.reading > header { border-bottom: 3px double var(--line); margin-bottom: 14px; }
.reading section p, .reading li { font-family: var(--serif); }
.author { font-style: italic; color: var(--dim); margin-top: -6px; }
.lead { font-size: 1.08rem; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; font-size: .88rem; }
.toc a { background: var(--soft); border-radius: 6px; padding: 2px 10px; text-decoration: none; }
section[id] { scroll-margin-top: 70px; }
.remember { background: var(--soft); border-radius: 12px; padding: 1px 20px 8px; border-left: 5px solid var(--brand); margin-top: 20px; }
.practice { margin-bottom: 14px; }
.practice p { margin: 4px 0; }
.practice details summary { cursor: pointer; color: var(--brand); font-size: .92rem; }
.example { background: var(--paper); border: 1px dashed var(--accent); border-radius: 10px; padding: 6px 14px; }
.example p { margin: 4px 0; }
.prevnext { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 24px; }
.idiom-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.idiom { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.idiom b { font-family: var(--serif); color: var(--brand); }
.idiom p { margin: 4px 0; font-size: .94rem; }
.idiom small { color: var(--dim); }
.timeline { border-left: 3px solid var(--accent); padding-left: 18px; }
.bigsearch { display: flex; gap: 8px; }
.bigsearch input { flex: 1; }
.results li { margin-bottom: 6px; }
.results small { color: var(--dim); }

/* ---- trò chơi, nghe viết ---- */
.game, .dict { max-width: 720px; margin: 16px auto; }
.game-start, .game-end { text-align: center; }
.big-icon { font-size: 3.4rem; display: block; }
.hud { display: flex; justify-content: space-between; font-weight: 600; font-size: .95rem; }
.bar { height: 6px; background: var(--soft); border-radius: 9px; margin: 8px 0; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.question { font: 600 1.25rem/1.6 var(--serif); white-space: pre-line; }
.choices { display: grid; gap: 10px; }
.choice, .word { background: var(--paper); border: 2px solid var(--line); border-radius: 12px; padding: 11px 16px; cursor: pointer; text-align: left; }
.choice:hover:not(:disabled), .word:hover:not(:disabled) { border-color: var(--brand); }
.choice.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 16%, transparent); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.choice.gone { visibility: hidden; }
.slots, .bank { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 8px 0; }
.slots { border-bottom: 2px dashed var(--line); }
.word { padding: 6px 14px; font-family: var(--serif); }
.feedback { margin-top: 14px; padding: 10px 14px; border-radius: 10px; background: var(--soft); }
.feedback.ok { border-left: 5px solid var(--ok); }
.feedback.no { border-left: 5px solid var(--bad); }
.game-actions { display: flex; justify-content: space-between; margin-top: 12px; }
.game-actions .btn:last-child { margin-left: auto; }
.speak { background: var(--soft); border: 1px solid var(--line); border-radius: 99px; padding: 4px 14px; cursor: pointer; margin-bottom: 10px; }
.tok-bad { background: color-mix(in srgb, var(--bad) 22%, transparent); border-radius: 4px; padding: 0 3px; text-decoration: line-through; }
.tok-fix { background: color-mix(in srgb, var(--ok) 22%, transparent); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.phonics { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.phon { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px; text-align: center; }
.phon button { cursor: pointer; border: 0; background: var(--soft); border-radius: 8px; margin: 2px; padding: 3px 9px; }
.phon button:disabled { cursor: default; background: none; }
.phon .phon-w { font: 700 1.9rem var(--serif); color: var(--brand); width: 100%; }

/* ---- phòng viết ---- */
.studio { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 18px; align-items: start; }
@media (max-width: 860px) { .studio { grid-template-columns: 1fr; } }
.studio-desk label select { max-width: 100%; }
.prompt-text { font: 600 1.05rem var(--serif); }
.w-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.w-tools output { font: 700 1.2rem monospace; }
#w-text { font: 1.05rem/1.8 var(--serif); }
.w-stats { font-size: .9rem; color: var(--dim); }
.w-warn { font-size: .9rem; color: var(--accent); padding-left: 20px; }
.checklist { border: 1px solid var(--line); border-radius: 10px; }
.checklist label { display: block; padding: 3px 0; }

/* ---- biểu mẫu, phiếu in ---- */
.auth { max-width: 420px; margin: 30px auto; display: grid; gap: 12px; }
.auth label, .ws-form label { display: grid; gap: 4px; }
.ws-form { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
.ws-form fieldset { flex-basis: 100%; border: 1px solid var(--line); border-radius: 10px; }
.ws-form fieldset label { display: inline-block; margin-right: 16px; }
.paper { background: #fff; color: #111; padding: 26px 34px; margin: 16px 0; border: 1px solid #ccc; font-family: var(--serif); }
.paper-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; border-bottom: 2px solid #111; }
.paper li { margin-bottom: 8px; break-inside: avoid; }
.paper li p { margin: 0; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }
@media (max-width: 560px) { .opts { grid-template-columns: 1fr; } .paper { padding: 14px; } }
.print-only { display: none; white-space: pre-wrap; }

/* ---- in ---- */
@media print {
  .top, .foot, .crumbs, .no-print, .btn, .toc, .prevnext, .print-row, .studio-guide, .studio-desk > :not(#w-print):not(#w-prompt-text) { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  main { padding: 0; max-width: none; }
  .studio { display: block; }
  .studio-desk { border: 0; box-shadow: none; padding: 0; }
  .print-only { display: block; }
  .paper { border: 0; padding: 0; }
  .paper.key { break-before: page; }
  body.no-key .paper.key { display: none; }
  textarea:placeholder-shown { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } .card:hover { transform: none; } }
