:root {
  --bg: #070b13;
  --bg-2: #0c1323;
  --paper: rgba(17, 24, 41, .91);
  --paper-strong: rgba(20, 28, 47, .98);
  --line: rgba(234, 207, 146, .22);
  --gold: #e4c987;
  --gold-bright: #f2dda7;
  --ink: #f7f2e7;
  --muted: #b9bdc8;
  --soft: #878d9b;
  --shadow: 0 22px 70px rgba(0,0,0,.43);
  --radius: 24px;
  --topbar-h: 58px;
  --footer-h: 46px;
}

* { box-sizing: border-box; }
html { height: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -15%, #1f2a4c 0, transparent 42%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}
body.result-mode { overflow-y: auto; }
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .095;
  background-image: url("data:image/svg+xml,%3Csvg width='160' height='160' viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.32'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
  z-index: 20;
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.orb { position: absolute; border-radius: 50%; filter: blur(85px); opacity: .18; }
.orb-a { width: 42vw; height: 42vw; background: #5a467f; top: 3%; left: -13%; animation: drift 18s ease-in-out infinite alternate; }
.orb-b { width: 35vw; height: 35vw; background: #245b57; right: -8%; top: 27%; animation: drift 22s ease-in-out infinite alternate-reverse; }
.orb-c { width: 28vw; height: 28vw; background: #84602e; left: 36%; bottom: -15%; animation: drift 20s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate3d(7vw, 4vh, 0) scale(1.12); } }

.stars span {
  position: absolute;
  width: 2px; height: 2px;
  background: rgba(255,244,205,.75);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255,232,160,.65);
  animation: twinkle var(--d,4s) ease-in-out infinite;
  opacity: var(--o,.5);
}
@keyframes twinkle {
  0%, 100% { opacity: calc(var(--o,.5) * .35); transform: scale(.72); box-shadow: 0 0 3px rgba(255,232,160,.25); }
  38% { opacity: var(--o,.5); transform: scale(1.18); box-shadow: 0 0 10px rgba(255,232,160,.72); }
  62% { opacity: calc(var(--o,.5) * .55); transform: scale(.88); box-shadow: 0 0 5px rgba(255,232,160,.4); }
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 clamp(15px,4vw,42px);
  z-index: 30;
  background: linear-gradient(180deg, rgba(6,9,16,.86), rgba(6,9,16,.12));
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-size: 13px;
  color: rgba(247,242,231,.77);
  letter-spacing: .018em;
  min-width: 0;
  white-space: nowrap;
}
.brand-mark { color: var(--gold); font-size: 17px; }
.sound-toggle {
  border: 1px solid var(--line);
  background: rgba(11,15,26,.62);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 11px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  font-size: 12px;
}
.sound-toggle[aria-pressed="true"] { color: var(--gold-bright); border-color: rgba(228,201,135,.52); }

.shell { min-height: 100dvh; }
.screen {
  height: 100dvh;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(var(--topbar-h) + 4px) clamp(14px,4vw,40px) calc(var(--footer-h) + 8px);
}
.screen.active { display: flex; animation: screenIn .42s ease both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.result-screen { height: auto; min-height: 100dvh; padding-top: calc(var(--topbar-h) + 28px); padding-bottom: 70px; }

.hero-card, .thinking-card {
  width: min(720px,100%);
  max-height: calc(100dvh - var(--topbar-h) - var(--footer-h) - 24px);
  text-align: center;
  padding: clamp(22px,3.8vh,40px) clamp(22px,4vw,48px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(255,255,255,.035), transparent 34%), var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  position: relative;
  overflow: hidden;
}
.hero-card::after, .thinking-card::after, .question-card::after, .panel::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(228,201,135,.075);
  border-radius: calc(var(--radius) - 8px);
  pointer-events: none;
}

.eyebrow { color: var(--gold); text-transform: uppercase; font-size: 10px; letter-spacing: .21em; font-weight: 750; }
.sigil { margin: clamp(10px,1.8vh,18px) auto clamp(8px,1.4vh,14px); width: clamp(56px,8vh,76px); height: clamp(56px,8vh,76px); }
.sigil svg { width: 100%; height: 100%; fill: rgba(228,201,135,.18); stroke: var(--gold); stroke-width: 1.2; }
.sigil .sigil-cut { fill: var(--paper-strong); }
.hero-card h1, .result-reveal h2, .certificate-house {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -.035em;
}
.hero-card h1 { font-size: clamp(35px,5.6vw,62px); line-height: 1; }
.lead { max-width: 570px; margin: clamp(10px,1.7vh,17px) auto clamp(12px,2vh,20px); color: var(--muted); font-size: clamp(13px,1.9vw,17px); line-height: 1.48; }
.lead-hook { display:block; color:var(--ink); font-weight:700; letter-spacing:.005em; margin-bottom:5px; }
.lead-detail { display:block; }

.name-field { width: min(420px,100%); margin: 0 auto clamp(10px,1.6vh,16px); text-align: left; }
.name-field label { display: block; font-size: 12px; margin-bottom: 6px; color: var(--ink); }
.name-field input {
  width: 100%;
  border: 1px solid rgba(228,201,135,.24);
  outline: none;
  background: rgba(4,7,13,.46);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  transition: .2s ease;
}
.name-field input:focus { border-color: rgba(228,201,135,.68); box-shadow: 0 0 0 4px rgba(228,201,135,.08); }
.name-field input[aria-invalid="true"] { border-color: rgba(231,164,164,.86); }
.microcopy { margin: 6px 2px 0; color: var(--soft); font-size: 10px; line-height: 1.35; }
.field-error { min-height: 15px; margin: 4px 2px 0; color: #e7a4a4; font-size: 11px; line-height: 1.3; }

.primary-button, .secondary-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  text-decoration: none;
}
.primary-button { color: #17150f; background: linear-gradient(135deg,#f0dda8,#c9a65c); box-shadow: 0 10px 24px rgba(195,153,68,.16); min-width: 215px; font-weight: 750; }
.primary-button:hover, .secondary-button:hover { transform: translateY(-2px); }
.primary-button:active, .secondary-button:active { transform: translateY(0); }
.primary-button:disabled { cursor: wait; opacity: .72; transform: none; }
.secondary-button { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.sound-note { color: var(--soft); font-size: 10px; margin: 8px 0 0; }

.quiz-screen { align-items: flex-start; }
.quiz-wrap { width: min(960px,100%); max-height: calc(100dvh - var(--topbar-h) - var(--footer-h) - 10px); margin-top: clamp(6px, 1.2vh, 12px); }
.quiz-header { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 10px; padding: 0 3px; }
.progress-label { margin-top: 4px; color: var(--muted); font-size: 12px; }
.progress-track { flex: 1; height: 4px; background: rgba(255,255,255,.08); border-radius: 999px; overflow: hidden; max-width: 360px; }
.progress-bar { width: 0; height: 100%; background: linear-gradient(90deg,#a98c50,#edd69d); transition: width .32s ease; }

.question-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: clamp(21px,3.4vh,34px) clamp(18px,3.5vw,38px);
  overflow: hidden;
}
.question-card.special { border-color: rgba(228,201,135,.45); }
.question-kicker { margin: 0 0 7px; color: var(--soft); font-size: 11px; }
.question-card h2 { margin: 0 0 clamp(14px,2.3vh,23px); max-width: 830px; font-family: Georgia,"Times New Roman",serif; font-size: clamp(23px,3.25vw,36px); line-height: 1.16; font-weight: 500; letter-spacing: -.023em; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.answer-button {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  color: var(--ink);
  padding: clamp(11px,1.7vh,15px) 14px;
  cursor: pointer;
  line-height: 1.34;
  min-height: clamp(62px,9.2vh,78px);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(12px,1.35vw,15px);
  transition: .16s ease;
}
.answer-button:hover { border-color: rgba(228,201,135,.43); background: rgba(228,201,135,.065); transform: translateY(-1px); }
.answer-button:focus-visible { outline: 3px solid rgba(228,201,135,.26); outline-offset: 2px; }
.answer-index { width: 24px; height: 24px; border: 1px solid rgba(228,201,135,.3); border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; color: var(--gold); font-size: 10px; }
.answer-button.chosen { border-color: rgba(228,201,135,.84); background: rgba(228,201,135,.11); }
.quiz-nav-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  margin-top: clamp(5px, .9vh, 9px);
}
.quiz-back {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(242,221,167,.88);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .01em;
  padding: 5px 12px 4px;
  cursor: pointer;
  transition: color .16s ease, transform .16s ease, opacity .16s ease;
}
.quiz-back:hover { color: var(--gold-bright); transform: translateY(-1px); }
.quiz-back:focus-visible { outline: 2px solid rgba(228,201,135,.3); outline-offset: 2px; border-radius: 999px; }
.quiz-back.is-hidden { visibility: hidden; pointer-events: none; }
.quiz-back:disabled { opacity: .35; cursor: default; }
.quiz-reset {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(185,189,200,.68);
  font-size: 10px;
  letter-spacing: .035em;
  padding: 5px 10px;
  cursor: pointer;
  transition: color .16s ease, transform .16s ease;
}
.quiz-reset:hover { color: var(--gold-bright); transform: translateY(-1px); }
.quiz-reset:focus-visible { outline: 2px solid rgba(228,201,135,.3); outline-offset: 2px; border-radius: 999px; }

.question-card.exit-left { animation: exitLeft .23s ease forwards; }
.question-card.enter-right { animation: enterRight .3s ease both; }
@keyframes exitLeft { to { opacity: 0; transform: translateX(-12px); } }
@keyframes enterRight { from { opacity: 0; transform: translateX(12px); } }

.thinking-card { min-height: min(420px, calc(100dvh - var(--topbar-h) - var(--footer-h) - 40px)); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.thinking-card h2 { margin: 12px 0 7px; font-family: Georgia,serif; font-weight: 500; font-size: clamp(27px,3.8vw,42px); }
.thinking-card p { color: var(--muted); margin: 5px 0; }
.thinking-ring { width: clamp(76px,10vh,96px); height: clamp(76px,10vh,96px); border-radius: 50%; border: 1px solid rgba(228,201,135,.22); display: grid; place-items: center; margin-bottom: 17px; position: relative; }
.thinking-ring::before, .thinking-ring::after { content:""; position:absolute; inset:8px; border-radius:50%; border:1px dashed rgba(228,201,135,.35); animation:spin 9s linear infinite; }
.thinking-ring::after { inset:18px; animation-direction:reverse; animation-duration:6s; }
.thinking-ring span { color:var(--gold); font-size:22px; }
@keyframes spin { to { transform:rotate(360deg); } }
.thoughts { display:flex; flex-wrap:wrap; justify-content:center; gap:7px; margin-top:18px; }
.thoughts span { border:1px solid rgba(255,255,255,.08); border-radius:999px; padding:6px 9px; color:var(--soft); font-size:10px; animation:pulse 2.8s ease-in-out infinite; }
.thoughts span:nth-child(2){animation-delay:.4s}.thoughts span:nth-child(3){animation-delay:.8s}.thoughts span:nth-child(4){animation-delay:1.2s}
@keyframes pulse { 50% { color:var(--gold-bright); border-color:rgba(228,201,135,.25); } }

.result-wrap { width:min(980px,100%); padding-top:8px; }
.result-reveal { text-align:center; margin-bottom:24px; }
.house-symbol { width:100px; height:100px; margin:17px auto 8px; display:grid; place-items:center; }
.house-symbol svg { width:100%; height:100%; }
.result-reveal h2 { font-size:clamp(50px,7.5vw,88px); line-height:1; }
.result-tagline { margin:11px auto 0; max-width:680px; color:var(--muted); font-family:Georgia,serif; font-size:clamp(17px,2.4vw,23px); line-height:1.4; }
.result-grid { display:grid; grid-template-columns:1.1fr .9fr; gap:14px; }
.panel { position:relative; border:1px solid var(--line); border-radius:20px; background:var(--paper); padding:24px; overflow:hidden; }
.panel-label { color:var(--gold); font-size:10px; text-transform:uppercase; letter-spacing:.18em; font-weight:750; margin-bottom:12px; }
.personality-panel>p { color:var(--muted); font-size:15px; line-height:1.65; margin:0; }
.trait-list { display:flex; flex-wrap:wrap; gap:7px; margin-top:18px; }
.trait { border:1px solid rgba(228,201,135,.22); border-radius:999px; padding:7px 10px; font-size:11px; color:var(--gold-bright); }
.score-row { margin:0 0 13px; }
.score-head { display:flex; justify-content:space-between; gap:12px; margin-bottom:6px; font-size:12px; }
.score-head span:last-child { color:var(--muted); }
.score-track { height:7px; border-radius:999px; background:rgba(255,255,255,.075); overflow:hidden; }
.score-fill { height:100%; border-radius:inherit; transform-origin:left; animation:growBar 1s .15s ease both; }
@keyframes growBar { from { transform:scaleX(0); } to { transform:scaleX(1); } }
.score-note { color:var(--soft); font-size:10px; line-height:1.45; margin:17px 0 0; }

.certificate { margin-top:14px; padding:12px; border-radius:20px; background:rgba(228,201,135,.11); border:1px solid rgba(228,201,135,.25); }
.certificate-inner { min-height:235px; display:grid; place-items:center; align-content:center; text-align:center; border:1px solid rgba(228,201,135,.32); border-radius:13px; padding:25px; background:radial-gradient(circle at 50% 0%,rgba(228,201,135,.08),transparent 42%); }
.certificate-star { color:var(--gold); font-size:23px; margin-bottom:6px; }
.certificate-small { color:var(--gold); text-transform:uppercase; letter-spacing:.22em; font-size:9px; }
.certificate h3 { margin:9px 0 4px; font-family:Georgia,serif; font-size:clamp(25px,3.8vw,38px); font-weight:500; }
.certificate p { margin:0; color:var(--muted); }
.certificate-house { margin-top:10px; font-size:clamp(30px,4.7vw,48px); color:var(--gold-bright); }
.certificate-date { color:var(--soft); font-size:10px; margin-top:10px; }
.result-actions { display:flex; flex-wrap:wrap; justify-content:center; gap:9px; margin:19px 0 0; }
.link-button { font-size:13px; }

.site-footer {
  position:fixed;
  left:0; right:0; bottom:0;
  min-height:var(--footer-h);
  display:flex;
  align-items:center;
  justify-content:center;
  flex-wrap:wrap;
  column-gap:10px;
  row-gap:2px;
  padding:5px 12px max(5px, env(safe-area-inset-bottom));
  color:#6f7582;
  font-size:9px;
  line-height:1.25;
  text-align:center;
  z-index:25;
  background:linear-gradient(0deg,rgba(6,9,16,.96),rgba(6,9,16,.48),rgba(6,9,16,.08));
}
.fan-disclaimer { opacity:.7; max-width:860px; }
.footer-actions { display:inline-flex; align-items:center; justify-content:center; gap:6px; white-space:nowrap; }
.site-footer a, .footer-link { color:#9aa0ab; }
.footer-link { appearance:none; border:0; background:none; padding:0; font:inherit; cursor:pointer; text-decoration:underline; text-underline-offset:2px; }

.legal-dialog { border:0; padding:0; background:transparent; color:var(--ink); width:min(620px,calc(100% - 28px)); }
.legal-dialog::backdrop { background:rgba(2,4,8,.78); backdrop-filter:blur(6px); }
.legal-card { position:relative; border:1px solid var(--line); border-radius:20px; background:#111827; box-shadow:var(--shadow); padding:28px; }
.legal-card h2 { margin:0 0 14px; font-family:Georgia,serif; font-weight:500; }
.legal-card p { color:var(--muted); font-size:13px; line-height:1.6; }
.dialog-close { position:absolute; top:10px; right:12px; width:34px; height:34px; border-radius:50%; border:1px solid var(--line); background:transparent; color:var(--ink); cursor:pointer; font-size:22px; }

@media (max-width: 720px) {
  :root { --topbar-h: 52px; --footer-h: 62px; }
  .topbar { padding:0 12px; }
  .brand { font-size:10.5px; max-width:calc(100vw - 126px); overflow:hidden; text-overflow:ellipsis; }
  .sound-toggle { padding:6px 8px; font-size:11px; }
  .screen { padding-left:10px; padding-right:10px; }
  .hero-card, .thinking-card { border-radius:19px; padding:clamp(16px,2.8vh,25px) 16px; }
  .hero-card h1 { font-size:clamp(31px,9.2vw,47px); }
  .lead { font-size:12px; line-height:1.38; }
  .sigil { width:clamp(45px,7vh,58px); height:clamp(45px,7vh,58px); }
  .name-field input { padding:10px 12px; }
  .microcopy { font-size:9px; }
  .question-card { border-radius:19px; padding:16px 13px; }
  .question-card h2 { font-size:clamp(20px,5.6vw,28px); margin-bottom:12px; }
  .quiz-header { margin-bottom:7px; }
  .progress-track { max-width:120px; }
  .answers { grid-template-columns:1fr; gap:6px; }
  .answer-button { min-height:0; padding:9px 10px; font-size:11px; line-height:1.25; border-radius:11px; }
  .answer-index { width:21px; height:21px; font-size:9px; }
  .quiz-wrap { margin-top: 2px; }
  .quiz-nav-stack { margin-top: 2px; gap: 0; }
  .quiz-back { padding: 3px 8px 2px; font-size: 11px; }
  .quiz-reset { padding: 2px 8px; font-size: 9px; }
  .site-footer { font-size: 7.5px; line-height: 1.18; padding-left: 8px; padding-right: 8px; }
  .fan-disclaimer { width: 100%; max-width: 680px; }
  .result-grid { grid-template-columns:1fr; }
  .panel { padding:20px 17px; }
  .certificate { padding:7px; }
  .certificate-inner { padding:22px 14px; }
  .result-actions>* { width:100%; }
  .site-footer { font-size:9px; }
}

@media (max-height: 740px) and (min-width: 721px) {
  .hero-card { padding-top:20px; padding-bottom:20px; }
  .sigil { width:52px; height:52px; margin-top:9px; margin-bottom:7px; }
  .hero-card h1 { font-size:42px; }
  .lead { margin:9px auto 12px; font-size:13px; line-height:1.35; }
  .name-field { margin-bottom:9px; }
  .microcopy { font-size:9px; }
  .sound-note { margin-top:5px; }
  .question-card { padding-top:18px; padding-bottom:18px; }
  .question-card h2 { font-size:28px; margin-bottom:12px; }
  .answer-button { min-height:58px; padding:9px 12px; font-size:12px; }
}

@media (max-height: 680px) and (max-width: 720px) {
  .hero-card { padding-top:12px; padding-bottom:12px; }
  .eyebrow { font-size:8px; }
  .sigil { width:38px; height:38px; margin:5px auto; }
  .hero-card h1 { font-size:29px; }
  .lead { margin:6px auto 8px; font-size:10px; }
  .name-field { margin-bottom:5px; }
  .name-field label { font-size:10px; margin-bottom:4px; }
  .name-field input { padding:8px 10px; font-size:12px; }
  .microcopy { margin-top:4px; font-size:8px; line-height:1.25; }
  .field-error { min-height:11px; font-size:9px; margin-top:2px; }
  .primary-button { padding:9px 15px; min-width:190px; font-size:12px; }
  .sound-note { font-size:8px; margin-top:4px; }
  .question-kicker { font-size:9px; margin-bottom:4px; }
  .question-card h2 { font-size:18px; margin-bottom:7px; }
  .answer-button { padding:6px 8px; font-size:9px; line-height:1.18; gap:7px; }
  .answer-index { width:18px; height:18px; font-size:8px; }
  .quiz-header { margin-bottom:4px; }
  .progress-label { font-size:9px; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { animation-duration:.001ms !important; animation-iteration-count:1 !important; scroll-behavior:auto !important; }
}

@media print {
  body { background:white !important; color:#111 !important; overflow:visible !important; }
  body::before,.ambient,.topbar,.site-footer,.result-reveal,.result-grid,.result-actions { display:none !important; }
  .screen { display:none !important; height:auto; min-height:auto; padding:0; }
  #resultScreen { display:block !important; }
  .result-wrap { width:100%; padding:0; }
  .certificate { margin:0; background:white; border:2px solid #8c7749; color:#111; }
  .certificate-inner { min-height:80vh; border-color:#8c7749; background:white; }
  .certificate p,.certificate-date { color:#444; }
  .certificate-house,.certificate-small,.certificate-star { color:#7d642d; }
}
