/* Quiz Platform — design system v2 (24 Nov 2026)
   Mobile-first. Pentastic identity: red → indigo gradient, light surfaces, rounded cards.
   Brand colours are overridden per client by js/branding.js (--red, --purple, --blue,
   --gradient, --gradient-btn), so components use only these tokens. */

:root {
  --red: #e53935;
  --purple: #5c6bc0;
  --blue: #3f51b5;
  --gradient: linear-gradient(135deg, #e53935 0%, #5c6bc0 50%, #3f51b5 100%);
  --gradient-btn: linear-gradient(90deg, #e53935 0%, #5c6bc0 100%);

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --text: #1f2430;
  --text-2: #5b6272;
  --text-3: #8a90a0;
  --border: #e3e6ef;
  --focus: 0 0 0 3px rgba(92, 107, 192, 0.25);

  --ok: #2e7d32;   --ok-bg: #e8f5e9;
  --warn: #b45309; --warn-bg: #fff4e5;
  --bad: #c62828;  --bad-bg: #fdecec;
  --info: #1565c0; --info-bg: #e8f1fd;

  --r-sm: 8px; --r: 12px; --r-lg: 18px;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-2: 0 8px 24px rgba(16, 24, 40, 0.10);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.55; color: var(--text); background: var(--bg); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .75em; }
a { color: var(--blue); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.muted { color: var(--text-2); } .small { font-size: .875rem; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px;
  border: 1px solid transparent; border-radius: var(--r-sm); font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer;
  text-decoration: none; transition: transform .08s ease, box-shadow .15s ease, background .15s ease; background: var(--surface); color: var(--text); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--gradient-btn); color: #fff; box-shadow: 0 4px 14px rgba(92, 107, 192, .25); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 18px rgba(92, 107, 192, .35); }
.btn-secondary { border-color: var(--border); background: var(--surface); }
.btn-secondary:hover:not(:disabled) { border-color: var(--purple); color: var(--purple); }
.btn-success { background: var(--ok); color: #fff; }
.btn-danger { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { color: var(--purple); background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .85rem; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; }

/* ── Forms ── */
.field { display: block; margin-bottom: 14px; }
.field > span, .field > label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.input, .field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font: inherit; color: var(--text); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--purple); box-shadow: var(--focus); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--purple); flex: none; }
.hint { font-size: .85rem; color: var(--text-2); }

/* ── Messages ── */
.msg { border-radius: var(--r-sm); padding: 10px 14px; font-size: .92rem; margin: 10px 0; }
.msg:empty { display: none; }
.msg-error, .error:not(:empty) { background: var(--bad-bg); color: var(--bad); }
.msg-ok, .success:not(:empty) { background: var(--ok-bg); color: var(--ok); }
.msg-warn { background: var(--warn-bg); color: var(--warn); }
.msg-info { background: var(--info-bg); color: var(--info); }
.error:not(:empty), .success:not(:empty) { border-radius: var(--r-sm); padding: 10px 14px; margin: 10px 0; font-size: .92rem; }

/* ── Cards, badges ── */
.card { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-1); padding: 20px; }
.card-lg { padding: 28px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--ok-bg); color: var(--ok); }
.badge-yellow { background: var(--warn-bg); color: var(--warn); }
.badge-red { background: var(--bad-bg); color: var(--bad); }
.badge-grey { background: #eef0f4; color: #5b6272; }
.badge-blue { background: var(--info-bg); color: var(--info); }

/* ── Top bar (language switch etc.) ── */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.lang-toggle-btn { min-height: 36px; padding: 6px 14px; border-radius: 999px; font-size: .85rem; }
.lang-float { position: fixed; top: 12px; right: 12px; z-index: 20; }

/* ── Login (split screen; stacked on phones) ── */
.screen { display: none; } .screen.active { display: block; }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr; grid-template-areas: 'brand' 'main' 'credit'; }
.auth-brand { grid-area: brand; } .auth-main { grid-area: main; } .auth-credit { grid-area: credit; text-align: center; padding: 8px 24px 32px; }
.auth-brand { background: linear-gradient(160deg, #f6f7fb 0%, #e8eaf6 100%); padding: 56px 24px 20px; text-align: center; }
.auth-brand .logo { max-height: 64px; margin: 0 auto 12px; display: block; }
.brand-title { font-size: 1.5rem; font-weight: 700; background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; margin: 0 0 4px; }
.brand-subtitle { color: var(--text-2); margin: 0; }
.pentastic-credit { margin-top: 20px; }
.pentastic-credit .pentastic-logo { max-width: 150px; margin: 0 auto 8px; display: block; border-radius: 6px; }
.pentastic-tagline { font-size: .82rem; color: var(--text-2); margin: 0 0 6px; }
.pentastic-lines { font-size: .78rem; color: var(--text-3); margin: 0 0 6px; }
.pentastic-link { font-size: .8rem; text-decoration: none; }
.brand-divider { display: none; }
/* provider credit switched off in Branding → no empty block (cross-check L9) */
.auth-credit:has(> .pentastic-credit[style*="none"]) { display: none; }
.auth-main { display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px 48px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h2 { font-size: 1.45rem; margin-bottom: 4px; }
.auth-sub { color: var(--text-2); margin-bottom: 20px; }
.sso-divider { display: flex; align-items: center; gap: 10px; color: var(--text-3); font-size: .85rem; margin: 18px 0; }
.sso-divider::before, .sso-divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.turnstile-container { margin: 6px 0 12px; min-height: 0; }
.forgot-row { text-align: right; margin-top: 10px; font-size: .9rem; }
.forgot-box { margin-top: 14px; padding: 16px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2); }

@media (min-width: 900px) {
  .auth-shell { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; grid-template-areas: 'brand main' 'credit main';
    background: linear-gradient(90deg, #eceef8 0 50%, var(--surface) 50% 100%); }
  .auth-brand { background: none; display: flex; flex-direction: column; justify-content: flex-end; padding: 48px 48px 0; }
  .auth-credit { padding: 0 48px 48px; }
  .auth-brand .logo { max-height: 96px; }
  .brand-title { font-size: 2.1rem; }
  .brand-divider { display: block; border: 0; border-top: 1px solid rgba(0,0,0,.08); width: 70%; margin: 28px auto; }
  .pentastic-credit .pentastic-logo { max-width: 190px; }
  .auth-main { align-items: center; padding: 48px; background: var(--surface); }
}

/* ── Learner home ── */
.app-header { background: var(--surface); box-shadow: var(--shadow-1); position: sticky; top: 0; z-index: 10; }
.app-header-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.app-header .logo-sm { max-height: 32px; }
.app-header .product { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header-inner { padding-right: 84px; }   /* the floating language button sits at the right */
.app-header .btn { white-space: nowrap; }
.welcome-row { justify-content: space-between; color: var(--text-2); }
.app-header .user { color: var(--text-2); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }
.page-title { margin: 6px 0 16px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 20px; }
.stat { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow-1); padding: 14px 10px; text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--purple); }
.stat-label { font-size: .8rem; color: var(--text-2); }
.quiz-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .quiz-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .quiz-grid { grid-template-columns: repeat(3, 1fr); } }
.quiz-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  padding: 18px; color: inherit; text-decoration: none; border: 1px solid transparent; transition: box-shadow .15s, transform .15s, border-color .15s; }
.quiz-card.active:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); border-color: rgba(92,107,192,.35); }
.quiz-card.locked { opacity: .6; pointer-events: none; }
.quiz-card h3 { color: var(--purple); margin: 0; }
.quiz-card p { color: var(--text-2); font-size: .9rem; margin: 0; }
/* 27 Nov: card + certificate button. The button is drawn inside the card's bottom area but is
   not inside the card link (a button inside a link is invalid and would open the quiz). */
