/* ==========================================================
   RESET
========================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #b4aff3;
  --card: #566fb8;
  --text: #000;
  --accent: #b4aff3;
  --result-theme: var(--bg);

  --overlay-bg: rgba(6, 10, 22, 0.96);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.16);
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overflow-x: hidden;

  background: radial-gradient(
    circle at top,
    color-mix(in srgb, var(--result-theme, var(--bg)), white 70%),
    var(--bg) 55%
  );

  color: var(--text);

  font-family: "Crimson Text", Georgia, serif;

  line-height: 1.5;
}

/* ==========================================================
   SCREEN SYSTEM
========================================================== */

.app-screen {
  display: none;
  min-height: 100vh;
}

.app-screen.active {
  display: block;
}

/* ==========================================================
   HEADER / LAYOUT
========================================================== */

.header {
  padding: 1.5rem 1rem 0.65rem;
  text-align: center;
}

.header h1 {
  margin: 0;
}

main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem 1rem 2rem;
}

/* ==========================================================
   SCREEN TOOLBARS
========================================================== */

.screen-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  margin-right: auto;
  margin-left: auto;
}

.quiz-toolbar {
  margin-top: 0;
  margin-bottom: 0.35rem;
}

.results-toolbar {
  margin-top: 0;
  margin-bottom: 1.75rem;
}

/* ==========================================================
   PROGRESS
========================================================== */

.progress-wrapper {
  margin-top: 0;
  margin-bottom: 2rem;
}

.progress-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

#quiz-progress {
  display: block;
  width: 100%;
  height: 14px;
}

.progress-text {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.95rem;
}

/* ==========================================================
   QUIZ
========================================================== */

.vn-question-card {
  padding: 1.5rem;

  border-radius: 16px;

  background: var(--card);

  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.14);
}

.question-title {
  margin-top: 0;
}

.vn-answer-list {
  display: grid;
  gap: 0.75rem;
}

.vn-choice {
  display: flex;
  align-items: center;
  gap: 0.75rem;

  padding: 0.75rem 0.9rem;

  border-radius: 10px;

  background: rgba(255, 255, 255, 0.18);

  cursor: pointer;

  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.vn-choice:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: translateX(4px);
}

.vn-choice:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.vn-choice input {
  flex-shrink: 0;
}

.vn-choice span {
  flex: 1;
}

.vn-navigation {
  display: flex;
  justify-content: center;
  gap: 1rem;

  margin-top: 1.5rem;
}

.vn-navigation button {
  flex: 0 0 auto;
  min-width: 110px;
  padding: 0.7rem 1.5rem;
  border-radius: 999px;
}

/* ==========================================================
   BUTTONS
========================================================== */

.actions,
.results-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;

  margin-top: 2rem;
}

button {
  padding: 0.8rem 1.3rem;

  border: none;
  border-radius: 10px;

  background: var(--card);
  color: var(--text);

  font: inherit;
  font-weight: 600;

  cursor: pointer;

  transition:
    transform 0.2s ease,
    filter 0.2s ease;
}

button:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ==========================================================
   MUSIC TOGGLES
========================================================== */

.music-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;

  width: auto;
  min-height: 44px;
  padding: 0.55rem 1rem;
  margin: 0;

  border: none;
  outline: none;
  box-shadow: none;
  border-radius: 999px;

  background: rgba(255, 255, 255, 0.22);

  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);

  color: #222;

  font: inherit;
  font-weight: 600;

  cursor: pointer;

  opacity: 0.82;

  transition:
    background 0.2s ease,
    opacity 0.2s ease,
    transform 0.15s ease,
    filter 0.2s ease;
}

.music-toggle:hover {
  background: rgba(255, 255, 255, 0.35);
  opacity: 1;
  transform: none;
}

.music-toggle:active {
  transform: scale(0.97);
}

.music-toggle[aria-pressed="false"] {
  opacity: 0.68;
}

.music-toggle:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* ==========================================================
   QUIZ PREFERENCES
========================================================== */

.quiz-preferences {
  display: flex;
  justify-content: center;

  margin: 2rem 0 0;
}

.quiz-toggle {
  display: flex;
  align-items: center;
  gap: 0.65rem;

  padding: 0.8rem 1.2rem;

  border-radius: 999px;

  background: rgba(255, 255, 255, 0.14);

  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);

  font-weight: 600;

  cursor: pointer;
  user-select: none;
}

.quiz-toggle input {
  accent-color: var(--accent);
}

/* ==========================================================
   RESULTS
========================================================== */

#results-container {
  display: grid;
  gap: 1rem;

  margin-bottom: 2rem;
}

.result-card {
  padding: 1rem;

  border-radius: 14px;
  border-right: 6px solid var(--card-accent);

  /* Remains uniformly blue. */
  background: var(--card);

  opacity: 1;
  transform: translateY(0);
}

.result-title {
  display: flex;
  justify-content: space-between;
  align-items: center;

  margin-bottom: 0.75rem;

  font-weight: 700;
}

.result-card-heading {
  margin: 0 0 0.75rem;

  color: var(--card-accent);

  font-weight: 700;

  /*
   A restrained dark shadow improves readability without
   creating a white outline around the letters.
   */
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.48);
}

