/* ── Design Tokens ──────────────────────────────────────────────── */

:root {
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --color-bg: #2a1a0a;
  --mg-purple: #7B2D8E;
  --mg-gold: #D4A843;
  --mg-green: #1B7A3A;
  --paper: #f4e6ce;
  --paper-end: #ecddc2;
  --ink: #2a1a0a;
  --ink-mid: #5a4a3a;
  --ink-light: #8a7a6a;
  --cream: #f7e8d0;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Reset ──────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100%;
  width: 100%;
  background: var(--color-bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Background ─────────────────────────────────────────────────── */

.bg {
  position: fixed;
  inset: 0;
}

.bg img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 63.5% 67.4%;
}

@media (orientation: portrait) {
  .bg img {
    object-position: 50% 67.4%;
  }
}

/* ── Confetti ───────────────────────────────────────────────────── */

.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.dot {
  position: absolute;
  bottom: -12px;
  border-radius: 50%;
  animation: confetti-float linear infinite;
}

.dot.diamond {
  border-radius: 2px;
}

@keyframes confetti-float {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  3%   { opacity: var(--dot-o, 0.35); }
  50%  { transform: translateY(-55vh) rotate(360deg) translateX(var(--drift, 15px)); }
  97%  { opacity: var(--dot-o, 0.35); }
  100% { transform: translateY(-115vh) rotate(720deg) translateX(var(--drift-end, -10px)); opacity: 0; }
}

.dot:nth-child(1) { left: 5%;  width: 7px; height: 7px; background: var(--mg-purple); animation-duration: 24s; animation-delay: 0s;  --dot-o: 0.35; --drift: 20px;  --drift-end: -15px; }
.dot:nth-child(2) { left: 15%; width: 5px; height: 5px; background: var(--mg-gold);   animation-duration: 30s; animation-delay: 4s;  --dot-o: 0.45; --drift: -15px; --drift-end: 25px; }
.dot:nth-child(3) { left: 28%; width: 6px; height: 6px; background: var(--mg-green);  animation-duration: 26s; animation-delay: 8s;  --dot-o: 0.3;  --drift: 25px;  --drift-end: -20px; }
.dot:nth-child(4) { left: 42%; width: 4px; height: 4px; background: var(--mg-gold);   animation-duration: 33s; animation-delay: 2s;  --dot-o: 0.4;  --drift: -20px; --drift-end: 10px; }
.dot:nth-child(5) { left: 55%; width: 6px; height: 6px; background: var(--mg-purple); animation-duration: 28s; animation-delay: 10s; --dot-o: 0.35; --drift: 18px;  --drift-end: -25px; }
.dot:nth-child(6) { left: 68%; width: 5px; height: 5px; background: var(--mg-green);  animation-duration: 22s; animation-delay: 6s;  --dot-o: 0.4;  --drift: -25px; --drift-end: 15px; }
.dot:nth-child(7) { left: 78%; width: 7px; height: 7px; background: var(--mg-gold);   animation-duration: 31s; animation-delay: 1s;  --dot-o: 0.3;  --drift: 12px;  --drift-end: -18px; }
.dot:nth-child(8) { left: 88%; width: 4px; height: 4px; background: var(--mg-purple); animation-duration: 27s; animation-delay: 7s;  --dot-o: 0.45; --drift: -18px; --drift-end: 22px; }
.dot:nth-child(9) { left: 95%; width: 5px; height: 5px; background: var(--mg-green);  animation-duration: 35s; animation-delay: 3s;  --dot-o: 0.35; --drift: 22px;  --drift-end: -12px; }

/* ── Stage ──────────────────────────────────────────────────────── */

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem 3rem;
  z-index: 2;
  pointer-events: none;
}

#stage > * {
  pointer-events: auto;
}

/* ── Postcard Container ─────────────────────────────────────────── */

#postcard {
  position: relative;
  width: 100%;
  max-width: 460px;
  perspective: 900px;
  visibility: hidden;
}

#postcard.ready {
  visibility: visible;
}

/* ── Postcard Inner (flip axis) ─────────────────────────────────── */

.postcard-inner {
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease);
}

/* Prevent hidden back face from stealing clicks */
.postcard-back-face { pointer-events: none; }
#postcard.flipped .postcard-front { pointer-events: none; }
#postcard.flipped .postcard-back-face { pointer-events: auto; }

#postcard.flipped .postcard-inner {
  transform: rotateY(180deg);
}

