/* ==========================================================================
   Personality Match (MBTI) — intro, type picker, test and results.
   Builds on ../assets/core.css.
   ========================================================================== */

.page-mbti {
  --accent: #c7b3ff;
  --accent-2: #ff8fb1;
}

.mbti { padding-block: clamp(18px, 4vw, 40px) 0; }


/* ---------- Portraits (paper frame + monogram fallback) ---------- */
.portrait {
  position: relative;
  display: block;
  aspect-ratio: 350 / 440;
  border-radius: 14px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 0 3px var(--paper), 0 18px 30px -14px rgb(0 0 0 / 0.75);
}
.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.portrait--fallback {
  display: grid;
  place-items: center;
  background:
    radial-gradient(90% 70% at 50% 30%, #fffdf8, transparent 70%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  color: color-mix(in oklab, var(--g, var(--accent)) 55%, var(--paper-ink));
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  container-type: inline-size;
}
.portrait--fallback span { font-size: 28cqi; letter-spacing: -0.02em; }

/* ---------- Intro ---------- */
.view--intro {
  justify-items: center;
  text-align: center;
  gap: 18px;
  padding-top: 6px;
}
.view--intro .lede { margin-inline: auto; }
.view--intro .eyebrow .icon { color: var(--accent); width: 15px; height: 15px; }
.view--intro .display { font-size: clamp(38px, 10vw, 84px); }

.fan {
  position: relative;
  width: 100%;
  height: clamp(170px, 46vw, 250px);
  margin-bottom: clamp(10px, 3vw, 26px);
}
.fan img {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: clamp(84px, 24vw, 132px);
  height: auto;
  border-radius: 14px;
  box-shadow: 0 0 0 3px var(--paper), 0 20px 34px -12px rgb(0 0 0 / 0.8);
  transform-origin: 50% 230%;
  translate: -50% 0;
  animation: fan-in 0.9s var(--spring) both;
}
.fan img:nth-child(1) { rotate: -22deg; z-index: 1; animation-delay: 0.05s; }
.fan img:nth-child(2) { rotate: -11deg; z-index: 2; animation-delay: 0.1s; }
.fan img:nth-child(3) { rotate: 0deg; z-index: 3; animation-delay: 0.15s; }
.fan img:nth-child(4) { rotate: 11deg; z-index: 2; animation-delay: 0.2s; }
.fan img:nth-child(5) { rotate: 22deg; z-index: 1; animation-delay: 0.25s; }
@keyframes fan-in { from { rotate: 0deg; opacity: 0; translate: -50% 30px; } }

.choices {
  display: grid;
  gap: 12px;
  width: min(100%, 520px);
  margin-top: 8px;
}
.choice {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background: rgb(255 255 255 / 0.04);
  text-align: left;
  transition: transform 0.4s var(--spring), border-color 0.25s, background-color 0.25s, box-shadow 0.3s;
}
.choice:hover { border-color: rgb(255 255 255 / 0.3); background: rgb(255 255 255 / 0.07); }
.choice:active { transform: scale(0.98); }
.choice--primary {
  border-color: transparent;
  background:
    linear-gradient(var(--ink-1), var(--ink-1)) padding-box,
    linear-gradient(135deg, var(--accent), var(--accent-2)) border-box;
  border: 1.5px solid transparent;
  box-shadow: 0 18px 40px -22px var(--accent);
}
.choice--primary:hover {
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) padding-box,
    linear-gradient(135deg, var(--accent), var(--accent-2)) border-box;
}
.choice__icon {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 15px;
  background: rgb(255 255 255 / 0.07);
  color: var(--accent);
}
.choice--primary .choice__icon {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
}
.choice__icon .icon { width: 22px; height: 22px; }
.choice__body { display: grid; gap: 2px; flex: 1; min-width: 0; }
.choice__body strong { font-size: 17px; font-weight: 800; }
.choice__body small { color: var(--text-3); font-size: 14px; font-weight: 600; text-wrap: balance; }
.choice__arrow { color: var(--text-3); transition: transform 0.35s var(--spring); }
.choice:hover .choice__arrow { transform: translateX(4px); color: var(--text); }

.resume .portrait { width: 30px; border-radius: 50%; aspect-ratio: 1; box-shadow: 0 0 0 2px var(--paper); }
.resume .portrait img { object-position: 50% 12%; }

