* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;    /* you're at the table; there is nowhere to scroll to */
}

html {
  /* a warm playroom floor for the table to sit on — no sky, this is indoors */
  background-color: #ddc6a2;
  background-image:
    radial-gradient(ellipse at 50% 20%, rgba(255, 244, 220, 0.55), rgba(0, 0, 0, 0) 60%),
    linear-gradient(180deg, #e8d5b5 0%, #dcc4a0 100%);
  background-attachment: fixed;
}

body {
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #3a2e26;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

.table-wrap {
  position: relative;
  /* fill the window but never spill: capped by width and by height-derived width
     (table aspect ratio incl. frame ≈ 1.9), leaving room for the caption line */
  width: min(1720px, 96vw, calc((100svh - 4.6rem) * 1.9));
  border-radius: 14px;
  overflow: hidden;
  /* the wooden table frame: thick brown border, darker inner rim, soft inner shadow */
  border: 18px solid #7c4a25;
  box-shadow:
    0 18px 44px rgba(60, 36, 16, 0.38),
    inset 0 0 0 3px #5f3717,
    inset 0 0 20px rgba(0, 0, 0, 0.18);
  background: #8fcf6b;
}

#trackSvg {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

/* the little label below the table — empty until a hand picks something up */
#caption {
  height: 1.6rem;
  line-height: 1.6rem;
  font-size: clamp(0.85rem, 1.6vw, 1.05rem);
  font-style: italic;
  color: #6b5233;
  text-align: center;
  padding: 0 1rem;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 1.4s ease;
}
#caption.show { opacity: 1; transition: opacity 0.25s ease; }

.track-ballast {
  fill: none;
  stroke: #d8b27a;
  stroke-width: 64;
  stroke-linecap: round;
}
.track-path {
  fill: none;
  stroke: #8a6a3f;
  stroke-width: 50;
  stroke-linecap: round;
}
.track-ties {
  fill: none;
  stroke: #6b4f2a;
  stroke-width: 50;
  stroke-dasharray: 6 16;
  stroke-linecap: butt;
  opacity: 0.55;
}

#decorLayer { pointer-events: none; }
#archLayer, #bridgeLayer, #smokeLayer, #mountainLayer { pointer-events: none; }

/* wild dinos grazing on the felt */
.figure { cursor: grab; }
.figure:active { cursor: grabbing; }
.figure:hover { filter: brightness(1.07); }
.fig-graze {
  transform-box: fill-box;
  transform-origin: 92% 12%;
  animation: figGraze 8.5s ease-in-out infinite;
}
@keyframes figGraze {
  0%, 46%, 100% { transform: rotate(0deg); }
  56%, 88% { transform: rotate(-9deg); }
}
.fig-peck {
  transform-box: fill-box;
  transform-origin: 88% 88%;
  animation: figPeck 5.6s ease-in-out infinite;
}
@keyframes figPeck {
  0%, 74%, 92%, 100% { transform: rotate(0deg); }
  80%, 86% { transform: rotate(14deg); }
}

.decor-sway {
  transform-box: fill-box;
  transform-origin: bottom center;
  animation: decorSway 5.8s ease-in-out infinite alternate;
}
.decor-grass { animation-duration: 4.6s; }
@keyframes decorSway {
  from { transform: rotate(-1.2deg); }
  to { transform: rotate(1.5deg); }
}

/* switch levers */
.lever { cursor: pointer; }
.lever-arm {
  transform-box: view-box;
  transition: transform 0.22s ease;
}

/* vehicles */
.car, .engine-group { cursor: grab; }
.car:active, .engine-group:active { cursor: grabbing; }
.car:hover, .engine-group:hover { filter: brightness(1.07); }
.held { cursor: grabbing; filter: drop-shadow(0 7px 6px rgba(0, 0, 0, 0.32)); }
.car .wagon-body { stroke: #2c2418; stroke-width: 3; }

@keyframes wheelspin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.wheel-spin { animation: wheelspin 0.7s linear infinite; animation-play-state: paused; }
.rolling .wheel-spin { animation-play-state: running; }

/* the perched Meganeura: mostly still, buzzes its wings now and then */
.mega-wings {
  transform-box: fill-box;
  transform-origin: center;
  animation: megaBuzz 9s linear infinite;
}
@keyframes megaBuzz {
  0%, 87%, 96%, 100% { transform: scaleX(1); }
  88%, 90%, 92%, 94% { transform: scaleX(0.72); }
  89%, 91%, 93%, 95% { transform: scaleX(1.04); }
}

/* animal idle life */
.blink,
.wing,
.tail-sway,
.trunk-sway,
.neck-sway,
.saber-ear-twitch,
.trex-head-bob,
.triceratops-nod,
.sail-shimmer,
.raptor-head-tilt,
.crest-sway,
.sail-sway {
  transform-box: fill-box;
}

.blink {
  transform-origin: center;
  animation: animalBlink 4.5s infinite;
}
.blink-saber { animation-delay: -0.2s; }
.blink-mammoth { animation-delay: -0.75s; }
.blink-trex { animation-delay: -1.2s; }
.blink-triceratops { animation-delay: -1.7s; }
.blink-stego { animation-delay: -2.1s; }
.blink-bronto { animation-delay: -2.55s; }
.blink-anky { animation-delay: -3s; }
.blink-ptero { animation-delay: -3.45s; }
.blink-dimetrodon { animation-delay: -3.85s; }
.blink-raptor { animation-delay: -4.15s; }
.blink-parasaur { animation-delay: -0.5s; }
.blink-spino { animation-delay: -1.95s; }
.blink-plesio { animation-delay: -2.9s; }
.blink-pachy { animation-delay: -3.3s; }
.blink-theri { animation-delay: -1.45s; }
.blink-glypto { animation-delay: -3.7s; }
.blink-rhino { animation-delay: -0.95s; }
.blink-archaeo { animation-delay: -2.35s; }

@keyframes animalBlink {
  0%, 88%, 94%, 100% { transform: scaleY(1); }
  90%, 92% { transform: scaleY(0.08); }
}

.wing { animation: wingDrift 3.8s ease-in-out infinite alternate; }
.wing-left { transform-origin: right center; }
.wing-right { transform-origin: left center; animation-name: wingDriftReverse; }
@keyframes wingDrift {
  from { transform: rotate(-1.4deg); }
  to { transform: rotate(2.2deg); }
}
@keyframes wingDriftReverse {
  from { transform: rotate(1.4deg); }
  to { transform: rotate(-2.2deg); }
}

.trunk-sway {
  transform-origin: top center;
  animation: trunkSway 4.9s ease-in-out infinite alternate;
}
@keyframes trunkSway {
  from { transform: rotate(-2deg); }
  to { transform: rotate(2deg); }
}

.tail-sway {
  transform-origin: left center;
  animation: tailSway 4.8s ease-in-out infinite alternate;
}
.anky-tail { animation-duration: 5.4s; }
@keyframes tailSway {
  from { transform: rotate(-1.7deg); }
  to { transform: rotate(1.7deg); }
}

.neck-sway {
  transform-origin: bottom center;
  animation: neckSway 5.6s ease-in-out infinite alternate;
}
.plesio-neck { animation-duration: 5.1s; }
@keyframes neckSway {
  from { transform: rotate(-1.4deg); }
  to { transform: rotate(1.4deg); }
}

.saber-ear-twitch {
  transform-origin: bottom center;
  animation: earTwitch 5.8s ease-in-out infinite;
}
@keyframes earTwitch {
  0%, 82%, 100% { transform: rotate(0deg); }
  87% { transform: rotate(-2deg); }
  92% { transform: rotate(1.2deg); }
}

.trex-head-bob {
  transform-origin: center bottom;
  animation: tinyHeadBob 4.4s ease-in-out infinite alternate;
}
@keyframes tinyHeadBob {
  from { transform: translateY(-1px) rotate(-0.5deg); }
  to { transform: translateY(1.5px) rotate(0.5deg); }
}

.triceratops-nod {
  transform-origin: center bottom;
  animation: smallNod 5.2s ease-in-out infinite alternate;
}
@keyframes smallNod {
  from { transform: rotate(-0.8deg); }
  to { transform: rotate(1.1deg); }
}

.sail-shimmer {
  transform-origin: bottom center;
  animation: sailShimmer 5.5s ease-in-out infinite alternate;
}
@keyframes sailShimmer {
  from { transform: skewX(-0.8deg) scaleX(0.99); }
  to { transform: skewX(0.8deg) scaleX(1.01); }
}

.raptor-head-tilt {
  transform-origin: right center;
  animation: raptorHeadTilt 4.2s ease-in-out infinite alternate;
}
@keyframes raptorHeadTilt {
  from { transform: rotate(-1deg); }
  to { transform: rotate(1.3deg); }
}

.crest-sway {
  transform-origin: left center;
  animation: crestSway 5.7s ease-in-out infinite alternate;
}
@keyframes crestSway {
  from { transform: rotate(-1.2deg); }
  to { transform: rotate(1.2deg); }
}

.sail-sway {
  transform-origin: bottom center;
  animation: spinoSailSway 5.9s ease-in-out infinite alternate;
}
@keyframes spinoSailSway {
  from { transform: rotate(-1deg); }
  to { transform: rotate(1deg); }
}

.held .blink,
.held [class*="sway"],
.held .wing,
.held .saber-ear-twitch,
.held .trex-head-bob,
.held .triceratops-nod,
.held .sail-shimmer,
.held .raptor-head-tilt {
  animation-play-state: paused;
}
