/* ============================================================
   Custom Search — Phase 4b Visual Design
   Warm serif on beige, coral accents
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body {
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.65;
  color: #2C2925;
  background: #F5F1EA;
  min-height: 100vh;
  overflow-x: hidden;
}

/* --- Layout --- */
#app {
  max-width: min(95vw, 1600px);
  margin: 0 auto;
  padding: 32px 24px 32px;
  overflow-x: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#form-section {
  max-width: min(95vw, 1600px);
  margin-left: auto;
  margin-right: auto;
}

.form-inner {
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

/* --- Greeting --- */
#greeting {
  font-size: 64px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: #2C2925;
  margin: 0;
}

#greeting-sub {
  font-size: 64px;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: #2C2925;
  margin-top: 8px;
  max-width: 100%;
}

/* --- Form --- */
#search-form {
  margin-top: 32px;
  width: 100%;
  min-width: 0;
}

.filter-hint {
  font-size: 18px;
  font-style: italic;
  color: #6B6660;
  line-height: 1.4;
  margin-bottom: 24px;
}

.filter-group {
  margin-bottom: 24px;
}

.filter-group-label {
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  color: #2C2925;
  margin-bottom: 0;
  margin-right: 32px;
  display: block;
  white-space: nowrap;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* Hide native checkbox visually but keep accessible */
.pill-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.pill-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 18px 30px;
  border: 1.5px solid #E8E2D5;
  border-radius: 999px;
  background: #FAF7F0;
  color: #2C2925;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: border-color 200ms ease, background-color 200ms ease, color 200ms ease;
}

.pill-label:hover {
  border-color: #6B6660;
}

.pill-label:has(input:checked) {
  border-color: #C9613F;
  background: rgba(201, 97, 63, 0.08);
  color: #C9613F;
}

.pill-label:has(input:focus-visible) {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
}

/* --- Validation errors --- */
.validation-error {
  font-size: 14px;
  color: #C9613F;
  margin-top: 8px;
  display: none;
  line-height: 1.4;
}

.validation-error.visible {
  display: block;
}

/* --- Narrative textarea --- */
.narrative-section {
  margin-bottom: 32px;
}

.narrative-section textarea {
  width: 100%;
  min-height: 120px;
  padding: 28px;
  border: 1.5px solid #E8E2D5;
  border-radius: 12px;
  background: #FAF7F0;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 22px;
  font-weight: 400;
  line-height: 1.65;
  color: #2C2925;
  resize: vertical;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.narrative-section textarea::placeholder {
  color: #6B6660;
  font-style: normal;
}

.narrative-section textarea:focus {
  outline: none;
  border-color: #C9613F;
  box-shadow: 0 0 0 3px rgba(201, 97, 63, 0.3);
}

/* --- Submit button --- */
.submit-wrap {
  display: flex;
  justify-content: center;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 320px;
  padding: 22px 44px;
  border: 1.5px solid #C9613F;
  border-radius: 14px;
  background: #FAF7F0;
  color: #C9613F;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease, transform 100ms ease;
}

.btn-primary:hover {
  background: #C9613F;
  color: #F5F1EA;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:focus-visible {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
}

.btn-primary:disabled {
  border-color: #E8E2D5;
  color: #6B6660;
  background: #FAF7F0;
  cursor: not-allowed;
}

.btn-primary:disabled:hover {
  background: #FAF7F0;
  color: #6B6660;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  padding: 14px 28px;
  border: 1.5px solid #C9613F;
  border-radius: 14px;
  background: #FAF7F0;
  color: #C9613F;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 17px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease, transform 100ms ease;
}

.btn-secondary:hover {
  background: #C9613F;
  color: #F5F1EA;
}

.btn-secondary:active {
  transform: scale(0.98);
}

.btn-secondary:focus-visible {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
}

/* Server error below submit */
#server-error {
  font-size: 14px;
  color: #C9613F;
  text-align: center;
  margin-top: 16px;
}

/* --- Section transitions --- */
.section {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 200ms ease, transform 200ms ease;
}

.section.hidden {
  display: none !important;
}

.section.fade-out {
  opacity: 0;
}

.section.fade-in {
  animation: fadeSlideIn 300ms ease forwards;
}

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

/* --- Loading state --- */
#loading-section {
  text-align: center;
  padding-top: 48px;
}

.loading-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
}

.loading-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #C9613F;
  animation: dotPulse 800ms ease-in-out infinite;
}

.loading-dot:nth-child(2) {
  animation-delay: 200ms;
}

