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

:root {
  --fade-ms: 500ms;            /* slide crossfade — set from the room's speed */
  --screen-fade-ms: 700ms;     /* waiting ↔ slideshow ↔ ending */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --gold: #c8a96e;
  --vh100: 100vh;
}

/* Dynamic viewport height keeps photos clear of mobile browser toolbars. */
@supports (height: 100dvh) {
  :root { --vh100: 100dvh; }
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a09;
  font-family: Georgia, 'Times New Roman', serif;
  color: #e8d5a8;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Screens: one is active at a time and they fade between each other ────── */
.screen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--screen-fade-ms) var(--ease), visibility 0s linear var(--screen-fade-ms);
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--screen-fade-ms) var(--ease), visibility 0s;
}

/* ── Waiting & Ending screens ──────────────────────────────────────────────── */
#waiting,
#ending {
  background: radial-gradient(120% 90% at 50% 38%, #181613 0%, #0a0a09 62%);
}

.waiting-inner {
  /* Sits slightly above the math centre so the title reads as visually centred. */
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 44rem;
  text-align: center;
  padding: 0 2rem;
  /* Hidden until the room's own text has loaded, so the default never flashes. */
  opacity: 0;
  transition: opacity 900ms var(--ease);
}

body.is-ready .waiting-inner { opacity: 1; }

.waiting-inner::before {
  content: '';
  display: block;
  width: 36px;
  height: 1px;
  margin: 0 auto 1.75rem;
  background: rgba(200, 169, 110, 0.5);
}

.waiting-title {
  font-size: clamp(2rem, 7vw, 3.6rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.2;
  color: var(--gold);
  text-wrap: balance;
}

.waiting-subtitle {
  margin-top: 1rem;
  font-size: clamp(0.95rem, 3vw, 1.25rem);
  line-height: 1.5;
  color: rgba(200, 169, 110, 0.6);
  font-style: italic;
  letter-spacing: 0.03em;
  text-wrap: balance;
}

.waiting-subtitle:empty { display: none; }

.waiting-dots {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 2.25rem;
}

.waiting-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.2;
  animation: waiting-dot 1.8s ease-in-out infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.3s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.6s; }

@keyframes waiting-dot {
  0%, 80%, 100% { opacity: 0.2; }
  40%           { opacity: 0.9; }
}

/* ── Slideshow (default theme: Elegant) ───────────────────────────────────── */
#slideshow {
  background: radial-gradient(120% 100% at 50% 35%, #fbf7ef 0%, #f1e9d8 55%, #e6dac0 100%);
}

#stage {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}

/* Each slide is its own layer. A new layer fades in over the old one only
   after its photo has loaded, so there is never a blank frame in between. */
.slide-layer {
  --chrome: 3rem;                       /* vertical space kept free of the photo */
  --max-w: calc(100vw - 2.5rem);
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1.25rem, env(safe-area-inset-top)) 1.25rem max(1.5rem, env(safe-area-inset-bottom));
  opacity: 0;
  transition: opacity var(--fade-ms) var(--ease);
  will-change: opacity;
}

.slide-layer.has-caption { --chrome: 10rem; }
.slide-layer.is-visible  { opacity: 1; }

.slide-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}

.slide-frame {
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.slide-frame img {
  display: block;
  width: auto;
  height: auto;
  max-width: var(--max-w);
  max-height: calc(var(--vh100) - var(--chrome));
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(60, 45, 20, 0.12), 0 14px 44px rgba(60, 45, 20, 0.2);
  user-select: none;
  -webkit-user-drag: none;
}

/* Once the photo's shape is known (viewer.js sets --ar = width / height) it is
   sized to fill the space available, with the frame hugging the photo. */
.slide-frame img.sized {
  width: min(var(--max-w), calc((var(--vh100) - var(--chrome)) * var(--ar)));
  max-width: none;
  max-height: none;
}

/* Several photos on one slide */
.slide-frame.count-2,
.slide-frame.count-3,
.slide-frame.count-4 {
  display: grid;
  gap: 8px;
  width: var(--max-w);
}
.slide-frame.count-2 { grid-template-columns: 1fr 1fr; }
.slide-frame.count-3 { grid-template-columns: 1fr 1fr 1fr; }
.slide-frame.count-4 { grid-template-columns: 1fr 1fr; }

.slide-frame.count-2 img,
.slide-frame.count-3 img,
.slide-frame.count-4 img,
.slide-frame.count-2 img.sized,
.slide-frame.count-3 img.sized,
.slide-frame.count-4 img.sized {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: calc((var(--vh100) - var(--chrome)) / 2);
  object-fit: cover;
}

.slide-caption {
  margin-top: 1rem;
  max-width: min(calc(100vw - 3rem), 46rem);
  font-size: clamp(1rem, 3.2vw, 1.35rem);
  line-height: 1.45;
  text-align: center;
  font-style: italic;
  letter-spacing: 0.01em;
  color: #5a4a30;
  text-wrap: balance;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.slide-caption:empty { display: none; }

/* Short screens (a phone held sideways): give the photo more of the height */

/* ── Theme: Classic ────────────────────────────────────────────────────────── */
body.theme-classic #slideshow {
  background: radial-gradient(120% 100% at 50% 35%, #26231d 0%, #161411 60%, #0c0b09 100%);
}

body.theme-classic .slide-frame img {
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 54px rgba(0, 0, 0, 0.55);
}

body.theme-classic .slide-caption {
  color: rgba(226, 205, 160, 0.92);
}

/* ── Theme: Elegant (default — same as base styles) ───────────────────────── */

/* ── Theme: Cinematic ─────────────────────────────────────────────────────── */
body.theme-cinematic #slideshow {
  background: #000;
}

body.theme-cinematic .slide-layer {
  padding: 0;
  overflow: hidden;
}

body.theme-cinematic .slide-card,
body.theme-cinematic .slide-frame {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: block;
  width: auto;
  max-width: none;
}

body.theme-cinematic .slide-frame img,
body.theme-cinematic .slide-frame img.sized {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  border-radius: 0;
  box-shadow: none;
  animation: kenburns 14s ease-in-out infinite alternate;
}

@keyframes kenburns {
  0%   { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.08) translate(-1%, -1%); }
}

