.story-page {
  --page: #f5f2ea;
  --surface: #fffcf5;
  --ink: #2c342c;
  --muted: #5c6257;
  --line: #d5d0c3;
  background: radial-gradient(ellipse at 50% 57%, #fdf9ee 0%, #f5f2ea 63%, #ece9df 100%);
}

.story-page .site-header { min-height: 58px; }
.story-page .studio { min-height: calc(100svh - 58px); padding-block: 18px 34px; }
.story-page .upload-view { width: min(100%, 580px); }
.story-page .upload-view h1 { font-size: clamp(2.15rem, 5.6vw, 3.65rem); }

.story-page .upload-card {
  min-height: clamp(186px, 29svh, 264px);
  margin-top: 30px;
  border-color: #b5b1a4;
  border-radius: 14px;
  background: #fffdf7b8;
  box-shadow: 0 13px 32px #4d473313;
}

.story-page .upload-card:is(:hover, .dragging) { border-color: #697263; background: var(--surface); }
.story-page .upload-icon { width: 45px; height: 45px; }
.story-page .progress-view h1 { font-size: clamp(1.85rem, 4.8vw, 2.9rem); }

.story-view {
  --paper: #fffcf4;
  --evergreen: #303a30;
  display: grid;
  justify-items: center;
  width: min(100%, 560px);
  margin-inline: auto;
  text-align: center;
}
.story-view[data-scene='letter'] { width: min(100%, 680px); }
.story-view[data-scene='letter'] .story-heading { min-height: 64px; }

.story-heading { min-height: 78px; }
.story-heading h1 { color: var(--evergreen); font-size: clamp(1.65rem, 4.1vw, 2.3rem); }
.story-heading p { margin-top: 8px; color: var(--muted); font-size: .9rem; line-height: 1.45; word-break: keep-all; }
.story-heading .feedback { font-size: .8rem; }

.postcard-stage {
  --art-width: clamp(166px, 29svh, 238px);
  position: relative;
  isolation: isolate;
  display: grid;
  justify-items: center;
  width: 100%;
  margin-top: 8px;
  padding: 8px 0 25px;
}
.story-view[data-format='desktop'] .postcard-stage { --art-width: min(calc(100% - 20px), 510px); }

.postcard-envelope {
  position: absolute;
  z-index: -1;
  bottom: 22px;
  width: min(87%, 338px);
  height: min(31%, 131px);
  transform: rotate(-8deg);
  border: 1px solid #bdb298;
  border-radius: 4px;
  background: linear-gradient(135deg, #c9c0a7, #afa586);
  box-shadow: 0 17px 32px #45372524;
  transition: opacity 380ms ease-out;
}
.story-view[data-scene='letter'] .postcard-envelope { opacity: 0; }

.postcard-envelope::before,
.postcard-envelope::after,
.postcard-envelope span {
  content: '';
  position: absolute;
  inset: 0;
}

.postcard-envelope::before { background: #d5cdb5; clip-path: polygon(0 0, 55% 64%, 0 100%); }
.postcard-envelope::after { background: #c7bda1; clip-path: polygon(100% 0, 45% 64%, 100% 100%); }
.postcard-envelope span { z-index: 1; background: linear-gradient(170deg, #e2d8bd, #c9bda0); clip-path: polygon(0 100%, 50% 43%, 100% 100%); }

.postcard-lift {
  width: min(100%, calc(var(--art-width) + 20px));
  perspective: 1200px;
  animation: postcard-arrive 560ms cubic-bezier(.22, .78, .24, 1) both;
}
.story-view[data-scene='letter'] .postcard-lift { width: 100%; height: auto; }
.postcard-lift.is-unfolding { overflow: clip; }

.postcard-card {
  position: relative;
  width: 100%;
  transform: rotateY(0deg);
  transform-style: preserve-3d;
  transition: transform 1100ms cubic-bezier(.42, .04, .23, 1);
}

.postcard-card[data-side='back'] { transform: rotateY(-180deg); }
.postcard-face {
  position: absolute;
  inset: 0;
  border: 1px solid #dad3c3;
  border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 15px 30px #3a312529, 0 3px 7px #3a312518;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.postcard-front { position: relative; inset: auto; padding: 9px; }
.story-view.is-replacing .postcard-front { outline: 2px dashed #697263; outline-offset: 6px; }
.postcard-front .board-art { width: 100%; border-radius: 1px; }
.postcard-front canvas { display: block; width: 100%; height: auto; }
.postcard-back { display: flex; flex-direction: column; gap: 13px; padding: 15px; transform: rotateY(180deg); visibility: hidden; transition: visibility 0s 620ms; color: var(--evergreen); text-align: left; }
.postcard-card[data-side='back'] .postcard-back { visibility: visible; transition-delay: 0s; }
.story-view[data-scene='letter'] .postcard-front { position: absolute; inset: 0; visibility: hidden; }
.story-view[data-scene='letter'] .postcard-back {
  position: relative;
  inset: auto;
  gap: clamp(20px, 4vw, 30px);
  padding: clamp(20px, 6vw, 54px);
  padding-bottom: clamp(26px, 7vw, 64px);
  border-radius: 5px;
}
.postcard-address { display: flex; align-items: flex-end; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid #ded7c7; font-size: .76rem; font-weight: 700; }
.postcard-stamp { display: grid; place-items: center; width: 28px; height: 34px; margin-inline-start: auto; border: 1px dashed #75816f; color: #465742; }
.postcard-stamp .brand-mark { width: 13px; height: 13px; }
.postcard-letter { min-height: 0; flex: 1; overflow: hidden; font-family: 'AppleMyungjo', 'Batang', Georgia, serif; font-size: .94rem; line-height: 1.65; }
.postcard-letter p { white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.postcard-letter p + p { margin-top: 1.1em; }
.story-view[data-scene='letter'] .postcard-letter { overflow: visible; font-size: clamp(1.02rem, 1.45vw, 1.14rem); line-height: 1.95; }
.postcard-letter .postscript { margin-top: 1.45em; padding-top: 1.2em; border-top: 1px solid #ded7c7; }
.postcard-letter:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.drag-guide { position: absolute; z-index: 1; display: grid; place-items: center; border: 2px dashed #fffdf4; box-shadow: 0 0 0 1px #2c342cab; pointer-events: none; }
.drag-guide span { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #fbf7e9; border-radius: 50%; color: #fff; background: var(--evergreen); box-shadow: 0 4px 12px #0005; font-size: 1.25rem; animation: guide-drag 1.1s ease-in-out 3; }
@keyframes guide-drag {
  0%, 100% { transform: translateY(8px); }
  50% { transform: translateY(-8px); }
}

.photo-tools { position: absolute; z-index: 1; bottom: 25px; right: max(0px, calc((100% - var(--art-width) - 20px) / 2 - 50px)); }
.story-view[data-format='desktop'] .photo-tools { bottom: 11px; }
.photo-reset { width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: #fffcf3; color: var(--ink); font-size: 1.4rem; line-height: 1; box-shadow: 0 2px 6px #3a31251f; }
.photo-reset:hover { background: #e8ebdf; }

.story-actions { display: grid; align-content: start; justify-items: center; min-height: 56px; width: 100%; }
.save-row { display: flex; align-items: stretch; justify-content: center; border-radius: 999px; color: #fff; background: var(--evergreen); }
.save-row .button { min-height: 48px; padding-inline: 22px 17px; border-radius: 999px 0 0 999px; background: transparent; }
.save-row .button:hover { background: #414d40; }

.save-row select {
  min-height: 48px;
  max-width: 100%;
  padding: 0 12px;
  border: 0;
  border-left: 1px solid #ffffff45;
  border-radius: 0 999px 999px 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
}
.save-row select:hover { background: #414d40; }
.save-row select:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.save-row option { background: var(--paper); color: var(--ink); }

.story-link {
  min-height: 48px;
  padding: 0 4px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: .8rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.story-link:hover { color: var(--ink); }
.story-view[data-scene='saved'] #resultFeedback {
  color: #364632;
  font-size: .9rem;
  font-weight: 680;
}
.story-view[data-scene='saved'] #resultFeedback::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 11px;
  margin-inline-end: 8px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-2px) rotate(45deg);
}
.story-view[data-scene='saved'] #resultFeedback { animation: confirmation-in 220ms ease-out both; }
.story-view[data-scene='arrived'] :is(#storyTitle, #resultFeedback) { animation: confirmation-in 360ms ease-out both; }
.story-view[data-scene='turning'] #resultFeedback { animation: confirmation-out 340ms ease-in both; }
.story-view:not([data-scene='board']) #resultSummary { display: none; }
.story-view[data-scene='letter'] #resultFeedback { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.story-view[data-scene='letter'] .story-link { animation: confirmation-in 240ms ease-out both; }

@keyframes postcard-arrive {
  from { opacity: .25; transform: translateY(26px) rotate(-3deg) scale(.96); }
  to { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}

@keyframes confirmation-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes confirmation-out { to { opacity: 0; } }

@media (max-width: 690px) {
  .story-page .site-header { min-height: 48px; }
  .story-page .studio { min-height: calc(100svh - 48px); padding-block: 12px 20px; }
  .story-page .upload-card { margin-top: 22px; }
  .postcard-envelope { width: min(86%, 302px); }
  .postcard-stage { --art-width: clamp(156px, 28.6svh, 216px); }
}

@media (max-width: 359px) {
  .story-heading { min-height: 89px; }
}

@media (prefers-reduced-motion: reduce) {
  .postcard-lift, .drag-guide span, .story-view #resultFeedback, .story-view[data-scene='letter'] .story-link { animation: none; }
  .story-view[data-scene='arrived'] :is(#storyTitle, #resultFeedback) { animation: none; }
  .story-view[data-scene='turning'] #resultFeedback { opacity: 0; }
  .postcard-card, .postcard-back, .postcard-envelope { transition: none; }
}
