/* ==========================================================================
   Quiz page styles. Builds on the tokens and components in app.css.
   ========================================================================== */

.quiz-page { min-height: 100vh; }
.no-js .quiz-loading { display: none; }

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-text); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; color: var(--accent-text); }

.quiz:focus { outline: none; }

/* --- Loading ------------------------------------------------------------- */
.quiz-loading {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 80px 0; color: var(--text-2);
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: aiq-spin .8s linear infinite;
}
.spinner--btn { width: 18px; height: 18px; border-color: color-mix(in srgb, currentColor 35%, transparent); border-top-color: currentColor; }
@keyframes aiq-spin { to { transform: rotate(360deg); } }

/* --- Shared bits --------------------------------------------------------- */
.eyebrow {
  margin: 0 0 10px; font-size: .8125rem; font-weight: 650; letter-spacing: .04em;
  text-transform: uppercase; color: var(--accent);
}
.lead { font-size: 1.0625rem; color: var(--text-2); max-width: 60ch; }
.btn__arrow { transition: transform .2s var(--ease); }
.btn:hover .btn__arrow { transform: translateX(3px); }
.btn[aria-disabled="true"]:hover { background: var(--accent); }
.btn--ghost[aria-disabled="true"]:hover { background: transparent; }
.btn[aria-disabled="true"]:hover .btn__arrow { transform: none; }
.btn[aria-disabled="true"]:active { transform: none; }
/* Headings receive focus programmatically on each screen change (for screen readers); no ring needed. */
[data-autofocus]:focus, [data-autofocus]:focus-visible { outline: none; }

/* --- Screen transitions -------------------------------------------------- */
@keyframes aiq-in-fwd   { from { opacity: 0; transform: translateX(28px); }  to { opacity: 1; transform: none; } }
@keyframes aiq-in-back  { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
@keyframes aiq-out-fwd  { to { opacity: 0; transform: translateX(-20px); } }
@keyframes aiq-out-back { to { opacity: 0; transform: translateX(20px); } }
.screen--in-fwd   { animation: aiq-in-fwd .32s var(--ease) both; }
.screen--in-back  { animation: aiq-in-back .32s var(--ease) both; }
.screen--out-fwd  { animation: aiq-out-fwd .16s ease-in both; }
.screen--out-back { animation: aiq-out-back .16s ease-in both; }

/* --- Intro --------------------------------------------------------------- */
.intro { padding-top: clamp(8px, 4vw, 32px); }
.intro__card h1 { margin-bottom: 14px; }
.cat-dots {
  list-style: none; margin: 4px 0 24px; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.cat-dots li {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: .875rem; font-weight: 600; color: var(--text);
}
.cat-dots li::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--cat);
}

