/* Main site (on top of app.css). */

#scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  /* plain night until scene.js paints */
  background: linear-gradient(#02050f 0%, #060f2b 45%, #0b1d4a 78%, #15306a 100%);
}

.page > * + * {
  margin-top: 22px;
}

/* ---------- Masthead + tear-off calendar ---------- */

.site-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 18px;
  margin: 26px 0 30px;
}

.masthead {
  display: block;
  color: var(--on-night);
  text-decoration: none;
}

.masthead .kicker {
  display: block;
  margin-bottom: 10px;
  color: var(--on-night-dim);
}

.site-head.small {
  margin: 10px 0 20px;
}

.site-head.small .title .t1 {
  font-size: clamp(34px, 8.5vw, 52px);
}

.site-head.small .title .t2 {
  font-size: clamp(30px, 7vw, 42px);
}

.site-head.small .kicker {
  margin-bottom: 6px;
}

@media (max-width: 520px) {
  .site-head {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .site-head .calendar {
    justify-self: start;
  }
}

.calendar {
  position: relative;
  width: 118px;
  padding: 16px 10px 10px;
  background: var(--grain), #fbf6ea;
  color: var(--ink);
  text-align: center;
  border-radius: 3px;
  box-shadow: var(--paper-shadow);
  transform: rotate(3deg);
  /* torn bottom edge */
  -webkit-mask: linear-gradient(#000, #000) top / 100% calc(100% - 6px) no-repeat, conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) bottom / 10px 6px repeat-x;
  mask: linear-gradient(#000, #000) top / 100% calc(100% - 6px) no-repeat, conic-gradient(from 135deg at top, #0000, #000 1deg 89deg, #0000 90deg) bottom / 10px 6px repeat-x;
}

.calendar::before {
  /* red header band with two binding holes */
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 10px;
  background: radial-gradient(circle 3px at 30% 50%, #2a2019 98%, transparent) , radial-gradient(circle 3px at 70% 50%, #2a2019 98%, transparent), var(--ink-red);
}

.cal-head {
  font-family: var(--font-type);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.cal-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 54px;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ink-red);
  font-variant-numeric: lining-nums;
  font-variation-settings: "opsz" 144;
}

.cal-unit {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
}

.cal-foot {
  margin-top: 4px;
  font-family: var(--font-type);
  font-size: 11px;
  color: var(--ink-soft);
}

.site-head.small .calendar {
  width: 96px;
  padding-top: 14px;
}

.site-head.small .cal-num {
  font-size: 40px;
}

.site-head.small .cal-unit {
  font-size: 20px;
}

/* ---------- Tree ---------- */

.tree-wrap {
  width: min(320px, 78vw);
  margin: 0 auto;
}

.tree-wrap.small {
  width: min(210px, 56vw);
}

.tree {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.tree .light {
  animation: twinkle 2.4s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.bauble-slot {
  cursor: pointer;
  outline: none;
}

.bauble {
  transform-box: fill-box;
  transform-origin: 50% 0%;
  animation: bauble-drop 0.9s var(--ease-spring) both;
}

.bauble-slot:hover .bauble,
.bauble-slot:focus-visible .bauble {
  animation: bauble-drop 0.9s var(--ease-spring) both, swing 1.4s ease-in-out infinite 0.9s;
}

.bauble.is-new {
  animation: bauble-drop 1.2s var(--ease-spring) both, swing 1.2s ease-in-out 3 1.2s;
}

@keyframes bauble-drop {
  from { transform: translateY(-70px); opacity: 0; }
  50% { opacity: 1; }
  to { transform: none; opacity: 1; }
}

@keyframes swing {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(10deg); }
  75% { transform: rotate(-10deg); }
}

.tree-label {
  transition: opacity 0.2s;
  pointer-events: none;
}

.tree-label text {
  fill: var(--ink);
  font: 700 17px var(--font-hand);
}

.tree-caption {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.1;
  color: var(--ink);
}

.name-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 8px;
  justify-content: center;
}

.name-chips .chip:nth-child(3n + 1) {
  transform: rotate(-1.5deg);
}

.name-chips .chip:nth-child(3n + 2) {
  transform: rotate(1.2deg);
}

.name-chips.pick {
  justify-content: flex-start;
}

.stamp-note {
  display: inline-block;
  align-self: center;
  padding: 6px 14px;
  border: 2.5px solid var(--ink-red);
  border-radius: 4px;
  color: var(--ink-red);
  font-family: var(--font-type);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transform: rotate(-3deg);
  opacity: 0.88;
}

/* ---------- Info ---------- */

.how-text {
  max-width: 52ch;
}

.ledger {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.ledger-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ledger-row .label {
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
}

.ledger-row .dots {
  flex: 1;
  border-bottom: 2px dotted rgba(42, 32, 25, 0.35);
  transform: translateY(-4px);
}

.ledger-row b {
  font-weight: 700;
  font-size: 25px;
  color: var(--ink-blue);
  text-align: right;
}

.sticky {
  margin-top: 16px;
  padding: 12px 16px 14px;
  background: #fbefa2;
  color: var(--ink);
  transform: rotate(-1deg);
  box-shadow: 0 8px 16px -8px rgba(0, 0, 0, 0.45);
  max-width: 420px;
}

.sticky .label {
  color: rgba(42, 32, 25, 0.6);
  font-size: 11px;
}

.sticky .hand {
  font-size: 24px;
  line-height: 1.2;
}

.prewrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.foot-links {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--on-night);
}

.foot-links a,
.back {
  font-family: var(--font-type);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--on-night);
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}

/* ---------- Forms ---------- */

.code-input {
  font-size: 34px !important;
  text-align: center;
}

.textarea.short {
  min-height: 102px;
}

fieldset.field {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

fieldset.field legend {
  padding: 0;
  margin-bottom: 8px;
}

.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 14px;
}

@media (max-width: 460px) {
  .grid3 {
    grid-template-columns: 1fr 1fr;
  }
  .grid3 > :first-child {
    grid-column: 1 / -1;
  }
}

.form-intro {
  color: var(--ink-soft);
  max-width: 48ch;
}

/* ---------- My page ---------- */

.greet {
  color: var(--on-night);
  margin: -6px 0 -4px;
}

.greet-name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(46px, 12vw, 66px);
  line-height: 1;
}

.greet .kicker {
  color: var(--on-night-dim);
}

/* A section of a filled-in form: typewriter label, handwritten answer. */
.wish-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 12px;
  border-top: 1.5px dashed rgba(42, 32, 25, 0.25);
}

