:root {
  --bg: #120f0c;
  --bg-2: #1a1612;
  --paper: #f4ede1;
  --paper-dim: #e7ddcc;
  --ink: #161310;
  --gold: #e0c088;
  --gold-hi: #f3ddb0;
  --gold-dim: rgba(224, 192, 136, 0.28);
  --muted: rgba(244, 237, 225, 0.58);
  --muted-2: rgba(244, 237, 225, 0.38);
  --line: rgba(224, 192, 136, 0.28);
  --copper: #c4623a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --serif: "Noto Serif TC", "Noto Serif CJK TC", "Songti TC", "PMingLiU", serif;
  --sans: "Noto Sans TC", "Noto Sans CJK TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --display: "Cormorant Garamond", "Noto Serif TC", "Noto Serif CJK TC", serif;
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  min-height: 100%;
}
html { height: 100%; }
body {
  min-height: 100dvh;
  min-height: 100svh;
  background:
    radial-gradient(1200px 500px at 50% -80px, rgba(224, 192, 136, 0.16), transparent 60%),
    var(--bg);
  color: var(--paper);
}
body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
#app { position: relative; z-index: 1; min-height: 100dvh; }

.view {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  min-height: 100svh;
}
.view-inner.view-fwd { animation: inFwd 0.42s cubic-bezier(0.22, 1, 0.32, 1) both; }
.view-inner.view-back { animation: inBack 0.42s cubic-bezier(0.22, 1, 0.32, 1) both; }

@keyframes inFwd {
  from { opacity: 0; transform: translate3d(28px, 0, 0); }
  to { opacity: 1; transform: none; }
}
@keyframes inBack {
  from { opacity: 0; transform: translate3d(-28px, 0, 0); }
  to { opacity: 1; transform: none; }
}

.screen { padding: calc(24px + var(--safe-top)) 22px calc(36px + var(--safe-bot)); }
.screen.intro, .screen.calc {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.intro-mark, .calc-mark { color: var(--gold); width: 88px; height: 88px; margin-bottom: 28px; }
.compass { width: 88px; height: 88px; display: block; }
.compass.spin { animation: slowspin 2.8s linear infinite; }
@keyframes slowspin { to { transform: rotate(360deg); } }

.eyebrow {
  letter-spacing: 0.28em;
  font-size: 12px;
  color: var(--gold);
  text-transform: none;
  margin: 0 0 18px;
  font-weight: 500;
}
.title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(64px, 18vw, 88px);
  letter-spacing: 0.28em;
  line-height: 1;
  margin: 0 0 28px 0.28em;
  color: var(--paper);
  text-shadow: 0 0 40px rgba(224, 192, 136, 0.18);
}
.lead {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.7;
  margin: 0 0 16px;
  color: var(--paper);
  max-width: 22em;
}
.note {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.75;
  margin: 0 0 36px;
  max-width: 26em;
}
.disclaimer-mini {
  margin-top: 28px;
  font-size: 12px;
  color: var(--muted-2);
  max-width: 26em;
}

.btn {
  appearance: none;
  border: 0;
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 0.08em;
  padding: 14px 28px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 48px;
  min-width: 44px;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.primary {
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
}
.btn.primary:hover { background: var(--gold-hi); }
.btn.ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--line);
  margin-top: 12px;
}
.intro-extra { display: flex; flex-direction: column; align-items: center; width: 100%; }

/* Quiz */
.quiz-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 28px;
  position: sticky;
  top: var(--safe-top);
  background: linear-gradient(to bottom, var(--bg) 70%, rgba(18,15,12,0));
  padding: 4px 0 16px;
  z-index: 2;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--paper);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:active { background: rgba(244, 237, 225, 0.08); }
.quiz-progress { flex: 1; min-width: 0; }
.quiz-count { font-size: 13px; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.quiz-count .dim { color: var(--muted-2); }
.bar {
  height: 3px;
  background: rgba(244, 237, 225, 0.12);
  border-radius: 99px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #b8894a, var(--gold-hi));
  border-radius: 99px;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.32, 1);
}

.q-body { padding-bottom: 12px; }
.q-num {
  font-family: var(--display);
  font-size: 13px;
  letter-spacing: 0.22em;
  color: var(--gold);
  margin: 0 0 14px;
}
.q-text {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 23px;
  line-height: 1.55;
  margin: 0 0 28px;
  letter-spacing: 0.01em;
}

