/* ==========================================================================
   PsyKey quiz UI
   Shared by the Enneagram test (tests1-9.html) and the Jungian MBTI test
   (mbti-test.html): question card, answer controls, progress and navigation.
   ========================================================================== */

.quiz-page {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem var(--gutter) 2rem;
}

.quiz-head {
  margin-bottom: 1.5rem;
}

.quiz-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.quiz-back:hover {
  color: var(--text-strong);
}

.quiz-title {
  color: var(--text-strong);
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.quiz-lead {
  margin-top: 0.5rem;
  max-width: 60ch;
  color: var(--muted);
}

/* ---------- Progress ---------- */

.quiz-progress {
  margin-top: 1.25rem;
}

.quiz-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quiz-progress-meta strong {
  color: var(--text-strong);
}

.progress-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #0f0f16;
  border: 1px solid var(--line);
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #3fd49a);
  transition: width 0.3s ease;
}

.quiz--mbti .progress-fill {
  background: linear-gradient(90deg, var(--mbti), #f4b07c);
}

/* ---------- Question list ---------- */

.quiz-questions {
  list-style: none;
  display: grid;
  gap: 1rem;
}

/* With JavaScript the questions are shown one at a time. */
.quiz.is-ready .q {
  display: none;
}

.quiz.is-ready .q.is-current {
  display: block;
  animation: q-in 0.22s ease; /* no fill-mode: content stays visible even if the animation never runs */
}

.quiz.is-ready .q.is-current.from-prev {
  animation-name: q-in-prev;
}

@keyframes q-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: none; }
}

@keyframes q-in-prev {
  from { opacity: 0; transform: translateX(-14px); }
  to { opacity: 1; transform: none; }
}

.q-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 4vw, 2.25rem);
  min-width: 0;
}

.q-text {
  float: left; /* lets the legend respect padding and width inside a fieldset */
  width: 100%;
  max-width: 40ch;
  margin-bottom: 1.75rem;
  color: var(--text-strong);
  font-size: clamp(1.12rem, 2.6vw, 1.4rem);
  font-weight: 600;
  line-height: 1.5;
}

.q-text + * {
  clear: both;
}