.wish-block .answer {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 25px;
  line-height: 1.25;
  color: var(--ink-blue);
}

.wish-block .answer.empty {
  color: var(--ink-faint);
}

.wish-block.nope .answer {
  color: var(--ink-red-dark);
}

.size-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
}

.size-row span {
  font-family: var(--font-type);
  font-size: 13px;
  color: var(--ink-soft);
}

.size-row b {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink-blue);
  margin-left: 6px;
}

.receiver-card .label {
  color: var(--ink-soft);
}

.receiver-name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(60px, 17vw, 96px);
  line-height: 0.95;
  color: var(--ink-red);
  transform: rotate(-2deg);
  margin: 2px 0 10px;
  overflow-wrap: anywhere;
}

.receiver-card.fresh .receiver-name {
  animation: write-in 1.4s var(--ease-out) both 0.2s;
}

@keyframes write-in {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

/* ---------- Sealed envelope ---------- */

.env-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 74px 0 4px;
}

.env3d {
  position: relative;
  width: min(330px, 78vw);
  aspect-ratio: 1.55;
  perspective: 900px;
}

.env-back,
.env-front,
.env-flap {
  position: absolute;
  inset: 0;
  border-radius: 4px;
}

.env-back {
  background: #d8c194;
  box-shadow: 0 18px 40px -8px rgba(0, 0, 0, 0.55);
}

