/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

img,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Typography */
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-body);
  background: var(--bg-gradient-page);
}

h1 {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-headline);
  margin: 0;
}

h2 {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-headline);
  margin: 0;
}

p {
  margin: 0;
}

/* Fluid Container */
.container {
  width: min(100% - 32px, 560px);
  margin-inline: auto;
}

/* Buttons */
.btn-primary {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1.5px;
  color: var(--text-on-gold);
  background: var(--gradient-cta);
  border: 1px solid var(--gold-bronze);
  border-radius: var(--radius-md);
  padding: 14px 32px;
  min-height: 48px;
  box-shadow: var(--shadow-cta);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: filter 150ms ease, transform 100ms ease;
  outline: none;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transition: none;
}

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) {
    filter: brightness(1.06);
  }

  .btn-primary:active:not(:disabled) {
    transform: translateY(1px);
  }
}

.btn-secondary {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 1.5px;
  color: #e7c273;
  background: linear-gradient(160deg, #2b2113, #1c150c);
  border: 1px solid #6a4c22;
  border-radius: var(--radius-md);
  padding: 14px 32px;
  min-height: 48px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 150ms ease;
  outline: none;
}

@media (hover: hover) {
  .btn-secondary:hover {
    border-color: var(--gold-warm);
  }
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
textarea,
select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text-headline);
  background: var(--bg-input);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  outline: none;
  transition: border-color 150ms ease;
}

input[type="text"]::placeholder,
input[type="email"]::placeholder,
input[type="password"]::placeholder,
input[type="tel"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  border-color: var(--gold-bright);
  outline: var(--focus-ring);
  outline-offset: 2px;
}

input[type="text"]:invalid,
input[type="email"]:invalid,
input[type="password"]:invalid,
input[type="tel"]:invalid,
input[type="number"]:invalid,
textarea:invalid,
select:invalid {
  border-color: var(--error-border);
  border-width: 2px;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"],
select[aria-invalid="true"] {
  border-color: var(--error-border);
  border-width: 2px;
}

textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.5;
}

select {
  appearance: none;
  color-scheme: dark;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23f0d488' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

select option {
  background: #241a0c;
  color: #f4e6c4;
  padding: 8px 12px;
  line-height: 1.5;
}

/* Field Error */
.field-error {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--error-text);
  margin: 0;
  margin-top: var(--space-sm);
}

/* Focus Visible */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* Card */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  padding: var(--space-lg);
}

/* Radio Button (custom) */
input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

input[type="radio"] + label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  cursor: pointer;
  min-height: 44px;
}

input[type="radio"] + label::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--gold-warm);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  transition: all 150ms ease;
}

input[type="radio"]:checked + label::before {
  background: var(--gold-bright);
  border-color: var(--gold-bronze);
  box-shadow: inset 0 0 0 4px var(--bg-card);
}

/* Keyboard focus lands on the hidden input — ring the visible circle instead */
input[type="radio"]:focus-visible + label::before,
input[type="checkbox"]:focus-visible + label::before {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

/* Checkbox (custom) */
input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

input[type="checkbox"] + label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  cursor: pointer;
  min-height: 44px;
  line-height: 1.5;
}

input[type="checkbox"] + label::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--gold-warm);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  transition: all 150ms ease;
}

input[type="checkbox"]:checked + label::before {
  background: var(--gold-bright);
  border-color: var(--gold-bronze);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Cpath stroke='%23241a0c' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' fill='none' d='M5 11l3 3 9-9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px;
}

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

/* Links */
a {
  color: var(--gold-bright);
  text-decoration: underline;
}

@media (hover: hover) {
  a:hover {
    color: var(--text-headline);
  }
}

/* Labels */
label {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-label);
  text-transform: uppercase;
  display: block;
  margin-bottom: var(--space-sm);
}

/* Form Groups */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* CTA Pair */
.cta-pair {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: center;
}

.cta-pair .btn-primary,
.cta-pair .btn-secondary {
  flex: 1 1 calc(50% - var(--space-sm));
}

