/* Layout: one narrow book-page column. Each screen is a page of the OC's love story:
   cover (name) → six chapters (questions) → character dossier (result) → relationship page.
   Dark-first: moonlight gold marks the 光 archetypes, wine red marks the 暗 archetypes. */
:root {
  --bg: #121018;
  --surface: #1a1722;
  --line: #2f2a3a;
  --fg: #ebe6f0;
  --muted: #a39bb0;
  --moon: #d9c48c;
  --wine: #e07a92;
  --on-accent: #121018;
  --arc: var(--moon);
  --font-zh: "Noto Serif SC", "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --font-latin: "Cormorant Garamond", "Noto Serif SC", Georgia, "Times New Roman", serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ecebf0;
    --surface: #f7f6f9;
    --line: #d5d1dc;
    --fg: #1d1925;
    --muted: #5f586a;
    --moon: #7d6019;
    --wine: #9e2f48;
    --on-accent: #f7f6f9;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #ecebf0;
  --surface: #f7f6f9;
  --line: #d5d1dc;
  --fg: #1d1925;
  --muted: #5f586a;
  --moon: #7d6019;
  --wine: #9e2f48;
  --on-accent: #f7f6f9;
  color-scheme: light;
}

.is-light { --arc: var(--moon); }
.is-dark { --arc: var(--wine); }
.is-mixed { --arc: var(--moon); }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
:root {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
html, body { margin: 0; }
[hidden] { display: none !important; }
img { max-width: 100%; }

body {
  background:
    radial-gradient(60rem 28rem at 50% -10rem, color-mix(in srgb, var(--moon) 9%, transparent), transparent 70%) no-repeat,
    var(--bg);
  color: var(--fg);
  font-family: var(--font-zh);
  font-size: 16px;
  line-height: 1.8;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible { outline: 2px solid var(--arc); outline-offset: 3px; }

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding-block: 28px 56px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.page > * { min-width: 0; }
section { display: grid; gap: 0; }

/* ---------- type ---------- */
.eyebrow { margin: 0; font-size: 0.85rem; letter-spacing: 0.2em; color: var(--muted); }
.eyebrow.latin {
  font-family: var(--font-latin);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.24em;
}
.masthead { display: grid; gap: 10px; padding-top: 8px; }
.title {
  margin: 0;
  font-size: clamp(2.3rem, 10vw, 3.2rem);
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-wrap: balance;
}
.title .oc {
  font-family: var(--font-latin);
  font-style: italic;
  font-weight: 500;
  font-size: 1.22em;
  letter-spacing: 0;
  color: var(--moon);
  margin-right: 0.12em;
}
.title-s { margin: 0; font-size: 1.9rem; line-height: 1.3; font-weight: 900; text-wrap: balance; }
.lede { margin: 0; font-size: 1.12rem; color: var(--muted); }

.section-h {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--muted);
}
.section-h::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.prose { margin: 0; font-size: 1.05rem; }

/* ---------- controls ---------- */
.btn {
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  padding: 12px 18px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.btn:hover { border-color: var(--arc); }
.btn.primary {
  background: var(--arc);
  border-color: var(--arc);
  color: var(--on-accent);
  font-weight: 600;
}
.btn.primary:hover { background: color-mix(in srgb, var(--arc) 85%, var(--fg)); }

.link {
  font: inherit;
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  justify-self: start;
  align-self: flex-start;
}
.link:hover { color: var(--fg); }

.namecard, .pick-form { display: grid; gap: 12px; }
.field { display: grid; gap: 8px; }
label, legend { font-weight: 600; }
.name-input {
  width: 100%;
  font: inherit;
  font-size: 1.3rem;
  padding: 12px 14px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.name-input::placeholder { color: var(--muted); opacity: 0.7; }
.name-input:focus {
  outline: none;
  border-color: var(--arc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--arc) 25%, transparent);
}
.hint { margin: 0; font-size: 0.88rem; line-height: 1.7; color: var(--muted); }
.error { margin: 0; font-size: 0.92rem; color: var(--wine); }

.resume {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  font: inherit;
  text-align: left;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.resume b { color: var(--fg); }
.resume:hover { border-color: var(--moon); }

/* ---------- intro cast ---------- */
.cast { gap: 12px; }
.cast .section-h { margin-bottom: 2px; }
.cast-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.cast-head {
  margin: 0 0 4px;
  padding-bottom: 4px;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--arc);
  border-bottom: 1px solid var(--line);
}
.cast-col ul { list-style: none; margin: 0; padding: 0; }
.cast-col button {
  width: 100%;
  padding: 5px 0;
  font: inherit;
  font-size: 1.05rem;
  text-align: left;
  color: var(--fg);
  background: none;
  border: 0;
  cursor: pointer;
}
.cast-col button:hover { color: var(--arc); }

/* ---------- quiz ---------- */
.quiz { gap: 24px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; }
.count {
  font-family: var(--font-latin);
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.progress { height: 2px; margin-top: -14px; background: var(--line); }
.progress i { display: block; height: 100%; background: var(--arc); transition: width 0.3s ease; }
.chapter { margin: 8px 0 0; font-size: 0.92rem; letter-spacing: 0.3em; color: var(--arc); }
.question {
  margin: -12px 0 0;
  font-size: 1.32rem;
  line-height: 1.65;
  font-weight: 600;
  text-wrap: pretty;
  animation: rise 0.35s ease both;
}
.options {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  animation: rise 0.35s 0.05s ease both;
}
.opt {
  width: 100%;
  display: grid;
  grid-template-columns: 1.8em minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
  padding: 14px 16px;
  font: inherit;
  font-size: 1.02rem;
  line-height: 1.6;
  text-align: left;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.opt .mk { font-size: 0.9rem; color: var(--muted); }
.opt:hover { border-color: color-mix(in srgb, var(--arc) 55%, var(--line)); }
.opt.chosen { border-color: var(--arc); background: color-mix(in srgb, var(--arc) 16%, var(--surface)); }
.opt.chosen .mk { color: var(--arc); }
.oc-tag { margin: 0; text-align: center; font-size: 0.85rem; color: var(--muted); }

/* ---------- loading ---------- */
.loading { min-height: 60vh; justify-content: center; align-items: center; text-align: center; gap: 28px; }
.loading p { margin: 0; font-size: 1.1rem; color: var(--muted); }
.ink {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--moon);
  filter: blur(8px);
  animation: bloom 1.5s ease-out both;
}

/* ---------- result ---------- */
.hero { display: grid; justify-items: center; gap: 10px; text-align: center; }
.seal {
  width: 136px;
  max-width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-block: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--arc);
  box-shadow: inset 0 0 0 5px var(--bg), inset 0 0 0 6px color-mix(in srgb, var(--arc) 50%, transparent);
  background: radial-gradient(circle, color-mix(in srgb, var(--arc) 22%, transparent), transparent 70%);
}
.seal span { font-size: 4rem; line-height: 1; font-weight: 900; color: var(--arc); }
.result .hero .seal { animation: seal 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.type-name {
  margin: 0;
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding-left: 0.08em;
}
.code { margin: 0; display: grid; }
.code .latin {
  font-family: var(--font-latin);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.5em;
  padding-left: 0.5em;
  color: var(--arc);
}
.code .code-zh { font-size: 0.85rem; letter-spacing: 0.1em; color: var(--muted); }
.tagline { margin: 0; max-width: 24em; font-size: 1.15rem; text-wrap: balance; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}
.chips.left { justify-content: flex-start; margin: 0; }
.chips li {
  padding: 2px 12px;
  font-size: 0.9rem;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.axes { display: grid; gap: 14px; }
.axis {
  display: grid;
  grid-template-columns: 2.6em minmax(0, 1fr);
  gap: 4px 12px;
  align-items: center;
}
.axis .dim { grid-row: span 2; font-size: 0.9rem; color: var(--muted); }
.axis-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.axis-labels .win { color: var(--fg); font-weight: 600; }
.track { display: flex; gap: 2px; height: 6px; border-radius: 3px; overflow: hidden; background: var(--line); }
.track i { display: block; height: 100%; }
.track .on { background: var(--arc); }
.track .dim-seg { background: color-mix(in srgb, var(--fg) 12%, transparent); }

.traits { margin: 0; display: grid; gap: 16px; }
.traits div { display: grid; gap: 2px; }
.traits dt { font-size: 0.9rem; letter-spacing: 0.15em; color: var(--arc); }
.traits dd { margin: 0; }

.quote {
  margin: 0;
  padding-block: 22px;
  text-align: center;
  border-block: 1px solid var(--line);
}
.quote p { margin: 0; font-size: 1.3rem; line-height: 1.6; font-weight: 600; text-wrap: balance; }

.part2 {
  gap: 10px;
  padding: 22px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.part2 h2 { margin: 0; font-size: 1.35rem; line-height: 1.4; font-weight: 900; text-wrap: balance; }
.part2 p { margin: 0; color: var(--muted); }
.part2 .eyebrow { color: var(--arc); }
.choice { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.choice .btn { flex: 1 1 10rem; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 auto; }

/* ---------- gallery & picker ---------- */
.legend {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 16px;
}
.legend div { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.legend dt { font-size: 0.9rem; color: var(--muted); }
.legend dd { margin: 0; }
.legend b { font-family: var(--font-latin); font-size: 1.1rem; color: var(--moon); }
.legend span { margin: 0 6px; color: var(--muted); }

.type-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.type-grid legend { margin-bottom: 10px; padding: 0; }
.grid-head {
  margin: 0;
  padding-bottom: 2px;
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--arc);
  border-bottom: 1px solid var(--line);
}
.card {
  position: relative;
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 12px 14px;
  font: inherit;
  font-weight: 400;
  text-align: left;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.card b { font-size: 1.15rem; font-weight: 900; color: var(--arc); }
.card-code { font-family: var(--font-latin); font-size: 0.9rem; letter-spacing: 0.25em; color: var(--muted); }
.card small { font-size: 0.85rem; line-height: 1.55; color: var(--muted); }
.card:hover { border-color: color-mix(in srgb, var(--arc) 55%, var(--line)); }
.card:has(input:checked) {
  border-color: var(--arc);
  background: color-mix(in srgb, var(--arc) 14%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--arc);
}
.card:has(input:focus-visible) { outline: 2px solid var(--arc); outline-offset: 2px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

/* ---------- pair ---------- */
.duo {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}
.who {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 4px;
  font: inherit;
  color: var(--fg);
  background: none;
  border: 0;
  cursor: pointer;
}
.who b { font-size: 1.1rem; overflow-wrap: anywhere; }
.who small { font-size: 0.9rem; letter-spacing: 0.1em; color: var(--arc); }
.seal.small { width: 76px; margin-block: 0 4px; box-shadow: inset 0 0 0 3px var(--bg), inset 0 0 0 4px color-mix(in srgb, var(--arc) 50%, transparent); }
.seal.small span { font-size: 2.1rem; }
.x { font-family: var(--font-latin); font-size: 2.2rem; line-height: 1; color: var(--muted); }
.rel-label { margin: 10px 0 0; font-size: 0.9rem; letter-spacing: 0.2em; color: var(--muted); }
.rel-name {
  margin: 0;
  font-size: clamp(2.4rem, 11vw, 3.2rem);
  line-height: 1.25;
  font-weight: 900;
  letter-spacing: 0.1em;
  padding-left: 0.1em;
  color: var(--arc);
  text-wrap: balance;
}
.is-mixed .rel-name {
  background: linear-gradient(90deg, var(--moon), var(--wine));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.meters { display: grid; gap: 12px; }
.meter {
  display: grid;
  grid-template-columns: 3em minmax(0, 1fr) 2.2em;
  gap: 12px;
  align-items: center;
}
.meter > span:first-child { font-size: 0.95rem; color: var(--muted); }
.meter .val {
  font-family: var(--font-latin);
  font-size: 1.2rem;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.is-mixed .meter .on { background: linear-gradient(90deg, var(--moon), var(--wine)); }

.dyn { margin: 0; display: grid; gap: 16px; }
.dyn div { display: grid; gap: 2px; }
.dyn dt { font-size: 0.92rem; letter-spacing: 0.12em; color: var(--arc); }
.dyn dt small { margin-left: 10px; font-size: 0.85rem; letter-spacing: 0; color: var(--muted); }
.dyn dd { margin: 0; }

.scene p { margin: 0; font-size: 1.15rem; line-height: 1.8; }
.scene p::before { content: "「"; color: var(--arc); }
.scene p::after { content: "」"; color: var(--arc); }

/* ---------- footer ---------- */
.foot { padding-top: 16px; border-top: 1px solid var(--line); font-size: 0.8rem; color: var(--muted); }
.foot p { margin: 0; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes seal { from { opacity: 0.15; transform: scale(0.86); } to { opacity: 1; transform: none; } }
@keyframes bloom { from { opacity: 0.9; transform: scale(0.3); } to { opacity: 0; transform: scale(2.4); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