.anon {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 18px 20px; margin: 0 0 28px;
  border-radius: var(--radius); background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.anon__icon {
  flex: none; width: 34px; height: 34px; border-radius: 10px; margin-top: 2px;
  background: var(--surface); position: relative; box-shadow: var(--shadow-sm);
}
/* A small padlock drawn with CSS */
.anon__icon::before {
  content: ""; position: absolute; left: 11px; top: 7px; width: 12px; height: 10px;
  border: 2.5px solid var(--accent); border-bottom: 0; border-radius: 7px 7px 0 0;
}
.anon__icon::after {
  content: ""; position: absolute; left: 9px; top: 15px; width: 16px; height: 12px;
  border-radius: 3px; background: var(--accent);
}
.anon__title { font-size: 1rem; margin: 4px 0 8px; }
.anon__list { margin: 0; padding-left: 18px; color: var(--text); font-size: .9375rem; }
.anon__list li + li { margin-top: 4px; }

.intro__actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.intro__resume-note { flex-basis: 100%; margin: 4px 0 0; }
.intro__last { margin: 20px 0 0; }

/* --- Progress bar -------------------------------------------------------- */
.progress {
  position: sticky; top: 0; z-index: 20;
  margin: 0 -20px 20px; padding: 10px 0 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.progress__row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin-bottom: 8px; font-size: .875rem; color: var(--text-2);
}
.progress__section { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress__section strong { color: var(--text); font-weight: 650; }
.progress__pct { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.progress__track { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress__fill {
  height: 100%; border-radius: inherit; background: var(--accent);
  transition: width .5s var(--ease);
}

/* --- Question card ------------------------------------------------------- */
.q-head { margin-bottom: 24px; }
.section-intro {
  margin: 0 0 18px; padding: 0 0 16px; border-bottom: 1px dashed var(--border-strong);
}
.section-intro__text { margin: 0; color: var(--text-2); }
.q-prompt { font-size: clamp(1.35rem, 3.4vw, 1.75rem); font-weight: 700; margin: 0 0 8px; }
.q-optional {
  display: inline-block; vertical-align: middle; margin-left: 10px;
  padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.q-server-error { margin-top: 14px; }
.q-help { margin: 0; color: var(--text-2); font-size: .9375rem; }

/* --- Nav ----------------------------------------------------------------- */
.q-nav {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  margin-top: 20px;
}
.q-nav__right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.btn--next { min-width: 132px; }
.q-reason {
  margin: 0; min-height: 1.4em; max-width: 34ch; text-align: right;
  font-size: .875rem; color: var(--text-2);
}
.q-reason--error { color: var(--danger); font-weight: 600; }
.q-reason.is-nudged { color: var(--warn); font-weight: 600; animation: aiq-nudge .4s var(--ease); }
@keyframes aiq-nudge {
  20% { transform: translateX(-5px); } 40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(2px); }
}
@media (min-width: 560px) {
  .q-nav__right { flex-direction: row; align-items: center; gap: 0; }
  .q-reason:not(:empty) { margin-right: 16px; }
}

/* --- Option cards -------------------------------------------------------- */
.opts { display: grid; gap: 10px; }
.opts--grid { grid-template-columns: 1fr; }
@media (min-width: 640px) { .opts--grid { grid-template-columns: 1fr 1fr; } }

.opt {
  position: relative; display: flex; align-items: center; gap: 14px;
  min-height: 56px; padding: 14px 16px;
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius);
  cursor: pointer; user-select: none;
  transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.opt:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.opt:active { transform: scale(.995); }
.opt__label { flex: 1; font-weight: 500; line-height: 1.35; }
.opt__mark {
  flex: none; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 7px;
  border: 1.5px solid var(--border-strong); background: var(--surface);
  color: var(--accent-text);
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.opts--stack .opt__mark, [role="radiogroup"] .opt__mark { border-radius: 50%; }
.opt__mark svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; transform: scale(.6); transition: opacity .15s, transform .2s var(--ease); }

.opt.is-selected {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.opt.is-selected .opt__mark { background: var(--accent); border-color: var(--accent); }
.opt.is-selected .opt__mark svg { opacity: 1; transform: none; }
.opt:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Pick: numbered order badges */
.opt__order { font-size: .8125rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1; }
.opt--pick .opt__mark { border-radius: 50%; width: 28px; height: 28px; }
.opt.is-capped { color: var(--text-2); background: var(--surface-2); border-style: dashed; }
.opt.is-capped:hover { border-color: var(--border-strong); box-shadow: none; }

.opts-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: -8px 0 14px; min-height: 1.5em; }
.opts-count {
  margin: 0; font-size: .875rem; font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.opts-count.is-active { color: var(--accent); }
.opts-count.is-done { color: var(--good); }
.opts-limit { margin: 0; font-size: .875rem; color: var(--warn); font-weight: 600; }

.opt-group + .opt-group { margin-top: 22px; }
.opt-group__title {
  font-size: .8125rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-2); margin: 0 0 10px;
}

/* --- Allocation ---------------------------------------------------------- */
.alloc { display: grid; gap: 14px; }
.alloc__row {
  padding: 14px 16px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, background .15s;
}
.alloc__row:not(.is-zero) { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.alloc__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.alloc__label { font-weight: 600; line-height: 1.35; }
.alloc__out { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); min-width: 3.5ch; text-align: right; }
.alloc__row.is-zero .alloc__out { color: var(--text-3); }
.alloc__controls { display: flex; align-items: center; gap: 14px; }
.alloc__numwrap { position: relative; flex: none; }
.alloc__num {
  width: 78px; min-height: 40px; padding: 6px 26px 6px 10px; text-align: right;
  font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.alloc__num::-webkit-outer-spin-button, .alloc__num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.alloc__pct { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }

/* Range slider */
.alloc__range {
  --fill: 0%;
  flex: 1; min-width: 0; height: 32px; margin: 0; background: transparent;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.alloc__range::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-2) var(--fill));
  border: 1px solid var(--border);
}
.alloc__range::-moz-range-track { height: 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.alloc__range::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--accent); }
.alloc__range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; margin-top: -9px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow);
  transition: transform .1s var(--ease);
}
.alloc__range::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: var(--shadow);
}
.alloc__range:active::-webkit-slider-thumb { transform: scale(1.12); }
.alloc__range:focus { outline: none; }
.alloc__range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 6px var(--accent); }
.alloc__range:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--accent-soft), 0 0 0 6px var(--accent); }