.q-kicker {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.quiz-noscript {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: #cc49491f;
  color: var(--text-strong);
}

/* ---------- 7-point Enneagram scale ---------- */

.likert7 {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
}

.likert7-side {
  font-weight: 700;
  font-size: 1.05rem;
}

.likert7-side--yes { color: #36d28b; }
.likert7-side--no { color: #e06a6a; }

.likert7-scale {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.25rem;
  max-width: 460px;
  width: 100%;
  margin: 0 auto;
}

.likert7-opt {
  --size: 44px;
  --tone: #8a8a9a;
  position: relative;
  display: grid;
  place-items: center;
  flex: 1 1 0;
  min-width: 0;
  height: 64px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 999px;
}

.likert7-opt:nth-child(1), .likert7-opt:nth-child(7) { --size: 52px; }
.likert7-opt:nth-child(2), .likert7-opt:nth-child(6) { --size: 44px; }
.likert7-opt:nth-child(3), .likert7-opt:nth-child(5) { --size: 36px; }
.likert7-opt:nth-child(4) { --size: 30px; }

.likert7-opt:nth-child(1) { --tone: #36d28b; }
.likert7-opt:nth-child(2) { --tone: #6ecea3; }
.likert7-opt:nth-child(3) { --tone: #8fb8a5; }
.likert7-opt:nth-child(4) { --tone: #9a9aae; }
.likert7-opt:nth-child(5) { --tone: #c49393; }
.likert7-opt:nth-child(6) { --tone: #d87373; }
.likert7-opt:nth-child(7) { --tone: #e05a5a; }

.likert7-dot {
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: 3px solid var(--tone);
  background: #00000040;
  transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.likert7-dot::after {
  content: "";
  width: 40%;
  height: 22%;
  border-left: 3px solid #0b0b10;
  border-bottom: 3px solid #0b0b10;
  transform: translateY(-15%) rotate(-45deg);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.likert7-opt:hover .likert7-dot {
  transform: scale(1.06);
  background: color-mix(in srgb, var(--tone) 25%, transparent);
}

.likert7-opt[aria-checked="true"] .likert7-dot {
  background: var(--tone);
  transform: scale(1.08);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tone) 30%, transparent);
}

.likert7-opt[aria-checked="true"] .likert7-dot::after {
  opacity: 1;
}

.likert7-opt:focus-visible {
  box-shadow: none;
}

.likert7-opt:focus-visible .likert7-dot {
  box-shadow: var(--focus);
}

.likert7-choice {
  min-height: 1.6em;
  margin-top: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

.likert7-choice strong {
  color: var(--text-strong);
}

@media (max-width: 600px) {
  .likert7 {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "yes no"
      "scale scale";
    row-gap: 0.25rem;
  }

  .likert7-side--yes { grid-area: yes; }
  .likert7-side--no { grid-area: no; text-align: right; }
  .likert7-scale { grid-area: scale; max-width: none; }

  .likert7-opt { height: 56px; }
  .likert7-opt:nth-child(1), .likert7-opt:nth-child(7) { --size: 42px; }
  .likert7-opt:nth-child(2), .likert7-opt:nth-child(6) { --size: 36px; }
  .likert7-opt:nth-child(3), .likert7-opt:nth-child(5) { --size: 30px; }
  .likert7-opt:nth-child(4) { --size: 26px; }
}

/* ---------- Navigation ---------- */

.quiz-nav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.quiz-nav-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.quiz-nav [data-action="next"].is-final {
  background: var(--accent);
}

.quiz-nav [data-action="next"].is-final:hover {
  background: #6a46dc;
}

.quiz-nav [data-action="prev"][hidden] {
  display: inline-flex;
  visibility: hidden;
}

@media (max-width: 600px) {
  .quiz-page {
    padding-top: 1rem;
  }

  .quiz-nav {
    position: sticky;
    bottom: 0;
    z-index: 5;
    grid-template-columns: 1fr 1.4fr;
    grid-template-areas:
      "hint hint"
      "prev next";
    gap: 0.5rem 0.75rem;
    margin: 1rem calc(var(--gutter) * -1) 0;
    padding: 0.75rem var(--gutter) calc(0.75rem + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, #16161ee6, #101016fa);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }

  .quiz-nav-hint { grid-area: hint; font-size: 0.85rem; }
  .quiz-nav [data-action="prev"] { grid-area: prev; }
  .quiz-nav [data-action="next"] { grid-area: next; }

  .quiz-nav .button {
    width: 100%;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .quiz-nav-hint:empty {
    display: none;
  }
}

/* ---------- MBTI: two-statement comparison ---------- */

.pair {
  display: grid;
  gap: 1rem;
}

.pair-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.pair-statement {
  position: relative;
  padding: 1rem 1.1rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--text);
  line-height: 1.55;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.pair-statement .pair-tag {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.85rem;
  color: #111;
}

.pair-statement--a .pair-tag { background: #b9a6ff; }
.pair-statement--b .pair-tag { background: #7fd6d8; }

.pair.lean-a .pair-statement--a,
.pair.lean-b .pair-statement--b {
  border-color: var(--line-strong);
  background: #22222e;
  color: var(--text-strong);
}

.pair-scale {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.pair-opt {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.4rem;
  min-height: 72px;
  padding: 0.5rem 0.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.pair-opt .pair-dot {
  width: var(--size, 30px);
  height: var(--size, 30px);
  border-radius: 50%;
  border: 3px solid var(--tone, #9a9aae);
  background: #00000040;
  transition: background-color 0.18s ease, transform 0.18s ease;
}

.pair-opt:nth-child(1) { --tone: #b9a6ff; --size: 36px; }
.pair-opt:nth-child(2) { --tone: #b9a6ff; --size: 28px; }
.pair-opt:nth-child(3) { --tone: #9a9aae; --size: 22px; }
.pair-opt:nth-child(4) { --tone: #7fd6d8; --size: 28px; }
.pair-opt:nth-child(5) { --tone: #7fd6d8; --size: 36px; }

.pair-opt:hover {
  background: #ffffff08;
  color: var(--text-strong);
}

.pair-opt[aria-checked="true"] {
  border-color: var(--line-strong);
  background: #ffffff0d;
  color: var(--text-strong);
  font-weight: 600;
}

.pair-opt[aria-checked="true"] .pair-dot {
  background: var(--tone);
  transform: scale(1.08);
}

.pair-opt:focus-visible {
  box-shadow: var(--focus);
}

@media (max-width: 600px) {
  .pair-options {
    grid-template-columns: 1fr;
  }

  .pair-scale {
    gap: 0.15rem;
  }

  .pair-opt {
    font-size: 0.72rem;
    padding: 0.4rem 0.1rem;
  }
}

/* ---------- MBTI: one choice out of several ---------- */

.choice-list {
  display: grid;
  gap: 0.6rem;
}

.choice-opt {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: start;
  gap: 0.85rem;
  width: 100%;
  min-height: 56px;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.choice-opt::before {
  content: "";
  width: 22px;
  height: 22px;
  margin-top: 0.1rem;
  border-radius: 50%;
  border: 2px solid #8a8aa6;
  box-sizing: border-box;
  transition: border-width 0.18s ease, border-color 0.18s ease;
}

.choice-opt:hover {
  border-color: var(--line-strong);
  color: var(--text-strong);
}

.choice-opt[aria-checked="true"] {
  border-color: var(--mbti);
  background: #ee8f4a14;
  color: var(--text-strong);
}

.choice-opt[aria-checked="true"]::before {
  border: 7px solid var(--mbti);
}

.choice-opt:focus-visible {
  box-shadow: var(--focus);
}

/* ---------- MBTI: 5-point agreement ---------- */

.likert5 {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
}

.likert5-opt {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.45rem;
  min-height: 76px;
  padding: 0.6rem 0.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-3);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.25;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.likert5-opt .likert5-num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #8a8aa6;
  color: var(--text-strong);
  font-weight: 700;
  font-size: 0.85rem;
}

.likert5-opt:hover {
  border-color: var(--line-strong);
  color: var(--text-strong);
}

.likert5-opt[aria-checked="true"] {
  border-color: var(--mbti);
  background: #ee8f4a14;
  color: var(--text-strong);
  font-weight: 600;
}

.likert5-opt[aria-checked="true"] .likert5-num {
  background: var(--mbti);
  border-color: var(--mbti);
  color: #1a1206;
}

.likert5-opt:focus-visible {
  box-shadow: var(--focus);
}

@media (max-width: 600px) {
  .likert5 {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .likert5-opt {
    grid-template-columns: 30px 1fr;
    justify-items: start;
    align-items: center;
    min-height: 52px;
    padding: 0.5rem 0.85rem;
    font-size: 0.95rem;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .quiz.is-ready .q.is-current {
    animation: none;
  }
}

/* ---------- Compact layout for phones ---------- */

@media (max-width: 600px) {
  .quiz .quiz-head {
    margin-bottom: 1rem;
  }

  .quiz .quiz-back {
    min-height: 36px;
  }

  .quiz .quiz-title {
    font-size: 1.3rem;
  }

  .quiz .quiz-lead {
    font-size: 0.92rem;
  }

  .quiz .quiz-progress {
    margin-top: 0.75rem;
  }

  .q-card {
    padding: 1.1rem 1rem 1.2rem;
    border-radius: var(--radius-md);
  }

  .q-text {
    margin-bottom: 1.1rem;
    font-size: 1.08rem;
  }

  .pair {
    gap: 0.75rem;
  }

  .pair-options {
    gap: 0.5rem;
  }

  .pair-statement {
    display: grid;
    grid-template-columns: 26px 1fr;
    gap: 0.65rem;
    padding: 0.7rem 0.8rem;
    font-size: 0.93rem;
    line-height: 1.5;
  }

  .pair-statement .pair-tag {
    width: 26px;
    height: 26px;
    margin: 0;
  }

  .pair-opt {
    min-height: 64px;
  }

  .choice-opt {
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
  }
}

/* Subtype section shown before the type questions are finished */
.subtype-blocked {
  display: grid;
  gap: 1rem;
  justify-items: start;
  padding: clamp(1.25rem, 4vw, 2rem);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.subtype-blocked[hidden] {
  display: none;
}
