/* ============================================================
   quiz.css - "How Healthy Is Your Home?" standalone quiz
   Shares design tokens with new-style.css (purple gradient,
   Inter, gray scale) but is intentionally self-contained:
   no site nav, footer or branding.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple: #5D00DE;
  --purple-end: #8A0D3D;
  --purple-dark: #4800B0;
  --purple-pale: #F3EEFF;
  --gradient: linear-gradient(150deg, #5D00DE 0%, #8A0D3D 100%);
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --green: #16A34A;
  --amber: #D97706;
  --red: #DC2626;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(17, 24, 39, 0.08);
}

html { -webkit-text-size-adjust: 100%; }

body.quiz-body {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--gray-900);
  background: linear-gradient(140deg, #F3EEFF 0%, #F5E8F7 45%, #fff 100%);
  min-height: 100dvh;
  overflow-x: hidden;
}

.quiz-shell {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.25rem 2rem;
  position: relative;
}

/* ---------- progress bar ---------- */

.quiz-progress {
  display: none;
  align-items: center;
  gap: 0.85rem;
  padding: 0.5rem 0 1.25rem;
}
.quiz-progress.visible { display: flex; }
.quiz-progress-track {
  flex: 1;
  height: 10px;
  background: rgba(93, 0, 222, 0.12);
  border-radius: 6px;
  overflow: hidden;
}
.quiz-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient);
  border-radius: 6px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.quiz-progress-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--purple);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- screens ---------- */

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
}
.screen.active { display: flex; animation: screenIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }
.screen.leaving { animation: screenOut 0.22s ease both; }
.screen.active.from-back { animation-name: screenInBack; }

