* { box-sizing: border-box; }
:root {
  --primary: #2563eb; --primary-d: #1d4ed8; --green: #16a34a; --red: #dc2626; --amber: #d97706;
  --bg: #f1f5f9; --card: #fff; --text: #0f172a; --muted: #64748b; --border: #e2e8f0;
}
body { margin: 0; font-family: "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .6rem; }
.mb0 { margin-bottom: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
.ml-auto { margin-left: auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1.5rem; background: #0f172a; color: #fff; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.15rem; }
.topbar nav a { color: #cbd5e1; margin-left: 1.2rem; }
.topbar nav a:hover { color: #fff; }
.container { max-width: 1150px; margin: 1.5rem auto; padding: 0 1rem; }
.footer { text-align: center; color: var(--muted); padding: 1.5rem; font-size: .85rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1.4rem; margin-bottom: 1.2rem; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row-center { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; }

.input, select, textarea { width: 100%; padding: .6rem .8rem; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 1rem; font-family: inherit; }
.input:focus, select:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.big { font-size: 1.15rem; padding: .8rem 1.2rem; }

.btn { display: inline-block; border: 0; border-radius: 8px; padding: .55rem 1.1rem; font-size: .95rem; cursor: pointer; background: #e2e8f0; color: var(--text); font-family: inherit; }
.btn:hover { filter: brightness(.95); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-light { background: #f1f5f9; border: 1px solid var(--border); }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }
.block { display: block; width: 100%; margin-top: 1rem; }

.alert { padding: .8rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-error { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.student-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; font-weight: 700; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-top: 1.2rem; }
.info-grid div { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: .7rem 1rem; }
.info-grid span { display: block; font-size: .8rem; color: var(--muted); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.mode.practice { border-top: 4px solid var(--green); }
.mode.exam { border-top: 4px solid var(--primary); }
.score-box { font-size: 1.2rem; background: #f8fafc; border-radius: 8px; padding: .6rem 1rem; margin: .6rem 0; }

.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; color: #fff; letter-spacing: .05em; }
.badge-exam { background: var(--primary); }
.badge-practice { background: var(--green); }

/* Exam */
.exam-layout { display: grid; grid-template-columns: 1fr 270px; gap: 1.2rem; align-items: start; }
.exam-title { margin-bottom: 1rem; display: flex; gap: .6rem; align-items: center; }
.sticky { position: sticky; top: 1rem; }
.timer { font-size: 2.4rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
.timer.warn { color: var(--red); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .5; } }
.progress { height: 8px; background: #e2e8f0; border-radius: 99px; margin: .8rem 0 .3rem; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--green); transition: width .3s; }
.q-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; margin-top: 1rem; max-height: 40vh; overflow: auto; }
.q-dot { display: block; text-align: center; padding: .35rem 0; border-radius: 6px; background: #f1f5f9; border: 1px solid var(--border); color: var(--text); font-size: .85rem; }
.q-dot.done { background: var(--primary); color: #fff; border-color: var(--primary); }
.save-status { font-size: .8rem; margin-top: .5rem; min-height: 1.2em; }

.question { scroll-margin-top: 1rem; }
.q-num { font-weight: 700; color: var(--primary); margin-bottom: .3rem; }
.q-text { font-size: 1.08rem; margin-bottom: .8rem; }
.options { display: flex; flex-direction: column; gap: .45rem; }
.option { display: flex; align-items: center; gap: .7rem; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.opt-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
label.option:hover { background: #f8fafc; }
.option input { margin: 0; flex: 0 0 auto; width: 1.15rem; height: 1.15rem; }
.option:has(input:checked) { background: #eff6ff; border-color: var(--primary); }
.opt-label { font-weight: 700; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: #f1f5f9; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.option.correct { background: #f0fdf4; border-color: #86efac; }
.option.correct .opt-label { background: var(--green); color: #fff; }
.option.wrong { background: #fef2f2; border-color: #fca5a5; }
.option.wrong .opt-label { background: var(--red); color: #fff; }
.review.is-correct { border-left: 4px solid var(--green); }
.review.is-wrong { border-left: 4px solid var(--red); }
.tag { font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; margin-left: .4rem; color: #fff; }
.tag.ok { background: var(--green); } .tag.bad { background: var(--red); } .tag.skip { background: var(--amber); }

.big-score { font-size: 4rem; font-weight: 800; line-height: 1.1; margin: .8rem 0; }
.big-score small { font-size: 1.4rem; color: var(--muted); }
.big-score.pass { color: var(--green); } .big-score.fail { color: var(--red); }

/* Tables / admin */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { background: #f8fafc; font-weight: 600; }
.table tr:hover td { background: #fafafa; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem 1rem; border-radius: 8px; background: #e2e8f0; color: var(--text); }
.tabs a.active { background: var(--primary); color: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem 1.5rem; }
.form-grid label { display: block; font-weight: 600; margin-bottom: .3rem; }
.form-grid .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; }
.stat b { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.status { font-size: .8rem; padding: .15rem .5rem; border-radius: 99px; white-space: nowrap; }
.status.none { background: #f1f5f9; color: var(--muted); }
.status.doing { background: #fef3c7; color: #92400e; }
.status.done { background: #dcfce7; color: #166534; }
.inline { display: inline; }
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .input { max-width: 280px; }

@media (max-width: 800px) {
  .modes, .exam-layout { grid-template-columns: 1fr; }
  .exam-side { order: -1; }
  .sticky { position: static; }
}

/* Môn học */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.subject-card { display: block; color: var(--text); transition: transform .1s, box-shadow .1s; border-top: 4px solid var(--primary); }
.subject-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.08); }
.subject-card h3 { margin: .2rem 0 .3rem; }
.subject-code { display: inline-block; font-size: .75rem; font-weight: 700; color: var(--primary); background: #eff6ff; padding: .1rem .5rem; border-radius: 6px; }
.subject-status { margin-top: .8rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.fieldset legend { font-weight: 700; padding: 0 .4rem; }
.subject-bar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.subject-bar select { max-width: 360px; }
.danger-zone { border: 1px solid #fecaca; }
.small { font-size: .85rem; }

[hidden] { display: none !important; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin: 1rem 0; }
.q-dot.current { outline: 2px solid var(--primary); outline-offset: 1px; }