body.theme-cinematic .slide-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: none;
  margin: 0;
  padding: 4.5rem 1.5rem max(1.75rem, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
  color: rgba(255, 255, 255, 0.92);
  font-style: normal;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ── Theme: Polaroid ──────────────────────────────────────────────────────── */
body.theme-polaroid #slideshow {
  background: radial-gradient(120% 100% at 50% 35%, #f1eee7 0%, #e6e2d8 70%, #dcd7cb 100%);
}

body.theme-polaroid .slide-layer,
body.theme-polaroid .slide-layer.has-caption {
  --chrome: 13rem;
  --max-w: min(calc(100vw - 4.5rem), 560px);
}

body.theme-polaroid .slide-card {
  background: #fff;
  padding: 12px 12px 14px;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 10px 30px rgba(0, 0, 0, 0.16);
  transform: rotate(-1.2deg);
}

body.theme-polaroid .slide-frame img {
  border-radius: 1px;
  box-shadow: none;
}

body.theme-polaroid .slide-caption,
body.theme-polaroid .slide-caption:empty {
  display: -webkit-box;
  min-height: 2rem;
  margin-top: 0.75rem;
  max-width: var(--max-w);
  color: #4a4540;
  font-family: 'Courier New', Courier, monospace;
  font-size: clamp(0.85rem, 2.5vw, 1.05rem);
  font-style: normal;
  -webkit-line-clamp: 2;
}

body.theme-polaroid #waiting,
body.theme-polaroid #ending {
  background: radial-gradient(120% 90% at 50% 38%, #f1eee7 0%, #e3dfd5 70%);
}

body.theme-polaroid .waiting-title { color: #4a4540; }
body.theme-polaroid .waiting-subtitle { color: rgba(74, 69, 64, 0.6); }
body.theme-polaroid .waiting-inner::before { background: rgba(74, 69, 64, 0.35); }
body.theme-polaroid .waiting-dots span { background: #4a4540; }

/* ── Short screens (a phone held sideways): give the photo more height ─────── */
@media (max-height: 500px) {
  .slide-layer.has-caption { --chrome: 7.5rem; }
  .slide-caption { margin-top: 0.6rem; -webkit-line-clamp: 2; }

  body.theme-polaroid .slide-layer,
  body.theme-polaroid .slide-layer.has-caption { --chrome: 8.5rem; }
  body.theme-polaroid .slide-card { padding: 8px 8px 10px; }
  body.theme-polaroid .slide-caption,
  body.theme-polaroid .slide-caption:empty { min-height: 1.4rem; margin-top: 0.4rem; -webkit-line-clamp: 1; }
}

/* ── Reconnect badge ───────────────────────────────────────────────────────── */
#reconnect-badge {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  background: rgba(18, 14, 6, 0.6);
  color: rgba(232, 213, 168, 0.8);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 11px;
  letter-spacing: 0.05em;
  padding: 5px 10px 5px 8px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(200, 165, 80, 0.9);
  animation: blink 1.2s ease-in-out infinite;
}

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

/* ── Reduced motion ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .screen,
  .screen.is-active,
  .slide-layer,
  .waiting-inner { transition-duration: 80ms; }

  .waiting-dots span,
  .dot,
  body.theme-cinematic .slide-frame img { animation: none; }
}