.scale { display: flex; flex-direction: column; gap: 8px; }
.scale-opt {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(244, 237, 225, 0.03);
  color: var(--paper);
  border-radius: 14px;
  min-height: 52px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.18s ease;
}
.scale-opt .dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  flex: 0 0 auto;
  position: relative;
  background: transparent;
}
.scale-opt .dot::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--gold);
  transform: scale(0);
  transition: transform 0.18s ease;
}
.scale-opt.selected {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}
.scale-opt.selected .dot { border-color: var(--ink); }
.scale-opt.selected .dot::after { background: var(--ink); transform: scale(1); }
.scale-opt:active { transform: scale(0.99); }

.calc-text {
  font-family: var(--serif);
  color: var(--muted);
  letter-spacing: 0.12em;
  margin-top: 8px;
}

/* Result */
.screen.result { padding-top: calc(36px + var(--safe-top)); }
.result-hero { text-align: center; margin-bottom: 28px; }
.type-code {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(64px, 20vw, 92px);
  letter-spacing: 0.08em;
  line-height: 1;
  margin: 6px 0 10px;
  color: var(--paper);
}
.type-code .letter {
  display: inline-block;
  animation: stamp 0.7s cubic-bezier(0.22, 1, 0.32, 1) both;
}
@keyframes stamp {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.type-nick {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 28px;
  margin: 8px 0 10px;
  color: var(--gold);
}
.type-tag {
  font-family: var(--serif);
  color: var(--muted);
  margin: 0;
  font-size: 16px;
}

.axes {
  margin: 8px 0 28px;
  padding: 20px 18px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(244, 237, 225, 0.03);
}
.axis { margin-bottom: 18px; }
.axis-labs, .axis-pcts {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted-2);
}
.axis-labs .on, .axis-pcts .on { color: var(--paper); font-weight: 600; }
.axis-pcts { margin-top: 6px; font-variant-numeric: tabular-nums; color: var(--muted-2); }
.axis-pcts .on { color: var(--gold); }
.axis-track {
  position: relative;
  height: 8px;
  margin-top: 8px;
  background: rgba(244, 237, 225, 0.12);
  border-radius: 99px;
}
.axis-fill {
  position: absolute;
  top: 0;
  height: 100%;
  background: rgba(224, 192, 136, 0.5);
  border-radius: 99px;
}
.axis-mid {
  position: absolute;
  left: 50%;
  top: -3px;
  width: 1px;
  height: 14px;
  background: rgba(244, 237, 225, 0.25);
}
.axis-knob {
  position: absolute;
  top: 50%;
  width: 16px;
  height: 16px;
  background: var(--gold);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 3px var(--bg), 0 0 16px rgba(224, 192, 136, 0.45);
}

.card {
  margin: 0 0 14px;
  padding: 20px 18px 18px;
  border-radius: var(--radius);
  background: #1c1814;
  border: 1px solid rgba(224, 192, 136, 0.14);
}
.card h3 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.18em;
  font-weight: 600;
  color: var(--gold);
}
.card p { margin: 0; color: var(--paper-dim); font-size: 16px; }
.card ul { margin: 0; padding: 0 0 0 1.1em; color: var(--paper-dim); }
.card li { margin: 0 0 8px; }
.card li:last-child { margin-bottom: 0; }
.compat li strong {
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
  color: var(--paper);
  font-weight: 600;
}
.compat li span { color: var(--muted); }

.disclaimer {
  font-size: 12px;
  color: var(--muted-2);
  line-height: 1.7;
  margin: 22px 0 20px;
}
.result-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  margin-bottom: 20px;
}
.result-actions .btn { width: 100%; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 7, 0.82);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + var(--safe-bot));
}
.sheet.hidden, .sheet[hidden] { display: none; }
.sheet-inner {
  width: min(480px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  text-align: center;
  max-height: 88dvh;
  overflow: auto;
}
.sheet-inner p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.sheet-inner img {
  width: 100%;
  border-radius: 12px;
  display: block;
  margin-bottom: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .view-inner.view-fwd, .view-inner.view-back, .type-code .letter, .compass.spin, .bar-fill, .btn, .scale-opt {
    animation: none !important;
    transition: none !important;
  }
}

@media (min-width: 720px) {
  body { font-size: 17px; }
  .view { box-shadow: 0 0 0 1px rgba(224, 192, 136, 0.08); }
}
