/* =============================
   Event page (/event, /events/{region}/{slug})
   =============================
   Loaded last by functions/src/event-template.ts, after main.css, auth.css,
   comments.css and local-events.css, and scoped to body.ev-page so it only
   restyles this page. main.css still carries the older full-screen layout;
   the rules here replace it with a page that scrolls as a whole:

     .ev-side              the invite: .ev-poster (title, date, address,
                           actions) plus .rsvp-section
     .scrollable-content   description, ad slot, comments

   Two kinds of surface:
   - The poster sits on the event's own background image and uses the
     event's own colors (app.js / the server set them inline on the title,
     date, address and buttons), so nothing here recolors that text or puts a
     tint between it and the image.
   - The content cards (description, comments) are site surfaces and follow
     the light/dark theme tokens.

   The background image arrives as an inline background-image on
   #event-screen. That element does not paint it (background-size: 0);
   the fixed page backdrop and, on wide screens, the poster card pick it up
   with background-image: inherit. */

:root {
  --ev-seal: #E8505B;
  --ev-seal-deep: #C8324A;
  --ev-mint: #4FD1A1;
  --ev-glass: rgba(4, 8, 20, 0.56);
  --ev-card: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  --ev-line: var(--overlay-strong);
  --ev-fallback: #1B2A4A;
  --ev-header-h: 56px;
  --ev-display: "Fraunces", Georgia, "Times New Roman", serif;
}

/* ── Header ──────────────────────────────────────────────── */

.ev-page .auth-header-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--ev-header-h);
  background: var(--bg-page-translucent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--overlay-mid);
}

.ev-page .auth-header-btn { border-radius: 999px; padding: 8px 16px; }

/* Signed in on a phone: the name gives way so it never runs over the logo. */
.ev-page .auth-header-brand { flex-shrink: 0; }
.ev-page .auth-header-user { min-width: 0; }

@media (max-width: 560px) {
  .ev-page .auth-header-name { display: none; }
}

.ev-page .auth-header-btn.primary,
.ev-page .auth-header-btn.primary:hover {
  background: var(--ev-seal-deep);
  border-color: var(--ev-seal-deep);
  color: #fff;
}

.ev-page .auth-header-btn.primary:hover { filter: brightness(1.1); }

/* ── Page frame and backdrop ─────────────────────────────── */

.ev-page .event-screen {
  position: relative;
  isolation: isolate;
  height: auto;
  min-height: calc(100vh - var(--ev-header-h));
  min-height: calc(100dvh - var(--ev-header-h));
  max-width: none;
  margin: 0;
  overflow: visible;
  background-size: 0 0;
  background-repeat: no-repeat;
}

/* The event's background, fixed behind the whole page. */
.ev-page .event-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: var(--ev-fallback);
  background-image: inherit;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.ev-page .main-content {
  display: block;
  height: auto;
  min-height: 0;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
  background-image: inherit;
  background-size: 0 0;
  background-repeat: no-repeat;
}

.ev-side {
  background-image: inherit;
  background-size: 0 0;
  background-repeat: no-repeat;
}

/* ── Poster: the invite itself ───────────────────────────── */

.ev-poster {
  display: flex;
  flex-direction: column;
  min-height: min(60vh, 500px);
  padding: 14px 0 30px;
  color: #fff;
  text-align: center;
  /* Soft halo behind the event's text: dark behind light text, light behind
     dark text. Browsers without relative colors keep the dark one. */
  --ev-halo: rgba(0, 0, 0, 0.58);
}

@supports (color: oklch(from currentColor l c h)) {
  .ev-poster { --ev-halo: oklch(from currentColor clamp(0, (0.6 - l) * 1000, 1) 0 0 / 0.58); }
}

.ev-poster-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
}

.ev-poster-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 22px;
  min-width: 0;
}

.ev-chip,
.ev-page .attendee-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--ev-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.ev-chip[hidden] { display: none; }

.ev-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.7;
}

.ev-chip[data-state="live"]::before {
  background: var(--ev-mint);
  opacity: 1;
  box-shadow: 0 0 0 4px rgba(79, 209, 161, 0.3);
}

.ev-chip[data-state="ended"] { color: rgba(255, 255, 255, 0.8); }
.ev-chip[data-state="ended"]::before { display: none; }

/* main.css positions the badge absolutely under the old floating ad. */
.ev-page .attendee-badge {
  position: static;
  min-width: 0;
  margin-left: auto;
  padding-left: 10px;
  transition: none;
}

