/* ============================================
   HOME PAGE: the dojo doors
   The whole home page is the "door". Tapping a link
   clones it into two halves that crack and slide apart
   (see js/door-split.js).
   ============================================ */

html, body.home {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: 'Bangers', cursive;
  text-align: center;
}

/* ---------- The scene (the door) ---------- */
.door-scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 2;
}

/* The stage covers the screen like background-size: cover,
   so meatball man always stands on the same spot of the porch. */
.stage {
  --vh: 100vh;
  --S: max(56.41vw, var(--vh));          /* stage height */
  position: absolute;
  left: 50%;
  width: max(100vw, calc(var(--vh) * 1.7727));
  height: var(--S);
  /* Centered, but on wide/short screens slide down just enough
     that the PIZZA DOJO sign clears the nav bar (--nav-h set by JS). */
  top: min(0px, max(calc((var(--vh) - var(--S)) / 2),
                    calc(var(--nav-h, 0px) + 8px - var(--S) * 0.175)));
  transform: translateX(-50%);
}
@supports (height: 100dvh) {
  .stage { --vh: 100dvh; }
}

.stage-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Meatball man stands on the porch, just left of center,
   so his peel lands right on the center line. */
.meatball-man {
  position: absolute;
  width: 14.48%;
  aspect-ratio: 1200 / 1122;
  left: 36.42%;
  top: 50.6%;
  transform-origin: 40% 97%;
}
.meatball-man img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.mm-peel,
.mm-body { visibility: hidden; }
/* Older phones without aspect-ratio: give him a real height */
@supports not (aspect-ratio: 1) {
  .meatball-man { height: 0; padding-top: 13.54%; }
}
.mm-peel { transform-origin: 74.875% 57.487%; }   /* his fist */

/* Phones (tall screens): smaller and a bit closer to center */
@media (max-aspect-ratio: 4/5) {
  .meatball-man {
    width: 12.07%;
    left: 38.68%;
    top: 54.5%;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.20), rgba(0,0,0,.45));
  pointer-events: none;
}
@media (max-width: 768px) {
  .overlay { display: none; }
}

/* ---------- Comic toolkit ---------- */
:root {
  --ink: #1d120b;
  --paper: #fffaf0;
  --caption: #ffd54a;
  /* old comic-print dots */
  --halftone: radial-gradient(rgba(29, 18, 11, .16) 1.1px, transparent 1.5px);
}

