/* ENG303 · Luyện đề thi — giao diện "giấy thi": nền giấy ấm, chữ serif cho câu đề, xanh mực làm màu chính.
   Token ở :root, bản tối qua prefers-color-scheme. Mobile-first (người dùng xem trên iPhone). */
:root {
  --bg: #f6f4ef; --card: #fffdf9; --ink: #1d2433; --muted: #566074; --line: #e0dacd;
  --brand: #1f4e79; --brand-ink: #ffffff; --brand-soft: #e4edf6;
  --bad: #a8261f; --bad-bg: #fdebe8; --good: #17693f; --good-bg: #e6f4ec;
  --warn: #7a5200; --warn-bg: #fff3d1; --mark: #ffe58a; --focus: #0b57d0;
  --r: 12px; --gap: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c; --card: #1a1f2a; --ink: #e8ebf2; --muted: #a2abbd; --line: #2e3546;
    --brand: #7db2ee; --brand-ink: #0b1d33; --brand-soft: #1b2a3d;
    --bad: #ff9b92; --bad-bg: #3a1f1d; --good: #7fdba6; --good-bg: #16301f;
    --warn: #ffd37a; --warn-bg: #392e12; --mark: #6b5a12; --focus: #8ab4f8;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 var(--gap); }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-ink); padding: 10px 14px; z-index: 20; }
.skip:focus { left: 8px; top: 8px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0; }
h2 { font-size: 1.35rem; margin-bottom: 6px; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 10px; }
small { color: var(--muted); }

/* --- header & tabs --- */
.top { background: var(--card); }
.tabbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 8px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font: 700 18px var(--serif); }
.brand h1 { font-size: 1.15rem; }
.sub { margin: 0; font-size: .8rem; color: var(--muted); }
.top-act { display: flex; align-items: center; gap: 10px; }
.prog { font-size: .82rem; color: var(--muted); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-top: 6px; padding-bottom: 6px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; text-decoration: none; color: var(--ink); padding: 9px 14px; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; border: 1px solid transparent; font-weight: 600; }
.tabs a small { font-weight: 500; }
.tabs a:hover { background: var(--brand-soft); }
.tabs a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.tabs a[aria-current="page"] small { color: inherit; opacity: .85; }

main { padding-top: 18px; padding-bottom: 40px; outline: none; }
.foot { padding-bottom: 36px; color: var(--muted); font-size: .85rem; }

/* --- chung --- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: var(--gap); }
.btn { font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn.sec { background: transparent; color: var(--brand); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); min-height: 40px; font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.sp { justify-content: space-between; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: thin; }
.chip { flex: none; text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 999px; min-height: 40px; min-width: 44px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; font-weight: 600; font-size: .92rem; }
.chip[aria-current="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip i { font-style: normal; font-size: .78rem; opacity: .85; }
.chip.done { border-color: var(--good); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .85rem; font-weight: 600; border: 1px solid var(--line); background: var(--card); }
.pill.ok { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.note { background: var(--brand-soft); border-left: 4px solid var(--brand); padding: 10px 14px; border-radius: 8px; font-size: .92rem; }
.lead { color: var(--muted); margin-bottom: 14px; }
mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 3px; }

/* --- AI Revision --- */
.sent { border-left: 5px solid; border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.sent.bad { background: var(--bad-bg); border-color: var(--bad); }
.sent.good { background: var(--good-bg); border-color: var(--good); }
.sent .lab { display: block; font-size: .74rem; letter-spacing: .06em; font-weight: 700; margin-bottom: 4px; }
.sent.bad .lab { color: var(--bad); } .sent.good .lab { color: var(--good); }
.sent p { margin: 0; font: 1.12rem/1.5 var(--serif); }
.tpl { font-family: var(--serif); font-size: 1.05rem; line-height: 2.7; }
.tpl .ln { margin: 0 0 4px; }
.tpl input[type=text], .full textarea, .wr textarea { font: 16px/1.4 var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; max-width: 100%; }
.tpl input[type=text]:focus, textarea:focus { border-color: var(--brand); }
.tpl .in-s { width: 9.5em; } .tpl .in-m { width: 13em; } .tpl .in-e { width: 12em; }
@media (max-width: 560px) { .sub.hide-s { display: none; } .tabs a { padding: 6px 12px; min-height: 44px; } }
.tpl .in-l { display: block; width: 100%; line-height: 1.4; margin: 4px 0 10px; }
.tpl .imp { display: grid; gap: 6px; margin: 4px 0 8px; line-height: 1.4; }
.tpl .imp label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--bg); min-height: 44px; }
.tpl .imp input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
.tpl .imp label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.tpl .imp b { font-weight: 700; }
.preview { font: 1.02rem/1.6 var(--serif); background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; }
.wcrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.res { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.res li { display: flex; gap: 10px; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); font-size: .93rem; }
.res .ic { flex: none; width: 22px; font-weight: 700; text-align: center; }
.res li.ok .ic { color: var(--good); } .res li.no .ic { color: var(--bad); } .res li.mid .ic { color: var(--warn); }
.model { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }
.vi { background: var(--brand-soft); border-radius: 10px; padding: 10px 14px; margin-top: 10px; font-size: .95rem; }
.vi h4 { margin: 0 0 2px; font-size: .78rem; letter-spacing: .05em; color: var(--brand); text-transform: uppercase; }
.vi p { margin-bottom: 8px; }
.modeswitch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.modeswitch button { font: inherit; background: transparent; color: var(--ink); border: 0; padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600; }
.modeswitch button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.full textarea, .wr textarea { width: 100%; min-height: 190px; resize: vertical; font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; }

