:root {
  color-scheme: light;
  --bg: #f5f2ea;
  --surface: #fffaf0;
  --surface-2: #ede7dc;
  --ink: #23251f;
  --muted: #6f716a;
  --line: #d7cdbc;
  --green: #315c54;
  --red: #bf5b42;
  --gold: #a77a32;
  --blue: #4d6f8f;
  --shadow: 0 18px 45px rgba(44, 38, 28, 0.12);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(49, 92, 84, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(191, 91, 66, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

body.is-locked {
  overflow: hidden;
}

button, input, select, textarea {
  font: inherit;
}

button, select, input, textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

button {
  min-height: 42px;
  padding: 0 14px;
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: var(--green); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.primary {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.soft {
  background: #eef3ef;
  border-color: #cbd8cf;
  color: var(--green);
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  background: #fffdf8;
  color: var(--ink);
}

textarea {
  resize: vertical;
  line-height: 1.8;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 0.88rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  background: #fbf7ed;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: var(--green);
  color: #fff8ea;
  border-radius: 50%;
  font-weight: 800;
}

.brand p, .brand strong {
  display: block;
  margin: 0;
  line-height: 1.1;
}

.brand p {
  color: var(--muted);
  font-size: 0.82rem;
}

.brand strong {
  font-size: 1.1rem;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: transparent;
  text-align: left;
}

.tab.is-active {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.tab span:not(:empty) {
  min-width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: 0.78rem;
}

.quiet-card {
  margin-top: auto;
  padding: 15px;
  background: #f1ebe0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.quiet-card span {
  color: var(--muted);
  font-size: 0.82rem;
}

.quiet-card strong {
  display: block;
  margin-top: 6px;
  line-height: 1.35;
}

.quiet-card p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.identity-card {
  margin-top: 0;
  display: grid;
  gap: 10px;
}

.identity-card label {
  gap: 5px;
}

.identity-card input {
  padding: 9px 10px;
}

.identity-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.identity-actions button {
  min-height: 38px;
  padding: 0 10px;
}

.identity-dialog {
  width: min(620px, calc(100vw - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

.identity-dialog::backdrop {
  background: rgba(31, 29, 24, 0.42);
  backdrop-filter: blur(4px);
}

.identity-panel {
  display: grid;
  gap: 14px;
  padding: 24px;
  background: #fffaf0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.identity-copy {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.identity-actions-modal {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.identity-password.hidden {
  display: none;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.workspace {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 26px;
}

.mobile-head { display: none; }
.view { display: none; }
.view.is-active { display: block; }

.view-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--red);
  font-weight: 800;
  letter-spacing: 0;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 1.02;
  letter-spacing: 0;
  max-width: 820px;
}

h2 { font-size: 1.12rem; }

.compose-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 380px;
  gap: 18px;
  align-items: start;
}

.composer,
.boundary-form,
.draft-drawer,
.contact-card,
.route-card,
.letter-card {
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer {
  display: grid;
  gap: 15px;
  padding: 18px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.letter-paper {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.letter-paper.cotton {
  background: linear-gradient(180deg, #fffdf9, #f8f0df);
}

.letter-paper.rice {
  background: linear-gradient(180deg, #fffef8, #f3ead0);
}

.letter-paper.blue {
  background: linear-gradient(180deg, #f9fcfe, #ecf5fb);
}

.letter-paper.night {
  background: linear-gradient(180deg, #283331, #1d2523);
  color: #f4ead5;
}

.letter-paper textarea {
  border: 0;
  min-height: 310px;
  background:
    linear-gradient(transparent 35px, rgba(49, 92, 84, 0.12) 36px),
    transparent;
  background-size: 100% 36px;
}

.letter-paper.rice textarea { background-color: #fffdf7; font-family: KaiTi, STKaiti, serif; }
.letter-paper.blue textarea { background-color: #f2f7fb; font-family: SimSun, serif; }
.letter-paper.night textarea { background-color: #25302f; color: #f8efd8; }
.letter-paper.night textarea::placeholder { color: rgba(248, 239, 216, 0.52); }

.font-serif textarea, .font-serif .envelope-preview { font-family: Georgia, "Noto Serif SC", SimSun, serif; }
.font-kai textarea, .font-kai .envelope-preview { font-family: KaiTi, STKaiti, serif; }
.font-song textarea, .font-song .envelope-preview { font-family: "Songti SC", SimSun, serif; }
.font-hand textarea, .font-hand .envelope-preview { font-family: "Segoe Print", KaiTi, cursive; }
.font-serif .letter-sheet, .font-serif .letter-stamp { font-family: Georgia, "Noto Serif SC", SimSun, serif; }
.font-kai .letter-sheet, .font-kai .letter-stamp { font-family: KaiTi, STKaiti, serif; }
.font-song .letter-sheet, .font-song .letter-stamp { font-family: "Songti SC", SimSun, serif; }
.font-hand .letter-sheet, .font-hand .letter-stamp { font-family: "Segoe Print", KaiTi, cursive; }

.attachments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.upload-tile {
  min-height: 78px;
  place-content: center;
  padding: 14px;
  border: 1px dashed var(--line);
  background: #fffdf8;
  border-radius: var(--radius);
}

.upload-tile input { padding: 0; border: 0; background: transparent; }

.attachment-preview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.attachment-chip {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
  overflow: hidden;
}

.attachment-chip img,
.attachment-chip video {
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border-radius: 6px;
}

.attachment-chip audio { width: 100%; }

.dialog-reading {
  display: grid;
  gap: 14px;
}

.letter-sheet {
  position: relative;
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.letter-sheet.cotton { background: linear-gradient(180deg, #fffdf9, #f7efdd); }
.letter-sheet.rice { background: linear-gradient(180deg, #fffef8, #f2e7ca); }
.letter-sheet.blue { background: linear-gradient(180deg, #fbfdff, #edf4fa); }
.letter-sheet.night {
  background: linear-gradient(180deg, #2a3431, #1d2422);
  color: #f4ead5;
}

.letter-stamp {
  justify-self: end;
  display: grid;
  gap: 4px;
  min-width: 110px;
  padding: 10px 12px;
  border: 1px solid rgba(49, 92, 84, 0.22);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--green);
  text-align: center;
}

.letter-stamp span {
  font-size: 0.8rem;
}

.letter-stamp strong {
  font-size: 1.02rem;
}

.letter-sheet h2 {
  margin-bottom: 0;
  font-size: 1.22rem;
}

.letter-sheet .dialog-body {
  margin-bottom: 0;
  line-height: 1.95;
  white-space: normal;
}

.letter-sheet .dialog-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.letter-sheet .dialog-attachments img,
.letter-sheet .dialog-attachments video {
  width: 100%;
  border-radius: 8px;
}

.letter-sheet .dialog-attachments audio {
  width: 100%;
}

.send-ritual {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.send-ritual button.is-done {
  background: #f8e8df;
  border-color: #d9a493;
  color: #8a3d2e;
}

.preview-column {
  display: grid;
  gap: 18px;
  position: sticky;
  top: 24px;
}

.envelope-preview {
  position: relative;
  min-height: 330px;
  padding: 26px;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.12) 50%, transparent 51%),
    linear-gradient(45deg, transparent 49%, rgba(191, 91, 66, 0.1) 50%, transparent 51%),
    #fff7e6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.envelope-preview.is-delivering {
  transform: translateY(-1px);
  box-shadow: 0 22px 48px rgba(49, 92, 84, 0.18);
}

.envelope-preview.is-folded { transform: rotate(-0.7deg); }
.envelope-preview.is-sealed { box-shadow: 0 18px 45px rgba(191, 91, 66, 0.18); }
.envelope-preview.is-stamped .stamp-preview { transform: rotate(7deg); }

.send-animation {
  position: absolute;
  inset: 18px;
  z-index: 4;
  display: grid;
  place-items: center;
  background: rgba(255, 250, 240, 0.86);
  border-radius: var(--radius);
  backdrop-filter: blur(2px);
}

.send-animation.is-running .send-sheet {
  animation: sheet-drop 0.95s ease-in-out forwards;
}

.send-animation.is-running .send-flap {
  animation: flap-open 0.55s ease forwards 0.45s;
}

.send-animation.is-posting .send-mailbox {
  animation: mailbox-pop 0.45s ease forwards;
}

.send-animation.is-done {
  opacity: 0;
  transition: opacity 220ms ease;
}

.send-envelope {
  position: relative;
  width: min(260px, 78%);
  height: 150px;
  margin-bottom: 18px;
  border: 2px solid rgba(49, 92, 84, 0.28);
  border-radius: 12px;
  background: #fffdf8;
  overflow: hidden;
}

.send-envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%);
}

.send-sheet {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 16px;
  bottom: 26px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fffef8, #efe7d5);
  box-shadow: 0 8px 18px rgba(44, 38, 28, 0.1);
}

.send-flap {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.22) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.22) 50%, transparent 51%);
  transform-origin: top center;
}

.send-seal {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #d45b3d;
  background: #f7ebe6;
  color: #d45b3d;
  font-size: 0.78rem;
  pointer-events: none;
}

.send-mailbox {
  display: grid;
  justify-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(12px) scale(0.78);
}

.send-mailbox-mark {
  color: var(--green);
  font-weight: 700;
}

.send-mailbox-icon {
  width: 92px;
  height: 68px;
  border-radius: 16px 16px 14px 14px;
  border: 3px solid var(--green);
  background:
    linear-gradient(180deg, rgba(49, 92, 84, 0.08), rgba(49, 92, 84, 0.02)),
    #f4fbf7;
  position: relative;
}

.send-mailbox-icon::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 14px;
  height: 5px;
  border-radius: 999px;
  background: var(--green);
}

.send-mailbox-icon::after {
  content: "";
  position: absolute;
  left: 34px;
  top: -18px;
  width: 24px;
  height: 24px;
  border: 4px solid var(--green);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}

@keyframes sheet-drop {
  0% { transform: translateY(-8px) scale(1); }
  45% { transform: translateY(26px) scale(0.98); }
  70% { transform: translateY(42px) scale(0.92); opacity: 1; }
  100% { transform: translateY(60px) scale(0.82); opacity: 0; }
}

@keyframes flap-open {
  0% { transform: rotateX(0deg); }
  100% { transform: rotateX(175deg); opacity: 0.5; }
}

@keyframes mailbox-pop {
  0% { opacity: 0; transform: translateY(14px) scale(0.72); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.stamp-preview {
  float: right;
  width: 90px;
  height: 90px;
  display: grid;
  place-items: center;
  align-content: center;
  border: 2px dashed var(--red);
  color: var(--red);
  text-align: center;
  transition: transform 180ms ease;
}

.stamp-preview span,
.stamp-preview strong {
  display: block;
}

.stamp-preview span { font-size: 0.78rem; }
.stamp-preview strong { font-size: 1rem; }

.envelope-preview h2 {
  margin-top: 54px;
  font-size: 1.55rem;
}

.envelope-preview p {
  color: var(--muted);
  line-height: 1.7;
}

.handwritten-preview img {
  width: 100%;
  max-height: 170px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.draft-drawer {
  padding: 14px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.section-title h2 { margin: 0; }

.mini-list,
.contact-list,
.route-list {
  display: grid;
  gap: 12px;
}

.mini-item {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.mini-item button { margin-top: 9px; }

.letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
}

.letter-card {
  min-height: 240px;
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.letter-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 48%, rgba(49, 92, 84, 0.08) 49%, transparent 51%);
  pointer-events: none;
}

.letter-card.unopened {
  cursor: pointer;
}

.letter-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  background: #f0eadf;
  border-radius: 999px;
  color: var(--muted);
}

.letter-card h2 {
  margin: 14px 0 9px;
  font-size: 1.28rem;
}

.letter-card p {
  color: var(--muted);
  line-height: 1.65;
}

.letter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.route-card {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 14px;
  padding: 15px;
  align-items: center;
}

.route-status {
  display: grid;
  gap: 8px;
}

.progress-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #e4d9ca;
  overflow: visible;
}

.progress-track span {
  display: block;
  height: 100%;
  width: var(--progress, 18%);
  background: var(--green);
  border-radius: inherit;
}

.route-carriage {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: clamp(0px, calc(var(--progress, 0%) - 48px), calc(100% - 96px));
  width: 96px;
  height: 60px;
  object-fit: contain;
  transform: translateY(-50%);
  filter: brightness(1.16) saturate(0.78) contrast(0.94) drop-shadow(0 4px 4px rgba(49, 40, 27, 0.16));
  pointer-events: none;
}

.boundary-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.boundary-form,
.contact-card {
  padding: 16px;
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}

.check input {
  width: auto;
}

.contact-card form {
  display: grid;
  gap: 11px;
}

.contact-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.danger {
  color: var(--red);
}

.search {
  max-width: 330px;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(31, 29, 24, 0.38);
}

.dialog-letter {
  position: relative;
  padding: 56px 44px 36px;
  background: #fffaf0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.open-animation {
  min-height: 280px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
}

.open-envelope {
  position: relative;
  width: min(310px, 86%);
  height: 170px;
  border: 2px solid rgba(49, 92, 84, 0.24);
  border-radius: 12px;
  background: #fffdf8;
  overflow: visible;
}

.open-envelope::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%);
}

.open-sheet {
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 18px;
  height: 98px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fffef8, #efe6d4);
  box-shadow: 0 8px 18px rgba(44, 38, 28, 0.12);
  transform: translateY(46px) scale(0.92);
  transition: transform 700ms ease, opacity 700ms ease;
}

.open-flap {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.24) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.24) 50%, transparent 51%);
  transform-origin: top center;
  transition: transform 700ms ease, opacity 700ms ease;
}

.seal-button {
  position: absolute;
  left: 42%;
  bottom: 28px;
  transform: translateX(-50%);
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 2px solid #d45b3d;
  background: #f7ebe6;
  color: #d45b3d;
  font-size: 0.9rem;
  box-shadow: 0 10px 20px rgba(191, 91, 66, 0.14);
}

.open-animation.is-opening .open-flap {
  transform: rotateX(160deg);
  opacity: 0.5;
}

.open-animation.is-opening .open-sheet {
  transform: translateY(-24px) scale(1);
}

.open-animation.is-opening .seal-button {
  transform: translateX(-50%) scale(0.92);
  opacity: 0.7;
}

.open-animation.is-open {
  opacity: 0;
  transform: translateY(6px) scale(0.985);
  pointer-events: none;
}

.dialog-reading {
  display: grid;
  gap: 12px;
  opacity: 0;
  transform: translateY(14px) scale(0.988);
  transition: opacity 260ms ease, transform 260ms ease;
}

.dialog-reading.hidden {
  display: none;
}

.dialog-reading.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.close {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 20;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  background: #fffaf0;
  border: 1px solid var(--line);
  pointer-events: auto;
}

.dialog-body {
  margin-top: 18px;
  white-space: pre-wrap;
  line-height: 1.9;
}

.dialog-attachments {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  padding: 12px 14px;
  background: var(--green);
  color: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.motion-stage {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(31, 27, 20, 0.18);
  backdrop-filter: blur(6px);
}

.motion-stage.hidden {
  display: none;
}

.motion-scene {
  position: relative;
  width: min(1320px, calc(100vw - 48px));
  height: min(820px, calc(100vh - 48px));
  display: grid;
  place-items: center;
  transform-origin: center center;
}

.motion-stack {
  position: relative;
  width: 100%;
  height: 100%;
}

.motion-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.985);
  transition:
    opacity 420ms cubic-bezier(.2, .8, .2, 1),
    transform 420ms cubic-bezier(.2, .8, .2, 1),
    filter 420ms ease;
  filter: drop-shadow(0 22px 42px rgba(34, 26, 18, 0.2));
  will-change: opacity, transform;
}

.motion-scene.is-running .motion-stack {
  animation: scene-bob 1.75s ease-in-out both;
}

.motion-scene[data-frame="1"] .frame-1,
.motion-scene[data-frame="2"] .frame-2,
.motion-scene[data-frame="3"] .frame-3 {
  opacity: 1;
  transform: scale(1);
}

.motion-scene[data-frame="1"] .frame-1 {
  opacity: 1;
  transform: translate3d(-1.8%, 1%, 0) scale(1.03) rotate(-1.1deg);
}

.motion-scene[data-frame="2"] .frame-2 {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1.015) rotate(0deg);
}

.motion-scene[data-frame="3"] .frame-3 {
  opacity: 1;
  transform: translate3d(1.4%, -0.6%, 0) scale(1.02) rotate(0.65deg);
}

.motion-scene[data-scene="dispatch"] .motion-stack {
  width: min(1280px, calc(100vw - 48px));
  height: min(760px, calc(100vh - 48px));
}

.motion-scene[data-scene="open"] .motion-stack {
  width: min(1180px, calc(100vw - 48px));
  height: min(760px, calc(100vh - 48px));
}

.motion-envelope {
  position: relative;
  width: min(320px, 68vw);
  height: 178px;
  border: 2px solid rgba(49, 92, 84, 0.24);
  border-radius: 14px;
  background: #fffdf8;
  overflow: hidden;
  box-shadow: 0 18px 42px rgba(28, 24, 18, 0.22);
}

.motion-envelope::before,
.motion-postbox::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.16) 50%, transparent 51%);
}

.motion-sheet {
  position: absolute;
  left: 28px;
  right: 28px;
  top: 20px;
  bottom: 28px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fffef8, #efe7d5);
  box-shadow: 0 10px 18px rgba(44, 38, 28, 0.12);
}

.motion-flap {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, transparent 49%, rgba(49, 92, 84, 0.22) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(49, 92, 84, 0.22) 50%, transparent 51%);
  transform-origin: top center;
}

.motion-seal {
  position: absolute;
  left: 50%;
  bottom: 22px;
  width: 62px;
  height: 62px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 2px solid #d45b3d;
  background: #f7ebe6;
  box-shadow: 0 8px 16px rgba(191, 91, 66, 0.14);
}

.motion-mailbox {
  position: absolute;
  right: 34px;
  bottom: 64px;
  display: grid;
  justify-items: center;
  gap: 8px;
  transform: translateY(12px) scale(0.84);
  opacity: 0;
}

.motion-mailbox-label,
.motion-postbox-label {
  color: var(--green);
  font-weight: 700;
}

.motion-mailbox-icon,
.motion-postbox-icon {
  width: 96px;
  height: 72px;
  position: relative;
  border-radius: 18px 18px 14px 14px;
  border: 3px solid var(--green);
  background: linear-gradient(180deg, rgba(49, 92, 84, 0.08), rgba(49, 92, 84, 0.02)), #f4fbf7;
}

.motion-mailbox-icon::before,
.motion-postbox-icon::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 14px;
  height: 5px;
  border-radius: 999px;
  background: var(--green);
}

.motion-mailbox-icon::after,
.motion-postbox-icon::after {
  content: "";
  position: absolute;
  left: 34px;
  top: -18px;
  width: 24px;
  height: 24px;
  border: 4px solid var(--green);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}

.motion-stage[data-mode="send"] .motion-envelope {
  transform: translateX(-36px);
}

.motion-stage[data-mode="incoming"] .motion-postbox {
  position: absolute;
  left: 32px;
  bottom: 58px;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.motion-stage[data-mode="incoming"] .motion-letter {
  position: absolute;
  left: 50%;
  top: 48px;
  width: min(240px, 56vw);
  height: 140px;
  transform: translateX(-50%) translateY(64px) scale(0.9);
  border: 2px solid rgba(49, 92, 84, 0.22);
  border-radius: 14px;
  background: #fffdf8;
  box-shadow: 0 16px 34px rgba(28, 24, 18, 0.2);
}

.motion-letter-sheet {
  position: absolute;
  inset: 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fffef8, #efe7d5);
}

.motion-letter-seal {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 54px;
  height: 54px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 2px solid #d45b3d;
  background: #f7ebe6;
}

.motion-stage.is-running[data-mode="send"] .motion-sheet {
  animation: sheet-drop 0.95s ease-in-out forwards;
}

.motion-stage.is-running[data-mode="send"] .motion-flap {
  animation: flap-open 0.55s ease forwards 0.42s;
}

.motion-stage.is-posting[data-mode="send"] .motion-mailbox {
  animation: mailbox-pop 0.45s ease forwards;
}

.motion-stage.is-running[data-mode="incoming"] .motion-letter {
  animation: incoming-letter 1.1s cubic-bezier(.2,.8,.2,1) forwards;
}

.motion-stage.is-posting[data-mode="incoming"] .motion-postbox {
  animation: mailbox-pop 0.45s ease forwards;
}

.motion-stage.is-done {
  opacity: 0;
  transition: opacity 220ms ease;
}

@keyframes incoming-letter {
  0% { transform: translateX(-50%) translateY(88px) scale(0.88); opacity: 0; }
  35% { transform: translateX(-50%) translateY(34px) scale(0.94); opacity: 1; }
  70% { transform: translateX(-50%) translateY(-20px) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) translateY(-42px) scale(1.05); opacity: 1; }
}

.motion-stage .motion-scene {
  position: relative;
  width: min(920px, calc(100vw - 48px));
  height: min(560px, calc(100vh - 48px));
}

.motion-stage .dispatch-envelope {
  position: absolute;
  left: 5%;
  top: 50%;
  width: min(380px, 44vw);
  height: min(235px, 28vw);
  transform: translateY(-50%) rotate(-7deg);
  filter: drop-shadow(0 22px 30px rgba(0, 0, 0, 0.2));
}

.motion-stage .dispatch-envelope-body,
.motion-stage .dispatch-envelope-flap {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background:
    linear-gradient(135deg, transparent 49%, rgba(155, 141, 111, 0.22) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(155, 141, 111, 0.18) 50%, transparent 51%),
    repeating-linear-gradient(45deg, #f1eadb 0 3px, #f7f1e5 3px 6px),
    #efe8d8;
}

.motion-stage .dispatch-envelope-body::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 10px;
  border: 1px solid rgba(142, 130, 107, 0.16);
}

.motion-stage .dispatch-envelope-flap {
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
  transform-origin: center top;
}

.motion-stage .dispatch-envelope-seal {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 241, 217, 0.9), transparent 34%),
    radial-gradient(circle at 60% 65%, rgba(112, 72, 24, 0.22), transparent 40%),
    linear-gradient(180deg, #cfa65d, #996f31);
  box-shadow: inset 0 1px 2px rgba(255, 248, 226, 0.5), 0 8px 18px rgba(82, 58, 22, 0.22);
}

.motion-stage .dispatch-mailbox {
  position: absolute;
  right: 4%;
  top: 50%;
  width: min(215px, 24vw);
  height: min(345px, 55vh);
  transform: translateY(-50%);
}

.motion-stage .dispatch-mailbox-cap {
  position: absolute;
  left: 50%;
  top: 0;
  width: 92%;
  height: 84px;
  transform: translateX(-50%);
  border-radius: 50% 50% 26px 26px / 68% 68% 22px 22px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 229, 111, 0.72), transparent 22%),
    linear-gradient(180deg, #2c7a54 0%, #1c6041 100%);
  box-shadow: inset 0 8px 16px rgba(255, 255, 255, 0.08), inset 0 -12px 18px rgba(0, 0, 0, 0.22);
}

.motion-stage .dispatch-mailbox-body {
  position: absolute;
  left: 50%;
  top: 48px;
  width: 84%;
  height: 250px;
  transform: translateX(-50%);
  border-radius: 34px 34px 34px 34px / 24px 24px 22px 22px;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 232, 120, 0.18), transparent 18%),
    radial-gradient(circle at 30% 34%, rgba(255, 255, 255, 0.1), transparent 40%),
    linear-gradient(180deg, #2c7a54 0%, #175d3c 100%);
  box-shadow:
    inset 0 16px 22px rgba(255, 255, 255, 0.08),
    inset 0 -18px 24px rgba(0, 0, 0, 0.2),
    0 22px 30px rgba(0, 0, 0, 0.18);
}

.motion-stage .dispatch-mailbox-slot {
  position: absolute;
  left: 50%;
  top: 54px;
  width: 82px;
  height: 20px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(18, 28, 22, 0.48), rgba(18, 28, 22, 0.72));
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.14);
}

.motion-stage .dispatch-mailbox-base {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 90%;
  height: 40px;
  transform: translateX(-50%);
  border-radius: 28px 28px 40px 40px / 100% 100% 80% 80%;
  background: linear-gradient(180deg, #226847, #124629);
  box-shadow: inset 0 10px 12px rgba(255, 255, 255, 0.05);
}

.motion-stage.is-running[data-mode="dispatch"] .dispatch-envelope {
  animation: dispatch-flight 1.1s cubic-bezier(.2,.8,.2,1) forwards;
}

.motion-stage.is-running[data-mode="dispatch"] .dispatch-envelope-flap {
  animation: dispatch-flap 0.55s ease forwards 0.38s;
}

.motion-stage.is-running[data-mode="dispatch"] .dispatch-mailbox-cap {
  animation: mailbox-bob 1.1s ease-in-out forwards;
}

.motion-stage.is-posting[data-mode="dispatch"] .dispatch-mailbox {
  animation: mailbox-glow 0.45s ease forwards;
}

.motion-stage .open-envelope {
  position: absolute;
  left: 50%;
  top: 48%;
  width: min(470px, 76vw);
  height: min(300px, 56vh);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 22px 30px rgba(0, 0, 0, 0.2));
}

.motion-stage .open-envelope-body,
.motion-stage .open-envelope-flap {
  position: absolute;
  inset: 0;
  border-radius: 16px;
  background:
    linear-gradient(135deg, transparent 49%, rgba(155, 141, 111, 0.2) 50%, transparent 51%),
    linear-gradient(225deg, transparent 49%, rgba(155, 141, 111, 0.16) 50%, transparent 51%),
    repeating-linear-gradient(45deg, #f4eddf 0 3px, #f9f4ea 3px 6px),
    #efe8d8;
}

.motion-stage .open-envelope-body::before {
  content: "";
  position: absolute;
  inset: 18px;
  border-radius: 12px;
  border: 1px solid rgba(142, 130, 107, 0.16);
}

.motion-stage .open-envelope-flap {
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 44%, 50% 100%, 0 44%);
  transform-origin: center top;
  transform: translateY(6px);
}

.motion-stage .open-envelope-seal {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 68px;
  height: 68px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, rgba(255, 241, 217, 0.9), transparent 34%),
    radial-gradient(circle at 60% 65%, rgba(112, 72, 24, 0.2), transparent 42%),
    linear-gradient(180deg, #cfa65d, #996f31);
  box-shadow: inset 0 1px 2px rgba(255, 248, 226, 0.5), 0 10px 20px rgba(82, 58, 22, 0.22);
}

.motion-stage .open-paper {
  position: absolute;
  left: 50%;
  bottom: 32px;
  width: min(360px, 60vw);
  height: min(260px, 44vh);
  transform: translateX(-50%) translateY(86px) scale(0.92);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 254, 248, 0.98), rgba(244, 236, 220, 0.98)),
    repeating-linear-gradient(180deg, transparent 0 24px, rgba(150, 138, 110, 0.18) 24px 25px);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.16);
  overflow: hidden;
}

