/* Easter egg — a little Trenitalia locomotive parked in the corner.
   Click it and Ric Fellini's "Welcome to Rimini" slides in like a film
   the train just delivered. Two pieces: the parked train (.rx-train) and
   the cinema overlay (.rx-cinema). Wired in js/easter-egg.js. */

/* ============================ The parked train ============================ */
.rx-train {
  position: fixed;
  right: clamp(10px, 2.4vw, 26px);
  bottom: clamp(10px, 2.4vw, 26px);
  bottom: calc(clamp(10px, 2.4vw, 26px) + env(safe-area-inset-bottom, 0px));
  z-index: 90;               /* above content, below the cinema overlay (100) */
  width: clamp(72px, 8vw, 104px);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  line-height: 0;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 4px 6px rgba(60, 40, 20, 0.28));
  transition:
    transform var(--hover-ms) var(--ease),
    filter var(--hover-ms) var(--ease),
    opacity 360ms var(--ease);
  /* Idle "chug": mostly still, a small bob so it reads as a living, waiting
     train without being distracting. */
  animation: rx-train-idle 3.6s ease-in-out infinite;
  transform-origin: 60% 100%;
}
.rx-train__svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

/* Hover / focus — the train revs: leans forward, lifts, steam speeds up,
   and the little "All aboard" hint slides up. */
.rx-train:hover,
.rx-train:focus-visible {
  transform: translateY(-3px) scale(1.05);
  filter: drop-shadow(0 7px 12px rgba(60, 40, 20, 0.34));
  animation-play-state: paused;
  outline: none;
}

/* Wheels turn a touch on hover for a sense of life */
.rx-train:hover .rx-train__wheel,
.rx-train:focus-visible .rx-train__wheel {
  animation: rx-wheel-spin 1.6s linear infinite;
}
.rx-train__wheel {
  transform-box: fill-box;
  transform-origin: center;
}

/* Steam puffs rising from the funnel. The container is anchored so its
   BOTTOM sits at the funnel mouth (viewBox ~x33 / y18 → ~29% / ~25% of the
   button box); puffs rise up and out from there. */
.rx-train__steam {
  position: absolute;
  left: 19%;
  top: -9%;
  width: 20%;
  height: 34%;
  pointer-events: none;
}
.rx-train__steam span {
  position: absolute;
  bottom: 0;
  left: 30%;
  width: 40%;
  padding-bottom: 40%;          /* keeps the puff round */
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff 0%, #f0e3c4 55%, rgba(240, 227, 196, 0) 72%);
  opacity: 0;
  animation: rx-steam 2.8s ease-out infinite;
}
.rx-train__steam span:nth-child(2) { animation-delay: 0.9s; }
.rx-train__steam span:nth-child(3) { animation-delay: 1.8s; }
.rx-train:hover .rx-train__steam span,
.rx-train:focus-visible .rx-train__steam span { animation-duration: 1.9s; }

/* "All aboard" hint — a small typewriter ticket that peeks up on hover,
   centered over the train so the text sits neatly inside its frame. */
.rx-train__hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  font-family: var(--f-type);
  font-size: 9.5px;
  line-height: 1;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink);
  background: var(--cream-light);
  border: 1px solid var(--ink-soft);
  border-radius: 2px;
  padding: 5px 9px 4px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translate(-50%, 6px);
  transition:
    opacity var(--hover-ms) var(--ease),
    transform var(--hover-ms) var(--ease);
  pointer-events: none;
}
.rx-train__hint::before { content: "▸ "; color: var(--red); }
.rx-train:hover .rx-train__hint,
.rx-train:focus-visible .rx-train__hint {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* While the cinema is open the train "departs" — slides off to the right */
.rx-train.is-departed {
  transform: translateX(160%) scale(0.9);
  opacity: 0;
  pointer-events: none;
  animation: none;
}

@keyframes rx-train-idle {
  0%, 88%, 100% { transform: translateY(0) rotate(0deg); }
  92%           { transform: translateY(-1.5px) rotate(-0.6deg); }
  96%           { transform: translateY(0) rotate(0.4deg); }
}
@keyframes rx-wheel-spin {
  to { transform: rotate(360deg); }
}
@keyframes rx-steam {
  0%   { opacity: 0;   transform: translateY(0) scale(0.5); }
  25%  { opacity: 0.9; }
  100% { opacity: 0;   transform: translateY(-150%) scale(1.5); }
}

/* ============================ Cinema overlay ============================ */
.rx-cinema {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 3vw, 40px);
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 245, 215, 0.5) 0%, transparent 55%),
    radial-gradient(ellipse at 70% 80%, rgba(180, 145, 90, 0.32) 0%, transparent 55%),
    rgba(20, 15, 9, 0.78);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: rx-cinema-fade 260ms var(--ease);
}
.rx-cinema.is-open { display: flex; }