/* The pocket: everything except the V-shaped opening under the top flap. */
.env-front {
  z-index: 3;
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cpath d='M0 100 L50 50 L100 100' fill='none' stroke='%23a8875099' stroke-width='.6' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 100% no-repeat,
    var(--grain),
    linear-gradient(170deg, #f1e3c3, #e2cd9f);
}

.env-flap {
  z-index: 4;
  bottom: auto;
  height: 58%;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: var(--grain), linear-gradient(#e6d3a8, #d6be8b);
}

.env3d.open .env-flap {
  z-index: 1;
}

.letter {
  position: absolute;
  z-index: 2;
  left: 6%;
  right: 6%;
  top: 6%;
  bottom: 4%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 12px;
  background: var(--grain), #fffaf0;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}

.env3d.letter-out .letter {
  z-index: 5;
}

.letter-pre,
.letter-post {
  font-family: var(--font-type);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.letter-name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(40px, 11vw, 56px);
  line-height: 1;
  color: var(--ink-red);
  transform: rotate(-2deg);
  overflow-wrap: anywhere;
}

.seal,
.fe-seal {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 58%;
  width: 74px;
  height: 74px;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 47% 53% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 38% 32%, #d23a2d 0%, #9e1b14 55%, #64100b 100%);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.45), inset 0 -4px 7px rgba(0, 0, 0, 0.35), inset 0 3px 5px rgba(255, 255, 255, 0.2);
  color: rgba(255, 214, 200, 0.82);
  font: 800 32px var(--font-display);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.22);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.seal::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 190, 180, 0.3);
}

.seal:not([disabled]) {
  animation: seal-nudge 2.6s ease-in-out infinite;
}

@keyframes seal-nudge {
  0%, 82%, 100% { transform: translate(-50%, -50%) rotate(0); }
  86% { transform: translate(-50%, -50%) rotate(-7deg); }
  90% { transform: translate(-50%, -50%) rotate(6deg); }
  94% { transform: translate(-50%, -50%) rotate(-3deg); }
}

.seal-half.left {
  clip-path: polygon(0 0, 52% 0, 44% 30%, 56% 55%, 46% 100%, 0 100%);
}

.seal-half.right {
  clip-path: polygon(52% 0, 100% 0, 100% 100%, 46% 100%, 56% 55%, 44% 30%);
}

.crumb {
  position: absolute;
  z-index: 7;
  width: 7px;
  height: 6px;
  border-radius: 40%;
  background: #8e1710;
}

.env-hint {
  min-height: 1.5em;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 26px;
  color: var(--ink-red);
}

/* ---------- Flying envelope ---------- */

.fly-env {
  position: fixed;
  z-index: 950;
  width: 230px;
  height: 150px;
  transform: translate(-50%, -50%);
  perspective: 600px;
  pointer-events: none;
}

.fe-body {
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background: var(--grain), linear-gradient(170deg, #f4e7cb, #e0c999);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
}

.fe-addr {
  position: absolute;
  left: 18px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  color: var(--ink-blue);
}

.fe-addr .script {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
}

.fe-addr small {
  font-family: var(--font-hand);
  font-size: 19px;
}

.fe-stamp {
  position: absolute;
  right: 14px;
  top: 12px;
  width: 38px;
  height: 46px;
  display: grid;
  place-items: center;
  background: #fffaf0;
  outline: 2px dashed var(--ink-red);
  outline-offset: -4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.fe-stamp svg {
  width: 22px;
  height: 22px;
}

.fe-flap {
  position: absolute;
  inset: 0 0 auto;
  height: 56%;
  transform-origin: 50% 0;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  background: linear-gradient(#e8d4a6, #d7bf8b);
  transform: rotateX(180deg);
}

.fly-env .fe-seal {
  top: 56%;
  width: 40px;
  height: 40px;
  font-size: 18px;
  opacity: 0;
  cursor: default;
}

.spark {
  position: fixed;
  z-index: 960;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
}

/* ---------- Messages: notes on paper ---------- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1.5px dashed rgba(42, 32, 25, 0.25);
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px 2px;
}

.bubble {
  max-width: 86%;
  padding: 6px 14px 8px;
  background: #fffaf0;
  box-shadow: 0 1px 0 rgba(42, 32, 25, 0.25), 0 6px 12px -8px rgba(0, 0, 0, 0.35);
}

.bubble small {
  display: block;
  font-family: var(--font-type);
  font-size: 11px;
  color: var(--ink-faint);
}

.bubble p {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 24px;
  line-height: 1.2;
  color: var(--ink-blue);
}

.bubble.mine {
  align-self: flex-end;
  background: #fbefa2;
  transform: rotate(0.6deg);
}

.bubble.theirs {
  align-self: flex-start;
  transform: rotate(-0.6deg);
}

.bubble.theirs p {
  color: var(--ink-red-dark);
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input {
  min-height: 70px;
}

/* ---------- Gallery: postage stamps ---------- */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 18px;
  padding-top: 6px;
}

.fx-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 14px 14px;
  background: #fffaf0;
  color: var(--ink);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
  /* perforated edge: solid middle + a ring of half-holes along the border */
  -webkit-mask: linear-gradient(#000 0 0) 5px 5px / calc(100% - 10px) calc(100% - 10px) no-repeat, radial-gradient(circle 5px at 5px 5px, #0000 96%, #000) -5px -5px / 13px 13px;
  mask: linear-gradient(#000 0 0) 5px 5px / calc(100% - 10px) calc(100% - 10px) no-repeat, radial-gradient(circle 5px at 5px 5px, #0000 96%, #000) -5px -5px / 13px 13px;
}

.fx-card:nth-child(odd) {
  transform: rotate(-1deg);
}

.fx-card:nth-child(even) {
  transform: rotate(0.8deg);
}

.fx-card h3 {
  font-family: var(--font-display);
  font-weight: 750;
  font-size: 21px;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--ink);
}

.fx-card .muted {
  font-size: 15px;
  line-height: 1.35;
}

.fx-card .faint {
  font-family: var(--font-type);
  font-size: 11.5px;
}

.fx-card .btn {
  margin-top: auto;
  align-self: flex-start;
}

/* ---------- Floating stamps (magic + sound) ---------- */

.fab-bar {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 1000;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.fab {
  display: grid;
  place-items: center;
  width: 62px;
  height: 70px;
  padding: 0;
  border: 0;
  background: #fffaf0;
  color: var(--ink-red);
  cursor: pointer;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
  -webkit-mask: linear-gradient(#000 0 0) 4px 4px / calc(100% - 8px) calc(100% - 8px) no-repeat, radial-gradient(circle 4px at 4px 4px, #0000 96%, #000) -4px -4px / 10px 10px;
  mask: linear-gradient(#000 0 0) 4px 4px / calc(100% - 8px) calc(100% - 8px) no-repeat, radial-gradient(circle 4px at 4px 4px, #0000 96%, #000) -4px -4px / 10px 10px;
  transform: rotate(6deg);
  transition: transform 0.25s var(--ease-spring);
}

.fab svg {
  width: 34px;
  height: 34px;
}

.fab .fab-frame {
  display: grid;
  place-items: center;
  width: calc(100% - 14px);
  height: calc(100% - 14px);
  border: 1.5px solid currentColor;
}

.fab:hover {
  transform: rotate(-4deg) scale(1.06);
}

.fab.small {
  width: 46px;
  height: 52px;
  color: var(--ink-green);
  transform: rotate(-5deg);
}

.fab.small svg {
  width: 22px;
  height: 22px;
}

.fab[aria-pressed="true"] {
  color: var(--ink-red);
}

.skip-chip {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 1001;
  padding: 8px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-type);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  animation: rise 0.35s var(--ease-out) both;
}

.skip-chip[hidden] {
  display: none;
}