.motion-stage .open-paper-border {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(166, 149, 114, 0.42);
  border-radius: 4px;
}

.motion-stage .open-paper-lines {
  position: absolute;
  inset: 28px 22px 22px;
  background:
    repeating-linear-gradient(180deg, transparent 0 22px, rgba(137, 126, 104, 0.22) 22px 23px),
    linear-gradient(90deg, transparent 0 32px, rgba(170, 153, 118, 0.16) 32px 33px, transparent 33px 100%);
  opacity: 0.7;
}

.motion-stage.is-running[data-mode="open"] .open-envelope-flap {
  animation: open-flap 0.62s ease forwards;
}

.motion-stage.is-running[data-mode="open"] .open-paper {
  animation: open-paper-rise 0.94s cubic-bezier(.2,.9,.15,1) forwards 0.12s;
}

.motion-stage.is-running[data-mode="open"] .open-envelope-seal {
  animation: seal-pop 0.72s ease forwards 0.16s;
}

.motion-stage.is-posting[data-mode="open"] .open-paper {
  animation: open-paper-final 0.34s ease forwards;
}

.open-animation {
  min-height: 340px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
}

.open-stage {
  position: relative;
  width: min(980px, calc(100vw - 84px));
  height: min(560px, calc(100vh - 260px));
}

