:root {
  --burgundy: #5a1e26;
  --burgundy-deep: #3d1418;
  --cream: #5a1e26;
  --cream-deep: #6b2530;
  --ink: #f5e8c8;
  --ink-soft: rgba(245, 232, 200, 0.7);
  --accent: #2d2d33;
  --accent-soft: #d8c8a0;
  --sage: rgba(245, 232, 200, 0.7);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--burgundy-deep);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.serif {
  font-family: 'Cormorant Garamond', serif;
  letter-spacing: 0.01em;
}

/* Phone frame chrome (desktop only) */
.phone-frame {
  width: 390px;
  height: 780px;
  background: var(--burgundy);
  border-radius: 44px;
  box-shadow:
    0 30px 80px -20px rgba(0,0,0,0.45),
    0 0 0 12px #1f1f23,
    0 0 0 14px #46464a;
  overflow: hidden;
  position: relative;
}
.phone-frame::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 110px;
  height: 28px;
  background: #1f1f23;
  border-radius: 20px;
  z-index: 50;
}

/* Scrollable content area inside the phone */
.phone-content {
  position: absolute;
  inset: 0;
  padding-top: 50px;
  padding-bottom: 72px;
  overflow-y: auto;
  color: var(--ink);
}
.phone-content::-webkit-scrollbar { width: 0; }

/* Bottom nav docked inside the phone frame */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(31, 31, 35, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(245, 232, 200, 0.08);
  display: flex;
  z-index: 60;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: rgba(245, 232, 200, 0.45);
  font-family: 'Cormorant Garamond', serif;
  font-size: 14px;
  letter-spacing: 0.02em;
  text-align: center;
  transition: color 0.15s;
}
.bottom-nav a:hover { color: rgba(245, 232, 200, 0.85); }
.bottom-nav a.active { color: var(--accent-soft); }
.bottom-nav svg { width: 22px; height: 22px; }

/* Page header inside the phone */
.page-header {
  position: sticky;
  top: 0;
  background: rgba(58, 18, 25, 0.92);
  backdrop-filter: blur(8px);
  padding: 16px 20px 14px;
  border-bottom: 1px solid rgba(245, 232, 200, 0.08);
  z-index: 40;
}

/* Primary action button (charcoal grey, cream text) */
.accent-btn {
  background: var(--accent);
  color: var(--ink);
  transition: all 0.15s;
  border: none;
  cursor: pointer;
}
.accent-btn:hover { background: #1a1a20; }
.accent-soft-bg { background: var(--accent-soft); }

.upload-cta {
  background:
    linear-gradient(135deg, rgba(216, 200, 160, 0.35), rgba(245, 232, 200, 0.08)),
    var(--accent);
  border: 2px solid var(--accent-soft);
  box-shadow: 0 18px 45px -28px rgba(0, 0, 0, 0.75);
}

/* Progress bar */
.progress-bar {
  height: 8px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* Selected upload tag chip */
.tag-pill.active {
  background: var(--accent-soft);
  color: var(--burgundy);
  border-color: var(--accent-soft);
}

/* Selected privacy option on the voice page */
.privacy-btn.active {
  background: var(--accent-soft);
  color: var(--burgundy);
  border-color: var(--accent-soft);
}

/* Recording state on the voice record button */
#recordButton.recording {
  animation: pulse-record 1.2s ease-in-out infinite;
}
@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(90, 30, 38, 0.45); }
  50% { box-shadow: 0 0 0 12px rgba(90, 30, 38, 0); }
}

/* Name popup (voice page) */
.name-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(31, 31, 35, 0.6);
  backdrop-filter: blur(4px);
}
.name-modal.hidden { display: none; }
.name-modal-card {
  width: 100%;
  max-width: 340px;
  background: #fff;
  color: #2d2d33;
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.55);
}
.name-modal-card .text-stone-500 { color: rgb(120 113 108); }
.name-modal-card input { color: #2d2d33; }
.name-modal-card input::placeholder { color: rgb(168 162 158); }

/* Shared lightbox: tap a Top 10 item to view it large */
.media-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  padding: 18px;
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  background: rgba(31, 31, 35, 0.9);
  backdrop-filter: blur(8px);
}
.media-modal.open { display: flex; align-items: center; justify-content: center; }
.media-modal-inner { width: min(960px, 100%); }
.media-modal-inner img,
.media-modal-inner video {
  width: 100%;
  max-height: 78vh;
  max-height: 78dvh;
  object-fit: contain;
  background: #1f1f23;
  border-radius: 10px;
  display: block;
}
.media-modal-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #2d2d33;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  z-index: 101;
}

/* Contributor's uploads popup (leaderboard) */
.contrib-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  padding: 18px;
  padding-top: calc(18px + env(safe-area-inset-top));
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
  background: rgba(31, 31, 35, 0.86);
  backdrop-filter: blur(8px);
}
.contrib-modal.open { display: flex; align-items: center; justify-content: center; }
.contrib-modal-panel {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  background: var(--burgundy);
  border: 1px solid rgba(245, 232, 200, 0.16);
  border-radius: 12px;
  color: var(--ink);
}
.contrib-name-btn { cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 640px) {
  .media-modal.open { align-items: flex-start; }
  .contrib-modal.open { align-items: flex-start; }
}

/* Video duration badge */
.score-badge {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  backdrop-filter: blur(4px);
}

/* Voice note waveform */
.waveform { display: flex; align-items: center; gap: 2px; height: 20px; }
.waveform span {
  display: block;
  width: 2px;
  background: var(--burgundy);
  border-radius: 1px;
}

