:root{
  --bg:#f5f7fb; --card:#ffffff; --text:#1f2937; --muted:#6b7280;
  --primary:#4f46e5; --primary-h:#4338ca; --success:#10b981; --danger:#ef4444;
  --border:#e5e7eb; --radius:14px; --shadow:0 10px 30px rgba(15,23,42,.06);
}
*{box-sizing:border-box}
body{margin:0;font-family:'Segoe UI',system-ui,-apple-system,sans-serif;background:var(--bg);color:var(--text);line-height:1.55}
a{color:var(--primary);text-decoration:none}
a:hover{text-decoration:underline}
.center{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:24px}
.container{max-width:1100px;margin:0 auto;padding:24px}
.card{background:var(--card);border-radius:var(--radius);padding:24px;box-shadow:var(--shadow);border:1px solid var(--border)}
.hero{max-width:640px;text-align:center}
.eyebrow{font-size:.75rem;letter-spacing:.16em;color:var(--primary);font-weight:700;margin-bottom:8px}
h1{margin:0 0 8px;font-size:1.7rem}
h2{margin:0 0 12px;font-size:1.3rem}
h3{margin:0 0 10px;font-size:1.1rem}
p{margin:8px 0;color:var(--muted)}
.form{display:flex;flex-direction:column;gap:14px;width:100%;max-width:420px}
.form label{display:flex;flex-direction:column;gap:6px;font-weight:600;font-size:.92rem}
input,textarea,select{width:100%;padding:11px 13px;border:1px solid var(--border);border-radius:10px;font:inherit;background:#fff;transition:.15s}
input:focus,textarea:focus,select:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(79,70,229,.15)}
textarea{resize:vertical;min-height:120px}
.btn{display:inline-block;background:var(--primary);color:#fff;border:0;border-radius:10px;padding:11px 18px;font-weight:600;cursor:pointer;text-align:center;transition:.15s;font-size:.95rem}
.btn:hover{background:var(--primary-h);text-decoration:none}
.btn.secondary{background:#eef2ff;color:var(--primary)}
.btn.secondary:hover{background:#e0e7ff}
.btn.danger{background:var(--danger)}
.btn.danger:hover{background:#dc2626}
.btn.success{background:var(--success)}
.btn.success:hover{background:#059669}
.btn.small{padding:6px 12px;font-size:.85rem}
.btn.tiny{padding:4px 10px;font-size:.8rem}
.actions{display:flex;gap:12px;justify-content:center;margin-top:16px;flex-wrap:wrap}
.alert{background:#fef2f2;color:#b91c1c;border:1px solid #fecaca;padding:10px 14px;border-radius:10px;font-size:.9rem}
.success{background:#ecfdf5;color:#047857;border:1px solid #a7f3d0;padding:10px 14px;border-radius:10px;font-size:.9rem}
.score{font-size:3rem;font-weight:800;color:var(--primary);margin:12px 0}
header.topbar{display:flex;justify-content:space-between;align-items:center;padding:14px 0;margin-bottom:20px;border-bottom:1px solid var(--border);flex-wrap:wrap;gap:12px}
.topbar nav a{margin-left:16px;font-weight:600}
.qrow{margin-bottom:18px}
.option{display:flex;align-items:flex-start;gap:10px;padding:10px 14px;border:1px solid var(--border);border-radius:10px;margin:6px 0;cursor:pointer;transition:.15s;flex-wrap:wrap}
.option:hover{background:#f9fafb}
.option input{width:auto;margin-top:4px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:16px}
.exam-card{display:flex;flex-direction:column;gap:8px}
.exam-card h3{margin:0}
.meta{font-size:.85rem;color:var(--muted)}
table{width:100%;border-collapse:collapse;background:#fff;border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow)}
th,td{padding:12px 14px;text-align:left;border-bottom:1px solid var(--border);font-size:.92rem}
th{background:#f9fafb;font-weight:700}
tr:last-child td{border-bottom:0}
.badge{display:inline-block;padding:2px 8px;border-radius:999px;font-size:.75rem;font-weight:700}
.badge.ok{background:#ecfdf5;color:#047857}
.badge.no{background:#fef2f2;color:#b91c1c}
.timer{position:fixed;top:16px;right:16px;background:#111827;color:#fff;padding:10px 16px;border-radius:999px;font-weight:700;z-index:100}

/* ==== ẢNH hiển thị ==== */
.qimg{
  max-width:100%;
  max-height:420px;
  border-radius:10px;
  border:1px solid var(--border);
  margin:10px 0;
  display:block;
}
.ans-img{
  max-height:140px !important;
  display:inline-block;
  margin:6px 0;
}

/* =================================================== */
/* ============ EDITOR SOẠN ĐỀ (nâng cấp) ============ */
/* =================================================== */
.editor-wrap{
  position:relative;
  border:2px solid var(--border);
  border-radius:12px;
  background:#fff;
  min-height:520px;
  max-height:900px;
  overflow-y:auto;
  padding:24px 26px;
  font-family:'Segoe UI',system-ui,sans-serif;
  font-size:1.05rem;
  line-height:1.75;
  white-space:pre-wrap;
  word-break:break-word;
  transition:.15s;
}
.editor-wrap:focus,
.editor-wrap:focus-within{
  outline:none;
  border-color:var(--primary);
  box-shadow:0 0 0 4px rgba(79,70,229,.15);
}
.editor-wrap.dragover{background:#eef2ff;border-color:var(--primary);border-style:dashed}
.editor-wrap.uploading::after{
  content:'⏳ Đang tải ảnh...';
  position:absolute;top:12px;right:16px;
  background:#4338ca;color:#fff;padding:4px 12px;border-radius:999px;font-size:.8rem;font-weight:600;
  box-shadow:0 4px 12px rgba(67,56,202,.3);
}
.editor-wrap:empty::before{
  content:attr(data-placeholder);
  color:#9ca3af;
  pointer-events:none;
  white-space:pre-wrap;
}

/* Ảnh trong editor: thumbnail nhỏ, hover phóng to */
.editor-img{
  display:inline-block;
  position:relative;
  margin:6px 4px;
  vertical-align:middle;
  max-width:220px;
}
.editor-img img{
  max-width:220px;
  max-height:140px;
  border-radius:8px;
  border:1px solid var(--border);
  display:block;
  cursor:zoom-in;
  transition:transform .2s, box-shadow .2s;
  background:#fafafa;
  object-fit:contain;
}
.editor-img:hover img{
  transform:scale(1.8);
  box-shadow:0 12px 32px rgba(0,0,0,.25);
  z-index:50;
  position:relative;
  cursor:zoom-out;
}
.editor-img .del-img{
  position:absolute;top:-8px;right:-8px;
  width:22px;height:22px;line-height:20px;text-align:center;
  background:var(--danger);color:#fff;border-radius:50%;
  font-size:14px;cursor:pointer;font-weight:700;
  opacity:.85;
  transition:.15s;
  z-index:60;
}
.editor-img .del-img:hover{opacity:1;transform:scale(1.15)}

.editor-hint{
  font-size:.85rem;color:var(--muted);
  margin-top:8px;padding:10px 14px;
  background:#f9fafb;border-left:3px solid var(--primary);
  border-radius:6px;
}
.editor-hint kbd{
  background:#eef2ff;color:#4338ca;
  border:1px solid #c7d2fe;border-radius:4px;
  padding:2px 7px;font-size:.78rem;font-family:inherit;font-weight:600;
}
.help-block{
  background:#f9fafb;
  border:1px dashed var(--border);
  border-radius:10px;
  padding:14px 18px;
  font-size:.87rem;
  color:var(--muted);
  line-height:1.7;
}
.help-block code{
  background:#eef2ff;
  color:#4338ca;
  padding:2px 6px;
  border-radius:4px;
  font-size:.82rem;
}

/* =================================================== */
/* ============ TRANG CHỈNH SỬA CÂU HỎI ============= */
/* =================================================== */
.q-edit{
  background:#fff;
  border:1px solid var(--border);
  border-radius:12px;
  padding:20px;
  margin-bottom:16px;
  box-shadow:0 4px 12px rgba(15,23,42,.04);
}
.q-edit .q-head{
  display:flex;justify-content:space-between;align-items:center;
  margin-bottom:14px;padding-bottom:12px;border-bottom:1px dashed var(--border);
  flex-wrap:wrap;gap:8px;
}
.q-edit .q-num{
  font-weight:800;color:var(--primary);font-size:1.05rem;
}
.q-edit .q-tools{display:flex;gap:8px;flex-wrap:wrap}
.q-edit textarea{
  font-size:.95rem;
  min-height:70px;
}
.q-edit .ans-row{
  display:flex;gap:10px;align-items:flex-start;
  margin:8px 0;padding:10px;
  border:1px solid var(--border);border-radius:10px;
  background:#fafafa;
  transition:.15s;
}
.q-edit .ans-row.is-correct{
  background:#ecfdf5;border-color:#10b981;
}
.q-edit .ans-letter{
  flex:0 0 34px;
  height:34px;line-height:34px;
  background:#eef2ff;color:var(--primary);
  border-radius:50%;text-align:center;font-weight:800;
}
.q-edit .ans-row.is-correct .ans-letter{
  background:#10b981;color:#fff;
}
.q-edit .ans-body{flex:1;min-width:0;display:flex;flex-direction:column;gap:8px}
.q-edit .ans-body input[type=text]{padding:8px 10px;font-size:.92rem}
.q-edit .ans-actions{display:flex;gap:6px;align-items:center}
.q-edit .thumb-inline{
  display:flex;align-items:center;gap:8px;font-size:.82rem;color:var(--muted);
}
.q-edit .thumb-inline img{
  max-height:60px;border-radius:6px;border:1px solid var(--border);
}
.q-edit .thumb-inline .del{
  color:var(--danger);cursor:pointer;font-weight:700;
}
.q-edit .radio-correct{
  display:flex;align-items:center;gap:6px;
  font-size:.82rem;font-weight:600;color:var(--muted);
  cursor:pointer;
}
.q-edit .radio-correct input{width:auto;margin:0}

/* Sticky action bar */
.sticky-actions{
  position:sticky;bottom:0;
  background:rgba(255,255,255,.95);
  backdrop-filter:blur(8px);
  padding:14px 0;
  margin-top:20px;
  border-top:1px solid var(--border);
  display:flex;gap:12px;justify-content:flex-end;
  z-index:40;
}

/* Toast */
.toast{
  position:fixed;bottom:24px;right:24px;
  background:#111827;color:#fff;
  padding:12px 20px;border-radius:10px;
  font-weight:600;font-size:.9rem;
  box-shadow:0 8px 24px rgba(0,0,0,.2);
  opacity:0;transform:translateY(20px);
  transition:.3s;z-index:999;
}
.toast.show{opacity:1;transform:translateY(0)}
.toast.ok{background:#047857}
.toast.err{background:#b91c1c}

/* Editor có nội dung prefill: các dòng đều có line-height rõ */
.editor-wrap > div{
  min-height:1.7em;
}
.editor-wrap > div:empty::after{
  content:'\00a0';
}

.short-answer-block{
  background:#fffbeb;border:1px dashed #fde68a;border-radius:10px;
  padding:12px 16px;margin-top:10px;display:flex;
  gap:8px;flex-wrap:wrap;align-items:center;
}
.short-answer-chip{
  display:inline-block;background:#fff;border:1px solid #fde68a;
  color:#78350f;font-weight:700;font-size:.9rem;
  padding:4px 12px;border-radius:999px;
}

.math-symbols {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  background: #f9fafb;
  border-radius: 10px;
  border: 1px dashed #e5e7eb;
}
.math-symbols button {
  min-width: 38px;
  height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 600;
  transition: .15s;
}
.math-symbols button:hover {
  background: #eef2ff;
  border-color: #4f46e5;
  color: #4f46e5;
  transform: translateY(-1px);
}
.math-symbols button:active {
  transform: scale(0.95);
}