.open-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.985);
  transition:
    opacity 420ms cubic-bezier(.2, .8, .2, 1),
    transform 420ms cubic-bezier(.2, .8, .2, 1);
  filter: drop-shadow(0 20px 36px rgba(34, 26, 18, 0.18));
  will-change: opacity, transform;
}

.open-animation[data-frame="1"] .frame-1,
.open-animation[data-frame="2"] .frame-2,
.open-animation[data-frame="3"] .frame-3 {
  opacity: 1;
  transform: scale(1);
}

.open-animation[data-frame="1"] .frame-1 {
  opacity: 1;
  transform: translate3d(-1.2%, 1%, 0) scale(1.02) rotate(-0.6deg);
}

.open-animation[data-frame="2"] .frame-2 {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1.01) rotate(0deg);
}

.open-animation[data-frame="3"] .frame-3 {
  opacity: 1;
  transform: translate3d(1.1%, -0.4%, 0) scale(1.02) rotate(0.5deg);
}

.open-animation.is-open {
  display: none;
}

.seal-button {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  min-width: 128px;
  height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid #cfa989;
  background: rgba(255, 248, 237, 0.92);
  color: #7d5d33;
  box-shadow: 0 12px 24px rgba(93, 68, 39, 0.16);
}

.seal-button:disabled {
  opacity: 0.7;
}