/* Video Modal Overlay */
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 200ms ease;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes scale-up {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(4px);
  z-index: 1;
  cursor: pointer;
}

.video-modal-content {
  position: relative;
  z-index: 2;
  width: min(90vw, 800px);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  animation: scale-up 200ms ease;
}

.video-modal-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.video-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  color: #f0e6c4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
  opacity: 0;
}

.video-modal-content:hover .video-modal-close,
.video-modal-close:focus {
  opacity: 1;
}

/* Touch devices have no hover — keep the close button visible */
@media (hover: none) {
  .video-modal-close {
    opacity: 1;
  }
}

.video-modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
  color: #f4d488;
}

.video-modal-close:focus {
  outline: 2px solid #f4d488;
  outline-offset: 2px;
}

.video-modal-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border: none;
  cursor: pointer;
  color: #f4d488;
  transition: all 150ms ease;
  z-index: 2;
}

.video-modal-play-overlay:hover {
  background: rgba(0, 0, 0, 0.6);
  color: #f4e6c4;
}

.video-modal-play-overlay:focus {
  outline: 2px solid #f4d488;
  outline-offset: -4px;
}

.video-modal-error {
  position: absolute;
  inset: auto 16px 16px 16px;
  z-index: 4;
  padding: var(--space-sm) var(--space-md);
  background: rgba(0, 0, 0, 0.85);
  color: #f0e6c4;
  font-family: var(--font-body);
  font-size: 14px;
  text-align: center;
  border-radius: var(--radius-sm);
}

/* Page-level load failure (utils.js showPageLoadError). Transient network/DB
   errors surface here instead of redirecting an authenticated pilgrim away. */
.page-load-error {
  position: fixed;
  inset: auto 16px 16px 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  max-width: 420px;
  margin: 0 auto;
  padding: var(--space-md);
  background: rgba(0, 0, 0, 0.9);
  color: #f0e6c4;
  font-family: var(--font-body);
  font-size: 14px;
  text-align: center;
  border-radius: var(--radius-sm);
}

.page-load-error-retry {
  padding: var(--space-xs) var(--space-md);
  background: transparent;
  color: #f4d488;
  font-family: var(--font-body);
  font-size: 14px;
  border: 1px solid #f4d488;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.page-load-error-retry:focus-visible {
  outline: 2px solid #f4d488;
  outline-offset: 2px;
}

/* Fade out animation when closing */
.video-modal.closing {
  animation: fade-out 200ms ease;
}

.video-modal.closing .video-modal-content {
  animation: scale-up 200ms ease reverse;
}

/* Phase I intro modal (bug #19) — reuses .video-modal-content's overlay
   chrome but needs a text-friendly box instead of a fixed 16:9 black frame. */
.phase-intro-modal-content {
  aspect-ratio: auto;
  background: #1c1508;
  padding: var(--space-lg, 32px) var(--space-md, 24px);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 12px);
  max-height: 80vh;
  overflow-y: auto;
}

.phase-intro-title {
  color: #f4d488;
  font-family: var(--font-display, serif);
  font-size: 22px;
  margin: 0;
  padding-right: 40px;
}

.phase-intro-text {
  color: #f0e6c4;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  margin: 0;
}

.phase-intro-watch-btn {
  align-self: flex-start;
  margin-top: var(--space-sm, 12px);
  padding: 10px 20px;
  border-radius: var(--radius-sm, 8px);
  border: none;
  background: #f4d488;
  color: #1c1508;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease;
}

.phase-intro-watch-btn:hover {
  background: #f4e6c4;
}

/* Responsive: Mobile video modal */
@media (max-width: 600px) {
  .video-modal-content {
    width: 95vw;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
  }

  .video-modal-close {
    width: 40px;
    height: 40px;
    top: 12px;
    right: 12px;
  }

  .video-modal-close svg {
    width: 20px;
    height: 20px;
  }
}
