:root {
  --brand: #7413dc;
  --brand-dark: #4d0d93;
  --brand-tint: #f1e7fc;
  --ink: #1d1b22;
  --muted: #5d5868;
  --line: #ddd8e5;
  --bg: #faf8fd;
  --card: #ffffff;
  --ok: #1f7a45;
  --warn: #9a5b00;
  --err: #b3261e;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; }
.wrap.wide { max-width: 1000px; }

header.top {
  background: var(--brand);
  color: #fff;
  padding: 14px 16px;
}
header.top .inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
header.top.wide .inner { max-width: 1000px; }
header.top h1 { font-size: 18px; margin: 0; font-weight: 700; }
header.top .sub { font-size: 14px; opacity: .85; }
header.top .spacer { flex: 1; }

.progress { height: 6px; background: rgba(255,255,255,.3); border-radius: 3px; overflow: hidden; margin-top: 10px; max-width: 640px; margin-left: auto; margin-right: auto; }
.progress > div { height: 100%; background: #fff; width: 0; transition: width .25s ease; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-top: 16px; }

.section-label { color: var(--brand-dark); font-weight: 700; font-size: 14px; text-transform: none; margin: 0 0 4px; }
.section-intro { color: var(--muted); font-size: 15px; margin: 0 0 14px; }
.qnum { color: var(--muted); font-size: 14px; font-weight: 600; }
.qtext { font-size: 21px; font-weight: 650; margin: 2px 0 8px; line-height: 1.3; }
.help { color: var(--muted); font-size: 15px; margin: 0 0 14px; }

.options { display: grid; gap: 10px; margin: 0; padding: 0; border: 0; }
.opt {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 12px 16px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font: inherit; color: inherit; text-align: left; cursor: pointer; width: 100%;
}
.opt:hover { border-color: #b9a3d9; }
.opt[aria-pressed="true"], .opt[aria-checked="true"] { border-color: var(--brand); background: var(--brand-tint); }
.opt[disabled] { opacity: .45; cursor: not-allowed; }
.opt .tick {
  flex: 0 0 24px; height: 24px; border: 2px solid #9c92ad; border-radius: 6px;
  display: grid; place-items: center; font-size: 15px; color: #fff;
}
.opt.radio .tick { border-radius: 50%; }
.opt[aria-pressed="true"] .tick, .opt[aria-checked="true"] .tick { background: var(--brand); border-color: var(--brand); }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale .opt { justify-content: center; font-size: 22px; font-weight: 700; padding: 0; min-height: 64px; }
.scale-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-top: 8px; gap: 12px; }
.scale-labels span:last-child { text-align: right; }

textarea, input[type=text], input[type=number], select {
  font: inherit; width: 100%; padding: 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
textarea { min-height: 140px; resize: vertical; }
textarea:focus, input:focus, select:focus, .opt:focus-visible, button:focus-visible { outline: 3px solid #c9a6f5; outline-offset: 2px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.count { color: var(--muted); font-size: 14px; margin-top: 6px; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-size: 26px; font-weight: 700; text-align: center; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: rgba(250,248,253,.97); border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.nav .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.btn {
  font: inherit; font-weight: 700; border-radius: 12px; min-height: 52px; padding: 0 20px; cursor: pointer;
  border: 2px solid var(--brand); background: var(--brand); color: #fff;
}
.btn.secondary { background: #fff; color: var(--brand-dark); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 15px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.nav .btn.next { flex: 1; }

.status { font-size: 13px; color: var(--muted); text-align: center; margin-top: 6px; min-height: 18px; }
.status.err { color: var(--err); }

.note { background: var(--brand-tint); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.note.warn { background: #fff4e0; color: #5c3900; }
.note.err { background: #fde8e7; color: var(--err); }
.center { text-align: center; }
.big-emoji { font-size: 48px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
ul.plain { padding-left: 20px; }

/* Results page */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar label { display: flex; gap: 6px; align-items: center; font-size: 15px; }
.toolbar select, .toolbar input[type=number] { width: auto; padding: 8px 10px; }
.toolbar label { max-width: 100%; min-width: 0; }
.toolbar select { max-width: 100%; min-width: 0; flex: 1 1 auto; text-overflow: ellipsis; }
header.top .btn { white-space: nowrap; }
table.t.fixed { table-layout: fixed; }
table.t.fixed td:nth-child(1) { width: 46%; }
table.t.fixed td:nth-child(2) { width: 34%; }
table.t.fixed td:nth-child(3), table.t.fixed td:nth-child(4) { width: 10%; }
table.t.fixed td { overflow-wrap: anywhere; }
@media (max-width: 560px) {
  table.t.fixed td:nth-child(1) { width: 52%; }
  table.t.fixed td:nth-child(2) { width: 22%; }
  table.t.fixed td:nth-child(3), table.t.fixed td:nth-child(4) { width: 13%; }
  .bar { min-width: 0; }
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 26px; font-weight: 750; }
.stat .k { font-size: 13px; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t th, table.t td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { font-size: 13px; color: var(--muted); font-weight: 600; }
table.t td.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--brand-tint); border-radius: 5px; min-width: 60px; }
.bar > div { height: 100%; background: var(--brand); border-radius: 5px; }
.tablewrap { overflow-x: auto; }
.quotes li { margin-bottom: 8px; }
.qr { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.qr canvas, .qr img { width: 180px; height: 180px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.linkbox { font-family: ui-monospace, monospace; font-size: 14px; word-break: break-all; }
h2 { font-size: 20px; margin: 0 0 10px; }
h3 { font-size: 17px; margin: 18px 0 8px; }
