:root {
  --bg: #ffffff;              /* the page */
  --paint: #2f5d7c;           /* the paint of the mailbox */
  --paint-light: #5f8fae;     /* the light on the painted metal */
  --paint-dark: #1b3a50;      /* the shadow on the painted metal */
  --flag: #d8402e;            /* the red flag */
  --flag-light: #f0705a;      /* the light on the flag */
  --wood: #9a6a43;            /* the post */
  --wood-light: #c18d60;      /* the light on the post */
  --wood-dark: #6b4529;       /* the shadow of the post and its grain */
  --brass: #c9a24f;           /* the name plate */
  --brass-light: #f1d68e;     /* the light on the brass */
  --brass-dark: #8a6a2a;      /* the shadow on the brass */
  --steel: #b9c2c9;           /* the hinge, the flag arm, the rivets */
  --steel-light: #f4f7f9;     /* the light on the steel */
  --steel-dark: #6c7780;      /* the shadow on the steel */
  --paper: #fbf7ee;           /* the letter */
  --paper-shade: #efe6d2;     /* the shade of the letter's paper */
  --ink: #1d2430;             /* the writing */
  --ink-soft: #5d6673;        /* the second line of the alert */
  --shipped: #2f8a5f;         /* the green envelope of a shipped order */
  --failed: #d0442f;          /* the red envelope of a failed payment */
  --message: #2f66c2;         /* the blue envelope of a new message */
  --saved: #e9d9b0;           /* the cream envelope of a saved list */
  --postmark: #3b3f52;        /* the ink of the postmark */
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  overflow-x: hidden;
  color: var(--ink);
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.stage {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 12px;
}

/* the whole component: the scene with the box and the alert, and the row of buttons under it */
.post {
  --tw: 300px;                /* the width of the alert, set by the script */
  width: min(600px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 2.4vh, 16px);
}

.post__scene {
  position: relative;
  width: 100%;
  height: clamp(232px, 64vh, 300px);
}

/* the mailbox, drawn in SVG, standing on the left (on narrow screens bottom left) */
.box {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 100%;
  width: auto;
  aspect-ratio: 200 / 240;
  overflow: visible;
  z-index: 2;
}

.stop-paint { stop-color: var(--paint); }
.stop-paint-light { stop-color: var(--paint-light); }
.stop-paint-dark { stop-color: var(--paint-dark); }
.stop-wood-light { stop-color: var(--wood-light); }
.stop-wood-dark { stop-color: var(--wood-dark); }
.stop-brass { stop-color: var(--brass); }
.stop-brass-light { stop-color: var(--brass-light); }
.stop-brass-dark { stop-color: var(--brass-dark); }
.stop-flag { stop-color: var(--flag); }
.stop-flag-light { stop-color: var(--flag-light); }
.stop-steel-light { stop-color: var(--steel-light); }
.stop-steel-dark { stop-color: var(--steel-dark); }

.box__ground { fill: rgba(20, 28, 40, 0.22); }
.box__grain { fill: none; stroke: var(--wood-dark); stroke-width: 0.8; opacity: 0.45; stroke-linecap: round; }
.box__grain--knot { fill: var(--wood-dark); opacity: 0.35; stroke: none; }
.box__bracket-shade { fill: var(--wood-dark); opacity: 0.4; }
.box__mouth { fill: #0d1720; }
.box__bevel { fill: none; stroke: var(--paint-light); stroke-width: 1; opacity: 0.35; }
.box__band { fill: var(--paint-dark); opacity: 0.55; }
.box__shine { fill: none; stroke: #ffffff; stroke-width: 3.2; stroke-linecap: round; opacity: 0.22; }
.box__shine--thin { stroke-width: 1.2; opacity: 0.18; }
.box__dent-shade { fill: var(--paint-dark); opacity: 0.45; }
.box__dent-light { fill: var(--paint-light); opacity: 0.45; }
.box__plate-edge { fill: none; stroke: var(--brass-dark); stroke-width: 0.6; opacity: 0.6; }
.box__plate-word { font: 700 7.2px 'Instrument Sans Variable', sans-serif; letter-spacing: 1.6px; fill: var(--brass-dark); }
.box__lid-lip { fill: var(--paint-dark); opacity: 0.55; }
.box__lid-shine { fill: none; stroke: #ffffff; stroke-width: 1.4; stroke-linecap: round; opacity: 0.3; }
.box__flag-fold { fill: none; stroke: #7d1c12; stroke-width: 0.8; opacity: 0.35; }
.box__flag-shine { fill: none; stroke: #ffffff; stroke-width: 1.2; stroke-linecap: round; opacity: 0.35; }
.box__pin-dot { fill: var(--steel-dark); }
.box__mark { fill: none; }

/* the envelope: placed, sized and moved by the script; its colour is the colour of the kind of alert */
.env {
  --env: var(--shipped);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--ew, 316px);
  height: var(--eh, 158px);
  visibility: hidden;
  pointer-events: none;
  will-change: transform;
}

.env--far, .env--near { z-index: 1; }
.env.is-out.env--far { z-index: 3; }
.env.is-out.env--near { z-index: 5; }

.env__sheet,
.env__face {
  position: absolute;
  inset: 0;
  border-radius: 5px;
  background:
    repeating-linear-gradient(97deg, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(7deg, rgba(0, 0, 0, 0.035) 0 1px, transparent 1px 5px),
    linear-gradient(170deg, color-mix(in srgb, var(--env) 82%, #ffffff), var(--env) 60%, color-mix(in srgb, var(--env) 86%, #000000));
}

.env__sheet {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.08) 40%, transparent),
    linear-gradient(170deg, color-mix(in srgb, var(--env) 70%, #000000), color-mix(in srgb, var(--env) 88%, #000000));
}

.env__face {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 14px 26px -14px rgba(20, 28, 40, 0.55), 0 2px 5px rgba(20, 28, 40, 0.18);
}

/* the address side, seen while it flies */
.env__face--front { overflow: hidden; }

.env__from {
  position: absolute;
  left: 7%;
  top: 11%;
  font-size: clamp(7px, 2.6%, 9px);
  font-size: calc(var(--eh, 158px) * 0.06);
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--env) 30%, #10161f);
  opacity: 0.75;
}

.env__to {
  position: absolute;
  left: 34%;
  top: 50%;
  font-family: 'Caveat Variable', cursive;
  font-weight: 600;
  font-size: calc(var(--eh, 158px) * 0.17);
  color: color-mix(in srgb, var(--env) 20%, #0e1420);
  transform: rotate(-3deg);
  white-space: nowrap;
}

.env__lines {
  position: absolute;
  left: 34%;
  right: 12%;
  top: 72%;
  height: 14%;
  background:
    linear-gradient(currentColor, currentColor) 0 0 / 100% 1px no-repeat,
    linear-gradient(currentColor, currentColor) 0 100% / 78% 1px no-repeat;
  color: color-mix(in srgb, var(--env) 40%, #0e1420);
  opacity: 0.35;
}

.env__stamp {
  position: absolute;
  right: 6%;
  top: 9%;
  height: 30%;
  width: auto;
  aspect-ratio: 36 / 42;
  transform: rotate(3deg);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}

.stamp__paper { fill: #fffaf0; }
.stamp__field { fill: #e8eef6; stroke: #c9b37a; stroke-width: 0.8; }
.stamp__stem { fill: none; stroke: #3d7a52; stroke-width: 1.2; stroke-linecap: round; }
.stamp__leaf { fill: #4f9466; }
.stamp__bloom { fill: #6a5bd0; }

.env__postmark {
  position: absolute;
  right: 15%;
  top: 14%;
  height: 26%;
  width: auto;
  aspect-ratio: 64 / 40;
  transform: rotate(-12deg);
  fill: none;
  stroke: var(--postmark);
  stroke-width: 1.3;
  opacity: 0.55;
  mix-blend-mode: multiply;
}

.env__postmark text { fill: var(--postmark); stroke: none; font: 700 6px 'Instrument Sans Variable', sans-serif; letter-spacing: 0.6px; }

/* the back, with the seams and the closed flap, seen once it has turned over */
.env__face--back { visibility: hidden; box-shadow: 0 14px 26px -14px rgba(20, 28, 40, 0.55), 0 2px 5px rgba(20, 28, 40, 0.18); }

.env__seams {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: rgba(0, 0, 0, 0.22);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.env__flap-shut,
.env__flap-open {
  position: absolute;
  left: 0;
  width: 100%;
  height: 58%;
  clip-path: polygon(0 0, 100% 0, 54% 92%, 50% 100%, 46% 92%);
}

.env__flap-shut {
  top: 0;
  transform-origin: 50% 0;
  background:
    repeating-linear-gradient(7deg, rgba(0, 0, 0, 0.035) 0 1px, transparent 1px 5px),
    linear-gradient(180deg, color-mix(in srgb, var(--env) 88%, #ffffff), color-mix(in srgb, var(--env) 92%, #000000));
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}

.env__flap-open {
  bottom: 100%;
  transform-origin: 50% 100%;
  clip-path: polygon(0 100%, 100% 100%, 54% 8%, 50% 0, 46% 8%);
  background: linear-gradient(0deg, color-mix(in srgb, var(--env) 72%, #000000), color-mix(in srgb, var(--env) 90%, #ffffff));
  transform: scaleY(0);
}

/* the corner a failed payment tears off, and the scrap that falls */
.env.is-torn .env__sheet,
.env.is-torn .env__face {
  clip-path: polygon(0 0, 100% 0, 100% 62%, 96% 66%, 93% 63%, 90% 70%, 86% 68%, 84% 76%, 80% 79%, 82% 86%, 78% 91%, 79% 100%, 0 100%);
}

.env__scrap {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22%;
  height: 38%;
  visibility: hidden;
  background:
    repeating-linear-gradient(7deg, rgba(0, 0, 0, 0.04) 0 1px, transparent 1px 5px),
    linear-gradient(170deg, var(--env), color-mix(in srgb, var(--env) 80%, #000000));
  clip-path: polygon(100% 0, 100% 100%, 9% 100%, 13% 76%, 5% 63%, 27% 55%, 36% 32%, 50% 38%, 64% 18%, 80% 26%);
}

/* the alert: the letter that comes out of the envelope */
.toast {
  --kind: var(--shipped);
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tw);
  height: 74px;
  z-index: 4;
  visibility: hidden;
  will-change: transform;
}

.toast.is-out { z-index: 6; }

.toast__sheet {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: 42px 1fr 34px;
  align-items: center;
  gap: 12px;
  padding: 0 10px 0 14px;
  border-radius: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(120, 96, 50, 0.035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(83deg, rgba(120, 96, 50, 0.03) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #fffdf8, var(--paper) 55%, var(--paper-shade));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 0 0 1px rgba(120, 96, 50, 0.12),
    0 18px 30px -18px rgba(20, 28, 40, 0.55),
    0 3px 8px rgba(20, 28, 40, 0.1);
}

/* the crease where the letter was folded, and the colour of the kind along its left edge */
.toast__sheet::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, rgba(120, 96, 50, 0.16), rgba(120, 96, 50, 0.1) 6%, transparent 10%, transparent 90%, rgba(120, 96, 50, 0.1) 94%, rgba(120, 96, 50, 0.16));
  pointer-events: none;
}

.toast__sheet::after {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--kind);
}

.toast__icon {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--kind);
  background: color-mix(in srgb, var(--kind) 13%, #ffffff);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--kind) 22%, transparent) inset;
}

.toast[data-kind='saved'] .toast__icon { color: #8a6a22; background: color-mix(in srgb, var(--saved) 55%, #ffffff); }

.toast__icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.toast__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.toast__title {
  font-size: 15.5px;
  font-weight: 640;
  font-stretch: 96%;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast__body {
  font-size: 13px;
  line-height: 1.25;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toast__close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.toast__close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }

.toast__close:focus-visible { outline: 2px solid var(--kind); outline-offset: 1px; color: var(--ink); }

@media (hover: hover) {
  .toast__close:hover { background: rgba(29, 36, 48, 0.07); color: var(--ink); }
}

/* the buttons that send each kind of alert */
.post__send {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  --kind: var(--shipped);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 560;
  color: var(--ink);
  background: #f3f1ec;
  box-shadow: 0 0 0 1px rgba(29, 36, 48, 0.08) inset;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chip[data-send='failed'] { --kind: var(--failed); }
.chip[data-send='message'] { --kind: var(--message); }
.chip[data-send='saved'] { --kind: #a07a26; }

.chip svg { width: 18px; height: 18px; fill: none; stroke: var(--kind); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.chip:active { transform: scale(0.95); }

.chip:focus-visible { outline: 2px solid var(--kind); outline-offset: 2px; }

.chip.is-on { background: color-mix(in srgb, var(--kind) 12%, #ffffff); box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--kind) 55%, transparent) inset; }

@media (hover: hover) {
  .chip:hover { background: color-mix(in srgb, var(--kind) 9%, #ffffff); }
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* narrow boxes: the alert on top, the mailbox smaller under it */
@media (max-width: 520px) {
  .post__scene { height: clamp(232px, 66vh, 300px); }
  .chip { height: 32px; font-size: 12px; padding: 0 9px 0 7px; gap: 4px; }
  .chip svg { width: 14px; height: 14px; }
  .post__send { gap: 5px; flex-wrap: nowrap; }
  .toast { height: 70px; }
  .env__flap-open { height: 40%; }
  .toast__sheet { grid-template-columns: 38px 1fr 30px; gap: 10px; padding: 0 6px 0 12px; }
  .toast__icon { width: 38px; height: 38px; }
  .toast__title { font-size: 14.5px; }
  .toast__body { font-size: 12.5px; }
}