/* ---------- Type picker ---------- */
.groups { display: grid; gap: 26px; }
.group { display: grid; gap: 12px; }
.group__title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-2);
}
.group__title::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--g);
  box-shadow: 0 0 12px var(--g);
}
.group__title small { color: var(--text-3); letter-spacing: 0.1em; }
.type-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.type-tile {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 8px 8px 10px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgb(255 255 255 / 0.03);
  transition: transform 0.4s var(--spring), border-color 0.25s, background-color 0.25s;
}
.type-tile:hover {
  border-color: color-mix(in oklab, var(--g) 60%, transparent);
  background: color-mix(in oklab, var(--g) 10%, transparent);
  transform: translateY(-3px);
}
.type-tile:active { transform: scale(0.96); }
.type-tile .portrait { width: 100%; border-radius: 10px; box-shadow: 0 0 0 2px var(--paper); }
.type-tile__code { font-size: 14px; font-weight: 800; letter-spacing: 0.06em; }
.type-tile__name { display: none; color: var(--text-3); font-size: 13px; font-weight: 600; margin-top: -6px; }
@media (min-width: 640px) {
  .type-tile { padding: 10px 10px 14px; }
  .type-tile__code { font-size: 16px; }
  .type-tile__name { display: block; }
}

/* ---------- Test ---------- */
.view--test {
  display: flex;
  flex-direction: column;
  max-width: 640px;
  width: 100%;
  min-height: calc(100svh - 100px);
  margin-inline: auto;
  gap: 26px;
}
.view--test[hidden] { display: none; }
.view--test .leaning { margin-top: auto; }
.test-bar {
  display: flex;
  align-items: center;
  gap: 14px;
}
.test-bar .meter { flex: 1; height: 8px; }
.test-count { min-width: 52px; text-align: right; color: var(--text-3); font-weight: 750; font-variant-numeric: tabular-nums; }
#testBack:disabled { opacity: 0.35; }

.question { display: grid; gap: 18px; }
.question.is-out { animation: q-out 0.22s var(--ease-in-out) forwards; }
.question.is-in { animation: q-in 0.5s var(--ease-out); }
.question.is-back { --dir: -1; }
@keyframes q-out { to { opacity: 0; transform: translateX(calc(-28px * var(--dir, 1))); } }
@keyframes q-in { from { opacity: 0; transform: translateX(calc(34px * var(--dir, 1))); } }
.question__text {
  font-family: var(--font-display);
  font-size: clamp(30px, 8vw, 46px);
  font-weight: 480;
  line-height: 1.08;
  letter-spacing: -0.02em;
  text-wrap: balance;
  min-height: 2.2em;
}
.answers { display: grid; gap: 12px; }
.answer {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 78px;
  padding: 16px 20px 16px 16px;
  border-radius: 22px;
  border: 1px solid var(--line-strong);
  background: rgb(255 255 255 / 0.04);
  text-align: left;
  font-size: 17px;
  font-weight: 650;
  line-height: 1.35;
  transition: transform 0.35s var(--spring), border-color 0.2s, background-color 0.2s, box-shadow 0.3s;
}
.answer:hover { border-color: color-mix(in oklab, var(--accent) 60%, transparent); background: rgb(255 255 255 / 0.07); }
.answer:active { transform: scale(0.98); }
.answer__key {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  border: 1px solid var(--line-strong);
  color: var(--text-2);
  font-size: 15px;
  font-weight: 800;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.answer.is-picked {
  border-color: transparent;
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 30%, transparent), color-mix(in oklab, var(--accent-2) 20%, transparent));
  box-shadow: 0 0 0 2px var(--accent), 0 16px 34px -18px var(--accent);
}
.answer.is-picked .answer__key { background: var(--accent); border-color: transparent; color: var(--on-accent); }

.leaning {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px 12px 12px;
  border-radius: 22px;
}
.leaning__portrait { width: 52px; flex: none; }
.leaning__portrait .portrait { border-radius: 10px; box-shadow: 0 0 0 2px var(--paper); }
.leaning__body { display: grid; gap: 2px; }
.leaning__label { color: var(--text-3); font-size: 13px; font-weight: 700; }
.leaning__code { display: flex; gap: 4px; font-family: var(--font-display); font-size: 30px; font-weight: 560; line-height: 1; }
.leaning__code b { font-weight: inherit; display: inline-block; min-width: 0.7em; text-align: center; }
.leaning__code b.is-unsure { color: var(--text-3); }
.leaning__code b.is-changed { animation: letter-pop 0.5s var(--spring); }
@keyframes letter-pop { from { transform: translateY(8px) scale(0.7); opacity: 0; } }

