/*
 * Mobile & small-screen refinements for Moonaura.
 *
 * Loaded after the main stylesheet. Everything that changes layout or type is
 * scoped to small screens (or to the collapsed navigation state), so the
 * desktop layout stays exactly as it was.
 */

/* ------------------------------------------------------------------------ */
/* Media: images and embeds always scale down to fit their container.        */
/* :where() keeps specificity at zero so existing component rules still win. */
/* ------------------------------------------------------------------------ */
:where(img, video, canvas, svg, iframe, embed, object) {
  max-width: 100%;
}

:where(img, video) {
  height: auto;
}

/* ------------------------------------------------------------------------ */
/* Collapsible navigation                                                    */
/* The menu button is added by /mobile-nav.js, which sets data-nav-collapsed */
/* on the header on small screens (or whenever the logo and buttons would    */
/* collide) and data-nav-open while the menu is showing.                     */
/* ------------------------------------------------------------------------ */
.mobile-nav-toggle {
  display: none;
}

.navbar[data-nav-collapsed] {
  position: relative !important;
  z-index: 60;
  flex-wrap: nowrap;
  justify-content: space-between !important;
  gap: 12px;
  height: 64px;
  min-height: 64px !important;
  padding: 0 16px;
}

.navbar[data-nav-collapsed] .logo {
  position: static !important;
  transform: none !important;
  min-width: 0;
  min-height: 44px;
  gap: 10px !important;
  font-size: clamp(22px, 7vw, 30px) !important;
  letter-spacing: 2px !important;
}

.navbar[data-nav-collapsed] .logo .logo-moon {
  width: 28px;
  height: 28px;
}

.navbar[data-nav-collapsed] .mobile-nav-toggle {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  padding: 0;
  color: #e5c995;
  background: transparent;
  border: 1px solid #c9a36a8c;
  border-radius: 6px;
  transition: background 0.2s, border-color 0.2s;
}

.navbar[data-nav-collapsed] .mobile-nav-toggle:hover,
.navbar[data-nav-open] .mobile-nav-toggle {
  background: #c9a36a1a;
  border-color: #c9a36a;
}

.navbar[data-nav-collapsed] .mobile-nav-toggle:focus-visible {
  outline: 2px solid #e5c995;
  outline-offset: 2px;
}

.mobile-nav-toggle-bars {
  position: relative;
  display: block;
  width: 20px;
  height: 14px;
}

.mobile-nav-toggle-bars span {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.2s, top 0.25s;
}

.mobile-nav-toggle-bars span:nth-child(1) { top: 0; }
.mobile-nav-toggle-bars span:nth-child(2) { top: 6px; }
.mobile-nav-toggle-bars span:nth-child(3) { top: 12px; }

.navbar[data-nav-open] .mobile-nav-toggle-bars span:nth-child(1) {
  top: 6px;
  transform: rotate(45deg);
}

.navbar[data-nav-open] .mobile-nav-toggle-bars span:nth-child(2) {
  opacity: 0;
}

.navbar[data-nav-open] .mobile-nav-toggle-bars span:nth-child(3) {
  top: 6px;
  transform: rotate(-45deg);
}

/* The button group becomes a drop-down panel under the header. */
.navbar[data-nav-collapsed] .nav-actions {
  display: none;
  position: absolute !important;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 70 !important;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 10px;
  margin: 0 !important;
  padding: 16px;
  background: #0d0a0cf7;
  border-bottom: 1px solid #b98f5b40;
  box-shadow: 0 18px 40px #000a;
}

.navbar[data-nav-open] .nav-actions {
  display: flex;
}

.navbar[data-nav-collapsed] .nav-actions > button {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  font-size: 16px;
  letter-spacing: 1px;
  white-space: normal;
}

.navbar[data-nav-collapsed] .language-button {
  border: 1px solid #c9a36a59;
  border-radius: 5px;
}

@media (prefers-reduced-motion: reduce) {
  .mobile-nav-toggle-bars span {
    transition: none;
  }
}

