:root {
  --navy: #0B2E6B;
  --blue: #1E6FD9;
  --sky: #2BB0F0;
  --ink: #14213D;
  --muted: #5B6B8A;
  --line: #D6DEEC;
  --paper: #F6F9FE;
  --card: #FFFFFF;
  --ok: #1B8A5A;
  --warn: #C77700;
  --bad: #C8322B;
  --radius: 10px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 16px; line-height: 1.5; color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .8rem; }
a { color: var(--blue); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.brush { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--navy), var(--blue) 55%, var(--sky)); }

/* --- centered page (login / check / done) --- */
.center { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.panel { width: 100%; max-width: 440px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 32px 32px 28px; }
.panel .logo { width: 170px; display: block; margin: 0 auto 6px; }
.panel .brush { margin: 0 auto 22px; width: 170px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.field input:focus { border-color: var(--blue); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 18px; border-radius: 8px; border: 1px solid transparent; background: var(--blue); color: #fff; font-weight: 600; text-decoration: none; }
.btn:hover { background: var(--navy); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.wide { width: 100%; }
.btn.ghost { background: #fff; color: var(--navy); border-color: var(--line); }
.btn.ghost:hover { background: var(--paper); }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 6px 12px; font-size: .9rem; font-weight: 500; }
.msg { padding: 10px 12px; border-radius: 8px; font-size: .95rem; margin: 10px 0; }
.msg.ok { background: #E6F6EE; color: #0F5F3C; }
.msg.warn { background: #FFF3E0; color: #7A4A00; }
.msg.bad { background: #FDECEB; color: #8A1F1A; }
.msg:empty { display: none; }

.checklist { list-style: none; padding: 0; margin: 0 0 18px; }
.checklist li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.dot { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; background: var(--line); }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

/* --- exam layout --- */
.exam { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar img { height: 34px; }
.topbar .title { font-weight: 600; }
.topbar .who { margin-left: auto; color: var(--muted); font-size: .95rem; }
.topbar .timer { font-variant-numeric: tabular-nums; font-size: 1.35rem; font-weight: 600; padding: 4px 14px; border-radius: 8px; background: var(--paper); color: var(--navy); min-width: 110px; text-align: center; }
.topbar .timer.low { background: #FFF3E0; color: var(--warn); }
.topbar .timer.critical { background: #FDECEB; color: var(--bad); }
.qarea { padding: 28px 32px 120px; max-width: 820px; width: 100%; }
.qmeta { display: flex; gap: 14px; align-items: baseline; color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.qmeta b { color: var(--navy); font-size: 1rem; }
.qtext { font-size: 1.15rem; margin: 0 0 22px; white-space: pre-wrap; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; transition: border-color .12s, background .12s; }
.opt:hover { border-color: var(--sky); }
.opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.opt .key { flex: 0 0 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; font-weight: 600; background: var(--paper); color: var(--navy); }
.opt.on { border-color: var(--blue); background: #EEF4FD; }
.opt.on .key { background: var(--blue); color: #fff; }
.written { width: 100%; min-height: 220px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); resize: vertical; line-height: 1.6; }
.wordcount { text-align: right; color: var(--muted); font-size: .85rem; margin-top: 6px; }
.qnav { display: flex; gap: 10px; margin-top: 26px; align-items: center; }
.qnav .spacer { flex: 1; }
.savestate { font-size: .85rem; color: var(--muted); }

.side { background: #fff; border-left: 1px solid var(--line); padding: 20px; position: sticky; top: 58px; height: calc(100vh - 58px); overflow: auto; }
.cam { width: 100%; aspect-ratio: 4/3; background: #0F1B33; border-radius: var(--radius); overflow: hidden; position: relative; }
.cam video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam .badge { position: absolute; left: 8px; bottom: 8px; font-size: .75rem; color: #fff; background: rgba(0,0,0,.5); padding: 2px 8px; border-radius: 6px; }
.cam .badge.rec::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #FF4D4D; margin-right: 6px; }
.cam .nocam { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: .85rem; text-align: center; padding: 12px; }
.legend { display: flex; gap: 12px; font-size: .8rem; color: var(--muted); margin: 14px 0 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid button { aspect-ratio: 1; border-radius: 6px; border: 1px solid var(--line); background: #fff; font-size: .85rem; color: var(--ink); }
.grid button.done { background: #DDEBFF; border-color: #B7D2FA; color: var(--navy); }
.grid button.mark { background: #FFF1D6; border-color: #F3D28E; }
.grid button.cur { outline: 2px solid var(--blue); outline-offset: 1px; }
.sec-label { font-size: .8rem; color: var(--muted); margin: 14px 0 6px; }
.progress { margin: 14px 0 6px; font-size: .9rem; display: flex; justify-content: space-between; }
.submit-area { margin-top: 18px; }

/* --- overlay / dialog --- */
.overlay { position: fixed; inset: 0; background: rgba(11,46,107,.55); display: grid; place-items: center; padding: 20px; z-index: 50; }
.overlay[hidden] { display: none; }
.dialog { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 520px; }
.dialog .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* --- lobby --- */
.lobby { max-width: 680px; margin: 40px auto; padding: 0 24px; }
.lobby .card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 28px 32px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.facts div { background: var(--paper); border-radius: 8px; padding: 12px; }
.facts b { display: block; font-size: 1.3rem; color: var(--navy); }
.facts span { font-size: .85rem; color: var(--muted); }

@media (max-width: 860px) {
  .exam { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
  .qarea { padding: 20px 18px 60px; }
  .facts { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