.dialog-letter .dialog-reading {
  margin-top: 0;
}

@keyframes dispatch-flight {
  0% { transform: translateY(-50%) translateX(0) rotate(-7deg) scale(1); }
  54% { transform: translateY(-54%) translateX(24vw) rotate(2deg) scale(0.94); }
  100% { transform: translateY(-58%) translateX(35vw) rotate(8deg) scale(0.78); opacity: 0; }
}

@keyframes dispatch-flap {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-18px) rotateX(160deg); opacity: 0.55; }
}

@keyframes mailbox-bob {
  0%, 100% { transform: translateY(-50%) scale(1); }
  50% { transform: translateY(-50%) scale(1.02); }
}

@keyframes mailbox-glow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.12) saturate(1.08); }
}

@keyframes open-flap {
  0% { transform: translateY(6px) rotate(0deg); }
  100% { transform: translateY(-18px) rotateX(164deg); opacity: 0.5; }
}

@keyframes open-paper-rise {
  0% { transform: translateX(-50%) translateY(86px) scale(0.92); }
  58% { transform: translateX(-50%) translateY(-18px) scale(0.98); }
  100% { transform: translateX(-50%) translateY(-62px) scale(1); }
}

@keyframes open-paper-final {
  0% { transform: translateX(-50%) translateY(-62px) scale(1); }
  100% { transform: translateX(-50%) translateY(-70px) scale(1.02); }
}