/* ── Shared Face Styles ─────────────────────────────────────────── */

.postcard-front,
.postcard-back-face {
  border-radius: 6px;
  box-shadow:
    0 14px 44px rgba(0, 0, 0, 0.5),
    0 4px 14px rgba(0, 0, 0, 0.35);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* ── Mardi Gras Tricolor Stripe ─────────────────────────────────── */

.mg-stripe {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(90deg,
    var(--mg-purple) 33.33%,
    var(--mg-gold) 33.33%, var(--mg-gold) 66.66%,
    var(--mg-green) 66.66%);
}

/* ── Color Accent Classes ───────────────────────────────────────── */

.mg-purple { --mg-accent: var(--mg-purple); }
.mg-gold   { --mg-accent: var(--mg-gold); }
.mg-green  { --mg-accent: var(--mg-green); }

/* ── Front Face ─────────────────────────────────────────────────── */

.postcard-front {
  position: relative;
  background: linear-gradient(155deg, var(--paper) 0%, var(--paper-end) 100%);
  padding: 2rem 1.5rem 1.5rem;
}

/* Fleur-de-lis watermark */
.postcard-front::after {
  content: '\269C';
  position: absolute;
  bottom: 0.6rem;
  right: 0.8rem;
  font-size: 3.5rem;
  line-height: 1;
  opacity: 0.055;
  color: var(--ink);
  pointer-events: none;
}

/* Postage stamp decoration */
.postcard-stamp {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 40px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border: 2px dashed var(--ink-light);
  border-radius: 2px;
  opacity: 0.2;
  transform: rotate(-4deg);
}

/* Category label */
.pc-label {
  margin: 0 0 0.55rem;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mg-accent, var(--mg-purple));
}

/* Fact text */
.pc-text {
  margin: 0 0 1rem;
  font-size: 0.98rem;
  font-weight: 400;
  line-height: 1.72;
  color: var(--ink);
  padding-right: 2.5rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Flip trigger button */
.pc-flip {
  display: none;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 20px;
  padding: 0.35rem 0.9rem;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--mg-accent, var(--mg-purple));
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.pc-flip.visible {
  display: inline-flex;
}

.pc-flip:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.22);
}

.pc-flip:focus-visible {
  outline: 2px solid var(--mg-accent);
  outline-offset: 2px;
}

/* ── Back Face ──────────────────────────────────────────────────── */

.postcard-back-face {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 1.65rem,
      rgba(0, 0, 0, 0.035) 1.65rem,
      rgba(0, 0, 0, 0.035) calc(1.65rem + 1px)
    ),
    linear-gradient(155deg, var(--paper) 0%, var(--paper-end) 100%);
  padding: 2rem 1.5rem 1.5rem;
  overflow: hidden;
}

/* Fleur-de-lis watermark on back */
.postcard-back-face::after {
  content: '\269C';
  position: absolute;
  bottom: 0.6rem;
  right: 0.8rem;
  font-size: 3.5rem;
  line-height: 1;
  opacity: 0.04;
  color: var(--ink);
  pointer-events: none;
}

/* Back button */
.pc-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: none;
  padding: 0.2rem 0;
  margin-bottom: 0.6rem;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--mg-accent, var(--mg-purple));
  cursor: pointer;
  transition: opacity 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.pc-back-btn:hover {
  opacity: 0.65;
}

.pc-back-btn:focus-visible {
  outline: 2px solid var(--mg-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Detail title */
.pc-detail-title {
  margin: 0 0 0.7rem;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

/* Detail info (dl) */
.pc-detail-info {
  margin: 0 0 0.7rem;
}

.pc-detail-info dt {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-light);
  margin-bottom: 0.05rem;
}

.pc-detail-info dd {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink);
  margin: 0 0 0.5rem;
}

/* Detail note */
.pc-detail-note {
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--ink-mid);
  margin: 0 0 0.8rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Detail links */
.pc-detail-links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.pc-detail-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  color: white;
  text-decoration: none;
  background: var(--mg-accent, var(--mg-purple));
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  transition: opacity 150ms ease;
}

.pc-detail-link:hover {
  opacity: 0.85;
}

.pc-detail-link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.pc-detail-link svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

/* ── Map Embed ──────────────────────────────────────────────────── */

.pc-detail-map {
  width: 100%;
  height: 140px;
  border: none;
  border-radius: 5px;
  display: block;
  background: var(--paper-end);
  transition: height 0.35s var(--ease);
}

