:root {
  --c-sky-1: #fde68a;
  --c-sky-2: #fcd34d;
  --c-paper: #fffdf5;
  --c-ink: #1f2937;
  --c-accent: #dc2626;
  --c-accent-dark: #991b1b;
  --c-gold: #f59e0b;
  --c-shadow: rgba(0, 0, 0, 0.18);
  --duration: 4s;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Patrick Hand', system-ui, sans-serif;
  color: var(--c-ink);
  background:
    radial-gradient(ellipse at top, #fef3c7 0%, #fbbf24 60%, #f59e0b 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255,255,255,0.5) 0, transparent 4px),
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.4) 0, transparent 3px),
    radial-gradient(circle at 40% 80%, rgba(255,255,255,0.4) 0, transparent 5px),
    radial-gradient(circle at 90% 20%, rgba(255,255,255,0.4) 0, transparent 4px);
  background-size: 200px 200px;
  pointer-events: none;
  z-index: 0;
}

.stage {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 3.75rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
}
.stage .readout { margin-top: -1.6rem; }
.stage .button-wrap { margin-top: 0.6rem; }

/* ---------- Title ---------- */
.title {
  font-family: 'Bungee', sans-serif;
  font-weight: 400;
  text-align: center;
  margin: 0 0 0.5rem;
  line-height: 0.95;
  text-shadow: 4px 4px 0 var(--c-accent), 7px 7px 0 var(--c-accent-dark);
  letter-spacing: 1px;
  transform: rotate(-2deg);
}
.title-the     { display: block; font-size: clamp(1.4rem, 3vw, 2rem); color: #fef3c7; }
.title-dad     { display: block; font-size: clamp(2.4rem, 7vw, 4.2rem); color: #fff; }
.title-machine { display: block; font-size: clamp(2rem, 6vw, 3.6rem); color: #fef3c7; }

/* ---------- Machine container ---------- */
.machine {
  width: 100%;
  max-width: 820px;
  background: linear-gradient(180deg, #fde68a, #fbbf24);
  border: 8px solid #1f2937;
  border-radius: 24px;
  box-shadow:
    0 12px 0 #92400e,
    0 24px 40px var(--c-shadow);
  overflow: hidden;
  position: relative;
}
.machine svg {
  display: block;
  width: 100%;
  height: auto;
}

/* ---------- Gear train (all spinning continuously, faster when running) ---------- */
.spin { transform-box: fill-box; transform-origin: center; }

@keyframes spinCW  { from { transform: rotate(0deg);   } to { transform: rotate(360deg);  } }
@keyframes spinCCW { from { transform: rotate(0deg);   } to { transform: rotate(-360deg); } }

.spin-cw  { animation: spinCW  linear infinite; }
.spin-ccw { animation: spinCCW linear infinite; }

.spin-slow     { animation-duration: 14s; }
.spin-medium   { animation-duration: 10s; }
.spin-fast     { animation-duration: 7s; }
.spin-veryfast { animation-duration: 4s; }

.machine.running .spin-slow     { animation-duration: 2.4s; }
.machine.running .spin-medium   { animation-duration: 1.6s; }
.machine.running .spin-fast     { animation-duration: 1s; }
.machine.running .spin-veryfast { animation-duration: 0.5s; }

/* ---------- Smokestack puffs ---------- */
.smoke-puff { transform-box: fill-box; transform-origin: center; }
@keyframes smokeRise {
  0%   { opacity: 0; transform: translate(0, 0) scale(0.6); }
  25%  { opacity: 0.8; }
  100% { opacity: 0; transform: translate(18px, -60px) scale(1.8); }
}
.smoke-1 { animation: smokeRise 4s ease-out infinite; }
.smoke-2 { animation: smokeRise 4s ease-out infinite; animation-delay: 1.3s; }
.smoke-3 { animation: smokeRise 4s ease-out infinite; animation-delay: 2.6s; }

.machine.running .smoke-1 { animation-duration: 1.3s; animation-delay: 0s; }
.machine.running .smoke-2 { animation-duration: 1.3s; animation-delay: 0.4s; }
.machine.running .smoke-3 { animation-duration: 1.3s; animation-delay: 0.8s; }

/* ---------- Piston pump ---------- */
.piston { transform-box: fill-box; transform-origin: center; }
@keyframes pistonPump {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(28px); }
}
/* gentle idle bob */
.piston { animation: pistonPump 4s ease-in-out infinite; }
.machine.running .piston { animation-duration: 0.45s; }

/* ---------- Pressure gauge needle ---------- */
.gauge-needle { transform-box: fill-box; transform-origin: center; transform: rotate(-110deg); }
@keyframes needleSwing {
  0%   { transform: rotate(-110deg); }
  20%  { transform: rotate(-50deg); }
  40%  { transform: rotate(20deg); }
  60%  { transform: rotate(60deg); }
  75%  { transform: rotate(75deg); }
  85%  { transform: rotate(70deg); }
  100% { transform: rotate(72deg); }
}
.machine.running .gauge-needle { animation: needleSwing 4s cubic-bezier(.45,.2,.55,1) forwards; }

/* ---------- Steam vent puffs (from cylinder side) ---------- */
.vent-puff { transform-box: fill-box; transform-origin: center; }
@keyframes ventBurst {
  0%   { opacity: 0; transform: translate(0,0) scale(0.4); }
  25%  { opacity: 0.95; }
  100% { opacity: 0; transform: translate(-14px, -36px) scale(1.7); }
}
.machine.running .vent-1 { animation: ventBurst 0.9s ease-out infinite; }
.machine.running .vent-2 { animation: ventBurst 0.9s ease-out infinite; animation-delay: 0.3s; }
.machine.running .vent-3 { animation: ventBurst 0.9s ease-out infinite; animation-delay: 0.6s; }

/* ---------- LEDs blinking ---------- */
.led { opacity: 0.35; transition: opacity 0.2s; }
.led-1 { opacity: 0.95; }   /* "power on" LED stays lit at idle */

@keyframes ledBlink {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}
.machine.running .led-1 { animation: ledBlink 0.25s linear infinite; }
.machine.running .led-2 { animation: ledBlink 0.25s linear infinite; animation-delay: 0.05s; }
.machine.running .led-3 { animation: ledBlink 0.25s linear infinite; animation-delay: 0.10s; }
.machine.running .led-4 { animation: ledBlink 0.25s linear infinite; animation-delay: 0.15s; }
.machine.running .led-5 { animation: ledBlink 0.25s linear infinite; animation-delay: 0.20s; }

/* ---------- Warning lamp pulse ---------- */
.warning-bulb { transform-box: fill-box; transform-origin: center; }
@keyframes warningPulse {
  0%, 100% { fill: #fde047; transform: scale(1); }
  50%      { fill: #ef4444; transform: scale(1.18); }
}
.machine.running .warning-bulb { animation: warningPulse 0.45s ease-in-out infinite; }

/* ---------- Output paper emerges near the end ---------- */
.paper-strip { transform-box: fill-box; transform-origin: center; }
@keyframes paperEmerge {
  0%   { opacity: 0; transform: translateY(8px); }
  35%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 1; transform: translateY(-6px); }
}
.machine.running .paper-strip { animation: paperEmerge 0.6s ease-out forwards; animation-delay: 3.3s; }

/* ---------- Subtle machine "rumble" while running ---------- */
@keyframes rumble {
  0%, 100% { transform: translate(0, 0); }
  25%      { transform: translate(-1px, 1px); }
  50%      { transform: translate(1px, -1px); }
  75%      { transform: translate(-1px, -1px); }
}
.machine.running svg { animation: rumble 0.12s linear infinite; }

/* ---------- Readout paper (the printer paper feeding from the slot) ---------- */
.readout {
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: center;
  perspective: 800px;
}
.readout-paper {
  position: relative;
  background: var(--c-paper);
  color: var(--c-ink);
  font-family: 'Patrick Hand', sans-serif;
  font-size: clamp(1.2rem, 2.4vw, 1.7rem);
  line-height: 1.4;
  padding: 1.8rem 1.75rem 1.6rem;
  min-height: 5.5rem;
  width: 100%;
  border-left: 2px solid #78716c;
  border-right: 2px solid #78716c;
  border-bottom: 2px solid #78716c;
  border-top: none;
  box-shadow:
    inset 0 8px 12px -8px rgba(0,0,0,0.35),
    0 10px 18px rgba(0,0,0,0.18);
  background-image:
    linear-gradient(transparent 95%, rgba(30,58,138,0.10) 95%);
  background-size: 100% 2.2rem;
  background-position: 0 1rem;
  transform-origin: top center;
  transition: transform 0.35s cubic-bezier(.5,.05,.4,.95), opacity 0.3s ease-in;
}

/* Perforation strip: tractor-feed holes along the top — looks like it tore from the machine */
.readout-perf {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 14px;
  background-color: var(--c-paper);
  background-image: radial-gradient(circle at 6px 7px, #94a3b8 2px, transparent 2.5px);
  background-size: 18px 14px;
  background-repeat: repeat-x;
  border-bottom: 1px dashed #a8a29e;
}

/* A small "torn corner" hint at the bottom-right */
.readout-tear {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 18px; height: 18px;
  background: linear-gradient(135deg, transparent 50%, var(--c-paper) 50.5%);
  border-bottom-right-radius: 4px;
}

.readout-text {
  margin: 0;
  text-align: center;
  transition: opacity 0.25s;
}

/* PRINTING: paper retracts up into the slot (only the perforation edge stays peeking) */
.readout-paper.printing {
  transform: translateY(-100%);
  opacity: 0.05;
}
.readout-paper.printing .readout-text { opacity: 0; }

/* REVEALED: paper feeds out of the slot with a satisfying drop */
.readout-paper.revealed {
  animation: paperFeed 0.7s cubic-bezier(.34,1.45,.5,1) forwards;
}
@keyframes paperFeed {
  0%   { transform: translateY(-95%) scaleY(0.6); opacity: 0; }
  35%  { opacity: 1; }
  70%  { transform: translateY(6px)  scaleY(1.02); opacity: 1; }
  100% { transform: translateY(0)    scaleY(1);    opacity: 1; }
}

/* Ink dries in: text fades in shortly after the paper lands */
.readout-paper.revealed .readout-text {
  animation: inkFadeIn 0.5s ease-out 0.25s both;
}
@keyframes inkFadeIn {
  from { opacity: 0; letter-spacing: -1px; }
  to   { opacity: 1; letter-spacing: 0; }
}

/* ---------- Big button ---------- */
.button-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.big-button {
  position: relative;
  width: 170px;
  height: 160px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.big-button:focus-visible .big-button-top {
  box-shadow: 0 0 0 4px #fef3c7, 0 0 0 8px var(--c-accent), inset 0 -10px 0 var(--c-accent-dark), inset 0 6px 16px rgba(255,255,255,0.35);
}
.big-button-top {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 140px;
  height: 140px;
  background: radial-gradient(circle at 35% 30%, #fca5a5, var(--c-accent) 55%, var(--c-accent-dark) 100%);
  border-radius: 50%;
  box-shadow:
    inset 0 -14px 0 rgba(0,0,0,0.25),
    inset 0 8px 18px rgba(255,255,255,0.35),
    0 10px 0 #7f1d1d,
    0 18px 24px var(--c-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.big-button-label {
  font-family: 'Bungee', sans-serif;
  font-size: 1.4rem;
  color: #fff;
  text-shadow: 0 2px 0 var(--c-accent-dark), 0 -1px 0 rgba(255,255,255,0.4);
  letter-spacing: 1px;
  pointer-events: none;
}

.big-button:hover .big-button-top {
  transform: translateX(-50%) translateY(-2px);
}
.big-button:active .big-button-top,
.big-button.pressed .big-button-top {
  transform: translateX(-50%) translateY(10px);
  box-shadow:
    inset 0 -6px 0 rgba(0,0,0,0.2),
    inset 0 4px 12px rgba(255,255,255,0.25),
    0 2px 0 #7f1d1d,
    0 6px 12px var(--c-shadow);
}

.big-button[disabled] {
  cursor: not-allowed;
  opacity: 0.85;
}

.hint {
  font-size: 1.1rem;
  color: #78350f;
  margin: 0;
  transform: rotate(-1.5deg);
  opacity: 0.9;
}
.hint.hidden { opacity: 0; }

/* ---------- Footer ---------- */
.footer {
  margin-top: 1.5rem;
  font-size: 0.95rem;
  color: #78350f;
  opacity: 0.7;
}
.footer a { color: #78350f; }

/* ---------- About modal (super small) ---------- */
.about-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.about-modal.open { display: flex; }
.about-modal-inner {
  background: var(--c-paper);
  border: 3px solid var(--c-ink);
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  max-width: 460px;
  font-size: 1.15rem;
  box-shadow: 0 8px 0 #92400e, 0 16px 32px var(--c-shadow);
}
.about-modal-inner h2 {
  font-family: 'Bungee', sans-serif;
  margin: 0 0 0.6rem;
  color: var(--c-accent);
}
.about-modal-inner button {
  margin-top: 0.8rem;
  font-family: 'Bungee', sans-serif;
  background: var(--c-accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 600px) {
  .stage { padding: 2.5rem 0.75rem 2rem; gap: 1rem; }
  .machine { border-width: 6px; border-radius: 16px; }
  .big-button { width: 150px; height: 140px; }
  .big-button-top { width: 120px; height: 120px; }
  .big-button-label { font-size: 1.2rem; }
}

/* ---------- Respect reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .spin-slow, .spin-fast { animation: none !important; }
  .machine.running * { animation-duration: 0.001s !important; animation-delay: 0s !important; }
}