/* ---------- Result ---------- */
.view--result { gap: 20px; }
.result-hero {
  display: grid;
  justify-items: center;
  gap: 22px;
  text-align: center;
}
.result-portrait {
  position: relative;
  width: clamp(170px, 50vw, 260px);
  rotate: -3deg;
  animation: portrait-in 1s var(--spring) both;
}
.result-portrait::before {
  content: "";
  position: absolute;
  inset: -30%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, var(--g) 55%, transparent), transparent);
  opacity: 0.8;
}
.result-portrait .portrait { border-radius: 18px; box-shadow: 0 0 0 5px var(--paper), 0 34px 60px -24px rgb(0 0 0 / 0.9); }
@keyframes portrait-in { from { opacity: 0; transform: translateY(30px) scale(0.85) rotate(-8deg); } }
.result-id { display: grid; gap: 8px; justify-items: center; }
.result-id .eyebrow { color: var(--g); }
.type-code {
  display: flex;
  gap: 0.04em;
  font-family: var(--font-display);
  font-weight: 560;
  font-size: clamp(64px, 19vw, 132px);
  line-height: 0.95;
  letter-spacing: -0.01em;
}
.type-code span {
  display: inline-block;
  background: linear-gradient(180deg, #fff, color-mix(in oklab, var(--g) 70%, #fff));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: letter-in 0.8s var(--spring) both;
}
.type-code span:nth-child(2) { animation-delay: 0.08s; }
.type-code span:nth-child(3) { animation-delay: 0.16s; }
.type-code span:nth-child(4) { animation-delay: 0.24s; }
@keyframes letter-in { from { opacity: 0; transform: translateY(40%) rotate(8deg); } }
.type-name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(24px, 5.6vw, 34px);
  color: var(--text-2);
}
.result-id .lede { margin-top: 6px; }

.traits {
  display: grid;
  gap: 18px;
  padding: 22px 20px;
}
.trait { display: grid; gap: 8px; }
.trait__labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-3);
}
.trait__labels .is-strong { color: var(--text); }
.trait__labels b { color: var(--g); font-weight: 800; }
.trait__bar {
  position: relative;
  height: 10px;
  border-radius: 99px;
  background: rgb(255 255 255 / 0.08);
  overflow: hidden;
}
.trait__bar i {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in oklab, var(--g) 70%, #fff), var(--g));
  transition: width 1s var(--ease-out) 0.3s;
}
.trait__bar i.from-left { left: 0; }
.trait__bar i.from-right { right: 0; background: linear-gradient(270deg, color-mix(in oklab, var(--g) 70%, #fff), var(--g)); }
.trait__bar::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--ink-0);
}
.traits__note { color: var(--text-3); font-size: 13px; text-align: center; }
.letters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.letter {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgb(255 255 255 / 0.04);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 14px;
}
.letter b {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: color-mix(in oklab, var(--g) 22%, transparent);
  color: var(--g);
  font-family: var(--font-display);
  font-size: 19px;
}

@media (max-width: 400px) {
  /* "Extraverted" / "Introverted" need the room on small phones. */
  .letter { gap: 8px; padding: 9px 10px; font-size: 13px; }
  .letter b { width: 30px; height: 30px; font-size: 17px; }
}

.block { display: grid; gap: 14px; }
.top-matches {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.top-match {
  --g: var(--accent);
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, color-mix(in oklab, var(--g) 12%, transparent), rgb(255 255 255 / 0.02));
  text-align: center;
  animation: view-in 0.6s var(--ease-out) both;
}
.top-match:nth-child(2) { animation-delay: 0.08s; }
.top-match:nth-child(3) { animation-delay: 0.16s; }
.top-match .portrait { width: 100%; border-radius: 12px; box-shadow: 0 0 0 2px var(--paper); }
.top-match__code { font-weight: 800; letter-spacing: 0.05em; }
.top-match__name { color: var(--text-3); font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.pct {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 99px;
  background: color-mix(in oklab, var(--good) 18%, transparent);
  color: var(--good);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.checker { padding: 22px 20px; }
.mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.mini-grid [role="radio"] {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgb(255 255 255 / 0.03);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s, transform 0.3s var(--spring);
}
.mini-grid [role="radio"]::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--g);
  vertical-align: 1px;
}
.mini-grid [role="radio"]:hover { color: var(--text); border-color: rgb(255 255 255 / 0.3); }
.mini-grid [role="radio"]:active { transform: scale(0.94); }
.mini-grid [aria-checked="true"] {
  background: color-mix(in oklab, var(--g) 26%, transparent);
  border-color: var(--g);
  color: var(--text);
}
.chem {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-top: 6px;
  animation: view-in 0.5s var(--ease-out);
}
.chem[hidden] { display: none; }
.ring {
  --p: 0;
  position: relative;
  width: 112px;
  height: 112px;
  flex: none;
}
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring__track { stroke: rgb(255 255 255 / 0.08); }
.ring__fill {
  stroke: var(--ring, var(--accent));
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: calc(326.73 * (1 - var(--p)));
  transition: stroke-dashoffset 1.1s var(--ease-out), stroke 0.4s;
}
.ring__value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 560;
  font-variant-numeric: tabular-nums;
}
.chem__body { display: grid; gap: 4px; }
.chem__pair { color: var(--text-3); font-size: 13px; font-weight: 800; letter-spacing: 0.12em; }
.chem__verdict { font-family: var(--font-display); font-size: 25px; font-weight: 520; line-height: 1.1; }
.fineprint { color: var(--text-3); font-size: 12.5px; }