@keyframes seal-pop {
  0% { transform: translate(-50%, -50%) scale(1); }
  70% { transform: translate(-50%, -50%) scale(0.88); opacity: 0.7; }
  100% { transform: translate(-50%, -50%) scale(0.78); opacity: 0; }
}

.motion-stage .motion-scene.hidden,
.open-animation.hidden {
  display: none;
}

.hidden { display: none !important; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail {
    position: static;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .rail .brand, .quiet-card { display: none; }
  .tabs {
    display: flex;
    overflow-x: auto;
  }
  .tab {
    flex: 0 0 auto;
    width: auto;
  }
  .workspace { padding: 16px; }
  .mobile-head {
    display: block;
    margin-bottom: 16px;
  }
  .compose-layout,
  .boundary-layout {
    grid-template-columns: 1fr;
  }
  .preview-column { position: static; }
  h1 { font-size: 2.25rem; }
}

@media (max-width: 680px) {
  .view-head,
  .field-row,
  .field-row.three,
  .attachments,
  .send-ritual,
  .route-card {
    grid-template-columns: 1fr;
    display: grid;
  }
  .view-head { align-items: stretch; }
  .search { max-width: none; }
}

/* New letter motion override */
.motion-stage {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: rgba(31, 27, 20, 0.18);
  backdrop-filter: blur(6px);
}

.motion-stage.hidden,
.open-animation.hidden {
  display: none !important;
}

.motion-scene {
  position: relative;
  width: min(1200px, calc(100vw - 56px));
  height: min(760px, calc(100vh - 56px));
  display: grid;
  place-items: center;
}

.letter-motion {
  position: relative;
  width: min(1080px, calc(100vw - 64px));
  height: min(700px, calc(100vh - 64px));
}

.motion-halo {
  position: absolute;
  inset: 12% 10%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 248, 235, 0.62), rgba(255, 248, 235, 0));
  filter: blur(10px);
}