@keyframes screenIn {
  from { opacity: 0; transform: translateX(36px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes screenInBack {
  from { opacity: 0; transform: translateX(-36px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes screenOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ---------- intro ---------- */

.intro-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 1.4rem;
  padding: 2rem 0.5rem 3rem;
}
.intro-emoji { font-size: 4rem; animation: floaty 3s ease-in-out infinite; }
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.intro-screen h1 {
  font-size: clamp(2.1rem, 8vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.08;
}
.intro-screen h1 em {
  font-style: normal;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}
.intro-sub {
  font-size: 1.05rem;
  color: var(--gray-600);
  line-height: 1.7;
  max-width: 30rem;
}
.intro-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}
.intro-pill {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

.btn-big {
  display: inline-block;
  background: var(--gradient);
  color: #fff;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  padding: 1.05rem 2.6rem;
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(93, 0, 222, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  text-align: center;
}
.btn-big:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(93, 0, 222, 0.42); }
.btn-big:active { transform: translateY(0) scale(0.98); }

.btn-ghost {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-500);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: color 0.15s;
}
.btn-ghost:hover { color: var(--purple); }

/* ---------- question ---------- */

.q-header { text-align: center; margin-bottom: 1.5rem; }
.q-emoji { font-size: 2.6rem; display: block; margin-bottom: 0.7rem; }
.q-text {
  font-size: clamp(1.3rem, 5vw, 1.65rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.q-options { display: flex; flex-direction: column; gap: 0.75rem; }

/* compact two-column layout for long option lists (e.g. the 15 NZ regions) */
.q-options.compact { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }
.q-options.compact .answer-btn { padding: 0.75rem 0.85rem; font-size: 0.86rem; gap: 0.55rem; }
.q-options.compact .answer-key { width: 1.5rem; height: 1.5rem; font-size: 0.7rem; }

.answer-row { display: flex; align-items: stretch; gap: 0.5rem; }

.answer-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-align: left;
  background: #fff;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
  animation: optionIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.answer-btn:nth-child(1) { animation-delay: 0.03s; }
.q-options .answer-row:nth-child(2) .answer-btn { animation-delay: 0.07s; }
.q-options .answer-row:nth-child(3) .answer-btn { animation-delay: 0.11s; }
.q-options .answer-row:nth-child(4) .answer-btn { animation-delay: 0.15s; }
.q-options .answer-row:nth-child(5) .answer-btn { animation-delay: 0.19s; }

@keyframes optionIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (hover: hover) {
  .answer-btn:hover { border-color: var(--purple); transform: translateY(-2px); }
}
.answer-btn.selected {
  border-color: var(--purple);
  background: var(--purple-pale);
  color: var(--purple-dark);
  animation: pop 0.25s ease;
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

.answer-key {
  flex-shrink: 0;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 8px;
  background: var(--gray-100);
  color: var(--gray-500);
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.answer-btn.selected .answer-key { background: var(--purple); color: #fff; }

.tip-btn {
  flex-shrink: 0;
  width: 44px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: #fff;
  color: var(--gray-400);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tip-btn:hover, .tip-btn.open { color: var(--purple); border-color: var(--purple); }

.tip-panel {
  display: none;
  margin-top: 0.9rem;
  background: #FFF8E6;
  border: 1px solid #F0E0B0;
  border-radius: 12px;
  padding: 0.8rem 1rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: #6B5518;
}
.tip-panel.open { display: block; animation: optionIn 0.25s ease both; }

.q-footer { margin-top: 1.5rem; display: flex; justify-content: space-between; align-items: center; }

/* ---------- result ---------- */

.result-screen { align-items: center; text-align: center; padding-top: 1rem; gap: 1.1rem; }

.score-ring-wrap { position: relative; width: 230px; height: 230px; }
.score-ring { transform: rotate(-90deg); width: 100%; height: 100%; }
.score-ring .ring-bg { fill: none; stroke: rgba(93, 0, 222, 0.1); stroke-width: 16; }
.score-ring .ring-fill {
  fill: none;
  stroke: url(#ringGradient);
  stroke-width: 16;
  stroke-linecap: round;
}
.score-ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.score-number {
  font-size: 4rem;
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 1;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-variant-numeric: tabular-nums;
}
.score-outof { font-size: 0.85rem; font-weight: 700; color: var(--gray-400); margin-top: 0.3rem; }

.result-band { font-size: 1.6rem; font-weight: 900; letter-spacing: -0.02em; }
.result-message { color: var(--gray-600); line-height: 1.7; max-width: 30rem; }

.rank-card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.4rem;
  max-width: 30rem;
  width: 100%;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--gray-700);
}
.rank-card strong { color: var(--purple); }
.rank-card .rank-headline { font-size: 1.05rem; font-weight: 800; color: var(--gray-900); margin-bottom: 0.2rem; }

.share-row { display: flex; gap: 0.7rem; flex-wrap: wrap; justify-content: center; width: 100%; }
.share-btn {
  flex: 1;
  min-width: 140px;
  max-width: 240px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.15s ease;
  text-decoration: none;
}
.share-btn:active { transform: scale(0.97); }
.share-btn.primary { background: var(--gradient); color: #fff; border: none; box-shadow: 0 8px 20px rgba(93, 0, 222, 0.3); }
.share-btn.secondary { background: #fff; color: var(--purple-dark); border: 2px solid var(--purple); }

.share-url {
  width: 100%;
  max-width: 30rem;
  background: #fff;
  border: 1px dashed var(--gray-400);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 0.82rem;
  color: var(--gray-500);
  word-break: break-all;
  user-select: all;
}

/* emoji confetti burst */
.confetti-piece {
  position: fixed;
  top: 40%;
  left: 50%;
  font-size: 1.6rem;
  pointer-events: none;
  z-index: 50;
  animation: confetti 1.4s cubic-bezier(0.15, 0.6, 0.4, 1) both;
}
@keyframes confetti {
  from { transform: translate(0, 0) rotate(0deg) scale(0.6); opacity: 1; }
  to   { transform: translate(var(--cx), var(--cy)) rotate(var(--cr)) scale(1.2); opacity: 0; }
}

/* ---------- footer note ---------- */

.quiz-footnote {
  text-align: center;
  font-size: 0.75rem;
  color: var(--gray-400);
  padding-top: 2rem;
  margin-top: auto;
  line-height: 1.6;
}

/* ---------- loading spinner ---------- */

.saving-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(93, 0, 222, 0.15);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-note { color: var(--red); font-size: 0.9rem; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

@media (max-width: 420px) {
  .quiz-shell { padding: 1rem 0.9rem 1.5rem; }
  .score-ring-wrap { width: 200px; height: 200px; }
  .score-number { font-size: 3.4rem; }
}

/* ---------- what to fix first ---------- */

.fix-first { width: 100%; max-width: 30rem; }

.fix-first-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  padding: 0.95rem 1.2rem;
  border-radius: 12px;
  border: 2px solid var(--purple);
  background: var(--purple-pale);
  color: var(--purple-dark);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.fix-first-toggle:active { transform: scale(0.98); }
.fix-first-caret { font-size: 0.8rem; transition: transform 0.2s ease; }
.fix-first-toggle.open .fix-first-caret { transform: rotate(180deg); }

.fix-first-panel { margin-top: 0.9rem; text-align: left; }

.fix-first-intro {
  font-size: 0.92rem;
  color: var(--gray-600);
  line-height: 1.6;
  text-align: center;
  margin-bottom: 0.9rem;
}

.fix-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0;
  margin: 0;
}

.fix-item {
  display: flex;
  gap: 0.85rem;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.fix-rank {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  margin-top: 0.1rem;
}

.fix-item-main { min-width: 0; }

.fix-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.fix-item-head h3 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--gray-900);
}
.fix-emoji { margin-right: 0.4rem; }

.fix-price {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--purple-dark);
  background: var(--purple-pale);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  white-space: nowrap;
}

.fix-why {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--purple-dark);
  line-height: 1.55;
  margin-top: 0.35rem;
}

.fix-body { font-size: 0.88rem; color: var(--gray-600); line-height: 1.6; margin-top: 0.35rem; }
.fix-body ul { padding-left: 1.2rem; margin: 0.3rem 0; }

.fix-divider {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.4rem;
}
.fix-divider::before,
.fix-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

.fix-item.is-done { padding: 0.7rem 1.1rem; box-shadow: none; background: var(--gray-100); border-color: transparent; }
.fix-item.is-done .fix-item-head h3 { color: var(--gray-500); font-weight: 700; }
.fix-rank-done { background: var(--green); }