.result-description {
  margin-top: 0.85rem;
  line-height: 1.55;
}

.top-result-card {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--card-accent), transparent 42%);
}

/* ==========================================================
   RESULT BARS
========================================================== */

.bar {
  width: 100%;
  height: 12px;

  overflow: hidden;

  border-radius: 999px;

  background: rgba(0, 0, 0, 0.18);
}

.bar-fill {
  width: 0%;
  height: 100%;

  background: var(--card-accent);

  transition: width 0.9s ease;
}

/* ==========================================================
   HERO RESULT
========================================================== */

.result-hero {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: center;

  margin-bottom: 1.5rem;
  padding: 1.5rem;

  overflow: hidden;

  border: 1px solid color-mix(in srgb, var(--hero-color), transparent 45%);

  border-right: 8px solid var(--hero-color);
  border-radius: 18px;

  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--hero-color), white 88%),
    rgba(255, 255, 255, 0.62)
  );

  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.16);

  opacity: 0;
  transform: translateY(24px) scale(0.98);

  transition:
    opacity 0.75s ease,
    transform 0.75s ease;
}

.result-hero.reveal {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.result-hero-portrait {
  display: block;

  width: 100%;
  max-width: 240px;
  aspect-ratio: 4 / 5;

  margin: 0 auto;
  padding: 0.35rem;

  object-fit: contain;
  object-position: center;

  border-radius: 18px;

  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent), white 40%),
    color-mix(in srgb, var(--accent), black 20%)
  );

  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.35),
    0 12px 30px rgba(0, 0, 0, 0.22);
}

.result-hero-portrait.placeholder {
  position: relative;
}

.result-hero-portrait.placeholder::after {
  content: "Portrait coming soon";

  position: absolute;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 1rem;

  color: rgba(255, 255, 255, 0.85);

  font-weight: 700;
  text-align: center;
}

.result-hero-copy {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;

  min-width: 0;
}

.result-kicker {
  margin: 0;

  font-size: 0.95rem;
  font-weight: 700;

  letter-spacing: 0.08em;
  text-transform: uppercase;

  opacity: 0.75;
}

.result-hero-name {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: "Alex Brush", cursive;
  font-size: clamp(2.2rem, 5.5vw, 4rem);
  font-weight: 400;
  line-height: 1.1;
}

.result-hero-heading {
  margin: 0;

  color: var(--hero-color);

  font-size: 1.25rem;
  font-weight: 800;

  text-shadow: none;
}

.result-hero-quote {
  margin: 0.75rem 0 0;

  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.55;
}

/* ==========================================================
   CINEMATIC OVERLAY
========================================================== */

.fate-overlay {
  position: fixed;
  inset: 0;

  z-index: 9999;

  display: flex;
  align-items: center;
  justify-content: center;

  overflow-y: auto;

  padding: 2rem;

  background: var(--overlay-bg);
}

.hidden {
  display: none !important;
}

.fate-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;

  width: min(92vw, 760px);
  margin: auto;

  text-align: center;
}

.fate-text {
  min-height: 4rem;

  color: white;

  font-size: clamp(1.8rem, 3vw, 2.5rem);
  font-weight: 600;

  letter-spacing: 0.03em;

  opacity: 0;
  transform: translateY(10px) scale(0.98);

  transition:
    opacity 0.45s ease,
    transform 0.45s ease;

  text-shadow:
    0 0 14px rgba(255, 255, 255, 0.35),
    0 0 28px rgba(255, 255, 255, 0.15);
}

.fate-text.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ==========================================================
   IDENTITY REVEAL
========================================================== */

.identity-reveal {
  display: grid;
  justify-items: center;
  gap: 0.75rem;

  width: 100%;
  max-width: 760px;
}

.identity-kicker {
  margin: 0;

  font-size: clamp(1.1rem, 2vw, 1.45rem);
  font-weight: 700;

  letter-spacing: 0.12em;
  text-transform: uppercase;

  opacity: 0.82;
}

.identity-name {
  margin: 0;
  color: #fff;
  overflow-wrap: anywhere;
  font-family: "Alex Brush", cursive;
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  font-weight: 400;
  line-height: 1.1;
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.88),
    0 0 22px rgba(255, 255, 255, 0.2);
}

.identity-heading {
  margin: 0;

  color: var(--cinematic-color, #fff);

  font-size: clamp(1.25rem, 3vw, 2rem);
  font-style: italic;
  font-weight: 700;

  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.92);
}

.identity-quote {
  max-width: 680px;

  margin: 0.5rem 0 0;

  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-style: italic;
  line-height: 1.55;

  opacity: 0.94;
}

.identity-quote::after {
  content: "";

  display: inline-block;

  width: 0.55ch;
}

.identity-portrait {
  display: block;

  width: min(260px, 54vw);
  max-height: 42vh;
  aspect-ratio: 4 / 5;

  margin-top: 1rem;
  padding: 0.35rem;

  object-fit: contain;
  object-position: center;

  border-radius: 22px;

  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent), white 35%),
    color-mix(in srgb, var(--accent), black 28%)
  );

  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.25),
    0 0 40px color-mix(in srgb, var(--accent), transparent 20%),
    0 16px 42px rgba(0, 0, 0, 0.4);

  animation: portraitReveal 0.9s ease forwards;
}