/* Live total meter: sticks to the bottom of the viewport while scrolling the sliders */
.meter {
  position: sticky; bottom: 12px; z-index: 5;
  margin-top: 18px; padding: 14px 16px;
  border-radius: var(--radius); background: var(--surface);
  border: 1.5px solid var(--border-strong); box-shadow: var(--shadow-lg);
  transition: border-color .2s, background .2s;
}
.meter__top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.meter__label { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.meter__caption { font-size: .8125rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.meter__value { font-size: 1.5rem; font-variant-numeric: tabular-nums; line-height: 1; }
.meter__hint { font-size: .9375rem; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.meter__track { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter__fill { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .25s var(--ease), background .2s; }
.meter.is-valid { border-color: var(--good); background: var(--good-soft); }
.meter.is-valid .meter__value, .meter.is-valid .meter__hint { color: var(--good); }
.meter.is-valid .meter__fill { background: var(--good); }
.meter.is-over { border-color: var(--danger); }
.meter.is-over .meter__value, .meter.is-over .meter__hint { color: var(--danger); }
.meter.is-over .meter__fill { background: var(--danger); }
.meter__balance { flex: none; }

/* --- Segmented controls (likert + scale) --------------------------------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg__opt {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 8px 4px; text-align: center;
  background: var(--surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; user-select: none; font-size: .75rem; font-weight: 600; line-height: 1.2; color: var(--text-2);
  transition: border-color .15s, background .15s, color .15s;
}
.seg__opt:hover { border-color: var(--accent); color: var(--text); }
.seg__opt:has(input:checked) { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
.seg__opt:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg__dot { display: none; }

/* Likert grid */
.likert__header { display: none; }
.likert__rows { display: grid; gap: 12px; }
.likert__row {
  padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  transition: border-color .15s, background .15s;
}
.likert__row.is-rated { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.likert__label { margin: 0 0 10px; font-weight: 600; line-height: 1.35; }

@media (min-width: 720px) {
  .likert { --likert-cols: minmax(200px, 1.6fr) repeat(5, minmax(64px, 1fr)); }
  .likert__header {
    display: grid; grid-template-columns: var(--likert-cols); gap: 6px; align-items: end;
    position: sticky; top: 58px; z-index: 4; padding: 8px 14px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    font-size: .75rem; font-weight: 650; color: var(--text-2); text-align: center; line-height: 1.2;
  }
  .likert__rows { gap: 0; }
  .likert__row {
    display: grid; grid-template-columns: var(--likert-cols); gap: 6px; align-items: center;
    padding: 10px 14px; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent;
  }
  .likert__row:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
  .likert__row.is-rated { border-color: var(--border); }
  .likert__label { margin: 0; font-weight: 500; }
  .seg--likert { display: contents; }
  .seg--likert .seg__opt { min-height: 44px; border: 0; background: transparent; }
  .seg--likert .seg__opt:has(input:checked) { background: transparent; }
  .seg--likert .seg__text {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .seg--likert .seg__dot {
    display: block; width: 24px; height: 24px; border-radius: 50%;
    border: 2px solid var(--border-strong); background: var(--surface);
    transition: border-color .15s, box-shadow .15s, background .15s;
  }
  .seg--likert .seg__opt:hover .seg__dot { border-color: var(--accent); }
  .seg--likert .seg__opt:has(input:checked) .seg__dot {
    border-color: var(--accent); background: var(--accent);
    box-shadow: inset 0 0 0 4px var(--surface);
  }
}

/* Scale */
.seg--scale .seg__opt { min-height: 60px; border-radius: var(--radius); }
.seg__num { font-size: 1.25rem; font-weight: 700; }
.seg--scale .seg__opt.is-selected { color: var(--accent-text); }
.scale__ends { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: .875rem; color: var(--text-2); }
.scale__ends span:last-child { text-align: right; }

/* --- Text ---------------------------------------------------------------- */
.text-input { min-height: 140px; line-height: 1.5; }
.text-count { margin: 8px 0 0; text-align: right; font-size: .8125rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.text-count.is-near { color: var(--warn); font-weight: 600; }

/* --- Review -------------------------------------------------------------- */
.review__section { margin-top: 26px; }
.review__title { display: flex; align-items: center; gap: 10px; font-size: 1.0625rem; margin-bottom: 6px; }
.review__num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .8125rem; font-weight: 700;
}
.review__list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.review__item {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.review__q { min-width: 0; }
.review__prompt { margin: 0 0 2px; font-size: .875rem; color: var(--text-2); }
.review__answer { font-weight: 500; overflow-wrap: anywhere; }
.review__picks { margin: 0; padding-left: 20px; }
.review__item.is-invalid .review__prompt { color: var(--danger); }
.review__error { margin: 4px 0 0; color: var(--danger); font-size: .875rem; font-weight: 600; }
.review__edit { flex: none; color: var(--accent); }
.review__footer {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap;
  margin-top: 20px;
}
.review__submit { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; flex: 1; }
.submit-status { display: grid; gap: 8px; justify-items: end; max-width: 46ch; }
.submit-status .q-reason { text-align: right; }
.btn--submit.is-loading { cursor: progress; }
.review__privacy { margin-top: 16px; text-align: center; }

/* --- Small screens ------------------------------------------------------- */
@media (max-width: 479px) {
  .q-nav { position: sticky; bottom: 0; z-index: 10; margin: 16px -20px 0; padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border); }
  .q-nav { flex-wrap: wrap; align-items: center; row-gap: 8px; }
  .q-nav__right { display: contents; }
  .q-reason { order: -1; flex-basis: 100%; max-width: none; min-height: 0; text-align: left; }
  .q-reason:empty { margin: 0; }
  .btn--next { margin-left: auto; }
  /* The sticky meter already shows the total; keep the reason for screen readers only. */
  .q--allocation .q-reason { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .meter { bottom: 80px; padding: 10px 12px; margin-top: 14px; }
  .meter__top { margin-bottom: 8px; }
  .meter__caption { display: none; }
  .meter__value { font-size: 1.25rem; white-space: nowrap; }
  .meter__hint { font-size: .875rem; }
  .meter__label { flex-wrap: nowrap; gap: 8px; min-width: 0; }
  .meter__balance { padding: 4px 10px; min-height: 32px; font-size: .8125rem; }
  .meter.is-valid .meter__balance { display: none; }
  .meter__balance-more { display: none; }
  .meter__top { gap: 8px; }
  .seg--likert { gap: 4px; }
  .seg--likert .seg__opt { font-size: .6875rem; padding: 6px 2px; min-height: 52px; }
  .intro__actions .btn { width: 100%; }
  .review__submit { align-items: stretch; }
  .review__submit .btn { width: 100%; }
}

/* --- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .screen--in-fwd, .screen--in-back, .screen--out-fwd, .screen--out-back { animation: none; }
  .progress__fill, .meter__fill { transition: none; }
}
