/* Bố cục: thanh trên dính + một cột nội dung; khi làm bài tách hai cột — câu hỏi bên trái,
   "phiếu trả lời" tô ô tròn bên phải. Bảng màu lấy từ bàn học: giấy ô li, mực bút bi xanh,
   mực đỏ chấm bài, bút chì tô phiếu, bút dạ quang (dành riêng cho AI). */
:root {
  --paper: #F3F5FA;  --surface: #FFFFFF;  --sunken: #E9EDF5;
  --ink: #16203A;    --ink-2: #4A5672;    --ink-3: #6F7A94;
  --line: #D7DDE9;   --line-2: #BCC5D6;
  --pen: #1F45C4;    --pen-2: #1838A3;    --on-pen: #FFFFFF;  --pen-soft: #E5EBFB;
  --red: #CF2E2A;    --red-soft: #FCE8E6; --on-red: #FFFFFF;
  --ok: #17794B;     --ok-soft: #E1F3E8;  --on-ok: #FFFFFF;
  --hl: #FFE566;     --hl-2: #F5D63C;     --on-hl: #3A2E00;   --hl-soft: #FFF8D2;  --hl-line: #E6CC4A;
  --graphite: #2A3145; --on-graphite: #FFFFFF;
  --grid: rgba(31, 69, 196, .05);
  --scrim: rgba(12, 18, 36, .5);
  --shadow: 0 1px 2px rgba(22, 32, 58, .05), 0 8px 24px rgba(22, 32, 58, .07);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hand: "Mali", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --r: 12px;  --r-sm: 8px;  --top-h: 56px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D1220;  --surface: #171D2C;  --sunken: #212940;
    --ink: #E7EBF5;    --ink-2: #B3BCD0;    --ink-3: #8690A8;
    --line: #2B3349;   --line-2: #414C69;
    --pen: #8FA8FF;    --pen-2: #AEC0FF;    --on-pen: #0B1126;  --pen-soft: #1C2749;
    --red: #FF8078;    --red-soft: #3A1B1E; --on-red: #2A0806;
    --ok: #5AD394;     --ok-soft: #13301F;  --on-ok: #06210F;
    --hl: #EBCB3D;     --hl-2: #F7DC62;     --on-hl: #221A00;   --hl-soft: #2D2811;  --hl-line: #6B5C1A;
    --graphite: #D8DEEC; --on-graphite: #10172A;
    --grid: rgba(143, 168, 255, .045);
    --scrim: rgba(0, 0, 0, .6);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0D1220;  --surface: #171D2C;  --sunken: #212940;
  --ink: #E7EBF5;    --ink-2: #B3BCD0;    --ink-3: #8690A8;
  --line: #2B3349;   --line-2: #414C69;
  --pen: #8FA8FF;    --pen-2: #AEC0FF;    --on-pen: #0B1126;  --pen-soft: #1C2749;
  --red: #FF8078;    --red-soft: #3A1B1E; --on-red: #2A0806;
  --ok: #5AD394;     --ok-soft: #13301F;  --on-ok: #06210F;
  --hl: #EBCB3D;     --hl-2: #F7DC62;     --on-hl: #221A00;   --hl-soft: #2D2811;  --hl-line: #6B5C1A;
  --graphite: #D8DEEC; --on-graphite: #10172A;
  --grid: rgba(143, 168, 255, .045);
  --scrim: rgba(0, 0, 0, .6);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 60; background: var(--surface); }
