/* QuizForge shell. Every colour and size below reads from a CSS variable that
   the tenant theme sets at runtime, so reskinning never needs a rebuild. */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --brand: #3d5afe; --brand-ink: #fff; --accent: #00b894;
  --bg: #f6f7fb; --surface: #fff; --ink: #151a2d; --muted: #5d6482; --line: #e3e6f0;
  --good: #12a150; --bad: #e5484d; --warn: #f5a524;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display-font: var(--font);
  --radius: 14px; --scale: 1; --weight: 650;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 12px 32px -12px rgba(16,24,40,.18);
  --pad: 18px;
}

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  font-size: calc(15px * var(--scale)); line-height: 1.55;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
h1, h2, h3, h4 { font-family: var(--display-font); font-weight: var(--weight); margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: calc(1.7rem * var(--scale)); }
h2 { font-size: calc(1.25rem * var(--scale)); }
h3 { font-size: calc(1.05rem * var(--scale)); }
p { margin: 0 0 1em; }
a { color: var(--brand); }
small, .small { font-size: .84em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; }

/* Layout ------------------------------------------------------------------ */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.wrap.narrow { max-width: 720px; }
main { flex: 1; padding: 22px 0 80px; }

.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line); backdrop-filter: saturate(1.4) blur(6px);
}
.topbar .row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.brandmark { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brandmark .chip {
  width: 36px; height: 36px; border-radius: calc(var(--radius) * .7); flex: none;
  background: var(--brand); color: var(--brand-ink); display: grid; place-items: center;
  font-weight: 800; font-family: var(--display-font); letter-spacing: .5px;
}
.brandmark img { width: 36px; height: 36px; object-fit: contain; border-radius: calc(var(--radius) * .7); }
.brandmark b { font-family: var(--display-font); font-weight: var(--weight); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }

nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  padding: 7px 13px; border-radius: 999px; text-decoration: none; color: var(--muted);
  font-weight: 600; white-space: nowrap; font-size: .92em; border: 1px solid transparent;
}
nav.tabs a:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); }
nav.tabs a.on { background: var(--brand); color: var(--brand-ink); }

/* Surfaces ---------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--pad); box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .n { font-size: calc(1.7rem * var(--scale)); font-weight: 800; font-family: var(--display-font); line-height: 1.1; }
.stat .k { color: var(--muted); font-size: .82em; text-transform: uppercase; letter-spacing: .06em; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: .78em; font-weight: 700; background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: color-mix(in srgb, var(--brand) 85%, black);
}
.pill.good { background: color-mix(in srgb, var(--good) 15%, transparent); color: color-mix(in srgb, var(--good) 80%, black); }
.pill.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: color-mix(in srgb, var(--bad) 80%, black); }
.pill.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: color-mix(in srgb, var(--warn) 65%, black); }
.pill.grey { background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--muted); }

/* Controls ---------------------------------------------------------------- */
button, .btn {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: calc(var(--radius) * .75);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 10px 16px; min-height: 44px; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; text-decoration: none; transition: transform .08s ease, filter .15s ease;
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); background: transparent; }
.btn-sm { padding: 6px 11px; min-height: 34px; font-size: .88em; }
.btn-block { width: 100%; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 650; margin-bottom: 5px; font-size: .9em; }
input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px; border-radius: calc(var(--radius) * .7);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); min-height: 44px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
input[type=color] { padding: 4px; height: 44px; }
.hint { color: var(--muted); font-size: .84em; margin-top: 4px; }
.err { color: var(--bad); font-weight: 650; }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; }

/* Tables ------------------------------------------------------------------ */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .94em; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .78em; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 4%, transparent); }
td.wrap-cell { white-space: normal; min-width: 220px; }

/* Module cards ------------------------------------------------------------ */
.modules { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.module {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--pad); display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
  cursor: pointer; text-align: left; align-items: stretch; min-height: 0;
}
.module:hover { border-color: var(--brand); }
.module .icon {
  width: 46px; height: 46px; border-radius: calc(var(--radius) * .8); display: grid; place-items: center;
  background: color-mix(in srgb, var(--brand) 12%, transparent); font-size: 24px;
}
.module h3 { margin: 0; }
.module p { margin: 0; color: var(--muted); font-size: .92em; }
.bar { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--muted) 18%, transparent); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }

/* Quiz -------------------------------------------------------------------- */
.quizhead { position: sticky; top: 56px; z-index: 10; background: var(--bg); padding: 10px 0; }
.passage {
  background: color-mix(in srgb, var(--brand) 6%, transparent); border-left: 4px solid var(--brand);
  padding: 12px 14px; border-radius: calc(var(--radius) * .6); margin-bottom: 14px; font-size: .95em;
}
.prompt { font-size: calc(1.15rem * var(--scale)); font-weight: var(--weight); font-family: var(--display-font); margin-bottom: 14px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 12px; padding: 14px; border: 2px solid var(--line);
  border-radius: calc(var(--radius) * .8); background: var(--surface); cursor: pointer;
  font-weight: 600; text-align: left; min-height: 56px; width: 100%;
}
.option:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.option.picked { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 9%, transparent); }
.option .key {
  flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--muted) 14%, transparent); font-weight: 800; font-size: .85em;
}
.option.picked .key { background: var(--brand); color: var(--brand-ink); }
.option.right { border-color: var(--good); background: color-mix(in srgb, var(--good) 10%, transparent); }
.option.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }

.dots { display: flex; gap: 5px; flex-wrap: wrap; }
.dots i {
  width: 9px; height: 9px; border-radius: 50%; background: color-mix(in srgb, var(--muted) 25%, transparent);
}
.dots i.done { background: var(--accent); }
.dots i.here { background: var(--brand); transform: scale(1.35); }

.result-hero { text-align: center; padding: 26px 18px; }
.score-ring {
  width: 150px; height: 150px; border-radius: 50%; margin: 0 auto 16px; display: grid; place-items: center;
  font-size: 2.4rem; font-weight: 800; font-family: var(--display-font);
}
.review-item { border-bottom: 1px solid var(--line); padding: 14px 0; }
.review-item:last-child { border-bottom: 0; }

/* Certificate ------------------------------------------------------------- */
.cert {
  position: relative; background: #fff; color: #1b1b1b; border-radius: var(--radius);
  padding: 34px 26px; text-align: center; border: 2px solid var(--brand);
  box-shadow: var(--shadow); overflow: hidden;
}
.cert::before {
  content: ''; position: absolute; inset: 10px; border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
  border-radius: calc(var(--radius) * .7); pointer-events: none;
}
.cert .seal {
  width: 74px; height: 74px; border-radius: 50%; margin: 0 auto 14px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 26px;
  font-family: var(--display-font);
}
.cert .eyebrow { letter-spacing: .3em; text-transform: uppercase; font-size: .7rem; color: var(--muted); }
.cert .who { font-family: var(--display-font); font-size: calc(2rem * var(--scale)); margin: 10px 0 4px; font-weight: 800; }
.cert .rule { width: 180px; height: 2px; background: var(--brand); margin: 12px auto; opacity: .5; }
.cert .sig { display: flex; justify-content: space-around; gap: 20px; margin-top: 24px; font-size: .82rem; }
.cert .sig div { border-top: 1px solid #bbb; padding-top: 6px; min-width: 120px; }

/* Designer ---------------------------------------------------------------- */
.qcard { border: 1px solid var(--line); border-radius: calc(var(--radius) * .8); padding: 14px; background: var(--surface); }
.qcard + .qcard { margin-top: 10px; }
.qcard.editing { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.qhead { display: flex; gap: 10px; align-items: flex-start; }
.qhead > div:nth-child(2) b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.qnum {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--brand) 12%, transparent); font-weight: 800; font-size: .8em;
}
.opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.opt-row input[type=text] { flex: 1; }

/* Overlays ---------------------------------------------------------------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(10,12,24,.5); display: grid; place-items: center;
  padding: 16px; z-index: 50; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: var(--radius); padding: 20px; width: min(560px, 100%); box-shadow: var(--shadow); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px; z-index: 90;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; font-weight: 650;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast.bad { background: var(--bad); }
.banner {
  background: color-mix(in srgb, var(--warn) 18%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  padding: 10px 14px; border-radius: calc(var(--radius) * .7); font-size: .9em; margin-bottom: 14px;
}
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.spinner {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--line);
  border-top-color: var(--brand); animation: spin .7s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(.85); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.pop { animation: pop .28s cubic-bezier(.2,1.4,.5,1) both; }

@media print {
  .topbar, nav.tabs, .noprint, button { display: none !important; }
  body { background: #fff; }
  .cert { border-width: 3px; page-break-inside: avoid; }
}

@media (max-width: 640px) {
  :root { --pad: 15px; }
  .wrap { padding: 0 12px; }
  .modules { grid-template-columns: 1fr; }
  main { padding-bottom: 60px; }
}
