:root {
  --reveal-cream: var(--cream, #ded2c0);
  --reveal-paper: var(--paper, #e9dfcf);
  --reveal-paper-deep: var(--paper-deep, #d8c5ac);
  --reveal-ink: var(--ink, #493629);
  --reveal-muted: var(--muted, #6b5545);
  --reveal-terracotta: var(--terracotta, #854e3b);
  --reveal-caramel: var(--caramel, #ac8058);
  --reveal-peach: var(--peach, #cdb296);
  --reveal-line: var(--line, rgba(73, 54, 41, 0.16));
  --reveal-shadow: 0 24px 70px rgba(73, 54, 41, 0.18);
  --origin-x: 0px;
  --origin-y: 0px;
  --origin-scale: 0.24;
}

.reveal-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(12px, 2.2vw, 24px);
  width: min(960px, 100%);
  margin: 28px auto;
}

.reveal-card {
  position: relative;
  display: block;
  min-width: 0;
}

.reveal-card,
.reveal-card > button {
  aspect-ratio: 3 / 4;
}

button.reveal-card,
.reveal-card > button {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(147, 76, 54, 0.22);
  border-radius: 8px;
  padding: 0;
  background:
    radial-gradient(circle at 50% 18%, rgba(233, 223, 207, 0.92), transparent 34%),
    linear-gradient(155deg, var(--reveal-paper), var(--reveal-paper-deep));
  box-shadow: 0 18px 44px rgba(73, 54, 41, 0.14);
  color: var(--reveal-ink);
  transform: translateZ(0);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    filter 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

button.reveal-card:not(:disabled):hover,
.reveal-card > button:not(:disabled):hover {
  border-color: rgba(147, 76, 54, 0.42);
  box-shadow: 0 24px 56px rgba(73, 54, 41, 0.18);
  transform: translateY(-3px);
}

.reveal-card.is-locked,
.reveal-card.is-locked > button,
button.reveal-card.is-locked,
button.reveal-card:disabled {
  opacity: 0.62;
  filter: saturate(0.82);
}

.reveal-card.is-locked > button,
button.reveal-card.is-locked,
button.reveal-card:disabled {
  cursor: default;
}

.reveal-card.is-locked .reveal-back,
button.reveal-card.is-locked .reveal-back,
button.reveal-card:disabled .reveal-back {
  background:
    radial-gradient(circle at 50% 18%, rgba(233, 223, 207, 0.88), transparent 32%),
    linear-gradient(160deg, #e5d9c7, #d5bea2);
}

.reveal-back,
.reveal-preview {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition:
    opacity 260ms ease,
    transform 260ms ease,
    visibility 260ms ease;
}

.reveal-back {
  z-index: 2;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 20%, rgba(233, 223, 207, 0.98), transparent 36%),
    repeating-linear-gradient(135deg, rgba(147, 76, 54, 0.05) 0 1px, transparent 1px 14px),
    linear-gradient(160deg, #e9dfcf, #d8c5ac);
  color: var(--reveal-terracotta);
  font-family: var(--serif, Georgia, "Times New Roman", serif);
  font-size: clamp(42px, 6vw, 76px);
  line-height: 1;
}

.reveal-back::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 76px;
  height: 76px;
  border: 1px solid rgba(147, 76, 54, 0.24);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: rgba(147, 76, 54, 0.72);
  font-size: 52px;
  transform: translate(-50%, -50%);
}

.reveal-back::after {
  content: attr(data-number);
  position: absolute;
  right: 18px;
  bottom: 16px;
  color: rgba(73, 54, 41, 0.5);
  font-family: var(--mono, Consolas, monospace);
  font-size: 13px;
  letter-spacing: 0.08em;
}

.reveal-preview {
  z-index: 1;
  visibility: hidden;
  background: #1e1610;
  opacity: 0;
  transform: scale(0.98);
  display: flex;
  flex-direction: column;
}

.reveal-back small { position: absolute; bottom: 18px; font: 13px var(--mono); }
.reveal-preview > span { padding: 10px 8px; background: var(--reveal-paper); width: 100%; font-size: 13px; line-height: 1.35; position: relative; flex: 0 0 auto; }
.reveal-card.is-revealed { animation: reveal-glow 3s ease-in-out infinite; }
@keyframes reveal-glow {
  50% { box-shadow: 0 0 32px 7px rgba(216, 197, 172, .9); border-color: var(--reveal-caramel); }
}

.reveal-preview video,
.reveal-preview img {
  display: block;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  width: 100%;
  height: 0;
  object-fit: contain;
  background: #1e1610;
}

.reveal-card.is-revealed .reveal-back,
button.reveal-card.is-revealed .reveal-back {
  visibility: hidden;
  opacity: 0;
  transform: rotateY(18deg) scale(0.96);
}

.reveal-card.is-revealed .reveal-preview,
button.reveal-card.is-revealed .reveal-preview {
  visibility: visible;
  opacity: 1;
  transform: scale(1);
}

.reveal-card.all-open,
button.reveal-card.all-open,
.reveal-grid.all-open .reveal-card,
.reveal-grid.all-open .reveal-card > button {
  box-shadow:
    0 0 0 1px rgba(172, 128, 88, 0.48),
    0 0 34px rgba(172, 128, 88, 0.42),
    0 20px 54px rgba(73, 54, 41, 0.16);
}

.reveal-card.is-beckoning:not(.is-revealed) .reveal-back,
button.reveal-card.is-beckoning:not(.is-revealed) .reveal-back {
  animation: reveal-beckon 1180ms ease-in-out infinite;
}

.reveal-card.is-softened,
button.reveal-card.is-softened {
  filter: blur(1.8px) saturate(0.86);
  opacity: 0.72;
}

.reveal-completion {
  width: min(680px, 100%);
  margin: 32px auto 0;
  text-align: center;
}

.reveal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
}

.reminder-message {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 35;
  width: min(520px, calc(100% - 40px));
  padding: 20px 24px;
  border: 1px solid rgba(147, 76, 54, 0.2);
  border-radius: 8px;
  background: rgba(233, 223, 207, 0.94);
  box-shadow: var(--reveal-shadow);
  color: var(--reveal-ink);
  font-family: var(--serif, Georgia, "Times New Roman", serif);
  font-size: clamp(24px, 6vw, 44px);
  line-height: 1.08;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -44%) scale(0.96);
  transition: opacity 700ms ease, transform 700ms ease;
}

.reminder-message.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

dialog.reveal-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 0;
  overflow: auto;
  background: transparent;
  color: var(--reveal-ink);
}

dialog.reveal-dialog::backdrop {
  background: rgba(38, 25, 18, 0.72);
  backdrop-filter: blur(12px);
  animation: reveal-backdrop-in 700ms ease both;
}
dialog.reveal-dialog.is-leaving::backdrop { animation: reveal-backdrop-out 850ms ease both; }
@keyframes reveal-backdrop-in {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; backdrop-filter: blur(12px); }
}
@keyframes reveal-backdrop-out {
  to { opacity: 0; backdrop-filter: blur(0); }
}

.reveal-stage {
  min-height: 100dvh;
  width: min(940px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(20px, 5dvh, 48px) 0 28px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  align-items: center;
  justify-items: center;
  gap: clamp(16px, 3dvh, 28px);
}

.reveal-flight {
  width: min(72vw, 390px);
  max-width: calc(100vw - 40px);
  perspective: 1400px;
  transform-origin: center;
}

.reveal-flipper {
  position: relative;
  aspect-ratio: 3 / 4;
  width: 100%;
  transform-style: preserve-3d;
}

.reveal-front,
.reveal-video-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid rgba(147, 76, 54, 0.2);
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow: var(--reveal-shadow);
}

.reveal-front {
  display: grid;
  place-items: center;
  font: 64px var(--serif);
  background:
    radial-gradient(circle at 50% 18%, rgba(233, 223, 207, 0.96), transparent 34%),
    linear-gradient(160deg, var(--reveal-paper), var(--reveal-paper-deep));
}

.reveal-video-face {
  display: grid;
  place-items: center;
  background: #1e1610;
  transform: rotateY(180deg);
}

.reveal-video-face video,
video#reveal-video {
  width: 100%;
  height: 100%;
  max-height: 52dvh;
  object-fit: contain;
  background: #1e1610;
}

video#reveal-video {
  display: block;
}

video#reveal-video::-webkit-media-controls {
  opacity: 1;
}

.reveal-copy {
  margin: 0;
  width: min(720px, 100%);
  color: var(--reveal-paper);
  text-shadow: 0 2px 18px rgba(38, 25, 18, 0.3);
  font-family: var(--serif, Georgia, "Times New Roman", serif);
  font-size: clamp(30px, 7vw, 64px);
  line-height: 1.02;
  text-align: center;
  text-wrap: balance;
  opacity: 0;
  transform: translateY(16px);
}

.reveal-media-status {
  width: min(560px, 100%);
  margin: -6px auto 0;
  color: var(--reveal-paper-deep);
  font-family: var(--mono, Consolas, monospace);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}
.reveal-media-status:empty { display: none; }

.reveal-close {
  position: sticky;
  bottom: max(14px, env(safe-area-inset-bottom));
  min-height: 44px;
  border: 1px solid rgba(147, 76, 54, 0.24);
  border-radius: 999px;
  padding: 12px 18px;
  background: rgba(233, 223, 207, 0.92);
  box-shadow: 0 10px 28px rgba(73, 54, 41, 0.14);
  color: var(--reveal-terracotta);
}

.reveal-play {
  min-height: 44px;
  border: 1px solid rgba(147, 76, 54, 0.28);
  border-radius: 999px;
  padding: 12px 18px;
  background: var(--reveal-terracotta);
  box-shadow: 0 12px 32px rgba(73, 54, 41, 0.18);
  color: var(--reveal-paper);
}

.reveal-play[hidden] {
  display: none !important;
}

.reveal-dialog.is-entering .reveal-flight {
  animation: reveal-flight-1 900ms cubic-bezier(0.2, 0.78, 0.18, 1) both;
}

.reveal-dialog.is-entering .reveal-flipper {
  animation: reveal-flip 900ms cubic-bezier(0.2, 0.78, 0.18, 1) both;
}

.reveal-dialog.is-entering .reveal-copy {
  animation: reveal-copy-in 520ms ease 620ms both;
}

.reveal-dialog.is-entering[data-variant="2"] .reveal-flight {
  animation-name: reveal-flight-2;
}

.reveal-dialog.is-entering[data-variant="2"] .reveal-copy {
  animation-name: reveal-copy-drift;
}
@keyframes reveal-copy-drift {
  from { opacity: 0; transform: translate(-24px, 20px) rotate(-2deg); }
  to { opacity: 1; transform: translate(0, 0) rotate(0); }
}

.reveal-dialog.is-entering[data-variant="3"] .reveal-flight {
  animation-name: reveal-flight-3;
}

.reveal-dialog.is-leaving .reveal-copy {
  animation: reveal-copy-out 700ms ease both;
}

.reveal-dialog.is-leaving .reveal-flight {
  animation: reveal-video-out 700ms ease both;
}

@keyframes reveal-beckon {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 rgba(233, 223, 207, 0);
    filter: brightness(1);
    transform: scale(1);
  }
  50% {
    box-shadow: inset 0 0 42px rgba(233, 223, 207, 0.86);
    filter: brightness(1.08);
    transform: scale(1.025);
  }
}