.ev-page .attendee-badge .attendee-icon {
  position: static;
  width: 16px;
  height: 16px;
  transform: none;
  opacity: 0.9;
}

.ev-page .attendee-badge #attendee-count::after { content: " going"; }

.ev-datebadge {
  display: flex;
  flex-direction: column;
  width: 62px;
  margin-bottom: 18px;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  color: #0F172A;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  text-align: center;
  line-height: 1;
}

.ev-datebadge[hidden] { display: none; }

.ev-datebadge-month {
  padding: 5px 0 4px;
  background: var(--ev-seal-deep);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ev-datebadge-day {
  padding: 6px 0 8px;
  font-size: 25px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ev-page .event-title {
  font-family: var(--ev-display);
  font-weight: 600;
  font-size: clamp(31px, 7.2vw, 44px);
  line-height: 1.08;
  letter-spacing: -0.012em;
  margin-bottom: 14px;
  text-shadow: 0 2px 14px var(--ev-halo), 0 1px 2px var(--ev-halo);
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.ev-page .event-date {
  font-size: 19px;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 12px;
  text-shadow: 0 1px 10px var(--ev-halo), 0 1px 2px var(--ev-halo);
}

.ev-page .address-section { margin-bottom: 22px; }

.ev-page .event-address {
  display: inline-block;
  max-width: 42ch;
  font-size: 15px !important; /* virtual addresses carry an inline 14px */
  line-height: 1.45;
  text-shadow: 0 1px 8px var(--ev-halo), 0 1px 2px var(--ev-halo) !important;
  overflow-wrap: anywhere;
}

.ev-page a.event-address {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  text-underline-offset: 3px;
}

.ev-page a.event-address:hover { text-decoration-color: currentColor; }
.ev-page a.event-address:empty { display: none; }
.ev-page .address-section:has(a.event-address:empty) { margin-bottom: 8px; }

.ev-page .action-buttons-row {
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 0;
}

/* Colors on these buttons are set inline from the event's own palette. */
.ev-page .event-action-btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: transform 0.15s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.ev-page .event-action-btn:hover:not(:disabled) {
  opacity: 1;
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.32);
}

.ev-page .event-action-btn:active:not(:disabled) { transform: scale(0.97); }

/* Owner share button (top-left, shown by script for the host). */
.ev-page .action-buttons { top: 12px; left: 16px; }

/* ── RSVP bar ────────────────────────────────────────────── */

/* Phones: pinned to the bottom of the screen. */
.ev-page .rsvp-section {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  max-height: none;
  overflow: visible;
  padding: 26px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent, rgba(4, 8, 20, 0.5) 46%);
  pointer-events: none;
  transition: none;
}

.ev-page .rsvp-section > * { pointer-events: auto; }

.ev-page .countdown-timer {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 10px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.94);
  font-size: 13px;
  font-weight: 700;
  text-shadow: none;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
}

/* Once the deadline has passed the button says so; don't say it twice. */
.ev-page .rsvp-section:has(#rsvp-btn:disabled) .countdown-timer { display: none; }

.ev-page .rsvp-button,
.ev-page .le-invite-btn-full,
.ev-page .preview-back-btn,
.ev-page .preview-publish-btn {
  min-height: 54px;
  padding: 0 22px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.ev-page .rsvp-button:hover:not(:disabled),
.ev-page .le-invite-btn-full:hover,
.ev-page .preview-publish-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.06);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.42);
}

.ev-page .rsvp-button:active:not(:disabled),
.ev-page .le-invite-btn-full:active { transform: scale(0.98); }

/* Stays opaque (content scrolls under the pinned bar); muted instead. */
.ev-page .rsvp-button:disabled { opacity: 1; filter: grayscale(0.45) brightness(0.9); }