.motion-envelope,
.motion-paper,
.motion-mailbox {
  position: absolute;
  display: block;
  max-width: none;
}

.motion-envelope-body,
.motion-envelope-flap,
.motion-seal,
.motion-paper,
.motion-mailbox img {
  display: block;
  width: 100%;
  height: 100%;
}

.dispatch-motion-art .dispatch-paper-art {
  left: 15%;
  top: 12%;
  width: 25%;
  opacity: 0;
  transform: translate(-22px, 28px) rotate(-10deg) scale(0.95);
}

.dispatch-motion-art .dispatch-envelope-art {
  left: 24%;
  top: 34%;
  width: 36%;
  transform: rotate(-7deg);
}

.dispatch-motion-art .dispatch-envelope-art .motion-seal {
  position: absolute;
  left: 46%;
  top: 56%;
  width: 12%;
  height: auto;
  transform: translate(-50%, -50%);
}

.dispatch-motion-art .mailbox-art {
  right: 10%;
  top: 14%;
  width: 20%;
  opacity: 0;
  transform: translateY(28px) scale(0.94);
}

.dispatch-motion-art .motion-caption,
.receive-motion-art .motion-caption,
.open-motion-art .motion-caption {
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translateX(-50%);
  color: var(--green);
  font-weight: 700;
}

.receive-motion-art .receive-mailbox-art {
  left: 8%;
  top: 14%;
  width: 20%;
}

.receive-motion-art .receive-envelope-art {
  left: 26%;
  top: 34%;
  width: 36%;
  transform: rotate(-6deg);
}

.receive-motion-art .receive-paper-art {
  left: 39%;
  top: 22%;
  width: 22%;
  opacity: 0;
  transform: translateY(50px) scale(0.94);
}

.open-motion-art {
  width: min(980px, calc(100vw - 64px));
  height: min(640px, calc(100vh - 64px));
}

.open-motion-art .open-envelope-art {
  left: 22%;
  top: 34%;
  width: 40%;
}

.open-motion-art .open-paper-art {
  left: 31%;
  top: 24%;
  width: 26%;
  opacity: 0;
  transform: translateY(60px) scale(0.92);
}

.open-motion-art .motion-seal {
  position: absolute;
  left: 46%;
  top: 56%;
  width: 12%;
  height: auto;
  transform: translate(-50%, -50%);
}

.open-animation {
  min-height: 340px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
}

.open-animation.is-opening .open-envelope-art .motion-envelope-flap {
  animation: flap-open 0.68s cubic-bezier(.2,.7,.2,1) forwards;
}

.open-animation.is-opening .open-paper-art {
  animation: paper-pop 0.9s cubic-bezier(.18,.84,.15,1) forwards 0.18s;
}

.open-animation.is-opening .motion-seal {
  animation: seal-pop 0.72s ease forwards 0.08s;
}

.open-animation.is-open {
  opacity: 0;
  transform: translateY(6px) scale(0.985);
  pointer-events: none;
}