/* --- Objective --- */
.q-stem { font: 1.18rem/1.55 var(--serif); margin: 6px 0 14px; }
.q-stem u { text-decoration: none; border-bottom: 2px solid var(--brand); white-space: normal; }
.q-stem u b { display: inline-block; font: 700 .72rem var(--sans); background: var(--brand); color: var(--brand-ink); border-radius: 4px; padding: 0 5px; margin-right: 3px; vertical-align: 2px; }
.opts { display: grid; gap: 8px; }
.opt { font: inherit; text-align: left; display: flex; gap: 10px; align-items: flex-start; min-height: 48px; padding: 10px 14px; background: var(--bg); border: 1px solid var(--line); color: var(--ink); border-radius: 10px; cursor: pointer; }
.opt .k { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--muted); display: grid; place-items: center; font-weight: 700; font-size: .82rem; }
.opt:hover:not([disabled]) { border-color: var(--brand); }
.opt.right { background: var(--good-bg); border-color: var(--good); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); }
.opt.picked { border-color: var(--brand); background: var(--brand-soft); }
.opt[disabled] { cursor: default; }
.why { margin-top: 12px; }
.bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--good); }

/* --- Free writing --- */
.reqs { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.reqs li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.reqs .ic { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; border: 1px solid var(--muted); font-size: .8rem; }
.reqs li.on { border-color: var(--good); background: var(--good-bg); }
.reqs li.on .ic { background: var(--good); color: var(--bg); border-color: var(--good); }
.reqs .u { font-size: .74rem; color: var(--muted); }
.reqs .ex { display: block; font: italic .92rem var(--serif); color: var(--muted); }
.sample { font: 1.05rem/1.7 var(--serif); }

/* --- Thi thử --- */
.timer { position: sticky; top: 58px; z-index: 5; background: var(--brand); color: var(--brand-ink); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 600; }
.timer .t { font: 700 1.3rem ui-monospace, Menlo, monospace; }
.timer a { color: inherit; }
.timer.low { background: var(--bad); color: #fff; }
.qn { font-weight: 700; color: var(--brand); }
.score { font: 700 2rem var(--serif); }

/* --- Tóm tắt --- */
.sheet details { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 8px; }
.sheet summary { cursor: pointer; padding: 12px 16px; font: 700 1.02rem var(--serif); min-height: 44px; }
.sheet .in { padding: 0 16px 14px; }
.sheet table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.sheet td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.sheet td:first-child { width: 48%; font-weight: 600; }
.tplcard { font: 1.02rem/1.9 var(--serif); }
.tplcard b { color: var(--bad); font-weight: 700; }

@media (min-width: 720px) {
  .tpl .in-l { display: inline-block; width: min(100%, 30em); margin: 0 4px; }
  .tpl .imp { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
@media print { .top, .foot, .btn, .tabs { display: none; } body { background: #fff; } }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .92rem; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* --- đồ hoạ âm nhạc (trang trí) --- */
.stage { position: relative; height: 150px; background: #07041f; overflow: hidden; border-bottom: 1px solid var(--line); }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.stage::after { content: ""; position: absolute; inset: auto 0 0 0; height: 36px; background: linear-gradient(to bottom, transparent, rgba(7,4,31,.55)); pointer-events: none; }
.stage-note { position: absolute; color: #fff; opacity: .55; font: 700 22px var(--serif); pointer-events: none; text-shadow: 0 0 10px #ff4fd8; animation: float 7s ease-in-out infinite; }
.stage-note.n1 { left: 8%; top: 22%; } .stage-note.n2 { right: 10%; top: 14%; animation-delay: -2.4s; } .stage-note.n3 { left: 46%; top: 8%; animation-delay: -4.6s; font-size: 18px; }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-9px) rotate(6deg); } }
@media (min-width: 720px) { .stage { height: 210px; } }
html.in-exam .stage { display: none; }
.vinyl { width: 100%; height: 100%; border-radius: 50%; display: block; background: radial-gradient(circle, #ffd54f 0 16%, #111 17% 22%, transparent 23%), repeating-radial-gradient(circle, #1b1b24 0 2px, #0b0b10 2px 4px); box-shadow: 0 0 0 2px var(--brand), 0 0 14px rgba(255,79,216,.55); animation: spin 5s linear infinite; }
.brand-mark:has(.vinyl) { background: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.eqstrip { display: flex; align-items: flex-end; justify-content: center; gap: 5px; height: 34px; margin-top: 14px; opacity: .75; }
.eqstrip i { display: block; width: 7px; height: 100%; border-radius: 3px 3px 1px 1px; background: linear-gradient(to top, var(--brand), #ff4fd8); transform-origin: bottom; animation: eq 1.1s ease-in-out infinite; }
.eqstrip i:nth-child(3n) { animation-duration: 1.5s; } .eqstrip i:nth-child(3n+1) { animation-duration: .8s; }
.eqstrip i:nth-child(2) { animation-delay: -.3s; } .eqstrip i:nth-child(4) { animation-delay: -.6s; } .eqstrip i:nth-child(5) { animation-delay: -.2s; } .eqstrip i:nth-child(7) { animation-delay: -.9s; } .eqstrip i:nth-child(8) { animation-delay: -.5s; } .eqstrip i:nth-child(10) { animation-delay: -.7s; } .eqstrip i:nth-child(11) { animation-delay: -.1s; }
@keyframes eq { 0%, 100% { transform: scaleY(.2); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .stage-note, .vinyl, .eqstrip i { animation: none !important; } .eqstrip i { transform: scaleY(.6); } }
@media print { .stage, .eqstrip { display: none; } }