/* Comic button: thick ink outline, solid offset shadow, squish on press */
.comic-btn {
  display: inline-flex;
  align-items: center;
  gap: .45em;
  font-family: 'Bangers', cursive;
  letter-spacing: .05em;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.comic-btn:hover { background: var(--dojo-gold-light, #f4d03f); transform: translate(-1px, -2px) rotate(-1deg); box-shadow: 5px 6px 0 var(--ink); }
.comic-btn:active { transform: translate(4px, 4px) scale(.97); box-shadow: 0 0 0 var(--ink); }
.comic-btn:focus-visible { outline: 3px dashed var(--dojo-gold-light, #f4d03f); outline-offset: 4px; }

/* ---------- Meatball man's speech bubble ---------- */
.speech-bubble {
  position: absolute;
  left: 18%;
  bottom: 104%;
  width: max-content;
  max-width: min(22rem, 27vw);
  margin: 0;
  padding: .8em 1.3em .5em;
  font-family: 'Bangers', cursive;
  font-weight: 400;
  font-size: clamp(1.25rem, 1.9vw, 2.15rem);
  line-height: 1.05;
  letter-spacing: .03em;
  color: var(--ink);
  text-align: center;
  background: var(--halftone) 0 0 / 7px 7px, var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 5px 5px 0 rgba(29, 18, 11, .85);
  transform-origin: 18% 120%;
  animation: bubble-pop 650ms cubic-bezier(.3, 1.6, .5, 1) 500ms both;
}
.speech-bubble span {
  display: block;
  font-size: 1.35em;
  color: #c0392b;
  -webkit-text-stroke: 1px var(--ink);
  paint-order: stroke fill;
}
/* the tail, pointing down at his hat */
.speech-bubble::before,
.speech-bubble::after {
  content: '';
  position: absolute;
  left: 14%;
  border-style: solid;
  border-color: transparent;
}
.speech-bubble::before {           /* ink outline of tail */
  top: 100%;
  border-width: 26px 10px 0 18px;
  border-top-color: var(--ink);
  transform: skewX(-18deg);
  margin-top: 1px;
}
.speech-bubble::after {            /* paper fill of tail */
  top: 100%;
  margin-left: 4px;
  margin-top: -3px;
  border-width: 22px 7px 0 13px;
  border-top-color: var(--paper);
  transform: skewX(-18deg);
}
@keyframes bubble-pop {
  0%   { transform: scale(0) rotate(-8deg); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: scale(1) rotate(-2deg); opacity: 1; }
}
@media (max-aspect-ratio: 4/5) {
  .speech-bubble {
    left: 8%;
    max-width: 56vw;
    padding: .9em 1.35em .6em;
    font-size: clamp(1.1rem, 5vw, 1.55rem);
  }
}

/* ---------- Living scene ---------- */
.lanterns span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 5.5%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 210, 120, .55) 0%, rgba(255, 170, 60, .22) 38%, transparent 70%);
  mix-blend-mode: screen;
  pointer-events: none;
  animation: flicker 3.2s ease-in-out var(--d) infinite;
}
@keyframes flicker {
  0%, 100% { opacity: .75; transform: translate(-50%, -50%) scale(1); }
  18% { opacity: .95; }
  22% { opacity: .6; }
  26% { opacity: .9; transform: translate(-50%, -50%) scale(1.06); }
  55% { opacity: .7; }
  70% { opacity: 1;  transform: translate(-50%, -50%) scale(1.03); }
  74% { opacity: .78; }
}

.firefly {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: .45%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #fff7b0;
  box-shadow: 0 0 6px 2px rgba(255, 240, 120, .9), 0 0 16px 6px rgba(200, 255, 90, .35);
  pointer-events: none;
  opacity: 0;
  animation:
    firefly-drift var(--dur) ease-in-out var(--delay) infinite alternate,
    firefly-blink var(--blink) ease-in-out var(--delay) infinite;
}
@keyframes firefly-drift {
  0%   { transform: translate(0, 0); }
  33%  { transform: translate(var(--dx1), var(--dy1)); }
  66%  { transform: translate(var(--dx2), var(--dy2)); }
  100% { transform: translate(var(--dx3), var(--dy3)); }
}
@keyframes firefly-blink {
  0%, 100% { opacity: 0; }
  30%, 55% { opacity: 1; }
  75% { opacity: .15; }
}

/* ---------- Comic caption box (footer) ---------- */
.home-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2.5vh;
  padding: 8px 16px;
  display: flex;
  justify-content: center;
}
.caption-box {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  max-width: 40rem;
  padding: .7rem 1rem .7rem 1.2rem;
  background: var(--halftone) 0 0 / 7px 7px, var(--caption);
  border: 3px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  transform: rotate(-1deg);
  text-align: left;
}
.footer-text {
  margin: 0;
  color: var(--ink);
  font-family: 'Bangers', cursive;
  font-size: 1.3rem;
  letter-spacing: .04em;
  line-height: 1.2;
}
.ig-btn {
  flex: none;
  padding: .35rem .8rem .35rem .45rem;
  font-size: 1.15rem;
}
.ig-btn .social-icon { width: 30px; height: 30px; display: block; }
.ig-btn .social-icon path { fill: var(--ink); }

@media (max-width: 768px) {
  .caption-box { gap: .7rem; padding: .55rem .7rem .55rem .85rem; }
  .footer-text { font-size: 1rem; }
  .ig-btn { font-size: .95rem; padding: .3rem .55rem .3rem .35rem; }
  .ig-btn .social-icon { width: 24px; height: 24px; }
}
@media (max-width: 380px) {
  .ig-btn span { display: none; }
}

/* Calm version for reduced-motion settings */
@media (prefers-reduced-motion: reduce) {
  .speech-bubble, .lanterns span, .firefly { animation: none; }
  .speech-bubble { transform: rotate(-2deg); }
  .firefly { opacity: .8; }
}

/* ---------- Behind the doors ---------- */
.reveal {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #000 url('../assets/images/InsideBackground.webp') center center / 100% auto no-repeat;
}
@media (max-width: 768px) {
  .reveal {
    background-image: url('../assets/images/MobileInsideBackground.webp');
    background-size: cover;
  }
}

/* ---------- The split ---------- */
.doors {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  display: none;
}
.is-opening .doors { display: block; }
.is-opening #door-scene { visibility: hidden; }

.door-half {
  position: absolute;
  inset: 0;
  will-change: transform;
}

/* Meatball man: swap the still picture for the two moving pieces */
.is-slamming .mm-rest { visibility: hidden; }
.is-slamming .mm-peel,
.is-slamming .mm-body { visibility: visible; }

.is-slamming .mm-peel {
  animation: peel-slam var(--slam-ms, 420ms) cubic-bezier(.5, 0, .9, .4) forwards;
}
.is-slamming .meatball-man {
  animation: body-slam var(--slam-ms, 420ms) ease-in-out forwards;
}

@keyframes peel-slam {
  0%   { transform: rotate(0deg); }
  45%  { transform: rotate(-30deg); }                      /* wind up */
  75%  { transform: rotate(123deg); animation-timing-function: ease-out; } /* SLAM */
  86%  { transform: rotate(114deg); }                      /* little bounce */
  100% { transform: rotate(123deg); }
}
@keyframes body-slam {
  0%   { transform: none; }
  45%  { transform: translateY(-4%) rotate(-4deg); }       /* lean back */
  75%  { transform: translateY(1%) rotate(5deg) scaleY(.93); } /* squash */
  100% { transform: rotate(3deg) scaleY(.97); }
}

/* Screen shake on impact */
.is-shaking {
  animation: shake 220ms linear;
}
@keyframes shake {
  0%, 100% { transform: translate(0, 0) scale(1); }
  15% { transform: translate(-7px, 4px) scale(1.02); }
  30% { transform: translate(6px, -5px) scale(1.02); }
  45% { transform: translate(-5px, -3px) scale(1.02); }
  60% { transform: translate(4px, 4px) scale(1.02); }
  80% { transform: translate(-2px, 1px) scale(1.01); }
}

/* Halves slide out */
.door-half.left,
.door-half.right {
  transition: transform var(--open-ms, 620ms) cubic-bezier(.55, 0, .25, 1);
}
.is-open .door-half.left  { transform: translateX(var(--left-travel, -100vw)); }
.is-open .door-half.right { transform: translateX(var(--right-travel, 100vw)); }

/* Crack + dust overlay */
.crack-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.crack-svg { filter: drop-shadow(0 0 6px #ffcc33) drop-shadow(0 0 14px #ff9900); } /* glow (Safari-safe) */
.crack-line {
  fill: none;
  stroke: #ffe9a8;
  stroke-width: 3;
  stroke-linejoin: miter;
}
.crack-fade { transition: opacity 250ms ease; }
.is-open .crack-fade { opacity: 0; }

.dust {
  fill: rgba(235, 210, 170, .8);
  transform-box: fill-box;
  transform-origin: center;
  animation: dust 520ms ease-out forwards;
}
@keyframes dust {
  0%   { transform: translate(0, 0) scale(.3); opacity: .9; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.6); opacity: 0; }
}

/* Short laptop screens: keep the caption clear of meatball man's feet */
@media (min-width: 769px) and (max-height: 820px) {
  .home-footer { bottom: 1vh; }
  .footer-text { font-size: 1.05rem; }
  .caption-box { padding: .45rem .8rem; }
}
@supports not (aspect-ratio: 1) {
  @media (max-aspect-ratio: 4/5) { .meatball-man { padding-top: 11.29%; } }
}

/* The split copies must not replay the bubble pop */
.door-half .speech-bubble { animation: none; transform: rotate(-2deg); }

/* ---------- Neon sign ----------
   The painted letters, cut out and lit like neon tubes.
   When a tube flickers off you see the painted letter underneath. */
.neon-sign {
  position: absolute;
  left: 38.248%;
  top: 18.561%;
  width: 25.107%;
  aspect-ratio: 470 / 82;
  pointer-events: none;
}
/* warm light spilling onto the sign board */
.neon-sign::before {
  content: '';
  position: absolute;
  inset: -40% -6%;
  background: radial-gradient(ellipse at center, rgba(255, 140, 40, .35), transparent 65%);
  mix-blend-mode: screen;
  animation: neon-on 1.6s steps(1, end) .3s both;
}
.door-half .neon-sign::before { animation: none; }
.neon-sign img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
/* the tubes stand off the board, so they cast a shadow */
.neon-shadow {
  filter: brightness(0) blur(2px);
  opacity: .85;
  transform: translate(1.4%, 11%);
}
.neon-tube {
  filter:
    drop-shadow(0 0 2px rgba(255, 225, 150, 1))
    drop-shadow(0 0 7px rgba(255, 160, 40, 1))
    drop-shadow(0 0 18px rgba(255, 110, 0, .9))
    drop-shadow(0 0 40px rgba(255, 70, 0, .6));
  animation: neon-on 1.6s steps(1, end) .3s both, neon-hum 4s ease-in-out 2s infinite;
}
/* I and J have loose wires: js/home-life.js flickers one at random now and then */
/* classic neon turn-on: sputter, sputter, ON */
@keyframes neon-on {
  0%   { opacity: 0; }
  10%  { opacity: 1; }
  14%  { opacity: 0; }
  30%  { opacity: .8; }
  34%  { opacity: 0; }
  42%  { opacity: 1; }
  46%  { opacity: .2; }
  60%  { opacity: 1; }
  100% { opacity: 1; }
}
@keyframes neon-hum {
  0%, 100% { opacity: 1; }
  50% { opacity: .9; }
}
/* split copies: sign stays lit, no replay */
.door-half .neon-tube { animation: none; opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .neon-tube { animation: none; opacity: 1; }
}
/* Very short laptop windows: smaller caption box */
@media (min-width: 769px) and (max-height: 560px) {
  .footer-text { font-size: .85rem; }
  .caption-box { padding: .3rem .6rem; gap: .6rem; }
  .ig-btn { font-size: .85rem; padding: .2rem .5rem .2rem .3rem; }
  .ig-btn .social-icon { width: 20px; height: 20px; }
}