.seal-button {
  position: absolute;
  left: 42%;
  top: 52%;
  bottom: auto;
  transform: translateX(-50%);
  z-index: 8;
  width: 96px;
  height: 96px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid #853025;
  background: #b74334;
  color: #fff8ed;
  font-weight: 800;
  letter-spacing: 0;
  box-shadow: 0 12px 22px rgba(120, 44, 31, 0.3), inset 0 0 0 3px rgba(255, 248, 237, 0.22);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 180ms ease, box-shadow 180ms ease, filter 180ms ease;
}

.seal-button::before {
  content: "";
  position: absolute;
  inset: 11px;
  border: 1px dashed rgba(255, 248, 237, 0.72);
  border-radius: 50%;
  pointer-events: none;
}

.seal-button:hover:not(:disabled) {
  transform: translateX(-50%) scale(1.06) rotate(-2deg);
  filter: brightness(1.08);
  box-shadow: 0 16px 28px rgba(120, 44, 31, 0.34), inset 0 0 0 3px rgba(255, 248, 237, 0.28);
}

.seal-button:active:not(:disabled) {
  transform: translateX(-50%) scale(0.96);
}

.seal-button:disabled {
  cursor: wait;
}

.dialog-reading {
  display: grid;
  gap: 12px;
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 260ms ease, transform 260ms ease;
}

.dialog-reading.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.motion-stage[data-mode="dispatch"] .dispatch-paper-art {
  animation: paper-fold-dispatch 1.05s ease-in-out forwards;
}

.motion-stage[data-mode="dispatch"] .dispatch-envelope-art {
  animation: envelope-nod 1.55s ease-in-out forwards;
}

.motion-stage[data-mode="dispatch"] .mailbox-art {
  animation: mailbox-rise 0.65s ease forwards 1.1s, mailbox-glow 0.45s ease forwards 1.62s;
}

.motion-stage[data-mode="dispatch"] .dispatch-envelope-art .motion-seal {
  animation: seal-pop 0.82s ease forwards 0.72s;
}

.motion-stage[data-mode="open"] .receive-mailbox-art {
  animation: mailbox-rise 0.55s ease forwards;
}

.motion-stage[data-mode="open"] .receive-envelope-art {
  animation: envelope-open-rise 0.95s cubic-bezier(.18,.84,.15,1) forwards 0.2s;
}

.motion-stage[data-mode="open"] .receive-paper-art {
  animation: paper-emerge 0.96s cubic-bezier(.18,.84,.15,1) forwards 0.68s;
}

.motion-stage[data-mode="open"] .receive-envelope-art .motion-seal {
  animation: seal-pop 0.68s ease forwards 0.1s;
}

.motion-stage.is-done {
  opacity: 0;
  transition: opacity 220ms ease;
}

@keyframes paper-fold-dispatch {
  0% { opacity: 1; transform: translate(-22px, 28px) rotate(-10deg) scale(0.95); }
  40% { opacity: 1; transform: translate(0, 6px) rotate(-6deg) scale(0.98); }
  72% { opacity: 0.94; transform: translate(18px, 0) rotate(-2deg) scale(0.9); }
  100% { opacity: 0; transform: translate(34px, 42px) rotate(4deg) scale(0.65); }
}

@keyframes envelope-nod {
  0%, 100% { transform: rotate(-7deg); }
  45% { transform: translateY(-6px) rotate(-4deg); }
  78% { transform: translateY(2px) rotate(-6deg); }
}

@keyframes mailbox-rise {
  0% { opacity: 0; transform: translateY(32px) scale(0.94); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes mailbox-glow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.12) saturate(1.08); }
}

@keyframes flap-open {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-18px) rotateX(165deg); opacity: 0.5; }
}

@keyframes paper-pop {
  0% { opacity: 0; transform: translateY(60px) scale(0.92); }
  40% { opacity: 1; transform: translateY(10px) scale(0.98); }
  100% { opacity: 1; transform: translateY(-58px) scale(1.02); }
}

@keyframes paper-emerge {
  0% { opacity: 0; transform: translateY(50px) scale(0.94); }
  45% { opacity: 1; transform: translateY(-12px) scale(0.98); }
  100% { opacity: 1; transform: translateY(-52px) scale(1.02); }
}

@keyframes seal-pop {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(0.86); opacity: 0.75; }
  100% { transform: translate(-50%, -50%) scale(0.72); opacity: 0; }
}

.motion-stage .motion-scene {
  position: relative;
  width: min(1200px, calc(100vw - 56px));
  height: min(760px, calc(100vh - 56px));
}

.motion-stage .motion-envelope {
  aspect-ratio: 1200 / 760;
  overflow: visible;
}

.motion-stage .motion-envelope-body,
.motion-stage .motion-envelope-flap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.motion-stage .motion-seal {
  object-fit: contain;
  pointer-events: none;
}

.motion-stage .motion-paper {
  aspect-ratio: 1200 / 900;
  height: auto;
}

.motion-stage .motion-mailbox {
  aspect-ratio: 500 / 840;
  height: auto;
}

.motion-stage .motion-mailbox img {
  width: 100%;
  height: auto;
}

.dispatch-motion-art .dispatch-paper-art {
  animation: paper-fold-dispatch 0.78s cubic-bezier(.2,.75,.15,1) forwards;
}

.dispatch-motion-art .dispatch-envelope-art {
  animation: dispatch-envelope-sequence 1.55s cubic-bezier(.2,.8,.2,1) forwards;
}

.dispatch-motion-art .dispatch-envelope-art .motion-seal {
  opacity: 0;
  animation: seal-apply 0.36s cubic-bezier(.2,.85,.2,1) forwards 0.92s;
}

.dispatch-motion-art .mailbox-art {
  animation: mailbox-rise 0.5s cubic-bezier(.2,.8,.2,1) forwards 0.74s, mailbox-glow 0.42s ease forwards 1.42s;
}

.receive-motion-art .receive-envelope-art .motion-seal {
  animation: seal-pop 0.42s ease forwards 0.12s;
}

.open-animation.is-opening .open-envelope-art .motion-seal {
  animation: seal-pop 0.42s ease forwards;
}