@keyframes reveal-flight-1 {
  0% {
    opacity: 0.86;
    transform: translate(
        var(--origin-x),
        var(--origin-y)
      )
      scale(var(--origin-scale))
      rotate(-5deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0);
  }
}

@keyframes reveal-flight-2 {
  0% {
    opacity: 0.86;
    transform: translate(
        var(--origin-x),
        var(--origin-y)
      )
      scale(var(--origin-scale))
      rotate(7deg);
  }
  56% {
    transform: translate(2vw, -2dvh) scale(0.94) rotate(-2deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0);
  }
}

@keyframes reveal-flight-3 {
  0% {
    opacity: 0.86;
    transform: translate(
        var(--origin-x),
        var(--origin-y)
      )
      scale(var(--origin-scale))
      rotate(-9deg);
  }
  52% {
    transform: translate(-3vw, 1dvh) scale(0.92) rotate(3deg);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0);
  }
}

@keyframes reveal-flip {
  0% {
    transform: rotateY(0);
  }
  100% {
    transform: rotateY(180deg);
  }
}

@keyframes reveal-copy-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes reveal-copy-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-42px) scale(0.96);
  }
}

@keyframes reveal-video-out {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.72);
  }
}

@media (max-width: 900px) {
  .reveal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(620px, 100%);
  }

  .reveal-flight {
    width: min(74vw, 340px);
  }
}