.quiz-item { position: relative; display: flex; flex-direction: column; }
.quiz-item > .quiz-card { flex: 1; }
.quiz-item > .quiz-card.has-cert { padding-bottom: 66px; }
.quiz-item > .quiz-card.has-cert.active:hover { transform: none; }
.quiz-item:hover > .quiz-card.has-cert.active { box-shadow: var(--shadow-2); border-color: rgba(92,107,192,.35); }   /* keep the hover look on the button */
.quiz-item > .cert-dl { position: absolute; left: 18px; bottom: 18px; min-height: 36px; }
.badge-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.empty { text-align: center; padding: 40px 16px; color: var(--text-2); }

/* ── Dialogs (native <dialog>) ── */
dialog.dlg { border: 0; border-radius: var(--r-lg); padding: 0; width: min(440px, calc(100vw - 24px)); box-shadow: var(--shadow-2); color: var(--text); }
dialog.dlg::backdrop { background: rgba(20, 24, 36, .45); }
.dlg-body { padding: 22px 22px 8px; }
.dlg-body h2 { font-size: 1.2rem; }
.dlg-content, .dlg-body p { white-space: pre-line; }   /* messages with line breaks */
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 22px 20px; flex-wrap: wrap; }

/* ── Toasts ── */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1000; width: min(460px, calc(100vw - 24px)); }
.toast { background: #1f2430; color: #fff; border-radius: var(--r); padding: 12px 16px; box-shadow: var(--shadow-2); font-size: .92rem; animation: toast-in .18s ease-out; }
body[data-page=quiz] .toasts { bottom: 92px; }   /* above the quiz action bar */
.toast-ok { background: #1e6b33; } .toast-error { background: #a32020; } .toast-warn { background: #8a4b07; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Quiz ── */
.quiz-layout { min-height: 100vh; display: grid; grid-template-columns: 1fr; align-content: start; }
.quiz-layout > * { min-width: 0; }   /* lets the question strip scroll instead of widening the page */
.quiz-side { background: var(--surface); box-shadow: var(--shadow-1); padding: 12px 16px; position: sticky; top: 0; z-index: 5; }
.quiz-side .logo-sm { max-height: 28px; display: none; }
.quiz-title { font-size: 1rem; margin: 0 0 6px; color: var(--text); padding-right: 76px; }   /* room for the language button on phones */
.quiz-head { display: flex; align-items: flex-start; gap: 8px; padding-right: 76px; }   /* 27 Nov: title + Exit; room for the language button on phones */
.quiz-head .quiz-title { flex: 1; min-width: 0; padding-right: 0; }
.quiz-exit { flex: none; min-height: 36px; padding: 4px 12px; margin-top: -6px; border: 1px solid var(--border); }
.progress { height: 6px; background: #e8eaf3; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--gradient-btn); transition: width .25s ease; }
.progress-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; color: var(--text-2); margin-top: 6px; }
.timer-warn { color: var(--bad); font-weight: 700; }
.qnav { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.qnav::-webkit-scrollbar { display: none; }
.qnav-item { flex: none; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.qnav-item.done { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.qnav-item.current { background: var(--purple); color: #fff; border-color: transparent; }
.qnav-item:disabled { cursor: default; opacity: .7; }
.quiz-main { padding: 20px 16px 120px; max-width: 820px; width: 100%; margin: 0 auto; }
.question-count { font-size: .85rem; font-weight: 600; color: var(--purple); text-transform: uppercase; letter-spacing: .03em; }
.question-text { font-size: 1.2rem; margin: 8px 0 18px; }
.options { display: grid; gap: 10px; }
.option-btn { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; min-height: 56px; padding: 12px 14px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--r); font: inherit; color: var(--text); cursor: pointer; transition: border-color .12s, background .12s; }
.option-btn:hover { border-color: rgba(92,107,192,.5); }
.option-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.option-btn.selected { border-color: var(--purple); background: #eef0fb; }
.option-circle { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .9rem;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.option-btn.selected .option-circle { background: var(--purple); color: #fff; border-color: transparent; }
.quiz-actions { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); box-shadow: 0 -4px 16px rgba(16,24,40,.08);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 10px; justify-content: flex-end; z-index: 6; }
.quiz-actions .btn { flex: 1; }
.quiz-warning { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 30; width: min(520px, calc(100vw - 24px)); }
@media (min-width: 900px) {
  .quiz-layout { grid-template-columns: 280px 1fr; }
  .quiz-side { position: sticky; top: 0; height: 100vh; padding: 24px 20px; box-shadow: 1px 0 0 var(--border); display: flex; flex-direction: column; overflow-y: auto; }   /* long quizzes: the question list scrolls (cross-check M3) */
  .quiz-side .logo-sm { display: block; margin-bottom: 12px; }
  .quiz-title { font-size: 1.15rem; padding-right: 0; }
  .quiz-head { padding-right: 0; }
  .quiz-actions .btn { max-width: 320px; }
  .qnav { flex-wrap: wrap; overflow: visible; padding-top: 18px; }
  .quiz-main { padding: 48px 40px 140px; }
  .question-text { font-size: 1.45rem; }
  .quiz-actions { left: 280px; justify-content: center; }
}

/* ── Results ── */
.result-card { max-width: 640px; margin: 24px auto; }
.score-ring { width: 140px; height: 140px; border-radius: 50%; margin: 6px auto 14px; display: grid; place-items: center;
  font-size: 2.2rem; font-weight: 800; background: conic-gradient(var(--ring-color) calc(var(--score) * 1%), #edf0f6 0); position: relative; }
.score-ring::before { content: ''; position: absolute; inset: 12px; background: var(--surface); border-radius: 50%; }
.score-ring span { position: relative; }
.score-ring.pass { --ring-color: var(--ok); } .score-ring.fail { --ring-color: var(--bad); }
.result-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0; }
.fact { background: var(--surface-2); border-radius: var(--r); padding: 10px 12px; }
.fact b { display: block; font-size: 1.05rem; }
.fact small { color: var(--text-2); }
.review-list { display: grid; gap: 10px; margin-top: 12px; }
.review-item { border-left: 4px solid var(--border); background: var(--surface-2); border-radius: var(--r-sm); padding: 12px 14px; }
.review-item.review-correct { border-left-color: var(--ok); }
.review-item.review-wrong { border-left-color: var(--bad); }
.review-item p { margin: 0 0 4px; }

/* ── Simple centred page (set-password, notices) ── */
.center-page { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 64px 16px 32px; }
.center-card { width: 100%; max-width: 460px; }
.center-card .brand-head { text-align: center; margin-bottom: 18px; }
.center-card .brand-head .logo { max-height: 56px; display: block; margin: 0 auto 6px; }
.rules { list-style: none; padding: 0; margin: 0 0 14px; font-size: .9rem; display: grid; gap: 2px; }
.rules li { color: var(--text-2); } .rules li.ok { color: var(--ok); }
@media (min-width: 640px) { .center-page { align-items: center; } }

@media print { .quiz-actions, .topbar, .lang-float { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