.identity-portrait-placeholder {
  position: relative;
}

.identity-portrait-placeholder::after {
  content: "Portrait coming soon";

  position: absolute;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 1rem;

  color: rgba(255, 255, 255, 0.85);

  font-size: 0.95rem;
  font-weight: 700;
}

@keyframes portraitReveal {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==========================================================
   PORTRAIT REVEAL PULSE
========================================================== */

.identity-portrait.pulse,
.result-hero-portrait.pulse {
  animation:
    portraitReveal 0.9s ease forwards,
    portraitPulse 0.9s 0.15s ease-out;
}

@keyframes portraitPulse {
  0% {
    box-shadow:
      0 0 0 5px rgba(255, 255, 255, 0.25),
      0 0 28px color-mix(in srgb, var(--accent), transparent 35%),
      0 16px 42px rgba(0, 0, 0, 0.4);
  }

  55% {
    box-shadow:
      0 0 0 7px rgba(255, 255, 255, 0.38),
      0 0 70px color-mix(in srgb, var(--accent), transparent 5%),
      0 18px 48px rgba(0, 0, 0, 0.44);
  }

  100% {
    box-shadow:
      0 0 0 5px rgba(255, 255, 255, 0.25),
      0 0 40px color-mix(in srgb, var(--accent), transparent 20%),
      0 16px 42px rgba(0, 0, 0, 0.4);
  }
}

/* ==========================================================
   OPTIONAL OVERLAY CONTROL PANEL
========================================================== */

.overlay-controls {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;

  padding: 1.25rem 1.6rem;

  border: 1px solid var(--glass-border);
  border-radius: 16px;

  background: var(--glass);

  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);

  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
}

.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 0.7rem;

  color: white;

  font-size: 0.98rem;

  cursor: pointer;
  user-select: none;
}

.overlay-toggle input {
  width: 18px;
  height: 18px;

  accent-color: var(--accent);

  cursor: pointer;
}

/* ==========================================================
   CINEMATIC REVEAL ANIMATION
========================================================== */

.cinematic-mode .result-hero,
.cinematic-mode .result-card {
  opacity: 0;
  transform: translateY(18px) scale(0.98);

  pointer-events: none;

  transition:
    opacity 0.6s ease,
    transform 0.6s ease;
}

.cinematic-mode .result-hero.reveal,
.cinematic-mode .result-card.reveal {
  opacity: 1;
  transform: translateY(0) scale(1);

  pointer-events: auto;
}

/* ==========================================================
   RESULTS SCREEN TRANSITIONS
========================================================== */

#results-section {
  animation: resultsFade 0.45s ease;
}

@keyframes resultsFade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ==========================================================
   ACCESSIBILITY
========================================================== */

.sr-only {
  position: absolute;

  width: 1px;
  height: 1px;

  margin: -1px;
  padding: 0;

  overflow: hidden;

  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);

  white-space: nowrap;

  border: 0;
}

/* ==========================================================
   MOBILE
========================================================== */

@media (max-width: 640px) {
  .header {
    padding: 1rem 1rem 0.5rem;
  }

  main {
    padding: 0.5rem 1rem 1rem;
  }

  .quiz-toolbar {
    margin-bottom: 0.25rem;
  }

  .results-toolbar {
    margin-bottom: 1.25rem;
  }

  .fate-overlay {
    align-items: flex-start;
    padding: 1rem;
  }

  .fate-overlay-content {
    gap: 1.5rem;
  }

  .overlay-controls {
    width: 100%;
  }

  .results-actions,
  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .music-toggle {
    width: auto;
  }

  .vn-navigation {
    flex-direction: column;
  }

  .vn-navigation button {
    flex: 0 0 auto;
    min-width: 110px;
    padding: 0.7rem 1.5rem;
    border-radius: 999px;
  }

  .result-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .result-hero {
    grid-template-columns: 1fr;

    padding: 1.1rem;

    text-align: center;
  }

  .result-hero-portrait {
    width: min(220px, 75vw);
    max-width: 220px;
    margin: 0 auto;
  }

  .result-hero-copy {
    align-items: center;
  }

  .identity-portrait {
    width: min(220px, 65vw);
    max-height: 38vh;
  }
}

/* ==========================================================
   REDUCED MOTION
========================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  .fate-text,
  .result-hero,
  .result-card,
  .result-card.reveal,
  .result-hero.reveal {
    opacity: 1;
    transform: none;
  }
}

.identity-quote em,
.result-hero-quote em,
.result-description em {
  font-style: italic;
  font-weight: 700;
  color: var(--accent);
}

/* ==========================================================
   HIDE PAGE UI DURING CINEMATIC
========================================================== */

.cinematic-mode .header,
.cinematic-mode #quiz-section,
.cinematic-mode #results-section > :not(#fate-overlay) {
  visibility: hidden;
}

.cinematic-mode #fate-overlay {
  visibility: visible;
}