h1, h2, h3, p, ul, ol, fieldset, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
h1 { font-size: 28px; line-height: 1.2; font-weight: 700; letter-spacing: -.015em; text-wrap: balance; }
h2 { font-size: 17px; line-height: 1.3; font-weight: 600; text-wrap: balance; }
h3 { font-size: 16px; line-height: 1.35; font-weight: 600; }
small { font-size: 12.5px; color: var(--ink-3); font-weight: 400; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--pen); }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.ico { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.wrap { max-width: 1120px; margin-inline: auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.view { padding-block: 26px 130px; display: flex; flex-direction: column; gap: 20px; min-height: 70vh; }
.narrow { width: 100%; max-width: 760px; margin-inline: auto; display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gap { flex: 1 1 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sub { color: var(--ink-2); max-width: 65ch; }
.hint { color: var(--ink-3); font-size: 13px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--pen); }
.t-red { color: var(--red); } .t-ok { color: var(--ok); } .t-hl { background: var(--hl); color: var(--on-hl); padding: 0 6px; border-radius: 4px; }
.hand { font-family: var(--hand); color: var(--red); font-size: 17px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Thanh trên ---- */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50; background: var(--surface); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; gap: 6px 18px; min-height: var(--top-h); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand svg { width: 46px; height: 20px; flex: none; }
.brand .ring { fill: var(--surface); stroke: var(--pen); stroke-width: 1.6; }
.brand .dot { fill: var(--graphite); stroke: var(--graphite); stroke-width: 1.6; }
.nav { display: flex; gap: 2px; }
.nav a { padding: 7px 12px; border-radius: var(--r-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--sunken); color: var(--ink); }
.nav a.on { background: var(--pen-soft); color: var(--pen); }
.save-state { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; }
.save-state.error { color: var(--red); font-weight: 600; }

/* ---- Thành phần chung ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 7px 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; list-style: none; }
.btn::-webkit-details-marker { display: none; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--pen); border-color: var(--pen); color: var(--on-pen); }
.btn.primary:hover { background: var(--pen-2); border-color: var(--pen-2); }
.btn.ai { background: var(--hl); border-color: var(--hl-2); color: var(--on-hl); }
.btn.ai:hover { background: var(--hl-2); }
.btn.lg { min-height: 46px; padding: 10px 22px; font-size: 15.5px; border-radius: 12px; }
.btn.sm { min-height: 32px; padding: 4px 11px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; }
.iconbtn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--ink-3); list-style: none; cursor: pointer; }
.iconbtn::-webkit-details-marker { display: none; }
.iconbtn:hover { background: var(--sunken); color: var(--ink); }
.iconbtn.sm { width: 28px; height: 28px; }
.iconbtn.ai { color: var(--on-hl); background: var(--hl); }
.iconbtn.ai:hover { background: var(--hl-2); color: var(--on-hl); }
.iconbtn:disabled { opacity: .35; }
.link { display: inline-flex; align-items: center; gap: 5px; padding: 0; border: 0; background: none; color: var(--pen); font-weight: 600; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: transparent; }
.link:hover { text-decoration-color: currentColor; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; background: var(--sunken); color: var(--ink-2); font-size: 12.5px; font-weight: 500; line-height: 1.5; max-width: 100%; }
.chip.hl { background: var(--hl); color: var(--on-hl); font-weight: 600; }
.chip.mute { background: transparent; border: 1px solid var(--line-2); color: var(--ink-3); }
.chip.bad { background: var(--red-soft); color: var(--red); font-weight: 600; }
.field { width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface); color: var(--ink); }
.field::placeholder, textarea::placeholder, input::placeholder { color: var(--ink-3); opacity: .85; }
.field:focus-visible { outline: 2px solid var(--pen); outline-offset: 0; border-color: var(--pen); }
textarea.field { resize: vertical; line-height: 1.5; }
.field.mono { font-family: var(--mono); font-size: 13.5px; }
.field.big { min-height: 52px; font-size: 17px; }
.field.good { border-color: var(--ok); background: var(--ok-soft); opacity: 1; }
.field.wrong { border-color: var(--red); background: var(--red-soft); opacity: 1; }
.fld { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fld > span { font-weight: 600; font-size: 13.5px; }
.fld.inline { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
.fld.inline .field { width: 92px; }
.fld.inline > span { font-weight: 500; font-size: 14px; }
.check { display: inline-flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--pen); flex: none; }
.note { padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.note.warn { background: var(--hl-soft); border-color: var(--hl-line); }
.note.err { background: var(--red-soft); border-color: var(--red); color: var(--red); font-weight: 500; }
.note.confirm { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow); }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--pen); animation: spin .8s linear infinite; }
.spinner.sm { width: 15px; height: 15px; border-width: 2px; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px; background: var(--sunken); align-self: flex-start; max-width: 100%; }
.seg button { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.seg.sm button { padding: 4px 11px; font-size: 13px; }

.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.how legend { font-weight: 600; font-size: 13.5px; padding: 0; margin-bottom: 6px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.radio-card input { margin: 4px 0 0; width: 16px; height: 16px; accent-color: var(--pen); flex: none; }
.radio-card span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.radio-card:has(input:checked) { border-color: var(--pen); background: var(--pen-soft); }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.tog { position: relative; cursor: pointer; }
.tog input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tog span { display: inline-block; padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--line-2); font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.tog input:checked + span { border-color: var(--pen); background: var(--pen-soft); color: var(--pen); font-weight: 600; }
.tog input:focus-visible + span { outline: 2px solid var(--pen); outline-offset: 2px; }

.menu { position: relative; }
.menu > summary { cursor: pointer; }
.menu-pop { position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; display: grid; gap: 2px; min-width: 210px; max-width: calc(100vw - 32px); padding: 6px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.menu-pop.right { left: auto; right: 0; }
.menu-pop.wide { min-width: 280px; }
.menu-pop.pad { padding: 14px; gap: 12px; }
.menu-pop > button { display: flex; flex-direction: column; gap: 1px; align-items: flex-start; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; text-align: left; font-size: 14px; font-weight: 500; }
.menu-pop > button:hover { background: var(--sunken); }

/* Ô tròn phiếu trả lời */
.bubble { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex: none; padding: 0; border-radius: 50%; border: 1.6px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: 13px; font-weight: 600; line-height: 1; }
.bubble.on { background: var(--graphite); border-color: var(--graphite); color: var(--on-graphite); }
.bubble.key:hover { border-color: var(--ok); color: var(--ok); }
.bubble.key.on { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }
.bubble.sm { width: 24px; height: 24px; font-size: 11.5px; }
.bubble.xs { width: 22px; height: 22px; font-size: 10.5px; border-width: 1.4px; }
button.bubble.xs:not(:disabled):hover { border-color: var(--graphite); }

.toasts { position: fixed; z-index: 90; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; max-width: min(440px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; background: var(--graphite); color: var(--on-graphite); font-size: 14px; font-weight: 500; box-shadow: var(--shadow); animation: rise .18s ease-out; }
.toast.err { background: var(--red); color: var(--on-red); }
.toast.warn { background: var(--hl); color: var(--on-hl); }
.toast button { flex: none; padding: 3px 10px; border-radius: 6px; border: 1px solid currentColor; background: transparent; color: inherit; font-weight: 600; font-size: 13px; }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }
.ai-bar { position: fixed; z-index: 80; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); padding: 9px 10px 9px 16px; border-radius: 999px; background: var(--hl); color: var(--on-hl); font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.ai-bar .spinner { border-color: rgba(0, 0, 0, .18); border-top-color: var(--on-hl); }
.ai-bar button { flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 12px; border-radius: 999px; border: 1.5px solid var(--on-hl); background: transparent; color: var(--on-hl); font-weight: 600; font-size: 13px; }
body.no-ai .btn.ai, body.no-ai .iconbtn.ai, body.no-ai .ai-link { opacity: .55; }

.dlg { border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 32px)); max-height: min(86vh, 760px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: var(--scrim); }
.dlg-in { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dlg-in header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dlg-in h2 { font-size: 20px; }
.fmt-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; }
.fmt { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); text-align: left; }
.fmt:hover { border-color: var(--pen); background: var(--pen-soft); }
.fmt .ext { flex: none; min-width: 52px; padding: 3px 0; border-radius: 6px; background: var(--sunken); color: var(--ink-2); font-family: var(--mono); font-size: 12px; font-weight: 600; text-align: center; }
.fmt-t { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.exp-msg { min-height: 1.5em; font-size: 14px; color: var(--ink-2); }
.exp-msg.ok { color: var(--ok); font-weight: 600; }
.exp-msg.err { color: var(--red); font-weight: 500; }
#exp-copy { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* ---- Thư viện ---- */
.head { display: flex; flex-wrap: wrap; gap: 14px 24px; align-items: flex-end; justify-content: space-between; }
.head > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 20px; text-align: center; border: 1.5px dashed var(--line-2); border-radius: 16px; background: var(--surface); }
.empty p { max-width: 52ch; color: var(--ink-2); }
.empty-art { display: flex; gap: 8px; margin-bottom: 4px; }
.empty-art .bubble { width: 40px; height: 40px; font-size: 15px; border-color: var(--pen); color: var(--pen); }
.empty-art .bubble.on { color: var(--on-graphite); border-color: var(--graphite); }
.qz-list { display: flex; flex-direction: column; gap: 10px; }
.qz { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.qz:hover { border-color: var(--line-2); }
.qz-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 320px; }
.qz-meta { color: var(--ink-3); font-size: 13.5px; }
.qz-act { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hist { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.tbl th { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td:first-child { min-width: 180px; }
.tbl th.num, .tbl td.num { text-align: right; }

/* ---- Tạo đề ---- */
.drop { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 26px 18px; text-align: center; border: 1.5px dashed var(--line-2); border-radius: 14px; background: var(--paper); cursor: pointer; }
.drop:hover, body.dragging .drop { border-color: var(--pen); background: var(--pen-soft); }
.drop-ico { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; background: var(--pen); color: var(--on-pen); font-size: 19px; }
.fmts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.fmts span { padding: 2px 9px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.fmts span.hl { background: var(--hl); border-color: var(--hl-2); color: var(--on-hl); font-weight: 600; }
.files { display: flex; flex-direction: column; gap: 6px; }
.files li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-radius: 10px; background: var(--sunken); }
.f-name { flex: 1 1 0; min-width: 0; font-weight: 500; }
.f-size { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.gen { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; padding: 14px; border-radius: var(--r); background: var(--hl-soft); border: 1px solid var(--hl-line); }
.gen .wide { grid-column: 1 / -1; }
.steps { display: flex; flex-direction: column; gap: 8px; }
.steps li { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.steps li > .ico, .steps li > .spinner { margin-top: 3px; }
.steps li.ok > .ico { color: var(--ok); }
.steps li.err > .ico { color: var(--red); }
.steps em { font-style: normal; font-weight: 400; color: var(--ink-3); }
.live { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: var(--r); background: var(--hl-soft); border: 1px solid var(--hl-line); font-size: 13.5px; color: var(--ink-2); min-height: 46px; }
.live:empty { display: none; }
body.dragging::after { content: "Thả tệp để tạo đề mới"; position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: var(--scrim); color: #FFFFFF; font-size: 24px; font-weight: 700; pointer-events: none; }

/* ---- Soạn đề ---- */
.back { display: inline-flex; align-items: center; gap: 4px; align-self: flex-start; color: var(--ink-2); font-weight: 500; font-size: 14px; text-decoration: none; }
.back:hover { color: var(--pen); }
.ed-head { display: flex; flex-direction: column; gap: 10px; }
.title-in { width: 100%; padding: 4px 8px; margin-left: -8px; border: 1px solid transparent; border-radius: 10px; background: transparent; font-size: 28px; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; }
.title-in:hover { border-color: var(--line); }
.title-in:focus-visible { outline: 2px solid var(--pen); outline-offset: 0; background: var(--surface); }
.ed-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ed-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); font-size: 14px; font-weight: 500; }
.banner, .review, .more { display: flex; flex-direction: column; gap: 12px; padding: 16px 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 4px; }
.review, .more { background: var(--hl-soft); border-color: var(--hl-line); }
.banner ul { list-style: disc; padding-left: 20px; color: var(--ink-2); margin-top: 4px; }
.banner p { color: var(--ink-2); margin-top: 4px; }
.banner-act { display: flex; flex-wrap: wrap; gap: 8px; }
.review header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.review h2, .more h2, .coach h2 { display: flex; align-items: center; gap: 8px; }
.review ul { display: flex; flex-direction: column; gap: 10px; }
.review li { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); }
.rv-top, .rv-act { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.more-row { display: flex; flex-wrap: wrap; gap: 12px; }
.more-row .grow { flex: 1 1 260px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.empty-cards { padding: 22px; text-align: center; color: var(--ink-3); border: 1.5px dashed var(--line-2); border-radius: 14px; }
.qcard { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.qcard.bad { border-color: color-mix(in srgb, var(--red) 55%, var(--line)); }
.qcard.flash { animation: flash 1.5s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--hl); } 100% { box-shadow: 0 0 0 3px transparent; } }
.qc-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.qno { font-size: 12.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--pen); white-space: nowrap; margin-right: 4px; }
.qno.big { font-size: 15px; }
.qno small { color: var(--ink-3); font-size: inherit; font-weight: 500; }
.mini { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink-2); font-size: 13px; max-width: 100%; }
.mini.topic { width: 150px; }
.mini:hover { border-color: var(--line-2); }
textarea.auto { display: block; width: 100%; min-height: 1.6em; padding: 5px 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; resize: none; overflow: hidden; line-height: 1.5; field-sizing: content; }
textarea.auto:hover { border-color: var(--line); }
textarea.auto:focus-visible { outline: 2px solid var(--pen); outline-offset: 0; background: var(--paper); }
textarea.stem { font-size: 16px; font-weight: 500; margin-left: -8px; width: calc(100% + 8px); }
.opts { display: flex; flex-direction: column; gap: 4px; }
.opt-row { display: flex; gap: 8px; align-items: flex-start; padding: 2px 4px 2px 2px; border-radius: 10px; }
.opt-row.on { background: var(--ok-soft); }
.opt-row .bubble { margin-top: 2px; }
.opt-row textarea { flex: 1 1 0; min-width: 0; }
.opt-fixed { padding: 6px 8px; font-weight: 500; }
.link.add-opt { align-self: flex-start; margin: 4px 0 0 6px; font-size: 13.5px; }
.exp-row { display: flex; gap: 8px; align-items: flex-start; padding-top: 8px; border-top: 1px dashed var(--line); }
.exp-row > span { flex: none; padding-top: 6px; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.exp-row textarea { flex: 1 1 0; min-width: 0; color: var(--ink-2); font-size: 14px; }
.qc-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.qc-foot:empty { display: none; }
.ed-foot { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- Làm bài ---- */
.cover { gap: 14px; padding-top: 12px; }
.cover-opts { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.player { display: flex; flex-direction: column; gap: 16px; }
.p-top { position: sticky; top: calc(env(safe-area-inset-top, 0px) + var(--top-h) + 1px); z-index: 20; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.p-title { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 220px; min-width: 0; }
.p-prog { display: flex; align-items: center; gap: 10px; flex: 1 1 160px; font-variant-numeric: tabular-nums; font-size: 13.5px; color: var(--ink-2); font-weight: 600; }
.bar { flex: 1 1 0; height: 8px; border-radius: 99px; background: var(--sunken); overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--pen); transition: width .25s; }
.bar.low i { background: var(--red); }
.p-timer { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; }
.p-timer.low { color: var(--red); }
.p-body { display: grid; grid-template-columns: minmax(0, 1fr) 264px; gap: 20px; align-items: start; }
.p-q { display: flex; flex-direction: column; gap: 14px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; min-width: 0; }
.p-qhead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.p-stem { font-size: 19px; line-height: 1.5; font-weight: 500; white-space: pre-wrap; max-width: 70ch; }
.p-stem.sm { font-size: 16px; }
.p-opts { display: flex; flex-direction: column; gap: 8px; }
.p-opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); text-align: left; font-size: 16px; }
.p-opt:not(:disabled):hover { border-color: var(--pen); }
.p-opt:disabled { cursor: default; }
.p-opt.on { border-color: var(--graphite); background: var(--sunken); }
.p-opt.key { border-color: var(--ok); background: var(--ok-soft); }
.p-opt.wrong { border-color: var(--red); background: var(--red-soft); }
.p-opt.dim { opacity: .6; }
.p-opt-t { flex: 1 1 0; min-width: 0; padding-top: 3px; white-space: pre-wrap; }
.mark { display: inline-flex; flex: none; font-size: 18px; padding-top: 4px; }
.mark.ok { color: var(--ok); } .mark.bad { color: var(--red); }
.fb { padding: 12px 14px; border-radius: var(--r); }
.fb.ok { background: var(--ok-soft); } .fb.ok strong { color: var(--ok); }
.fb.bad { background: var(--red-soft); } .fb.bad strong { color: var(--red); }
.fb p { margin-top: 6px; white-space: pre-wrap; }
.p-nav { display: flex; justify-content: space-between; gap: 8px; padding-top: 4px; }
.sheet { position: sticky; top: calc(env(safe-area-inset-top, 0px) + var(--top-h) + 84px); display: flex; flex-direction: column; gap: 10px; padding: 14px 12px 12px; border: 1.5px solid var(--pen); border-radius: 14px; background: var(--surface); max-height: calc(100vh - var(--top-h) - 120px); min-width: 0; }
.sheet-head { display: flex; flex-direction: column; gap: 1px; padding: 0 4px 10px; border-bottom: 1.5px solid var(--pen); }
.sheet-head strong { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--pen); }
.sheet-rows { display: flex; flex-direction: column; gap: 1px; overflow-y: auto; min-height: 0; }
.sheet-rows li { display: flex; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 8px; }
.sheet-rows li.cur { background: var(--pen-soft); }
.sheet-no { flex: none; width: 30px; padding: 2px 0; border: 0; border-radius: 6px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; }
.sheet-no:hover { background: var(--sunken); }
.sheet-rows li.good .sheet-no { color: var(--ok); }
.sheet-rows li.wrong .sheet-no { color: var(--red); }
.sheet-b { display: flex; flex-wrap: wrap; gap: 5px; }
.sheet-text { font-size: 12.5px; color: var(--ink-3); }

/* ---- Kết quả ---- */
.res-head { display: flex; flex-wrap: wrap; gap: 20px 28px; align-items: center; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.mark-box { position: relative; width: 132px; height: 132px; flex: none; display: flex; align-items: center; justify-content: center; transform: rotate(-4deg); }
.mark-box svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.mark-box path { fill: none; stroke: var(--red); stroke-width: 3.2; stroke-linecap: round; }
.mark-num { font-family: var(--hand); font-size: 46px; font-weight: 700; color: var(--red); line-height: 1; }
.res-info { display: flex; flex-direction: column; gap: 8px; flex: 1 1 320px; min-width: 0; }
.remark { font-family: var(--hand); font-size: 21px; font-weight: 500; color: var(--red); line-height: 1.3; }
.topics, .coach, .rv-list { display: flex; flex-direction: column; gap: 12px; }
.topics { padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.t-row { display: grid; grid-template-columns: minmax(110px, 240px) minmax(60px, 1fr) 52px; gap: 12px; align-items: center; font-size: 14px; }
.t-name { font-weight: 500; }
.t-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 600; }
.coach { padding: 18px 20px; border-radius: 16px; background: var(--hl-soft); border: 1px solid var(--hl-line); }
.ai-out { white-space: pre-wrap; max-width: 72ch; }
.rv .ai-out { padding: 10px 14px; border-radius: 10px; background: var(--hl-soft); border: 1px solid var(--hl-line); font-size: 14.5px; }
.rv-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; }
.rv { display: flex; flex-direction: column; gap: 10px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.rv header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.verdict { font-weight: 700; font-size: 13.5px; }
.rv-opts { display: flex; flex-direction: column; gap: 4px; }
.rv-opts li { display: flex; gap: 10px; align-items: flex-start; padding: 5px 8px; border-radius: 8px; }
.rv-opts li > span:nth-child(2) { flex: 1 1 0; min-width: 0; padding-top: 1px; white-space: pre-wrap; }
.rv-opts li.key { background: var(--ok-soft); font-weight: 500; }
.rv-opts li.wrong { background: var(--red-soft); }
.rv-opts em { flex: none; font-style: normal; font-size: 12.5px; color: var(--ink-3); padding-top: 3px; }
.rv-opts .mark { font-size: 16px; padding-top: 3px; }
.rv-exp { color: var(--ink-2); font-size: 14.5px; white-space: pre-wrap; padding-top: 8px; border-top: 1px dashed var(--line); }
.link.ai-link { align-self: flex-start; font-size: 13.5px; color: var(--ink); background: var(--hl); padding: 2px 10px; border-radius: 999px; text-decoration: none; }
.link.ai-link:hover { background: var(--hl-2); }

@media (max-width: 860px) {
  h1, .title-in { font-size: 23px; }
  .p-body { grid-template-columns: minmax(0, 1fr); }
  .sheet { position: static; order: -1; max-height: none; padding: 10px; }
  .sheet-head { display: none; }
  .sheet-rows { flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 6px; padding-bottom: 2px; }
  .sheet-rows li { padding: 0; flex: none; }
  .sheet-b { display: none; }
  .sheet-no { width: 34px; height: 34px; border-radius: 50%; border: 1.6px solid var(--line-2); }
  .sheet-rows li.done .sheet-no { background: var(--graphite); border-color: var(--graphite); color: var(--on-graphite); }
  .sheet-rows li.good .sheet-no { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }
  .sheet-rows li.wrong .sheet-no { background: var(--red); border-color: var(--red); color: var(--on-red); }
  .sheet-rows li.cur { background: transparent; }
  .sheet-rows li.cur .sheet-no { outline: 2px solid var(--pen); outline-offset: 1px; }
  .p-q { padding: 16px; }
  .p-stem { font-size: 17.5px; }
  .p-top { top: calc(env(safe-area-inset-top, 0px) + var(--top-h) + 1px); }
}
@media (max-width: 560px) {
  .brand span { display: none; }
  .top-in { gap: 6px 8px; }
  .nav a { padding: 7px 9px; }
  #ai-state span { display: none; }
  .p-title { display: none; }
  .gen { grid-template-columns: minmax(0, 1fr); }
  .panel { padding: 16px; }
  .res-head { justify-content: center; text-align: center; }
  .res-info { align-items: center; }
  .res-info .row { justify-content: center; }
  .t-row { grid-template-columns: minmax(0, 1fr) 70px 44px; }
  .toasts { left: max(16px, env(safe-area-inset-left, 0px)); align-items: stretch; }
  .mini.topic { width: 120px; }
  .qz-act { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---- Bổ sung cho bản máy chủ ---- */
html { color-scheme: light; }
body { margin: 0; }
[hidden] { display: none !important; }
.btn.danger { background: var(--red); border-color: var(--red); color: var(--on-red); }
.chip.ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 12px; }
.actions.end { justify-content: flex-end; }
.center { text-align: center; }
.form-err { color: var(--red); font-weight: 500; }
.mono { font-family: var(--mono); }
.acct-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r-sm); color: var(--ink-2); font-weight: 500; cursor: pointer; list-style: none; max-width: 200px; }
.acct-btn::-webkit-details-marker { display: none; }
.acct-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-btn:hover { background: var(--sunken); color: var(--ink); }
.menu-pop > a { display: block; padding: 8px 10px; border-radius: 7px; color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; }
.menu-pop > a:hover { background: var(--sunken); }
.auth { display: flex; justify-content: center; padding-top: 4vh; }
.auth-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; padding: 26px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.panel-plain { display: flex; flex-direction: column; gap: 12px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.stat-n { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-n.hand { font-family: var(--hand); color: var(--red); }
.stat-l { color: var(--ink-3); font-size: 13px; }
.dist { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 6px; align-items: end; height: 160px; padding-top: 8px; }
.dist-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; min-width: 0; }
.dist-bar { width: 100%; max-width: 40px; min-height: 2px; border-radius: 6px 6px 2px 2px; background: var(--pen); }
.dist-bar.low { background: var(--red); }
.dist-n { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; min-height: 1em; }
.dist-x { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.qstats { display: flex; flex-direction: column; gap: 8px; }
.qstats .t-row { grid-template-columns: minmax(0, 3fr) minmax(60px, 1fr) 52px; }
.switch-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); border: 1.5px solid var(--line); cursor: pointer; }
.switch-row input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--ok); flex: none; }
.switch-row span { display: flex; flex-direction: column; gap: 2px; }
.switch-row:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.share-link { display: flex; gap: 8px; }
.share-link .field { flex: 1 1 0; min-width: 0; }
.share-link.off .field { opacity: .5; }
.share-set { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; border-top: 1px dashed var(--line); }
.row-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
.p-who { color: var(--ink-3); font-size: 13px; }
.coach.sm { padding: 12px 14px; }
.banner.warn { background: var(--hl-soft); border-color: var(--hl-line); }
.save-state.conflict { color: var(--red); font-weight: 600; }
body.student .top .nav, body.student #acct, body.student #ai-state { display: none; }
@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-form { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .row2 { grid-template-columns: minmax(0, 1fr); }
  .acct-btn span { display: none; }
  .dist { gap: 3px; }
}