.loading-dot:nth-child(3) {
  animation-delay: 400ms;
}

@keyframes dotPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.loading-text {
  font-size: 18px;
  color: #2C2925;
  line-height: 1.65;
}

/* --- Results --- */
#results-section {
  padding-top: 16px;
  max-width: min(95vw, 1600px);
  margin-left: auto;
  margin-right: auto;
}

.result-row {
  display: flex;
  gap: 32px;
  margin-bottom: 64px;
}

.result-text {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 38px;
  font-weight: 400;
  line-height: 1.2;
  color: #2C2925;
  margin-bottom: 24px;
  max-width: 820px;
}

.result-bio {
  font-size: 21px;
  line-height: 1.65;
  color: #2C2925;
  margin-bottom: 24px;
  max-width: 820px;
}

.meet-link {
  max-width: 720px;
  display: inline-block;
  font-size: 17px;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  color: #C9613F;
  text-decoration: none;
  cursor: pointer;
  transition: text-decoration 200ms ease;
}

.meet-link:hover {
  text-decoration: underline;
}

.meet-link:focus-visible {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
  border-radius: 4px;
}

.result-media {
  flex: 0 0 40%;
  max-width: 40%;
}

.result-media video,
.result-media img {
  width: 100%;
  display: block;
  border-radius: 12px;
  background: #FAF7F0;
  cursor: pointer;
  transition: transform 200ms ease;
}

.result-media video:hover,
.result-media img:hover {
  transform: scale(1.02);
}

.result-media video:focus-visible,
.result-media img:focus-visible {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
}

.results-footer {
  text-align: center;
  margin-top: 16px;
  padding-bottom: 48px;
}

/* --- Empty & Error states --- */
#empty-section,
#error-section {
  text-align: center;
  padding-top: 48px;
}

#empty-section p,
#error-section p {
  font-size: 18px;
  color: #2C2925;
  line-height: 1.65;
  margin-bottom: 32px;
}

/* --- Popup overlay --- */
#popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(44, 41, 37, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#popup-overlay.hidden {
  display: none !important;
}

.popup-container {
  background: #F5F1EA;
  border-radius: 16px;
  max-width: 540px;
  width: 100%;
  padding: 32px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.popup-close {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 8px 16px;
  border: 1.5px solid #E8E2D5;
  border-radius: 14px;
  background: #FAF7F0;
  color: #6B6660;
  font-family: 'Source Serif 4', 'Source Serif Pro', Georgia, serif;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 200ms ease, color 200ms ease;
}

.popup-close:hover {
  border-color: #6B6660;
  color: #2C2925;
}

.popup-close:focus-visible {
  outline: 3px solid rgba(201, 97, 63, 0.3);
  outline-offset: 2px;
}

#popup-name {
  font-size: 32px;
  font-weight: 400;
  line-height: 1.2;
  color: #2C2925;
  margin-bottom: 24px;
  padding-right: 80px;
}

#popup-photo {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 24px;
  display: block;
}

#popup-bio-placeholder {
  font-size: 17px;
  line-height: 1.65;
  color: #2C2925;
}

/* --- Responsive: Desktop (≥1024px) — inline Sex/Age rows --- */
@media (min-width: 1024px) {
  .filter-group {
    display: flex;
    align-items: center;
  }
}

/* --- Responsive: Tablet (768–1023) --- */
@media (min-width: 768px) and (max-width: 1023px) {
  #app {
    padding-left: 48px;
    padding-right: 48px;
  }
}

/* --- Responsive: Mobile (<768px) --- */
@media (max-width: 767px) {
  #app {
    padding-top: 64px;
  }

  #greeting,
  #greeting-sub {
    font-size: 36px;
  }

  .filter-group-label {
    margin-bottom: 16px;
    margin-right: 0;
  }

  .btn-primary {
    width: 100%;
  }

  .narrative-section textarea {
    font-size: 17px;
  }

  .result-row {
    flex-direction: column-reverse;
    margin-bottom: 48px;
  }

  .result-media {
    flex: none;
    max-width: 100%;
    margin-bottom: 24px;
  }

  .result-text {
    flex: none;
  }

  .result-bio {
    font-size: 17px;
  }

  .btn-secondary {
    width: 100%;
  }

  .pill-label {
    padding: 10px 16px;
    font-size: 15px;
  }

  .pill-row {
    gap: 8px;
  }

  /* Force age pills to 2x2 grid on mobile */
  .filter-group .pill-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .pill-label {
    justify-content: center;
  }
}
