/* The opening postcard (plan/NEXT-REVISION-PLAN.md §1). The arrival and the turn are CSS animations
   of transform and opacity only, so they stay smooth while the campus is still being built. */
@property --wash { syntax: '<percentage>'; inherits: false; initial-value: 0%; }

#postcard { display: none; }
[data-reveal='postcard'] #postcard {
  --pw: min(80vw, 760px, 108vh);
  --ph: calc(var(--pw) / 1.5);
  --turn: 3.1s;
  --soft: cubic-bezier(0.65, 0, 0.35, 1);
  display: block; position: fixed; z-index: 12; left: 50%; top: 47%; width: var(--pw); height: var(--ph);
  transform: translate(-50%, -50%); perspective: 1800px;
  transition: width 1.25s var(--soft), height 1.25s var(--soft), top 1.25s var(--soft), opacity 1.1s ease;
}
@media (max-aspect-ratio: 1/1) {
  [data-reveal='postcard'] #postcard { --pw: min(84vw, 430px, 52vh); --ph: calc(var(--pw) / 0.72); top: 46%; }
}
/* waiting its turn: the sealed envelope and the letter come first on a direct link */
[data-reveal='postcard'] #postcard:not(.pc-play) { visibility: hidden; }

.pc-tilt { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform 0.5s ease-out; }
.pc-lift { position: absolute; inset: 0; transform-style: preserve-3d; animation: pc-arrive 0.95s cubic-bezier(0.2, 0.7, 0.25, 1) both; }
@keyframes pc-arrive { from { opacity: 0; transform: translateY(46px) rotate(-3.5deg) scale(0.96); } to { opacity: 1; transform: rotate(-1.4deg); } }
.pc-card { position: absolute; inset: 0; transform-style: preserve-3d; animation: pc-turn 1.15s var(--soft) var(--turn) both; }
@keyframes pc-turn {
  0% { transform: rotateY(180deg); }
  50% { transform: rotateY(90deg) translateZ(40px) scale(1.04); }
  100% { transform: rotateY(0deg); }
}
.pc-face { position: absolute; inset: 0; border-radius: 8px; overflow: hidden; -webkit-backface-visibility: hidden; backface-visibility: hidden;
  box-shadow: 0 34px 60px -18px rgba(60, 40, 20, 0.34), 0 10px 22px rgba(60, 40, 20, 0.14), 0 1px 3px rgba(60, 40, 20, 0.18);
  transition: border-radius 1.25s var(--soft), box-shadow 1.25s var(--soft); }
.pc-paper { background: var(--fibres), var(--grain), linear-gradient(150deg, #fffefa, #fbf4e4 68%, #f6ecd6); background-size: 420px, 160px, 100%; }

/* a band of light crosses each face as it turns toward the viewer */
.pc-face::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 250, 232, 0.75) 50%, transparent 62%); background-size: 260% 100%; background-position: 130% 0;
  animation: pc-gloss 1.3s ease-in-out calc(var(--turn) + 0.35s) both; }
@keyframes pc-gloss { 0% { opacity: 0; background-position: 130% 0; } 25% { opacity: 1; } 100% { opacity: 0; background-position: -30% 0; } }