/* ------------------------------------------------------------------------ */
/* Phones                                                                    */
/* ------------------------------------------------------------------------ */
@media (max-width: 700px) {
  /* Readable body text: at least 16px. The #root prefix lifts these above
     the component rules without needing !important. */
  #root p,
  #root li,
  #root label,
  #root small,
  #root figcaption,
  #root time,
  #root input,
  #root select,
  #root textarea {
    font-size: 16px;
  }

  /* Keep the paragraphs that were already larger than 16px. */
  #root .lo-lead { font-size: 21px; }
  #root .lc-highlight { font-size: 20px; }
  #root .do-reading { font-size: 17px; }

  /* Rules that were marked !important in the main stylesheet. */
  #root .tarot-summary p,
  #root .tarot-advice p,
  #root .tarot-disclaimer,
  #root .lo-micro,
  #root .do-small,
  #root .auth-error,
  #root .auth-message {
    font-size: 16px !important;
  }

  /* Small text set inline in the app's markup. */
  #root [style*="font-size: 10px"],
  #root [style*="font-size: 11px"],
  #root [style*="font-size: 12px"],
  #root [style*="font-size: 13px"],
  #root [style*="font-size: 14px"],
  #root [style*="font-size: 15px"] {
    font-size: 16px !important;
  }

  /* Other small text blocks. */
  #root .tarot-instructions,
  #root .tarot-position,
  #root .tarot-orientation,
  #root .tarot-back-link,
  #root .lc-subgrid span,
  #root .do-history span,
  #root .coffee-coming-soon,
  #root .auth-divider,
  #root .language-button,
  #root .login-button,
  #root .history-nav-button,
  #root .do-scratch-fallback,
  #root .google-login-button,
  #root .auth-switch,
  #root .lo-choice {
    font-size: 16px;
  }

  /* Small uppercase, letter-spaced labels (eyebrows/kickers): brought up to
     16px with slightly tighter tracking so they still fit on one line. */
  #root .eyebrow,
  #root .do-eyebrow,
  #root .lc-eyebrow,
  #root .lo-eyebrow,
  #root .service-link {
    font-size: 16px;
    letter-spacing: 1.5px;
  }

  /* Tap targets: at least 44 x 44px. */
  #root button,
  #root select,
  #root input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="hidden"]) {
    min-height: 44px;
  }

  /* Card backs in the draw decks are sized by their grid instead. */
  #root button:not(.tarot-card-back):not(.lo-cardback) {
    min-width: 44px;
  }

  #root input[type="checkbox"],
  #root input[type="radio"] {
    width: 24px;
    height: 24px;
    flex: none;
  }

  #root label:has(> input[type="checkbox"]),
  #root label:has(> input[type="radio"]) {
    min-height: 44px;
    align-items: center !important;
  }

  #root .logo {
    min-height: 44px;
  }

  #root .auth-switch button {
    display: inline-flex;
    align-items: center;
    padding: 0 6px;
    vertical-align: middle;
  }

  #root .do-scratch-fallback,
  #root .do-history-button {
    padding: 10px 12px;
  }

  /* Close buttons (×) get a full-size, centred hit area. */
  #root .do-close,
  #root .modal-close,
  #root button[style*="position: absolute"] {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    line-height: 1;
  }

  #root .do-close { top: 6px; right: 6px; }
  #root .modal-close { top: 6px; right: 8px; }

  #root .coffee-photo button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    line-height: 1;
  }

  /* Overflow: let long words and tight rows wrap instead of pushing the
     page sideways. */
  #root h1,
  #root h2,
  #root h3,
  #root p {
    overflow-wrap: break-word;
  }

  #root .do-open-button,
  #root .history-nav-button {
    white-space: normal;
  }

  #root .cupid-topline {
    flex-wrap: wrap;
    gap: 12px 24px;
  }

  #root .lc-versus {
    flex-wrap: wrap;
  }

  #root .lc-versus > div {
    min-width: 0;
  }

  #root .lc-saved-list > div {
    flex-wrap: wrap;
  }

  #root .lc-buttons > button,
  #root .lo-actions > button {
    flex: 1 1 auto;
  }

  #root .service-modal {
    padding: 48px 20px 28px;
  }
}

/* Very narrow phones: fewer cards per row so each stays easy to tap. */
@media (max-width: 380px) {
  #root .tarot-deck,
  #root .tarot-page .tarot-deck {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
