:root {
  --navy: #1f3864; --navy-2: #2b4a80; --teal: #0f7b7b; --teal-l: #e3f1f0; --gold: #b7860b; --gold-l: #f8f0dc;
  --red: #a33a3a; --red-l: #f8e6e6; --ink: #1f2933; --grey: #5f6b7a; --line: #d9e0e8; --bg: #f4f6f9; --white: #fff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.5; }
h1, h2, h3 { font-family: Cambria, Georgia, "Times New Roman", serif; color: var(--navy); margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
a { color: var(--teal); }
.hidden { display: none !important; }
.muted { color: var(--grey); }
.small { font-size: .875rem; }
.wrap { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }

/* top bar */
.topbar { background: var(--navy); color: #fff; }
.topbar .inner { max-width: 1200px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar .brand { font-family: Cambria, Georgia, serif; font-weight: 700; font-size: 1.05rem; }
.topbar .brand small { display: block; font-family: "Segoe UI", system-ui, sans-serif; font-weight: 400; font-size: .78rem; color: #b9c7de; }
.topbar .spacer { flex: 1; }
.topbar .who { text-align: right; font-size: .85rem; color: #d6deeb; }
.topbar .who b { color: #fff; display: block; font-size: .95rem; }

/* cards and forms */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.login { max-width: 420px; margin: 8vh auto 0; }
.login .head { text-align: center; margin-bottom: 18px; }
.login .head .seal { width: 56px; height: 56px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; margin: 0 auto 10px; font-family: Cambria, Georgia, serif; font-weight: 700; }
label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #c4ceda; border-radius: 8px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 123, 123, .35); border-color: var(--teal); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 8px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: var(--navy); color: #fff; text-decoration: none; }
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--navy); border-color: #c4ceda; }
.btn.secondary:hover { background: #f1f4f8; }
.btn.teal { background: var(--teal); } .btn.teal:hover { background: #0c6969; }
.btn.danger { background: var(--red); } .btn.small { padding: 6px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.error { background: var(--red-l); color: var(--red); border-radius: 8px; padding: 10px 12px; margin-top: 12px; font-size: .92rem; }
.note { background: var(--teal-l); border-radius: 8px; padding: 10px 12px; font-size: .92rem; }
.warn { background: var(--gold-l); border-radius: 8px; padding: 10px 12px; font-size: .92rem; }

/* badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef2f6; color: var(--grey); }
.badge.open { background: var(--teal-l); color: var(--teal); } .badge.run { background: var(--gold-l); color: var(--gold); }
.badge.done { background: #e7ecf5; color: var(--navy); } .badge.closed { background: #eef0f2; color: #6b7280; } .badge.late { background: var(--red-l); color: var(--red); }

/* quiz list */
.quiz-item { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.quiz-item .meta { font-size: .88rem; color: var(--grey); }
.quiz-item .score { font-family: Cambria, Georgia, serif; font-size: 1.4rem; color: var(--navy); font-weight: 700; }

/* rules */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 16px; margin: 12px 0; }
.kv div:nth-child(odd) { color: var(--grey); }
.rules { padding-left: 1.2em; } .rules li { margin-bottom: 6px; }
.agree { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; margin: 16px 0; }
.agree input { margin-top: 4px; width: 18px; height: 18px; }

/* exam */
.exam-bar { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.exam-bar .inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.exam-bar .title { font-weight: 600; font-size: .95rem; } .exam-bar .title small { display: block; font-weight: 400; color: #b9c7de; font-size: .8rem; }
.timer { margin-left: auto; font-variant-numeric: tabular-nums; font-family: Consolas, "Courier New", monospace; font-size: 1.7rem; font-weight: 700;
  background: rgba(255,255,255,.12); padding: 4px 14px; border-radius: 8px; letter-spacing: 1px; }
.timer.warn { background: #f2c94c; color: #3d2b00; } .timer.danger { background: #e05252; color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .75; } }
.exam { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
.noselect { user-select: none; -webkit-user-select: none; }
.qcard { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.qhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--grey); font-size: .9rem; }
.qtext { font-size: 1.08rem; line-height: 1.6; margin-bottom: 18px; white-space: pre-line; }
.opt { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 10px; border: 1.5px solid #cfd8e3;
  border-radius: 10px; background: #fff; cursor: pointer; font: inherit; color: var(--ink); line-height: 1.45; }
.opt:hover { border-color: var(--teal); background: #f7fbfb; }
.opt .letter { flex: 0 0 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #eef2f6; font-weight: 700; color: var(--grey); }
.opt.sel { border-color: var(--teal); background: var(--teal-l); } .opt.sel .letter { background: var(--teal); color: #fff; }
.qnav { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.flag { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--gold); cursor: pointer; }
.flag input { width: 18px; height: 18px; accent-color: var(--gold); }
.side { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; position: sticky; top: 76px; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 10px 0 14px; }
.grid button { aspect-ratio: 1; border-radius: 8px; border: 1.5px solid #cfd8e3; background: #fff; font-weight: 700; cursor: pointer; font: inherit; color: var(--ink); }
.grid button.ans { background: var(--teal); border-color: var(--teal); color: #fff; }
.grid button.flg { background: var(--gold-l); border-color: var(--gold); color: var(--gold); }
.grid button.ans.flg { background: var(--gold); border-color: var(--gold); color: #fff; }
.grid button.cur { outline: 3px solid var(--navy); outline-offset: 1px; }
.legend { font-size: .8rem; color: var(--grey); display: grid; gap: 4px; margin-bottom: 14px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1.5px solid #cfd8e3; }
.legend .l-ans::before { background: var(--teal); border-color: var(--teal); } .legend .l-flg::before { background: var(--gold-l); border-color: var(--gold); }
.save { font-size: .82rem; color: var(--grey); margin-top: 10px; min-height: 1.2em; } .save.bad { color: var(--red); font-weight: 600; }

/* modal + toast */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; max-width: 480px; width: 100%; padding: 24px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 18px; text-align: center; }
.modal .stats div { background: #f4f6f9; border-radius: 8px; padding: 10px 4px; } .modal .stats b { display: block; font-size: 1.5rem; color: var(--navy); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; top: 80px; transform: translateX(-50%); background: #3d2b00; color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 60;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); font-weight: 600; }

/* finish */
.done-box { text-align: center; padding: 32px 24px; }
.done-box .proof { font-family: Consolas, "Courier New", monospace; font-size: 1.6rem; letter-spacing: 3px; background: #f4f6f9; display: inline-block; padding: 8px 18px; border-radius: 8px; margin: 8px 0 14px; }
.done-box .big { font-family: Cambria, Georgia, serif; font-size: 3rem; color: var(--navy); font-weight: 700; line-height: 1; }

/* review */
.rv .opt { cursor: default; } .rv .opt.correct { border-color: var(--teal); background: var(--teal-l); } .rv .opt.wrong { border-color: var(--red); background: var(--red-l); }
.rv .expl { background: #f7f8fa; border-left: 3px solid var(--gold); padding: 10px 14px; border-radius: 6px; font-size: .95rem; }

/* tables (admin) */
table { width: 100%; border-collapse: collapse; font-size: .9rem; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid #e6ebf1; text-align: left; vertical-align: top; }
th { background: #f1f4f8; color: var(--navy); font-weight: 700; position: sticky; top: 0; }
tr:hover td { background: #fafbfc; }
.tbl-wrap { overflow: auto; max-height: 65vh; border: 1px solid var(--line); border-radius: 8px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: transparent; color: #d6deeb; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px 8px 0 0; }
.tabs button.on { background: var(--bg); color: var(--navy); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; } .row > * { flex: 1 1 160px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-row div { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; } .stat-row b { display: block; font-size: 1.5rem; color: var(--navy); font-family: Cambria, Georgia, serif; }
.token { font-family: Consolas, monospace; font-weight: 700; letter-spacing: 2px; background: #f4f6f9; padding: 2px 8px; border-radius: 6px; }

@media (max-width: 860px) {
  .exam { grid-template-columns: 1fr; }
  .side { position: static; order: 2; }
  .timer { font-size: 1.35rem; }
  .kv { grid-template-columns: 1fr; } .kv div:nth-child(odd) { margin-top: 6px; }
  .exam-bar .title small { display: none; }
}
