:root {
  --bg-a: #9ee5ff;
  --bg-b: #c9f2ff;
  --bg-c: #effcff;
  --ink: #0f3851;
  --muted: #3e6987;
  --panel: rgba(255, 255, 255, 0.88);
  --line: rgba(20, 90, 130, 0.25);
  --accent: #ff8e47;
  --accent-soft: rgba(255, 142, 71, 0.25);
  --off-window: rgba(89, 160, 210, 0.35);
  --on-window: rgba(255, 205, 96, 0.94);
  --car-top: 0px;
  --stop-h: min(85svh, 740px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100svh;
  color: var(--ink);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 45%, var(--bg-c) 100%);
  transition: background 500ms ease;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 14% 10%, rgba(255, 221, 133, 0.62), transparent 24%),
    radial-gradient(circle at 82% 14%, rgba(255, 255, 255, 0.82), transparent 22%),
    radial-gradient(circle at 25% 74%, rgba(255, 255, 255, 0.45), transparent 30%),
    radial-gradient(circle at 76% 68%, rgba(255, 255, 255, 0.4), transparent 35%),
    radial-gradient(rgba(18, 96, 138, 0.08) 1px, transparent 1px);
  background-size: auto, auto, auto, auto, 10px 10px;
}

.hud {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.5rem 0.7rem;
  min-width: 128px;
  box-shadow: 0 8px 16px rgba(38, 110, 153, 0.18);
  transition: opacity 260ms ease, transform 260ms ease;
}

.hud-label,
.hud-value,
.hud-sub {
  margin: 0;
}

.hud-label {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-value {
  font-size: 1.05rem;
  font-weight: 700;
}

.hud-sub {
  color: #2c6285;
  font-size: 0.76rem;
}

.hud-stats {
  margin-top: 0.45rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(20, 90, 130, 0.2);
  display: grid;
  gap: 0.2rem;
}

.hud-stats p {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  font-size: 0.72rem;
}

.hud-stats span {
  color: var(--muted);
}

.hud-stats strong {
  color: #1e5a80;
  font-size: 0.74rem;
}

.scroll-cue {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  z-index: 45;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: rgba(255, 255, 255, 0.93);
  color: #1f5a7f;
  padding: 0.3rem 0.75rem;
  font-weight: 700;
  animation: bob 1.2s ease-in-out infinite;
  transition: opacity 220ms ease, transform 220ms ease;
}

.scroll-cue.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(8px);
  pointer-events: none;
}

.simonski-link {
  position: fixed;
  right: 0.9rem;
  bottom: 0.9rem;
  z-index: 60;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.74rem;
  color: #1f5a7f;
  text-decoration: none;
  border: 1px solid rgba(20, 90, 130, 0.3);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  padding: 0.18rem 0.45rem;
}

.simonski-link:hover {
  color: #123f5b;
}

@keyframes bob {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-4px);
  }
}

.layout {
  width: min(1160px, calc(100% - 2rem));
  margin: 1rem auto 3rem;
  display: grid;
  grid-template-columns: minmax(230px, 360px) minmax(0, 1fr);
  gap: clamp(1rem, 2.5vw, 2rem);
  transition: opacity 320ms ease, transform 320ms ease;
}

.tower-sticky {
  position: sticky;
  top: 0.8rem;
  background: rgba(255, 255, 255, 0.72);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 0.8rem;
}

.tower-sticky h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.intro {
  margin: 0.3rem 0 0.8rem;
  color: var(--muted);
}

.tower {
  position: relative;
  margin: 0 auto;
  width: min(220px, 100%);
  border-radius: 16px;
  border: 3px solid rgba(26, 89, 126, 0.32);
  background: linear-gradient(180deg, #ffffff 0%, #eef7fd 100%);
  box-shadow: 0 12px 24px rgba(39, 112, 156, 0.2);
  padding: 0.95rem 0.7rem;
}

.tower::before {
  content: "";
  position: absolute;
  top: 0.95rem;
  bottom: 0.95rem;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(55, 132, 176, 0.18), rgba(55, 132, 176, 0.55), rgba(55, 132, 176, 0.18));
}

