.modal-shade,
.call-overlay {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  background: rgba(35, 29, 26, .62);
  backdrop-filter: blur(2px);
}

.modal-shade.is-open,
.call-overlay.is-open { display: flex; }

.modal {
  position: relative;
  width: min(760px, 100%);
  max-height: min(88dvh, 840px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3vw, 24px);
  border: 3px solid var(--ink);
  border-radius: 2% 4% 3% 2% / 3% 2% 4% 3%;
  background:
    repeating-linear-gradient(0deg, transparent 0 28px, rgba(80,70,60,.045) 28px 29px),
    var(--paper);
  box-shadow: 8px 9px 0 rgba(25, 21, 19, .9);
}

.modal::after {
  content: "";
  position: absolute;
  inset: 6px 4px 4px 7px;
  border: 1.5px solid rgba(48,43,40,.3);
  border-radius: 4% 2% 3% 5% / 2% 4% 3% 4%;
  pointer-events: none;
  transform: rotate(.15deg);
}

.modal__close {
  position: sticky;
  z-index: 10;
  top: 0;
  float: right;
  width: var(--tap);
  min-width: var(--tap);
  height: var(--tap);
  border: 0;
  background: rgba(255,250,240,.92);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.modal-head {
  margin: 0 48px 14px 0;
  padding-bottom: 8px;
  border-bottom: 4px solid var(--red);
  transform: rotate(-.25deg);
}

.modal-head h2 { margin: 0; }
.modal-head p { margin: 5px 0 0; color: var(--muted); }

.paper-blob {
  margin: 10px 0;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 2% 4% 3% 5% / 4% 2% 5% 3%;
  background: #fffdf7;
  box-shadow: 3px 3px 0 rgba(48,43,40,.78);
}

.paper-blob--yellow { background: #fff1b9; }
.paper-blob--blue { background: #e1f0f9; }
.paper-blob--green { background: #e8f2da; }
.paper-blob--pink { background: #f8dfe9; }
.paper-blob--orange { background: #fbe4cf; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 9px;
}

.row--center { justify-content: center; }
.row--spread { justify-content: space-between; }

.btn {
  --btn-fill: #fff;
  --btn-tilt: -.5deg;
  position: relative;
  z-index: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 15px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
  line-height: 1.12;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  isolation: isolate;
}

.btn::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 1px;
  border: 2px solid var(--ink);
  border-radius: 45% 55% 48% 52% / 55% 45% 54% 46%;
  background: var(--btn-fill);
  box-shadow: 2px 2px 0 rgba(48,43,40,.72);
  transform: rotate(var(--btn-tilt));
  transition: transform .12s ease, box-shadow .12s ease;
}

.btn:hover::before,
.btn:focus-visible::before {
  transform: translateY(-1px) rotate(calc(var(--btn-tilt) - .3deg));
  box-shadow: 3px 3px 0 rgba(48,43,40,.72);
}

.btn:active::before {
  transform: translateY(1px) rotate(calc(var(--btn-tilt) + .3deg));
  box-shadow: 1px 1px 0 rgba(48,43,40,.72);
}

.btn--red { --btn-fill: var(--red); color: white; }
.btn--blue { --btn-fill: #dbeef9; }
.btn[disabled] { opacity: .45; cursor: default; }

.answer {
  min-height: 52px;
  margin-top: 10px;
  padding: 10px 11px;
  border: 2px dashed var(--ink);
  border-radius: 3% 5% 2% 4% / 4% 2% 5% 3%;
  background: rgba(255,255,255,.78);
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  white-space: pre-wrap;
}

.small { color: var(--muted); font-size: .78rem; }

.toast {
  position: fixed;
  z-index: 500;
  left: 50%;
  bottom: max(72px, calc(env(safe-area-inset-bottom) + 58px));
  max-width: min(88vw, 560px);
  padding: 9px 13px;
  border: 2px solid var(--ink);
  border-radius: 45% 55% 47% 53%;
  background: var(--paper);
  box-shadow: 3px 4px 0 var(--ink);
  font-family: "Segoe Print", "Comic Sans MS", cursive;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 14px) rotate(-1deg);
  transition: opacity .18s, transform .18s;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0) rotate(-1deg); }

.incoming-call {
  width: min(340px, 100%);
  padding: 24px;
  border: 3px solid #fff;
  border-radius: 22px;
  background: #24242a;
  color: #fff;
  text-align: center;
  box-shadow: 7px 8px 0 rgba(0,0,0,.5);
}

.incoming-call__avatar { font-size: 5rem; }
.incoming-call h2 { margin: 0; }
.incoming-call p { min-height: 2.5em; }

.call-actions { display: flex; justify-content: center; gap: 40px; }

.call-actions button {
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  background: #5ca667;
  color: white;
  font-size: 1.8rem;
  cursor: pointer;
}

.call-actions button:last-child { background: var(--red); }

.float-heart,
.confetti-bit,
.burst-bit,
.emoji-rain,
.rare-runner,
.rare-word {
  position: fixed;
  z-index: 450;
  pointer-events: none;
}

.float-heart { animation: heart-float 1.6s ease-out forwards; }
.confetti-bit { top: -20px; animation: confetti-fall 2.8s linear forwards; }
.burst-bit { font-style: normal; font-size: 1rem; animation: burst-out .85s ease-out forwards; }
.emoji-rain { top: -44px; font-style: normal; font-size: 1.45rem; animation: emoji-rain-fall 2.4s linear forwards; }
.rare-runner { animation: runner-cross 3.3s linear forwards; font-size: 2.3rem; }
.rare-word { color: var(--red); font: 900 1rem "Segoe Print", cursive; animation: rare-pop 2.2s ease forwards; }

@keyframes heart-float {
  to { opacity: 0; transform: translate(var(--dx), -150px) rotate(25deg) scale(.6); }
}

@keyframes confetti-fall {
  to { transform: translate(var(--dx), 110vh) rotate(800deg); }
}

@keyframes burst-out {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--burst-x)), calc(-50% + var(--burst-y))) rotate(var(--burst-rotate)) scale(.7); }
}

@keyframes emoji-rain-fall {
  to { transform: translateY(110vh) rotate(520deg); }
}

@keyframes runner-cross {
  from { transform: translateX(-80px) rotate(-8deg); }
  to { transform: translateX(calc(100vw + 100px)) rotate(8deg); }
}

@keyframes rare-pop {
  0%, 100% { opacity: 0; transform: scale(.6) rotate(-8deg); }
  20%, 70% { opacity: 1; transform: scale(1) rotate(3deg); }
}

body.chaos-2 .scene-track { filter: saturate(1.04); }
body.chaos-3 .brand { animation: tiny-wobble 2.4s steps(2) infinite; }
body.chaos-4 .scene.is-active .doodle-layer { animation: tiny-wobble 1.4s steps(2) infinite; }

@keyframes tiny-wobble {
  50% { transform: translate(1px, -1px) rotate(.18deg); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