.open-animation.is-opening .open-envelope-art .motion-envelope-flap {
  animation: flap-open 0.72s cubic-bezier(.2,.72,.2,1) forwards;
}

.open-animation.is-opening .open-paper-art {
  animation: paper-pop 0.94s cubic-bezier(.18,.84,.15,1) forwards 0.2s;
}

@keyframes dispatch-envelope-sequence {
  0% { transform: rotate(-7deg) translate(0, 0) scale(1); opacity: 1; }
  18% { transform: rotate(-4deg) translate(0, -7px) scale(1.02); opacity: 1; }
  38% { transform: rotate(-6deg) translate(0, 2px) scale(1); opacity: 1; }
  52% { transform: rotate(-6deg) translate(0, 0) scale(1); opacity: 1; }
  78% { transform: rotate(7deg) translate(30vw, -4px) scale(0.68); opacity: 1; }
  100% { transform: rotate(12deg) translate(38vw, -12px) scale(0.42); opacity: 0; }
}

@keyframes seal-apply {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.42) rotate(-14deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(4deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

.seal-editor {
  margin-bottom: 16px;
  padding: 18px;
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.seal-editor-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(150px, 190px);
  gap: 12px;
  align-items: end;
}

.seal-editor-preview {
  min-height: 140px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.wax-seal {
  --seal-color: #9e302c;
  width: 104px;
  aspect-ratio: 1;
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 46% 54% 52% 48% / 52% 46% 54% 48%;
  border: 6px solid color-mix(in srgb, var(--seal-color) 86%, #351915);
  background:
    radial-gradient(circle at 33% 27%, rgba(255,255,255,.3), transparent 18%),
    radial-gradient(circle at 68% 74%, rgba(72, 10, 7, .26), transparent 35%),
    var(--seal-color);
  color: #fff7ed;
  box-shadow:
    inset 0 0 0 3px rgba(255, 238, 216, .32),
    inset 0 -8px 12px rgba(64, 12, 8, .24),
    0 8px 16px rgba(74, 35, 25, .18);
  transform: rotate(-2deg);
  overflow: hidden;
}

.wax-seal::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(255, 239, 215, .76);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(60, 16, 12, .22);
}

.wax-seal::after {
  content: "";
  position: absolute;
  inset: 17px;
  border: 1px solid rgba(255, 246, 232, .42);
  border-radius: 50%;
}

.wax-seal-core {
  position: relative;
  z-index: 1;
  margin-top: -13px;
  font-family: Georgia, serif;
  font-size: 2rem;
  line-height: 1;
  text-shadow: 1px 1px 1px rgba(83, 19, 14, .48);
}

.wax-seal strong {
  position: absolute;
  z-index: 1;
  bottom: 16px;
  max-width: 78px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: Georgia, serif;
  font-size: .8rem;
  letter-spacing: .02em;
  text-shadow: 1px 1px 1px rgba(83, 19, 14, .48);
}

.wax-seal[data-pattern="ring"] .wax-seal-core {
  font-size: 2.4rem;
  font-weight: 400;
}

.wax-seal[data-pattern="star"] .wax-seal-core {
  font-size: 2.2rem;
}

.wax-seal[data-pattern="laurel"] .wax-seal-core {
  font-size: 2.3rem;
}

.compose-seal {
  position: absolute;
  right: 28px;
  bottom: 25px;
  z-index: 3;
}

.compose-seal .wax-seal {
  width: 70px;
  border-width: 4px;
}

.compose-seal .wax-seal::before {
  inset: 7px;
}

.compose-seal .wax-seal::after {
  inset: 12px;
}

.compose-seal .wax-seal-core {
  font-size: 1.35rem;
  margin-top: -8px;
}

.compose-seal .wax-seal strong {
  bottom: 10px;
  max-width: 54px;
  font-size: .56rem;
}

.seal-button {
  width: 116px !important;
  height: 116px !important;
  min-width: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  box-shadow: none !important;
  color: inherit !important;
}

.seal-button .wax-seal {
  width: 100%;
  height: 100%;
  transition: transform 180ms ease, filter 180ms ease;
}

.seal-button:hover:not(:disabled) .wax-seal {
  transform: rotate(-2deg) scale(1.06);
  filter: brightness(1.08);
}

.seal-button:active:not(:disabled) .wax-seal {
  transform: rotate(-2deg) scale(.95);
}

.motion-seal.wax-seal {
  display: grid;
}

.motion-seal .wax-seal-core {
  font-size: clamp(.72rem, 1.8vw, 1.7rem);
}

.motion-seal strong {
  font-size: clamp(.34rem, .7vw, .68rem);
  bottom: 14%;
}

.letter-seal {
  display: flex;
  justify-content: flex-end;
  margin: -4px 8px 4px;
}

.letter-seal .wax-seal {
  width: 78px;
}

@media (max-width: 720px) {
  .seal-editor-grid {
    grid-template-columns: 1fr 1fr;
  }

  .seal-editor-grid label:last-of-type {
    grid-column: 1 / -1;
  }

  .seal-editor-preview {
    grid-column: 1 / -1;
  }
}

@keyframes paper-fold-dispatch {
  0% { opacity: 1; transform: translate(-22px, 28px) rotate(-10deg) scale(0.95); }
  34% { opacity: 1; transform: translate(0, 8px) rotate(-6deg) scale(0.98); }
  68% { opacity: 0.95; transform: translate(14px, 6px) rotate(-2deg) scale(0.78); }
  100% { opacity: 0; transform: translate(32px, 38px) rotate(5deg) scale(0.5); }
}

@keyframes flap-open {
  0% { transform: translateY(0) rotateX(0deg); opacity: 1; }
  100% { transform: translateY(-18px) rotateX(165deg); opacity: 0.44; }
}

@keyframes paper-pop {
  0% { opacity: 0; transform: translateY(60px) scale(0.92); }
  38% { opacity: 1; transform: translateY(8px) scale(0.98); }
  72% { opacity: 1; transform: translateY(-12px) scale(1.03); }
  100% { opacity: 1; transform: translateY(-56px) scale(1.02); }
}