.tower-cap,
.tower-base {
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, #badcf0, #dceffb);
}

.tower-base {
  margin-top: 0.5rem;
}

.tower-floors {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
  display: grid;
  gap: 0.32rem;
}

.tower-floor {
  min-height: 26px;
  border-radius: 4px;
  border: 1px solid rgba(51, 88, 114, 0.25);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(222, 238, 248, 0.95)),
    repeating-linear-gradient(
      90deg,
      var(--off-window) 0,
      var(--off-window) 12px,
      transparent 12px,
      transparent 18px
    );
  transition: transform 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.tower-floor.active {
  transform: translateX(4px);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft) inset;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(222, 238, 248, 0.95)),
    repeating-linear-gradient(
      90deg,
      var(--on-window) 0,
      var(--on-window) 12px,
      transparent 12px,
      transparent 18px
    );
}

.car {
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  top: var(--car-top);
  height: 26px;
  border-radius: 4px;
  border: 3px solid var(--accent);
  background: rgba(255, 158, 90, 0.25);
  box-shadow: 0 2px 0 rgba(255, 141, 70, 0.36);
  transition: top 380ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.active-floor {
  margin: 0.75rem 0 0;
  text-align: center;
  color: var(--muted);
}

.stops {
  min-width: 0;
}

.stop {
  min-height: var(--stop-h);
  display: flex;
  align-items: center;
  padding: 0.8rem 0;
}

.card {
  position: relative;
  width: 100%;
  border-radius: 20px;
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: 0 12px 20px rgba(44, 112, 153, 0.14);
  padding: clamp(1rem, 2.4vw, 1.7rem);
  opacity: 0;
  transform: translateX(34px) translateY(12px);
  transition: opacity 560ms ease, transform 560ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stop.reveal .card {
  opacity: 1;
  transform: translateX(0) translateY(0);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
}

.badges span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.2rem 0.55rem;
  font-size: 0.8rem;
  color: #2a607f;
}

.card h2 {
  margin: 0;
  font-size: clamp(1.3rem, 2.7vw, 2rem);
}

.subtitle {
  margin: 0.4rem 0 0.8rem;
  color: var(--accent);
  font-weight: 700;
}

.card p {
  margin: 0;
  line-height: 1.5;
}

.welcome {
  margin-top: 0.95rem;
  border: 2px dashed rgba(255, 142, 71, 0.55);
  border-radius: 14px;
  padding: 0.65rem 0.75rem;
  background: rgba(255, 250, 240, 0.9);
  color: #7d4e2f;
  font-weight: 700;
}

.landing {
  min-height: 100svh;
  display: grid;
  place-items: center;
  width: min(1160px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1rem 0 1.2rem;
}

.landing-card {
  max-width: 700px;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 28px rgba(39, 112, 156, 0.15);
  padding: clamp(1rem, 3.2vw, 2rem);
  transform: translateY(calc((1 - var(--landing-progress, 1)) * 16px));
  opacity: calc(0.2 + (0.8 * var(--landing-progress, 1)));
  transition: opacity 180ms linear, transform 180ms linear;
}

.landing-kicker {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.landing-card h2 {
  margin: 0.35rem 0 0.65rem;
  font-size: clamp(1.6rem, 3.4vw, 2.4rem);
}

.landing-card p {
  margin: 0;
  line-height: 1.6;
}

.landing-note {
  margin-top: 0.8rem !important;
  color: #834d2d;
  font-weight: 700;
}

.landing-whimsy {
  margin-top: 1rem;
  border: 2px dashed rgba(42, 113, 157, 0.35);
  border-radius: 16px;
  padding: 0.75rem;
  background: rgba(239, 251, 255, 0.95);
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 150px) minmax(150px, 1fr);
  gap: 0.75rem;
  align-items: center;
  opacity: var(--landing-progress, 1);
  transform:
    translateY(calc((1 - var(--landing-progress, 1)) * 24px))
    scale(calc(0.92 + (0.08 * var(--landing-progress, 1))));
  transition: opacity 180ms linear, transform 180ms linear;
}

.retro-rig {
  animation: sway 4.4s ease-in-out infinite;
  transform-origin: 50% 85%;
}

.retro-screen {
  border: 3px solid rgba(24, 82, 114, 0.5);
  border-radius: 12px;
  background: linear-gradient(180deg, #12364d, #0d293b);
  color: #b4ffb4;
  font-family: "Courier New", monospace;
  font-size: 0.72rem;
  line-height: 1.35;
  padding: 0.55rem 0.6rem;
  box-shadow: inset 0 0 0 2px rgba(124, 184, 219, 0.18);
}

.retro-screen p {
  margin: 0;
}

.retro-base {
  width: 88%;
  margin: 0.35rem auto 0;
  height: 10px;
  border-radius: 7px;
  background: linear-gradient(90deg, #9ac8e5, #c4dff2);
}

.punch-cards {
  position: relative;
  height: 90px;
}

.punch-cards .card {
  position: absolute;
  inset: 0 auto auto 0;
  width: 100px;
  height: 64px;
  border-radius: 8px;
  border: 2px solid rgba(74, 127, 160, 0.4);
  background:
    radial-gradient(circle at 14px 16px, rgba(74, 127, 160, 0.45) 2px, transparent 3px),
    radial-gradient(circle at 28px 16px, rgba(74, 127, 160, 0.45) 2px, transparent 3px),
    radial-gradient(circle at 42px 16px, rgba(74, 127, 160, 0.45) 2px, transparent 3px),
    radial-gradient(circle at 56px 16px, rgba(74, 127, 160, 0.45) 2px, transparent 3px),
    linear-gradient(180deg, #fffdf0, #f8f0ce);
  box-shadow: 0 3px 0 rgba(71, 114, 136, 0.15);
}

.punch-cards .card-a {
  transform: rotate(-9deg) translateY(8px);
}

.punch-cards .card-b {
  left: 18px;
  top: 10px;
  transform: rotate(4deg);
}

.punch-cards .card-c {
  left: 34px;
  top: 20px;
  transform: rotate(13deg);
}

.pcb-scene {
  position: relative;
  min-height: 118px;
  border: 2px solid rgba(17, 102, 98, 0.28);
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 20%, rgba(121, 249, 200, 0.12), transparent 35%),
    linear-gradient(180deg, #2e8f7a, #267262);
  box-shadow: inset 0 0 0 2px rgba(154, 255, 231, 0.1);
  overflow: hidden;
}

.trace {
  position: absolute;
  top: 52%;
  height: 6px;
  border-radius: 99px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, rgba(187, 255, 227, 0.3), rgba(187, 255, 227, 0.7));
}

.trace-in {
  left: 8px;
  width: calc(50% - 42px);
}

.trace-out {
  right: 8px;
  width: calc(50% - 42px);
}

.trace-glow {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0, rgba(189, 255, 237, 0.28) 20%, transparent 40%),
    linear-gradient(90deg, transparent 55%, rgba(255, 201, 112, 0.24) 74%, transparent 90%);
  animation: traceFlow 2.6s linear infinite;
  pointer-events: none;
}

.cpu-core {
  --cpu-glow: #7ce3ff;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 66px;
  height: 52px;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(12, 76, 79, 0.7);
  border-radius: 10px;
  background: linear-gradient(180deg, #b7fff1, #7fd4bd);
  color: #0f4a4f;
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 4px rgba(22, 117, 110, 0.26);
  transition: box-shadow 160ms ease, background 160ms ease, color 160ms ease;
}

.cpu-core::before,
.cpu-core::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 6px;
  background: repeating-linear-gradient(
    180deg,
    rgba(19, 90, 91, 0.6) 0,
    rgba(19, 90, 91, 0.6) 3px,
    transparent 3px,
    transparent 7px
  );
}

.cpu-core::before {
  left: -9px;
}

.cpu-core::after {
  right: -9px;
}

.cpu-core.hot {
  box-shadow: 0 0 0 4px rgba(22, 117, 110, 0.26), 0 0 18px var(--cpu-glow);
  background: linear-gradient(180deg, #fff8c6, #ffc66f);
  color: #6a3b10;
}

.packet-lane {
  position: absolute;
  inset: 0;
}

.packet {
  --c-in: #65d6ff;
  --c-mid: #ffe08f;
  --c-out: #ff8bcf;
  position: absolute;
  left: 8px;
  top: 52%;
  transform: translate(-50%, -50%);
  min-width: 42px;
  height: 18px;
  padding: 0 0.35rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  background: var(--c-in);
  color: #123a50;
  font-family: "Courier New", monospace;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: grid;
  place-items: center;
  box-shadow: 0 0 8px color-mix(in srgb, var(--c-in) 60%, white 40%);
  animation: packetFlow 2.5s linear forwards;
  pointer-events: none;
}

.pcb-caption {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 0.62rem;
  color: rgba(224, 255, 243, 0.88);
  text-align: center;
  letter-spacing: 0.02em;
}

@keyframes packetFlow {
  0% {
    left: 10px;
    background: var(--c-in);
    box-shadow: 0 0 8px color-mix(in srgb, var(--c-in) 62%, white 38%);
  }
  46% {
    left: calc(50% - 32px);
    background: var(--c-in);
    box-shadow: 0 0 8px color-mix(in srgb, var(--c-in) 62%, white 38%);
  }
  56% {
    left: calc(50% + 34px);
    background: var(--c-mid);
    box-shadow: 0 0 10px color-mix(in srgb, var(--c-mid) 66%, white 34%);
  }
  100% {
    left: calc(100% - 10px);
    background: var(--c-out);
    box-shadow: 0 0 10px color-mix(in srgb, var(--c-out) 64%, white 36%);
  }
}

@keyframes traceFlow {
  0% {
    transform: translateX(-22%);
    opacity: 0.45;
  }
  50% {
    opacity: 0.9;
  }
  100% {
    transform: translateX(22%);
    opacity: 0.45;
  }
}

@keyframes sway {
  0%,
  100% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(2deg);
  }
}

.entry-stop .card {
  border-style: dashed;
  border-color: rgba(255, 142, 71, 0.55);
  background: rgba(255, 248, 236, 0.92);
}

body.in-landing .layout,
body.in-landing .hud {
  opacity: 0;
  transform: translateY(30px);
  pointer-events: none;
}

body[data-layer="city-layer"] {
  --bg-a: #90e0ff;
  --bg-b: #c0ecff;
  --bg-c: #e7f9ff;
}

body[data-layer="builder-layer"] {
  --bg-a: #9cd6ff;
  --bg-b: #d3ecff;
  --bg-c: #f0f9ff;
}

body[data-layer="systems-layer"] {
  --bg-a: #a7cfff;
  --bg-b: #deebff;
  --bg-c: #f6f9ff;
}

body[data-layer="frontier-layer"] {
  --bg-a: #c4c8ff;
  --bg-b: #e8eaff;
  --bg-c: #fcfcff;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .tower-sticky {
    top: 0.5rem;
  }

  .tower {
    width: min(300px, 100%);
  }

  .hud {
    top: auto;
    bottom: 0.8rem;
    right: 0.8rem;
  }

  .stop {
    min-height: min(76svh, 620px);
  }

  .landing-whimsy {
    grid-template-columns: 1fr;
  }

  .punch-cards {
    height: 72px;
  }

  .pcb-scene {
    min-height: 108px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .retro-rig,
  .trace-glow {
    animation: none;
  }

  .packet {
    animation-duration: 0.01ms !important;
  }
}