/* Photo tile */
.photo-tile { position: relative; overflow: hidden; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s; }

/* === Text color overrides for burgundy interior === */
.phone-content { color: var(--ink); }
.phone-content .text-stone-300 { color: rgba(245, 232, 200, 0.35); }
.phone-content .text-stone-400 { color: rgba(245, 232, 200, 0.5); }
.phone-content .text-stone-500 { color: rgba(245, 232, 200, 0.65); }
.phone-content .text-stone-600 { color: rgba(245, 232, 200, 0.8); }
.phone-content .text-stone-800 { color: var(--ink); }
.phone-content .border-stone-50 { border-color: rgba(245, 232, 200, 0.08); }
.phone-content .border-stone-100 { border-color: rgba(245, 232, 200, 0.12); }
.phone-content .border-stone-200 { border-color: rgba(245, 232, 200, 0.18); }

/* Revert to dark text inside white/amber cards */
.phone-content .bg-white,
.phone-content .bg-amber-50 { color: #2d2d33; }
.phone-content .bg-white .text-stone-300 { color: rgb(214 211 209); }
.phone-content .bg-white .text-stone-400 { color: rgb(168 162 158); }
.phone-content .bg-white .text-stone-500 { color: rgb(120 113 108); }
.phone-content .bg-white .text-stone-600 { color: rgb(87 83 78); }
.phone-content .bg-white .text-stone-800 { color: rgb(41 37 36); }
.phone-content .bg-white .border-stone-50 { border-color: rgb(250 250 249); }
.phone-content .bg-white .border-stone-100 { border-color: rgb(245 245 244); }
.phone-content .bg-white .border-stone-200 { border-color: rgb(231 229 228); }
.phone-content .bg-amber-50 .text-stone-500 { color: rgb(120 113 108); }

/* Inputs */
.phone-content input {
  color: var(--ink);
  border-color: rgba(245, 232, 200, 0.3) !important;
  background: transparent;
}
.phone-content input::placeholder { color: rgba(245, 232, 200, 0.4) !important; }
.phone-content .bg-white input { color: #2d2d33; border-color: rgb(231 229 228) !important; }
.phone-content .bg-white input::placeholder { color: rgb(168 162 158) !important; }

/* Admin desktop layout (no phone frame) */
.admin-host {
  width: 100%;
  max-width: 1100px;
  padding: 32px 24px;
}

/* Desktop: show the guest app as a desktop web view, not inside a phone bezel */
@media (min-width: 641px) {
  body {
    display: block;
    background: var(--burgundy);
  }

  .phone-frame {
    width: 100%;
    min-height: 100vh;
    height: auto;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }

  .phone-frame::before { display: none; }

  .phone-content {
    position: relative;
    inset: auto;
    min-height: 100vh;
    padding-top: 0;
    padding-bottom: 0;
    overflow: visible;
  }

  .phone-frame:has(.bottom-nav) .phone-content {
    padding-top: 72px;
  }

  .bottom-nav {
    position: fixed;
    top: 0;
    bottom: auto;
    height: 72px;
    justify-content: center;
    padding: 0 24px;
  }

  .bottom-nav a {
    flex: 0 1 148px;
    flex-direction: row;
    justify-content: center;
    gap: 8px;
    font-size: 19px;
  }

  .bottom-nav a:first-child {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    flex: none;
    min-width: 156px;
    padding: 12px 18px;
    border: 1px solid rgba(245, 232, 200, 0.3);
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--burgundy);
    box-shadow: 0 12px 30px -22px rgba(0, 0, 0, 0.8);
  }

  .bottom-nav a:first-child:hover,
  .bottom-nav a:first-child.active {
    color: var(--burgundy);
  }

  .bottom-nav svg {
    width: 20px;
    height: 20px;
  }

  .page-header {
    padding: 24px 32px 18px;
  }

  .phone-content > :not(.page-header) {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 32px !important;
    padding-right: 32px !important;
  }

  .phone-content .grid:has(.photo-tile) {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 12px !important;
  }

  .upload-cta {
    width: min(360px, 100%) !important;
    align-items: flex-start;
    text-align: left;
    padding-left: 28px !important;
    padding-right: 28px !important;
  }
}

/* Mobile: use the document's own scroll so one swipe reaches the very top/bottom
   (an inner overflow container is what caused the "stops short, swipe again" feel on iOS). */
@media (max-width: 640px) {
  body { display: block; align-items: stretch; }
  .phone-frame {
    width: 100%;
    min-height: 100vh;
    height: auto;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    position: static;
  }
  .phone-frame::before { display: none; }

  /* Content flows in the normal document (no inner scroller). */
  .phone-content {
    position: static;
    inset: auto;
    height: auto;
    overflow: visible;
    padding-top: 0;
    padding-bottom: 0;
  }

  /* Fixed navigation pinned to the very top on mobile */
  .bottom-nav {
    position: fixed;
    top: 0;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid rgba(245, 232, 200, 0.08);
  }

  /* With nav: clear the fixed top bar. Title bar flows in normal order under it. */
  .phone-frame:has(.bottom-nav) .phone-content { padding-top: 64px; }
  .phone-frame:has(.bottom-nav) .page-header { position: static; }

  /* Make Upload (the primary action) stand out as a highlighted button. */
  .bottom-nav a:first-child {
    background: var(--accent-soft);
    color: var(--burgundy);
    margin: 8px 6px;
    border-radius: 12px;
    font-weight: 600;
  }
  .bottom-nav a:first-child:hover,
  .bottom-nav a:first-child.active { color: var(--burgundy); }

  .admin-host { padding: 16px; }
}
