/* ---- biến màu ---- */
:root { --bg: #f5f7fb; --paper: #ffffff; --ink: #0f172a; --dim: #55637a; --line: #dbe3ef; --brand: #1d4ed8; --brand-ink: #fff; --accent: #b45309; --jade: #0f766e; --soft: #eaf0fb; --ok: #15803d; --bad: #b91c1c; --shadow: 0 2px 12px rgb(30 58 138 / .08);
  --code-bg: #0f172a; --code-ink: #e2e8f0; --code-dim: #94a3b8;
  --serif: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif; --mono: "Cascadia Code", "JetBrains Mono", Consolas, "DejaVu Sans Mono", Menlo, monospace; }
:root[data-theme="dark"] { --bg: #0b1120; --paper: #131c31; --ink: #e5ecf7; --dim: #9fb0ca; --line: #26334f; --brand: #7aa2ff; --brand-ink: #0a1022; --accent: #fbbf24; --jade: #5eead4; --soft: #1a2540; --ok: #4ade80; --bad: #fca5a5; --shadow: 0 2px 12px rgb(0 0 0 / .4); --code-bg: #060b17; }

/* ---- 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: 1px solid var(--line); box-shadow: var(--shadow); }
.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: 1px solid var(--line); font-size: .94rem; }
.foot a { display: block; text-decoration: none; padding: 2px 0; }
.foot .contact a { display: inline; font-weight: 700; }
.foot-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 1240px) {
  .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); }
.lesson-chips { max-height: 220px; overflow: auto; padding: 2px; }
.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; }
.bigsearch { display: flex; gap: 8px; }
.bigsearch input { flex: 1; }
.results li { margin-bottom: 6px; }
.results small { color: var(--dim); }

/* ---- trò chơi ---- */
.game { 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 progress { display: block; width: 100%; height: 6px; border: 0; background: var(--soft); accent-color: var(--accent); }
.bar progress::-webkit-progress-bar { background: var(--soft); }
.bar progress::-webkit-progress-value { background: var(--accent); transition: width .3s; }
.bar progress::-moz-progress-bar { background: var(--accent); }
.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; }
/* ---- 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, .prevnext, .quiz-score, .code-actions { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  main { padding: 0; max-width: none; }
  .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; } }

/* ---- trang chủ: đường vào theo đối tượng ---- */
.hero-code { max-width: 460px; margin: 14px auto; text-align: left; }
.paths { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.path { display: flex; flex-direction: column; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 18px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.path:hover { border-color: var(--brand); transform: translateY(-3px); }
.path > span { font-size: 2.2rem; }
.path b { font-size: 1.15rem; }
.path p { color: var(--dim); font-size: .93rem; margin: 6px 0 12px; }
.path em { margin-top: auto; font-style: normal; font-weight: 700; color: var(--brand); }

/* ---- mục lục, bài học ---- */
.unit h2 { font-size: 1.1rem; margin: .4em 0; }
.unit h2 small { font-size: .75rem; color: var(--jade); }
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { padding: 5px 0; border-top: 1px dashed var(--line); }
.toc-list a { text-decoration: none; }
.toc-list i { font-style: normal; font-weight: 700; display: inline-block; min-width: 64px; color: var(--dim); }
.soon { font-size: .76rem; color: var(--dim); }
.course { counter-reset: bai; }
.course li { counter-increment: bai; }
.course a { display: block; padding: 6px 4px; }
.course a b::before { content: counter(bai) ". "; }
.course a span { display: block; color: var(--dim); font-size: .92rem; }
.is-done::after { content: " ✓"; color: var(--ok); font-weight: 700; }
.card.is-done { border-color: var(--ok); }
.goals, .story, .tip, .warn, .challenge, .explain { border-radius: 12px; padding: 10px 16px; margin: 12px 0; }
.goals { background: var(--soft); }
.goals ul { margin: 4px 0; }
.story { background: color-mix(in srgb, var(--jade) 12%, transparent); border-left: 5px solid var(--jade); }
.tip { background: color-mix(in srgb, var(--accent) 12%, transparent); border-left: 5px solid var(--accent); }
.warn { background: color-mix(in srgb, var(--bad) 10%, transparent); border-left: 5px solid var(--bad); }
.tip p, .warn p { margin: 4px 0; }
.challenge { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; border: 2px dashed var(--brand); }
.explain { background: var(--soft); border-left: 5px solid var(--brand); }
.steps li { padding: 5px 4px; border-radius: 8px; }
.steps li.playing, .remember li.playing { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.say { margin-left: 8px; border: 1px solid var(--line); background: var(--paper); border-radius: 99px; cursor: pointer; padding: 0 8px; }
.speak[aria-pressed="false"] { opacity: .65; }
.notes { display: grid; gap: 4px; font-size: .9rem; color: var(--dim); }
.quiz fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 14px; padding: 10px 14px; background: var(--paper); display: grid; gap: 8px; }
.quiz legend { font-weight: 600; padding: 0 4px; }
.quiz .choice { padding: 7px 14px; }
.why { margin: 4px 0 0; color: var(--dim); font-size: .93rem; }
.table-wrap { overflow-x: auto; margin: 10px 0; }

/* ---- mã nguồn ---- */
code { font-family: var(--mono); font-size: .92em; background: var(--soft); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }
pre { font-family: var(--mono); font-size: .9rem; line-height: 1.55; background: var(--code-bg); color: var(--code-ink); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 8px 0; tab-size: 4; }
pre code { background: none; padding: 0; font-size: 1em; overflow-wrap: normal; color: inherit; }
.code { margin: 12px 0; }
.code figcaption { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.io small { color: var(--dim); font-weight: 600; }
.io pre { margin-top: 2px; }
.io.out pre { background: var(--soft); color: var(--ink); border-left: 4px solid var(--jade); }
.code-actions { display: flex; gap: 8px; flex-wrap: wrap; }
pre.has-error { color: var(--bad) !important; white-space: pre-wrap; }
.stdin { display: grid; gap: 4px; font-size: .88rem; color: var(--dim); margin-top: 8px; }
.stdin textarea { font-family: var(--mono); }
canvas.turtle { display: block; width: 100%; max-width: 480px; aspect-ratio: 1; margin: 10px auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; }

/* trình soạn mã: lớp tô màu (.paint) nằm dưới ô nhập chữ trong suốt */
.code-edit { display: flex; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 8px 0; }
.code-edit:focus-within { outline: 3px solid var(--accent); }
.code-edit .gutter { margin: 0; border-radius: 0; padding: 12px 8px; text-align: right; color: var(--code-dim); user-select: none; overflow: hidden; background: rgb(255 255 255 / .04); min-width: 3.2em; max-height: 70vh; }
.code-edit .stack { position: relative; flex: 1; min-width: 0; }
.code-edit .paint, .code-edit textarea { font: .92rem/1.55 var(--mono); letter-spacing: 0; padding: 12px; margin: 0; white-space: pre; tab-size: 4; font-variant-ligatures: none; }
.code-edit .gutter { font-size: .92rem; line-height: 1.55; }
.code-edit .paint { position: absolute; inset: 0; overflow: hidden; pointer-events: none; background: none; border-radius: 0; color: var(--code-ink); }
.code-edit textarea { display: block; position: relative; width: 100%; height: 100%; min-height: 6em; max-height: 70vh; background: transparent; color: transparent; caret-color: #fff; border: 0; border-radius: 0; resize: vertical; overflow: auto; }
.code-edit textarea:focus { outline: none; }
.code-edit textarea::selection { background: rgb(122 162 255 / .4); }
.t-kw { color: #c4b5fd; } .t-str { color: #86efac; } .t-com { color: #7c8aa5; } .t-num { color: #fdba74; } .t-fn { color: #7dd3fc; }

@media print { pre, .io.out pre { background: #fff !important; color: #000 !important; border: 1px solid #999; white-space: pre-wrap; } .t-kw, .t-str, .t-com, .t-num, .t-fn { color: #000; } .quiz .choice { border: 0; padding: 0; } .why { display: none; } }
.q-code { white-space: pre; }
.word.line { font-family: var(--mono); white-space: pre; text-align: left; }
.slots.code-lines, .code-lines + .bank { flex-direction: column; align-items: stretch; }
.code-lines + .bank { display: flex; }
.choice { white-space: pre-wrap; }
