:root {
  --brand: #1e3a8a;
  --brand-dark: #142a63;
  --gold: #f2b705;
  --gold-dark: #c99400;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2333;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --red: #dc2626;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Poppins', -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: 'Poppins', -apple-system, Segoe UI, Roboto, Arial, sans-serif; font-weight: 700; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .container { display: flex; align-items: center; justify-content: space-between; height: 68px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--brand-dark); }
.brand img { height: 40px; width: auto; display: block; }
.brand .brand-txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand .brand-txt small { font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: .02em; }
.nav a { margin-left: 18px; color: var(--muted); font-size: 15px; font-weight: 500; }
.nav a:hover { color: var(--brand); }
.nav .btn { margin-left: 18px; }

.btn { display: inline-block; padding: 10px 20px; border-radius: 8px; background: var(--brand); color: #fff !important; border: none; cursor: pointer; font-size: 15px; font-weight: 600; font-family: inherit; transition: background .15s, transform .15s; }
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: #fff; color: var(--brand) !important; border: 1px solid var(--brand); }
.btn.secondary:hover { background: #eef1fb; }
.btn.danger { background: var(--red); }
.btn.block { display: block; width: 100%; text-align: center; }
.btn.gold { background: var(--gold); color: var(--brand-dark) !important; }
.btn.gold:hover { background: var(--gold-dark); }

.page { padding: 32px 0 60px; }
.flash { max-width: 1100px; margin: 16px auto 0; padding: 12px 16px; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 8px; }

/* ---- Hero ---- */
.hero { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%); color: #fff; padding: 56px 0 48px; position: relative; overflow: hidden; }
.hero::after { content: ''; position: absolute; right: -60px; top: -60px; width: 260px; height: 260px; border-radius: 50%; background: radial-gradient(circle, rgba(242,183,5,.25), transparent 70%); }
.hero .eyebrow { display: inline-block; background: rgba(242,183,5,.18); color: var(--gold); border: 1px solid rgba(242,183,5,.4); padding: 5px 14px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; margin-bottom: 16px; }
.hero h1 { font-size: 36px; margin: 0 0 12px; max-width: 640px; }
.hero p { color: #dbe3ff; font-size: 16px; max-width: 560px; margin: 0 0 22px; }
.hero-badges { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 26px; }
.hero-badges .b { display: flex; align-items: center; gap: 10px; }
.hero-badges .b .n { font-size: 22px; font-weight: 800; color: var(--gold); }
.hero-badges .b .l { font-size: 13px; color: #cfd8f7; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.section-wrap { padding-top: 48px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 22px; margin-top: 24px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 1px 2px rgba(20,42,99,.04); transition: transform .18s, box-shadow .18s; }
.card:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(20,42,99,.12); }
.card .thumb { height: 168px; background: linear-gradient(135deg, var(--brand), var(--brand-dark)); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; font-weight: 700; text-align: center; padding: 10px; position: relative; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .body { padding: 18px; flex: 1; display: flex; flex-direction: column; }
.card h3 { margin: 0 0 6px; font-size: 18px; }
.card p.desc { color: var(--muted); font-size: 14px; margin: 0 0 12px; flex: 1; }
.meta { display: flex; gap: 14px; color: var(--muted); font-size: 13px; margin-bottom: 14px; flex-wrap: wrap; }

.form-card { max-width: 420px; margin: 40px auto; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: 0 1px 2px rgba(20,42,99,.04); }
.form-card h2 { margin-top: 0; }
label { display: block; margin: 14px 0 6px; font-size: 14px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=file], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(30,58,138,.12); }
textarea { resize: vertical; }

.q-timer { position: sticky; top: 68px; z-index: 15; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; margin: 20px 0; display: flex; align-items: center; justify-content: space-between; }
.q-timer .time { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.q-timer.warn { background: var(--red); }

.exam-h1 { font-size: 20px; margin: 0 0 12px; }
.q-timer.compact { margin: 0 0 14px; padding: 8px 16px; }

.exam-layout { display: flex; gap: 20px; align-items: flex-start; }
.exam-main { flex: 1; min-width: 0; scroll-margin-top: 98px; }
.exam-sidebar { width: 270px; flex-shrink: 0; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; position: sticky; top: 80px; max-height: calc(100vh - 98px); overflow-y: auto; }
.qnav-label { font-weight: 700; color: var(--muted); margin-bottom: 12px; background: none; border: none; padding: 0; text-align: left; cursor: default; font-family: inherit; display: block; width: auto; font-size: inherit; }
.qpalette-title { font-weight: 700; margin-bottom: 6px; font-size: 13px; display: flex; align-items: center; justify-content: space-between; }
.exam-nav-btns { display: flex; justify-content: space-between; margin-top: 6px; }

.qpalette-group + .qpalette-group { margin-top: 6px; }
.qpalette-group-title { font-size: 9px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 2px; }
.qpalette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.palbtn { width: 100%; height: 20px; border-radius: 4px; background: #fff; border: 1px solid var(--border); font-size: 9px; line-height: 1; cursor: pointer; font-family: inherit; padding: 0; }
.palbtn:hover { border-color: var(--brand); }
.palbtn.answered { background: #dcfce7; border-color: #86efac; }
.palbtn.current { outline: 2px solid var(--brand); border-color: var(--brand); font-weight: 700; }
.qpalette-legend { display: flex; gap: 12px; margin-top: 8px; font-size: 10px; color: var(--muted); flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }
.dot.answered { background: #86efac; }
.dot.current { background: var(--brand); }

/* ---- Mobile/tablet exam mode: everything on one screen, no scrolling to reach nav or the
   palette. The palette becomes a bottom-sheet drawer opened by a toggle button; Prev/Next/Submit
   are pinned to the bottom of the viewport. Desktop (>800px) keeps the always-visible sidebar. ---- */
.pal-toggle-icon { display: none; }
.pal-close { display: none; }
.pal-backdrop { display: none; }
.nav-submit-mobile { display: none; }

@media (max-width: 800px) {
  .exam-layout { flex-direction: column; }
  .hero h1 { font-size: 28px; }

  .qnav-label.qnav-toggle {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
    background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
    font-weight: 600; font-size: 14px; color: var(--text); cursor: pointer; font-family: inherit; margin-bottom: 12px;
  }
  .pal-toggle-icon { display: inline-block; color: var(--brand); font-weight: 700; font-size: 12px; white-space: nowrap; }

  /* Palette becomes a bottom-sheet drawer, hidden until toggled open */
  .exam-sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: 12%; width: 100%;
    border-radius: 18px 18px 0 0; z-index: 45; max-height: none; overflow-y: auto;
    padding-bottom: 24px;
    transform: translateY(105%); transition: transform .25s ease;
    box-shadow: 0 -10px 30px rgba(15,23,42,.3);
  }
  body.pal-open .exam-sidebar { transform: translateY(0); }
  body.pal-open .pal-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 40; }
  body.pal-open { overflow: hidden; }
  .pal-close { display: inline-block; background: none; border: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 6px; }

  .qpalette { grid-template-columns: repeat(8, 1fr); gap: 4px; }
  .palbtn { height: 34px; font-size: 12px; }

  /* Prev / Next / Submit pinned to the bottom of the screen */
  .exam-main { padding-bottom: 76px; }
  .exam-nav-btns {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 30;
    background: #fff; border-top: 1px solid var(--border); padding: 10px 12px;
    box-shadow: 0 -6px 16px rgba(15,23,42,.08); gap: 8px;
  }
  .exam-nav-btns .btn { flex: 1; padding: 12px 8px; font-size: 14px; text-align: center; }
  .nav-submit-mobile { display: inline-block; background: var(--gold); color: var(--brand-dark) !important; }
}

@media (max-width: 480px) {
  .container { padding: 0 12px; }
  .qpalette { grid-template-columns: repeat(7, 1fr); }
  .exam-h1 { font-size: 17px; }
  .q-timer.compact { flex-wrap: wrap; gap: 4px; }
  .hero { padding: 40px 0 52px; }
  .hero h1 { font-size: 24px; }
  .hero-badges { gap: 18px; }
}

.question { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; scroll-margin-top: 120px; }
.question .qnum { font-weight: 700; color: var(--brand-dark); margin-bottom: 8px; }
.q-stack { display: inline-block; vertical-align: top; font-family: 'Courier New', Consolas, monospace; white-space: pre-line; text-align: right; line-height: 1.35; font-weight: 800; font-size: 17px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; margin-bottom: 6px; border: 1px solid transparent; }
.opt:hover { background: #f9fafb; }
.opt.correct { background: #dcfce7; border-color: #86efac; }
.opt.wrong { background: #fee2e2; border-color: #fca5a5; }
.opt input { width: auto; }

.score-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 28px; text-align: center; margin-bottom: 24px; }
.score-box .big { font-size: 42px; font-weight: 800; color: var(--brand-dark); }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 18px 0 30px; }
.stat-card { flex: 1; min-width: 150px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--brand-dark); }
.stat-card .label { color: var(--muted); font-size: 13px; margin-top: 4px; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.admin-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.admin-table th, table.admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; white-space: nowrap; }
table.admin-table th { background: #f9fafb; }

.tabs { display: flex; gap: 8px; margin: 20px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a { padding: 10px 16px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--brand-dark); border-color: var(--brand); font-weight: 600; }

.errlist { background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 12px 16px; margin: 14px 0; font-size: 13px; color: #991b1b; }
.hint { color: var(--muted); font-size: 13px; }
code.tpl { display: block; background: #111827; color: #d1fae5; padding: 12px 14px; border-radius: 8px; font-size: 13px; white-space: pre; overflow-x: auto; }

/* ---- Footer ---- */
.site-footer { background: var(--brand-dark); color: #cfd8f7; margin-top: 56px; padding: 40px 0 22px; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 36px; justify-content: space-between; }
.site-footer .f-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.site-footer .f-brand img { height: 34px; background: #fff; border-radius: 6px; padding: 3px 6px; }
.site-footer .f-brand span { font-weight: 700; color: #fff; font-size: 16px; }
.site-footer .f-col { min-width: 180px; }
.site-footer .f-col h4 { color: #fff; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 12px; }
.site-footer .f-col p, .site-footer .f-col a { display: block; font-size: 14px; color: #cfd8f7; margin-bottom: 8px; }
.site-footer .f-col a:hover { color: var(--gold); }
.site-footer .f-bottom { border-top: 1px solid rgba(255,255,255,.12); margin-top: 28px; padding-top: 18px; text-align: center; font-size: 13px; color: #9fb0e0; }
.site-footer .f-bottom a { color: var(--gold); }

@media (max-width: 600px) {
  .nav a { margin-left: 10px; font-size: 13px; }
  .form-card { margin: 20px auto; padding: 20px; }
  .stat-card { min-width: 45%; }
  .site-footer { text-align: center; }
  .site-footer .container { justify-content: center; }
}