.all { padding: 6px 20px; }
.all summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 56px;
  cursor: pointer;
  list-style: none;
  font-weight: 800;
}
.all summary::-webkit-details-marker { display: none; }
.all summary .icon { transition: transform 0.4s var(--spring); color: var(--text-3); }
.all[open] summary .icon { transform: rotate(180deg); }
.all-list { display: grid; gap: 10px; padding-bottom: 18px; }
.all-row {
  display: grid;
  grid-template-columns: 34px 58px 1fr 42px;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.all-row .portrait { width: 34px; border-radius: 8px; box-shadow: 0 0 0 1.5px var(--paper); }
.all-row b { font-weight: 800; letter-spacing: 0.04em; }
.all-row .meter i { background: linear-gradient(90deg, color-mix(in oklab, var(--g) 70%, #fff), var(--g)); }
.all-row span:last-child { text-align: right; color: var(--text-2); font-weight: 750; font-variant-numeric: tabular-nums; }


@media (min-width: 860px) {
  .result-hero {
    grid-template-columns: auto minmax(0, 1fr);
    justify-items: start;
    align-items: center;
    text-align: left;
    gap: 48px;
    padding: 12px 0 10px;
  }
  .result-id { justify-items: start; }
  .view--result {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 20px;
    row-gap: 20px;
    align-items: start;
  }
  .result-hero,
  .checker,
  .all,
  .result-actions { grid-column: 1 / -1; }
  .top-matches { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .groups { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
}

/* ---------- 中文 (zh-Hant-TW) ---------- */
/* Chinese has no italics, and wide tracking pulls the characters apart. */
:lang(zh) .type-name { font-style: normal; letter-spacing: 0.04em; }
:lang(zh) .group__title { letter-spacing: 0.06em; }
:lang(zh) .question__text { letter-spacing: 0; line-height: 1.3; min-height: 2.6em; }
:lang(zh) .chem__verdict { letter-spacing: 0.02em; }
/* Short lines break between phrases (after ，、。 or at a space), never inside a word; a phrase
   longer than the line still wraps anywhere. */
:lang(zh) .question__text,
:lang(zh) .view--intro .lede,
:lang(zh) .traits__note,
:lang(zh) .fineprint {
  word-break: keep-all;
  overflow-wrap: anywhere;
}
/* Even line lengths: no lone character left on the last line of a centred paragraph. */
:lang(zh) .view--intro .lede,
:lang(zh) .result-id .lede,
:lang(zh) .traits__note,
:lang(zh) .chem .muted { text-wrap: balance; }