/* ---- the written side ---- */
.pc-back { transform: rotateY(180deg); display: grid; grid-template-columns: 1.35fr 1px 1fr; gap: 4%; padding: 6% 6% 5.5%; color: #1a2238; }
.pc-crest { position: absolute; left: 4%; bottom: -12%; width: 44%; aspect-ratio: 1; opacity: 0.07; color: #8a6300; }
.pc-msg { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.pc-name { font-family: 'Pinyon Script', cursive; font-size: calc(var(--pw) * 0.083); line-height: 1.05; overflow-wrap: anywhere; clip-path: inset(-20% 100% -20% -2%); animation: pc-write 0.95s cubic-bezier(0.45, 0.05, 0.55, 0.95) 0.6s forwards; }
@keyframes pc-write { to { clip-path: inset(-20% -2% -20% -2%); } }
.pc-line { margin-top: 5%; font: italic 500 calc(var(--pw) * 0.03)/1.5 'Cormorant Garamond', Georgia, serif; color: #2b2a27; opacity: 0; animation: pc-in 0.7s ease 1.25s forwards; }
.pc-sign { margin-top: 7%; font-family: 'Pinyon Script', cursive; font-size: calc(var(--pw) * 0.036); line-height: 1.2; opacity: 0; animation: pc-in 0.7s ease 1.6s forwards; }
@keyframes pc-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.pc-rule { background: linear-gradient(180deg, transparent, rgba(138, 99, 0, 0.45) 12%, rgba(138, 99, 0, 0.45) 88%, transparent); }
.pc-side { position: relative; display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; min-width: 0; }
.pc-stamp { width: 52%; aspect-ratio: 4 / 5; filter: drop-shadow(0 2px 3px rgba(60, 40, 20, 0.22)); transform: rotate(2deg); }
.pc-stamp svg { width: 100%; height: 100%; display: block; }
.pc-mark { position: absolute; top: 9%; right: 30%; width: 62%; color: #33456e; opacity: 0; mix-blend-mode: multiply; animation: pc-thud 0.38s cubic-bezier(0.5, 0, 0.9, 0.6) 1.55s forwards; }
@keyframes pc-thud { 0% { opacity: 0; transform: scale(1.7) rotate(-2deg); } 100% { opacity: 0.74; transform: scale(1) rotate(-11deg); } }
.pc-addr { align-self: stretch; text-align: left; }
.pc-addr span { display: block; padding: 0 0 5px; margin-top: 9%; border-bottom: 1px solid rgba(138, 99, 0, 0.32); font-size: calc(var(--pw) * 0.0145); letter-spacing: 0.2em; text-transform: uppercase; color: #6b5a33; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-aspect-ratio: 1/1) {
  .pc-back { grid-template-columns: 1fr; grid-template-rows: auto 1px 1fr; gap: 4.5%; padding: 7% 8%; }
  .pc-msg { order: 1; }
  .pc-side { order: -1; flex-direction: row; justify-content: flex-end; align-items: flex-start; }
  .pc-stamp { width: 34%; }
  .pc-mark { right: 22%; top: 12%; width: 44%; }
  .pc-addr { display: none; }
  .pc-rule { background: linear-gradient(90deg, transparent, rgba(138, 99, 0, 0.45) 12%, rgba(138, 99, 0, 0.45) 88%, transparent); }
  .pc-msg { justify-content: flex-start; }
  .pc-name { font-size: calc(var(--pw) * 0.15); }
  .pc-line { font-size: calc(var(--pw) * 0.058); }
  .pc-sign { font-size: calc(var(--pw) * 0.066); }
}

/* ---- the picture side ---- */
.pc-front img { position: absolute; left: 14px; top: 14px; width: calc(100% - 28px); height: calc(100% - 28px); object-fit: cover; border-radius: 2px;
  transition: left 1.25s var(--soft), top 1.25s var(--soft), width 1.25s var(--soft), height 1.25s var(--soft); }
/* colour soaks into the drawing from the tower outward, in soft uneven pools */
.pc-front .pc-clay { --wash: 0%;
  -webkit-mask-image: radial-gradient(circle at 50% 34%, #000 calc(var(--wash) * 0.78 - 9%), transparent calc(var(--wash) * 0.78)),
    radial-gradient(circle at 39% 61%, #000 calc(var(--wash) * 0.66 - 14%), transparent calc(var(--wash) * 0.66 - 3%)),
    radial-gradient(circle at 66% 55%, #000 calc(var(--wash) * 0.7 - 16%), transparent calc(var(--wash) * 0.7 - 5%)),
    radial-gradient(ellipse 140% 90% at 17% 82%, #000 calc(var(--wash) * 0.9 - 40%), transparent calc(var(--wash) * 0.9 - 26%)),
    radial-gradient(ellipse 120% 100% at 85% 18%, #000 calc(var(--wash) * 0.9 - 44%), transparent calc(var(--wash) * 0.9 - 30%));
  mask-image: radial-gradient(circle at 50% 34%, #000 calc(var(--wash) * 0.78 - 9%), transparent calc(var(--wash) * 0.78)),
    radial-gradient(circle at 39% 61%, #000 calc(var(--wash) * 0.66 - 14%), transparent calc(var(--wash) * 0.66 - 3%)),
    radial-gradient(circle at 66% 55%, #000 calc(var(--wash) * 0.7 - 16%), transparent calc(var(--wash) * 0.7 - 5%)),
    radial-gradient(ellipse 140% 90% at 17% 82%, #000 calc(var(--wash) * 0.9 - 40%), transparent calc(var(--wash) * 0.9 - 26%)),
    radial-gradient(ellipse 120% 100% at 85% 18%, #000 calc(var(--wash) * 0.9 - 44%), transparent calc(var(--wash) * 0.9 - 30%));
}
.pc-wash .pc-front .pc-clay { --wash: 190%; transition: --wash 1.7s cubic-bezier(0.4, 0.1, 0.5, 1), left 1.25s var(--soft), top 1.25s var(--soft), width 1.25s var(--soft), height 1.25s var(--soft); }
.pc-foil { position: absolute; inset: 24px; border: 1px solid transparent; border-image: linear-gradient(120deg, #8a6300, #f3d57a 30%, #b58a12 55%, #f7e29c 75%, #8a6300) 1; pointer-events: none; transition: opacity 0.6s ease; }
.pc-caption { position: absolute; left: 38px; bottom: 34px; padding: 8px 18px 9px; background: rgba(252, 248, 238, 0.93); border-radius: 3px; box-shadow: 0 4px 14px rgba(60, 40, 20, 0.16); transition: opacity 0.6s ease; }
.pc-caption b { display: block; font: 400 clamp(20px, 2.6vw, 30px)/1.15 'Pinyon Script', cursive; color: #6e4f00; }
.pc-caption small { display: block; margin-top: 2px; font-size: 9px; letter-spacing: 0.3em; text-transform: uppercase; color: #6b5a33; }

/* ---- shortcuts ---- */
.pc-front-first .pc-card, .pc-front-first .pc-face::after { --turn: 0s; animation: none; }
.pc-front-first .pc-back { visibility: hidden; }

/* ---- it grows into the screen ---- */
[data-reveal='postcard'] #postcard.pc-grow { width: 100vw; height: 100vh; height: 100dvh; top: 50%; }
.pc-grow .pc-lift { animation: none; transform: none; transition: transform 1.25s var(--soft); }
.pc-grow .pc-tilt { transform: none !important; }
.pc-grow .pc-card { animation: none; }
.pc-grow .pc-back { visibility: hidden; }
.pc-grow .pc-face { border-radius: 0; box-shadow: none; }
.pc-grow .pc-face::after { animation: none; }
.pc-grow .pc-front img { left: 0; top: 0; width: 100%; height: 100%; border-radius: 0; }
.pc-grow .pc-foil, .pc-grow .pc-caption { opacity: 0; }
[data-reveal='postcard'] #postcard.pc-gone { opacity: 0; pointer-events: none; }

/* ---- the stage around it ---- */
[data-reveal='postcard'] #letter-stage:has(#postcard.pc-play) { perspective: none; }
[data-reveal='postcard'] #letter-stage:has(#postcard.pc-play):not(.show-letter) { background: radial-gradient(ellipse 90% 70% at 50% 40%, #fdf9ef, #efe7d6 78%, #e6dcc6); }
[data-reveal='postcard'] #letter-stage.leave:has(.pc-grow) { opacity: 1; }
[data-reveal='postcard'] #letter-stage.card-leave { background: transparent !important; pointer-events: none; }
[data-reveal='postcard'] #letter-stage.card-leave > :not(#postcard) { opacity: 0 !important; transition: opacity 0.3s ease; }
[data-reveal='postcard'][data-opening='email'] #letter-stage:is(*, .show-letter)::before { display: none; }
[data-reveal='postcard'][data-opening='email'] .email-plan { display: none; }
[data-reveal='postcard'][data-opening='email'] .email-note { left: 0; right: 0; top: auto; bottom: max(24px, 5vh); text-align: center; }
[data-reveal='postcard'][data-opening='email'] .email-note::before, [data-reveal='postcard'][data-opening='email'] .email-note .script, [data-reveal='postcard'][data-opening='email'] .email-note > p:not(.status) { display: none; }
[data-reveal='postcard'][data-opening='email'] #letter-stage.show-letter #postcard { visibility: hidden; }
/* the card waits tucked behind the letter on a direct link */
.pc-tuck { display: none; }
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  [data-reveal='postcard']:not([data-opening='email']) .pc-tuck { display: block; position: fixed; z-index: 9; left: calc(clamp(28px, 5vw, 84px) + min(36vw, 500px) - 36px); top: 13%; width: min(23vw, 340px); aspect-ratio: 1.5; padding: 9px; background: #fffdf6; border-radius: 6px;
    box-shadow: 0 22px 40px -12px rgba(60, 40, 20, 0.32), 0 3px 8px rgba(60, 40, 20, 0.14); opacity: 0; transform: translateX(-90px) rotate(0deg); transition: opacity 0.8s ease 0.5s, transform 1.1s cubic-bezier(0.2, 0.7, 0.25, 1) 0.5s; pointer-events: none; }
  [data-reveal='postcard']:not([data-opening='email']) #letter-stage.reading .pc-tuck { opacity: 1; transform: rotate(5deg); }
  .pc-tuck img { width: 100%; height: 100%; object-fit: cover; border-radius: 2px; }
}
.card-playing #plan-note { display: none; }
[data-reveal='postcard'] #letter-stage:has(#postcard.pc-play) { cursor: pointer; }

@media (prefers-reduced-motion: reduce) {
  .pc-lift, .pc-card, .pc-face::after, .pc-mark { animation: none !important; }
  .pc-mark { opacity: 0.74; transform: rotate(-11deg); }
}
