:root {
  --brand: #6a3377;
  --brand-dark: #4d2358;
  --brand-tint: #f3ecf5;
  --accent: #006633;
  --accent-tint: #e4f1ea;
  --ink: #241a29;
  --muted: #6d6373;
  --line: #ded4e2;
  --paper: #faf8fb;
  --danger: #b3261e;
}
* { -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body { font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; color: var(--ink); background: var(--paper); }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-brand:disabled { background: var(--brand); border-color: var(--brand); opacity: .45; color: #fff; }
.btn:focus-visible, .opt:focus-visible, .form-control:focus { outline: 3px solid rgba(0,102,51,.45); outline-offset: 2px; box-shadow: none; }
.form-control:focus { border-color: var(--accent); }

/* ---------- login ---------- */
.login-body { background: linear-gradient(160deg, var(--brand) 0%, var(--brand) 42%, var(--paper) 42%); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 430px; background: #fff; border-radius: 14px; padding: 28px 24px; box-shadow: 0 10px 30px rgba(45,20,52,.18); }
.login-logo { height: 46px; margin-bottom: 18px; }
.login-title { font-size: 1.4rem; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: .92rem; margin-bottom: 20px; }
.login-note { text-align: center; color: var(--muted); font-size: .82rem; margin: 18px 0 0; }

/* ---------- app shell ---------- */
.app-bar { background: var(--brand); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); display: flex; align-items: center; justify-content: space-between; }
.app-logo { height: 36px; }
.app-main { max-width: 760px; padding-top: 20px; padding-bottom: 40px; }
.team-card { border: 0; border-left: 6px solid var(--accent); border-radius: 10px; box-shadow: 0 2px 10px rgba(45,20,52,.08); }
.team-name { font-size: 1.35rem; font-weight: 600; margin: 0; }
.team-inst { color: var(--muted); margin: 2px 0 14px; }
.team-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0; }
.team-dl dt { font-size: .78rem; font-weight: 500; color: var(--muted); }
.team-dl dd { margin: 0; font-weight: 500; }
.exam-card { border: 1px solid var(--line); border-radius: 10px; }
.exam-stage { font-size: 1.25rem; font-weight: 600; color: var(--brand); }
.rules { padding-left: 1.1rem; font-size: .93rem; }
.rules li { margin-bottom: 6px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.result-grid div { background: var(--brand-tint); border-radius: 8px; padding: 10px; text-align: center; }
.result-grid span { display: block; font-size: .75rem; color: var(--muted); }
.result-grid strong { font-size: 1.15rem; }

/* ---------- exam ---------- */
.fs-bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; background: var(--accent-tint); color: var(--accent); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: .88rem; }
.exam-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.exam-team { font-size: .85rem; color: var(--muted); }
.exam-count { font-size: 1.15rem; font-weight: 600; color: var(--brand); }
.timer { position: relative; width: 68px; height: 68px; flex: 0 0 auto; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; }
.timer .ring-bg { stroke: var(--line); }
.timer .ring { stroke: var(--accent); stroke-linecap: round; transition: stroke .3s; }
.timer span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.timer.low .ring { stroke: var(--danger); }
.timer.low span { color: var(--danger); }
.q-progress { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 16px; }
.q-progress div { height: 100%; width: 0; background: var(--brand); transition: width .3s; }
.q-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px; margin-bottom: 96px; }
.q-text { font-size: 1.08rem; font-weight: 500; line-height: 1.55; white-space: pre-wrap; margin-bottom: 14px; }
.q-img { display: block; max-width: 100%; max-height: 300px; margin: 0 auto 16px; border-radius: 8px; border: 1px solid var(--line); object-fit: contain; }
.opts { display: grid; gap: 10px; }
.opt { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 12px; font-size: 1rem; color: var(--ink); min-height: 54px; }
.opt-key { flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; background: var(--brand-tint); color: var(--brand); font-weight: 600; display: flex; align-items: center; justify-content: center; }
.opt-text { padding-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
.opt.selected { border-color: var(--accent); background: var(--accent-tint); }
.opt.selected .opt-key { background: var(--accent); color: #fff; }
.opt:disabled { opacity: .7; }
.exam-actions { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; padding: 12px 16px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 1px solid var(--line); z-index: 20; }
.exam-actions .btn { flex: 1 1 0; padding: 12px; font-weight: 500; }
.exam-actions .btn-outline-secondary.armed { background: var(--danger); border-color: var(--danger); color: #fff; }
.no-select { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ---------- overlay & toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(36,26,41,.88); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.overlay-card { background: #fff; border-radius: 12px; padding: 24px; max-width: 380px; text-align: center; }
.toast-box { position: fixed; left: 12px; right: 12px; top: 12px; z-index: 60; pointer-events: none; }
.toast-box .alert { pointer-events: auto; margin-bottom: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.15); }

@media (min-width: 768px) {
  .q-card { padding: 26px 28px; margin-bottom: 100px; }
  .exam-actions { padding-left: calc(50% - 360px); padding-right: calc(50% - 360px); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- admin ---------- */
.admin-nav { background: var(--brand); }
.admin-nav .nav-link { color: #f0e6f3; padding: .6rem .8rem; }
.admin-nav .nav-link:hover, .admin-nav .nav-link.active { color: #fff; background: rgba(255,255,255,.14); border-radius: 6px; }
.admin-nav .navbar-brand { color: #fff; font-weight: 600; }
.admin-wrap { padding-top: 22px; padding-bottom: 50px; }
.stat-card { border: 0; border-top: 4px solid var(--accent); border-radius: 8px; box-shadow: 0 1px 8px rgba(45,20,52,.08); }
.stat-card .num { font-size: 1.8rem; font-weight: 600; color: var(--brand); line-height: 1.1; }
.table thead th { background: var(--brand-tint); color: var(--brand-dark); font-weight: 600; white-space: nowrap; }
.thumb { height: 38px; width: 38px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.board-item { display: flex; align-items: center; gap: 16px; background: #fff; border: 1px solid var(--line); border-left: 6px solid var(--accent); border-radius: 10px; padding: 14px 18px; margin-bottom: 10px; }
.board-rank { font-size: 1.6rem; font-weight: 600; color: var(--brand); width: 56px; text-align: center; }
.board-team { font-size: 1.15rem; font-weight: 600; }
.board-score { margin-left: auto; text-align: right; font-weight: 600; color: var(--accent); }
@media print { .admin-nav, .no-print { display: none !important; } }