@media (max-width: 430px) {
  .reveal-grid {
    gap: 10px;
  }

  .reveal-back::before {
    width: 56px;
    height: 56px;
    font-size: 40px;
  }

  .reveal-stage {
    width: min(100% - 24px, 360px);
    min-height: 100dvh;
    padding-block: 16px 18px;
    overflow: visible;
  }

  .reveal-flight {
    width: min(78vw, 260px);
  }

  .reveal-copy {
    font-size: clamp(26px, 11vw, 40px);
  }
}

@media (max-width: 360px), (max-height: 740px) {
  dialog.reveal-dialog {
    overflow-y: auto;
  }

  .reveal-stage {
    min-height: 100dvh;
    align-content: start;
    gap: 14px;
  }

  .reveal-flight {
    width: min(70vw, 230px);
  }

  .reveal-video-face video,
  video#reveal-video {
    max-height: 46dvh;
  }

  .reveal-copy {
    font-size: clamp(24px, 10vw, 34px);
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog.reveal-dialog::backdrop { animation: none; }
  .reveal-card,
  .reveal-card > button,
  .reveal-back,
  .reveal-preview,
  .reminder-message,
  .reveal-flight,
  .reveal-flipper,
  .reveal-copy {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }

  .reveal-dialog.is-entering .reveal-flight,
  .reveal-dialog.is-leaving .reveal-flight {
    opacity: 1;
    transform: none;
  }

  .reveal-dialog.is-entering .reveal-flipper {
    transform: rotateY(180deg);
  }

  .reveal-dialog.is-entering .reveal-copy {
    opacity: 1;
    transform: none;
  }
}