.ev-page .le-invite-btn-full {
  width: 100%;
  margin: 0;
  border: 0;
  color: #fff;
  background: linear-gradient(135deg, #D63C50 0%, var(--ev-seal-deep) 100%);
}

.ev-page .preview-mode-bar { margin-top: 10px; gap: 10px; }

.ev-page .preview-back-btn {
  flex: 0 1 auto;
  background: var(--ev-glass);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: #fff;
}

.ev-page .preview-back-btn:hover { background: rgba(4, 8, 20, 0.72); }

/* ── Content column ──────────────────────────────────────── */

.ev-page .scrollable-content {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;
  overflow: visible;
  min-height: 0;
  padding: 0 0 calc(var(--rsvp-h, 96px) + 24px);
}

.ev-page .description-container,
.ev-page .comments-section {
  margin: 0;
  padding: 22px 20px;
  border-radius: 22px;
  border: 1px solid var(--ev-line);
  background: var(--ev-card);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
}

/* A draft or a sparse listing can have nothing to say here. */
.ev-page .description-container:not(:has(.event-description:not(:empty), .event-source-link, .le-companion-highlight)) {
  display: none;
}

.ev-page .event-description {
  color: var(--text-primary);
  font-size: 16.5px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.ev-page .event-description:empty { display: none; }

.ev-page .event-description a,
.ev-page .event-description a:visited,
.ev-page .event-description a:hover,
.ev-page .event-description a:active,
.ev-page .event-description a:focus {
  color: var(--accent-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ev-page .event-description img { border-radius: 14px !important; }

.ev-page .event-source-link { color: var(--text-muted); }
.ev-page .event-source-link a:hover { color: var(--text-primary); }

/* Ad slot: a card in the flow between the description and the comments.
   Its space is reserved up front (main.css gives the slot a min-height), so
   the page does not jump when the ad arrives; it is removed only when the ad
   server answers that it has nothing to show. */
.ev-page .floating-ad {
  position: static;
  /* main.css gives the slot z-index 100, which still applies here because the
     slot is a flex item; it would then slide over the pinned RSVP bar. */
  z-index: auto;
  padding: 12px 14px 8px;
  gap: 8px;
  border-radius: 16px;
  border: 1px solid var(--ev-line);
  background: var(--ev-card);
  box-shadow: none;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  transition: none;
}

.ev-page .floating-ad:has(ins[data-ad-status="unfilled"]) { display: none; }

.ev-page .floating-ad .floating-ad-label {
  color: var(--text-muted);
  border-top-color: var(--overlay-mid);
}

.ev-page .floating-ad .ad-icon { color: currentColor; }

/* Comments: the thread itself keeps comments.css; only the frame changes. */
.ev-page .comments-title {
  font-family: var(--ev-display);
  font-size: 22px;
  font-weight: 600;
}

.ev-page .comments-composer { border-radius: 14px; }

.ev-page .comments-composer-submit,
.ev-page .comments-load-more { border-radius: 999px; }

/* Keep the fixed theme toggle clear of the pinned RSVP bar. */
.ev-page .theme-toggle-btn { bottom: calc(var(--rsvp-h, 96px) + 8px); }

/* ── Dialogs (RSVP, confirmation, download, published) ───── */

.ev-page .modal { -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }

.ev-page .modal-content { border-radius: 22px; }

.ev-page .modal h2 {
  font-family: var(--ev-display);
  font-weight: 600;
}

.ev-page .modal .btn-primary,
.ev-page .modal .btn-secondary,
.ev-page .modal .btn-copy-url { border-radius: 999px; }

/* ── Wide screens: poster card beside the content ────────── */

@media (min-width: 960px) {
  .ev-page .event-screen::before {
    filter: blur(38px) saturate(1.15);
    transform: scale(1.18);
  }

  /* Dim the blurred backdrop so the cards and the poster stand out. */
  .ev-page .event-screen::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: rgba(6, 10, 22, 0.58);
  }

  [data-theme="light"] .ev-page .event-screen::after { background: rgba(241, 245, 249, 0.62); }

  .ev-page .main-content {
    display: grid;
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
    padding: 32px 28px 72px;
  }

  .ev-side {
    position: sticky;
    top: calc(var(--ev-header-h) + 24px);
    display: flex;
    flex-direction: column;
    min-height: min(680px, calc(100vh - var(--ev-header-h) - 48px));
    max-height: calc(100vh - var(--ev-header-h) - 48px);
    border-radius: 32px;
    overflow: hidden;
    background-color: var(--ev-fallback);
    background-size: cover;
    background-position: center;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.14);
  }

  .ev-poster {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
    padding: 18px 26px 18px;
  }

  .ev-poster::-webkit-scrollbar { display: none; }

  .ev-page .event-title { font-size: clamp(32px, 3.4vw, 42px); }

  .ev-page .rsvp-section {
    position: static;
    flex: none;
    padding: 6px 20px 20px;
    background: none;
    pointer-events: auto;
  }

  .ev-page .scrollable-content { padding-bottom: 0; gap: 20px; }

  .ev-page .description-container,
  .ev-page .comments-section { padding: 28px 30px; border-radius: 26px; }

  .ev-page .theme-toggle-btn { bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .ev-page .event-action-btn,
  .ev-page .rsvp-button,
  .ev-page .le-invite-btn-full,
  .ev-page .preview-publish-btn { transition: none; }
}