@keyframes rx-cinema-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* The paper film frame — arrives sliding up from below, like the train
   pulled it in on the tracks. */
.rx-cinema__dialog {
  position: relative;
  width: min(920px, 100%);
  background: var(--cream-light);
  background-image:
    url("../../assets/textures/paper-grain.svg"),
    radial-gradient(ellipse at 20% 0%, rgba(255, 245, 215, 0.7) 0%, transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(220, 195, 140, 0.4) 0%, transparent 55%);
  background-repeat: repeat, no-repeat, no-repeat;
  background-size: 280px 280px, auto, auto;
  border-radius: var(--radius-md);
  box-shadow:
    0 10px 30px rgba(40, 25, 10, 0.5),
    0 30px 90px rgba(40, 25, 10, 0.55);
  padding: 14px;
  animation: rx-cinema-arrive 420ms var(--ease);
}

@keyframes rx-cinema-arrive {
  from { opacity: 0; transform: translateY(40px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.rx-cinema__header {
  display: flex;
  align-items: center;
  padding: 2px 44px 12px 6px;   /* right pad clears the close button */
  position: relative;
}
.rx-cinema__title {
  font-family: var(--f-display);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(26px, 4.2vw, 38px);
  color: var(--navy);
  line-height: 1.02;
}

/* Close button — matches the archive modal's paper-stamped X */
.rx-cinema__close {
  position: absolute;
  top: -2px;
  right: 0;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--ink-soft);
  background: var(--cream);
  color: var(--ink);
  font-family: var(--f-type);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--hover-ms) var(--ease),
    color var(--hover-ms) var(--ease),
    transform var(--hover-ms) var(--ease);
}
.rx-cinema__close:hover,
.rx-cinema__close:focus-visible {
  background: var(--red);
  color: var(--cream-light);
  border-color: var(--red);
  transform: rotate(90deg);
}

/* The screen — 16:9, black, with a thin navy film border */
.rx-cinema__screen {
  position: relative;
  aspect-ratio: 16 / 9;
  width: 100%;
  background: #0b0b0d;
  border: 2px solid var(--navy);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.rx-cinema__screen iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Placeholder shimmer while the iframe boots */
.rx-cinema__screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    115deg,
    rgba(255, 255, 255, 0.03) 0 8px,
    rgba(255, 255, 255, 0) 8px 16px);
  pointer-events: none;
}

/* Lock body scroll while open */
body.rx-cinema-open { overflow: hidden; }

/* ============================ Responsive ============================ */
@media (max-width: 768px) {
  /* On mobile the train isn't a floating corner button (it would sit over
     content) — it parks at the very bottom of the page, in normal flow. */
  .rx-train {
    position: static;
    right: auto;
    bottom: auto;
    display: block;
    margin: 26px auto calc(30px + env(safe-area-inset-bottom, 0px));
  }
  /* No hover on touch; and the departure slide would shift page layout. */
  .rx-train__hint { display: none; }
  .rx-train.is-departed { transform: none; opacity: 0; }

  .rx-cinema { padding: 0; align-items: flex-end; }
  .rx-cinema__dialog {
    width: 100%;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    padding: 12px 12px 18px;
  }
  .rx-cinema__header { padding: 2px 44px 10px 4px; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .rx-train,
  .rx-train__steam span,
  .rx-train__wheel,
  .rx-cinema,
  .rx-cinema__dialog { animation: none !important; }
  .rx-train { transition: opacity 200ms linear; }
  .rx-train.is-departed { transform: none; }
}