.pc-detail-map.expanded {
  height: 300px;
}

.pc-map-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.7rem;
  padding: 0.3rem 0.7rem;
  background: var(--mg-accent, var(--mg-purple));
  border: none;
  border-radius: 4px;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: white;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.pc-map-toggle:hover {
  opacity: 1;
}

.pc-map-toggle:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ── Navigation ─────────────────────────────────────────────────── */

.stage-nav {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  margin-top: 1.2rem;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--cream);
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transition: background 150ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover {
  background: rgba(0, 0, 0, 0.75);
  transform: scale(1.06);
}

.nav-btn:active {
  background: rgba(0, 0, 0, 0.85);
  transform: scale(0.96);
}

.nav-btn:focus-visible {
  outline: 2px solid var(--mg-gold);
  outline-offset: 2px;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-counter {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(247, 232, 208, 0.7);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

/* ── Hint ───────────────────────────────────────────────────────── */

.stage-hint {
  margin: 0.7rem 0 0;
  font-size: 0.56rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: rgba(247, 232, 208, 0.2);
  text-align: center;
}

@media (pointer: coarse) {
  .stage-hint { display: none; }
}

/* ── Brand Mark ─────────────────────────────────────────────────── */

.brand-mark {
  margin: 1.2rem 0 0;
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(247, 232, 208, 0.25);
  text-align: center;
}

/* ── Responsive: Mobile ─────────────────────────────────────────── */

@media (max-width: 520px) {
  #stage {
    justify-content: flex-end;
    padding: 1rem 0.75rem 1.5rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  }

  #postcard {
    max-width: none;
  }

  .postcard-front,
  .postcard-back-face {
    padding: 1.6rem 1.25rem 1.25rem;
  }

  .pc-text {
    font-size: 0.94rem;
    padding-right: 2rem;
  }

  .brand-mark {
    margin-top: 0.8rem;
  }
}

/* ── Responsive: Landscape mobile ───────────────────────────────── */

@media (orientation: landscape) and (max-height: 500px) {
  #stage {
    padding: 0.5rem 1rem 1rem;
  }

  .postcard-front,
  .postcard-back-face {
    padding: 1.2rem 1.2rem 1rem;
  }

  .pc-text {
    font-size: 0.88rem;
    line-height: 1.55;
  }

  .stage-nav {
    margin-top: 0.6rem;
  }

  .brand-mark {
    margin-top: 0.5rem;
  }
}

/* ── Bead Throw Animation ───────────────────────────────────────── */

.bead-throw {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  overflow: hidden;
}

.bead {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: bead-arc forwards;
  animation-timing-function: cubic-bezier(0.15, 0.8, 0.3, 1);
}

@keyframes bead-arc {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.3); }
  8%   { opacity: 0.85; }
  40%  { opacity: 0.85; transform: translate(var(--bx), var(--by)) scale(1); }
  100% { opacity: 0; transform: translate(var(--bx2), calc(var(--by) + 60vh)) scale(0.5); }
}

/* Bead strand effect — connected beads on a string */
.bead-strand {
  position: absolute;
  opacity: 0;
  animation: strand-swing forwards;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
}

.bead-strand::before,
.bead-strand::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: inherit;
}

.bead-strand::before {
  width: 10px;
  height: 10px;
  top: 0;
  left: 0;
}

.bead-strand::after {
  width: 8px;
  height: 8px;
  top: 14px;
  left: 12px;
}

@keyframes strand-swing {
  0%   { opacity: 0; transform: translateY(-40px) rotate(-30deg); }
  15%  { opacity: 0.7; }
  50%  { transform: translateY(20vh) rotate(15deg); opacity: 0.7; }
  100% { transform: translateY(100vh) rotate(45deg); opacity: 0; }
}

/* Fleur-de-lis burst — appears on card navigation */
.fleur-burst {
  position: fixed;
  font-size: 1.6rem;
  opacity: 0;
  pointer-events: none;
  z-index: 3;
  animation: fleur-pop 0.9s var(--ease) forwards;
}

@keyframes fleur-pop {
  0%   { opacity: 0; transform: scale(0) rotate(-20deg); }
  25%  { opacity: 0.5; transform: scale(1.2) rotate(5deg); }
  60%  { opacity: 0.3; transform: scale(1) rotate(0deg) translateY(-30px); }
  100% { opacity: 0; transform: scale(0.6) rotate(10deg) translateY(-60px); }
}

/* ── Reduced Motion ─────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
  }
}
