* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 28%, #304458, #141e2e 76%);
  color: #eef7fb; font-family: system-ui, sans-serif;
}
main { width: min(100%, 1080px, calc((100dvh - 92px) * 16 / 9)); }
.stage {
  position: relative; overflow: hidden; border: 1px solid #a0b6c7; border-radius: 15px;
  background: #abe4e3; box-shadow: 0 20px 60px #0a152c8c;
}
canvas { width: 100%; display: block; }
#bridge-switch { position: absolute; left: 39%; top: 18%; width: clamp(34px, 6%, 65px); aspect-ratio: 1;
  min-height: 0; min-width: 0; border: 3px solid #272b39; border-radius: 50%;
  background: radial-gradient(circle at 38% 29%, #ff8582, #e73246 64%); box-shadow: 0 3px 0 #592235; }
#bridge-switch:disabled { cursor: default; filter: saturate(.6); }
#start-walk {
  position: absolute; left: 21%; top: 55%; display: flex; align-items: center;
  gap: clamp(4px, 1vw, 12px); min-height: 44px; padding: 0 4px; border: 0;
  background: transparent; color: #14263b; font: 800 clamp(11px, 2.2vw, 23px)/1 system-ui, sans-serif;
  white-space: nowrap; text-shadow: 0 1px 0 #effff5;
}
.start-hand {
  width: clamp(30px, 6vw, 66px); overflow: visible;
  fill: none; stroke: #172935; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
}
.start-glove { transform-origin: 45px 48px; animation: show-tap 1.25s ease-in-out infinite; }
.start-tap-marks { animation: show-tap-marks 1.25s ease-in-out infinite; }
.start-keys { display: grid; gap: 3px; grid-template-columns: 1fr 1fr; }
.start-keys kbd {
  padding: 2px 5px; border: 1.5px solid #29435a; border-radius: 4px; text-align: center;
  color: #172935; background: #e3f8f4; font: 700 clamp(9px, 1.35vw, 14px)/1 system-ui, sans-serif;
}
.start-keys .space-key { grid-column: span 2; }
@keyframes show-tap {
  0%, 100% { transform: translate(2px, 3px) rotate(-8deg); }
  45%, 60% { transform: translate(-4px, -3px) rotate(4deg); }
}
@keyframes show-tap-marks {
  0%, 100% { opacity: 0.2; }
  45%, 60% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .start-glove, .start-tap-marks { animation: none; }
}
#start-walk[hidden] { display: none; }
header { position: absolute; inset: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: clamp(8px, 2vw, 22px); pointer-events: none; }
h1, #level {
  margin: 0; background: #233447; color: #f2fbff; border-radius: 6px;
  padding: 8px 12px; font: 700 clamp(10px, 1.6vw, 16px)/1 ui-monospace, monospace; text-transform: uppercase;
  letter-spacing: .1em;
}
.hud, .directions { display: flex; align-items: center; gap: 8px; }
button {
  border: 1px solid #658099; background: #293c52; color: #f1faff; border-radius: 8px;
  min-width: 42px; min-height: 42px; font: inherit; font-weight: 700; cursor: pointer;
  touch-action: none; user-select: none;
}
button:hover, button:active { background: #45617b; }
button:focus-visible { outline: 3px solid #ffdd71; outline-offset: 2px; }
#pause { display: flex; align-items: center; justify-content: center; gap: 4px; pointer-events: auto; }
#pause i { display: block; width: 4px; height: 14px; background: currentColor; }
footer { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding-top: 11px; }
footer button { font-size: 22px; }
footer p { margin: 0; text-align: center; color: #d2e2eb; font-size: clamp(10px, 2.5vw, 14px); }
#overlay { position: absolute; inset: 0; background: #172839b8; display: grid; place-items: center; }
#overlay[hidden], #resume[hidden] { display: none; }
.panel { border-radius: 12px; border: 1px solid #839eb4; background: #1d3043; padding: 14px 22px 20px; text-align: center; }
.panel h2 { margin: 0 0 12px; font-size: clamp(16px, 4vw, 30px); }
.panel button { padding: 0 12px; }
@media (max-width: 540px) {
  body { padding: 8px; }
  .stage { border-radius: 9px; }
  #pause { min-width: 34px; min-height: 34px; }
}

#bridge-switch[hidden] { display: none; }
#bridge-switch { font-size: clamp(8px, 1.3vw, 14px); padding: 0; transform: translateX(-50%); }

#scene-fade { position: absolute; inset: 0; background: #111c2c; opacity: 0; pointer-events: none; }
#level { pointer-events: auto; }
#level:hover { background: #45617b; }
#level-picker {
  width: min(420px, calc(100% - 32px)); padding: 20px; border: 1px solid #86a2bc;
  border-radius: 12px; background: #203449; color: #f1faff; text-align: center;
}
#level-picker::backdrop { background: #10223bb8; }
#level-picker h2 { margin: 0 0 14px; font-size: 20px; }
#level-options { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
#level-options button { min-width: 0; }
#level-options button[aria-current="true"] { border-color: #ffdd71; color: #ffdd71; }
#level-picker form { margin-top: 14px; }
#level-picker form button { padding: 0 16px; }

#bridge-switch.wall-switch {
  width: clamp(30px, 5%, 54px);
  transform: translate(-50%, -50%);
  border: 1px solid #3b4951;
  border-radius: 16%;
  background: linear-gradient(155deg, #d9e0e4, #79858e);
  box-shadow: inset 0 1px 1px #f2f6f8, 0 2px 3px #17253466;
  cursor: pointer;
}
#bridge-switch.wall-switch:disabled {
  filter: none;
  cursor: default;
}
#bridge-switch.wall-switch::before {
  content: "";
  position: absolute;
  inset: 12%;
  border: 1px solid #52616a;
  border-radius: 50%;
  background: linear-gradient(#313c44, #808b90);
  box-shadow: inset 0 1px 2px #131c24;
}
#bridge-switch.wall-switch::after {
  content: "";
  position: absolute;
  inset: 21% 23% 27%;
  border: 1px solid #642326;
  border-radius: 50%;
  background: linear-gradient(#c65c60, #9d3338);
  box-shadow: inset 0 1px 1px #f4b2a8, 0 4px 0 #5c2327, 0 5px 3px #24252a9e;
  transition: transform 70ms ease-out, box-shadow 70ms ease-out;
}
#bridge-switch.wall-switch:active:not(:disabled)::after,
#bridge-switch.wall-switch.depressed::after {
  transform: translateY(3px) scale(.94);
  box-shadow: inset 0 1px 2px #6b2729, 0 1px 0 #5c2327;
}

#bridge-switch.wall-switch:disabled:not(.depressed)::after {
  filter: saturate(.48);
}

#bridge-switch.rotary-switch::after {
  inset: 22%;
  border-color: #24414a;
  border-radius: 26%;
  background: linear-gradient(90deg, #477a79 32%, #b6d4c9 32% 66%, #477a79 66%);
  box-shadow: inset 0 1px 2px #c5e3d4, 0 2px 2px #182d35;
  transition: transform 170ms ease-out;
}
#bridge-switch.rotary-switch.depressed::after {
  transform: rotate(88deg);
}

#level-picker { max-height: calc(100dvh - 32px); }
#level-chapters {
  width: 100%; margin-bottom: 12px; padding: 9px;
  background: #182c3e; color: #eef7fb; border: 1px solid #86a2bc; border-radius: 6px;
}
#level-options button[hidden] { display: none; }

#bridge-switch.spring-lever {
  touch-action: none;
  cursor: ns-resize;
  color: #e7b47d;
  font-size: clamp(13px, 2vw, 24px);
  background: linear-gradient(145deg, #5c737f, #334857);
  border: 2px solid #263944;
  box-shadow: inset 0 1px 0 #879ba3, 0 3px 0 #253845;
}
#bridge-switch.spring-lever::before,
#bridge-switch.spring-lever::after { display: none; }

#bridge-switch.pixel-gate-switch {
  border: 0;
  border-radius: 0;
  background: #243842;
  outline: 2px solid #526d76;
  box-shadow: inset 0 3px #7e99a0, inset 0 -3px #192a2e, 0 3px #192a2e;
}
#bridge-switch.pixel-gate-switch::before {
  inset: 6%;
  border: 0;
  border-radius: 0;
  background: linear-gradient(0deg, #263a45 0 26%, #405864 26% 100%);
  box-shadow: inset 0 2px #a0b2b3;
}
#bridge-switch.pixel-gate-switch::after {
  inset: 20% 22% 27%;
  border: 0;
  border-radius: 0;
  clip-path: polygon(13% 0, 87% 0, 87% 13%, 100% 13%, 100% 87%, 87% 87%, 87% 100%, 13% 100%, 13% 87%, 0 87%, 0 13%, 13% 13%);
  background: linear-gradient(0deg, #742b2c 0 24%, #bc4a49 24% 79%, #eb8e7a 79% 100%);
  box-shadow: none;
}
#bridge-switch.pixel-gate-switch.depressed::after {
  transform: translateY(3px);
  box-shadow: none;
}

.victory-callout {
  position: absolute;
  z-index: 1;
  top: 19%;
  inset-inline: 4%;
  width: fit-content;
  max-width: 92%;
  margin-inline: auto;
  pointer-events: none;
  color: #fff0b5;
  font: 950 clamp(20px, 5.1vw, 74px)/1.05 system-ui, sans-serif;
  text-align: center;
  letter-spacing: .015em;
  -webkit-text-stroke: clamp(1px, .24vw, 3px) #293950;
  paint-order: stroke fill;
  text-shadow: 0 .08em #a64744, .035em .15em #293950, 0 0 .38em #ffdc9b70;
  animation: victory-pop .96s cubic-bezier(.2,.76,.27,1) both;
}
.victory-callout[hidden] { display: none; }
@keyframes victory-pop {
  0% { opacity: 0; transform: translateY(.4em) rotate(-8deg) scale(.58); }
  25% { opacity: 1; transform: translateY(-.13em) rotate(3deg) scale(1.1); }
  52% { transform: translateY(0) rotate(-2deg) scale(1); }
  82% { opacity: 1; transform: translateY(0) rotate(-2deg) scale(1); }
  100% { opacity: 0; transform: translateY(-.26em) rotate(-2deg) scale(.96); }
}
@media (prefers-reduced-motion: reduce) {
  .victory-callout { animation: none; }
}

#bridge-switch.wall-switch.ferry-crank {
  width: clamp(38px, 8.25%, 90px);
  touch-action: none;
  cursor: grab;
  border: 2px solid #273e49;
  border-radius: 50%;
  background:
    radial-gradient(circle, #819fa6 0 42%, #436471 44% 48%, transparent 50% 64%, #52727d 66% 100%),
    repeating-conic-gradient(from var(--crank-turn, -48deg), #c3d5d1 0deg 31deg, #496a76 31deg 40deg);
  box-shadow: inset 0 1px 2px #d3e3df, 0 3px 2px #243a4c6b;
}
#bridge-switch.wall-switch.ferry-crank:active { cursor: grabbing; }
#bridge-switch.wall-switch.ferry-crank::before {
  inset: 39%;
  z-index: 1;
  border-color: #2a4851;
  background: linear-gradient(150deg, #dbe4da, #8fa7aa);
  box-shadow: 0 1px 1px #263f49;
  pointer-events: none;
}
#bridge-switch.wall-switch.ferry-crank::after,
#bridge-switch.wall-switch.ferry-crank:active:not(:disabled)::after {
  inset: 36% auto 36% 50%;
  width: 75%;
  transform-origin: 0 50%;
  transform: rotate(var(--crank-turn, -48deg));
  background:
    radial-gradient(circle at 83% 50%, #ffdda0 0 15%, #ce8c50 18% 55%, #663b2c 59% 69%, transparent 73%)
      right center / 40% 100% no-repeat,
    linear-gradient(#2c4956 0 15%, #e5e8d7 16% 40%, #aebfc0 41% 78%, #2c4956 79% 100%)
      left center / 87% 43% no-repeat;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: none;
}

#bridge-switch.wall-switch.workshop-switch {
  width: clamp(33px, 5.6%, 60px);
  border: 2px solid #344c59;
  border-radius: 28%;
  background:
    radial-gradient(circle at 17% 17%, #d9e5e3 0 2%, #4a626b 3% 5%, transparent 6%),
    radial-gradient(circle at 83% 17%, #d9e5e3 0 2%, #4a626b 3% 5%, transparent 6%),
    radial-gradient(circle at 17% 83%, #d9e5e3 0 2%, #4a626b 3% 5%, transparent 6%),
    radial-gradient(circle at 83% 83%, #d9e5e3 0 2%, #4a626b 3% 5%, transparent 6%),
    linear-gradient(150deg, #c9d8db, #748d97 72%, #5a747f);
  box-shadow: inset 0 1px 2px #edf4f2, 0 3px 3px #233a4d55;
}
#bridge-switch.wall-switch.workshop-switch::before {
  inset: 12%;
  border-color: #304953;
  background: radial-gradient(circle, #2c414b 0 48%, #597783 49% 68%, #ccd9d7 69%);
  box-shadow: inset 0 1px 2px #243743;
}
#bridge-switch.wall-switch.workshop-switch::after {
  inset: 22% 22% 28%;
  border-color: #733334;
  background: radial-gradient(ellipse at 38% 27%, #ef9a86, #c45c52 48%, #923c3d 86%);
}

#bridge-switch.rope-scissors {
  width: clamp(34px, 5%, 54px);
  border: 2px solid #493728;
  border-radius: 50%;
  background: #ffe6a7;
  color: #36291f;
  box-shadow: 0 2px 3px #34251870;
  font-size: clamp(22px, 3vw, 38px);
  line-height: 1;
  transform: translate(-50%, -50%) rotate(-22deg);
}
#bridge-switch.rope-scissors:disabled { opacity: .55; }
#bridge-switch.rope-scissors.depressed { visibility: hidden; }

#bridge-switch.wall-switch.fan-switch {
  border-radius: 18%;
  background: linear-gradient(145deg, #dae3e5, #8095a0);
}
#bridge-switch.wall-switch.fan-switch::before { inset: 20% 25%; border-radius: 12%; }
#bridge-switch.wall-switch.fan-switch::after {
  inset: 23% 29% 35%;
  border-radius: 8%;
  border-color: #20323a;
  background: linear-gradient(#557377 0 12%, #304a54 16% 43%, #b0c6c0 46% 56%, #233a46 60%);
}
#bridge-switch.wall-switch.fan-switch.depressed::after {
  inset: 32% 29% 25%;
  background: linear-gradient(#8c2928 0 35%, #ff7865 37% 56%, #b93631 58%);
  box-shadow: 0 0 7px #ff514e;
}

#bridge-switch.wall-switch.rig-control {
  width: clamp(36px, 5.2%, 55px);
  border-radius: 18%;
  background: linear-gradient(145deg, #a9bec1, #516e79);
  color: #eff6e7;
  text-shadow: 0 2px #263743;
  font: 800 clamp(17px, 2.4vw, 31px)/1 system-ui;
}
#bridge-switch.wall-switch.rig-control::before,
#bridge-switch.wall-switch.rig-control::after { display: none; }
#bridge-switch.wall-switch.rig-control.depressed {
  background: linear-gradient(145deg, #83b8a7, #356469);
}
#bridge-switch.wall-switch.plunger-control {
  background: linear-gradient(145deg, #d78359, #823a32);
}
#bridge-switch.wall-switch.plunger-control.depressed { background: #75342b; }

#bridge-switch.wall-switch.plunger-control {
  font-size: 0;
  border-radius: 12%;
  background: linear-gradient(145deg, #cf9368, #8e4a37);
}
#bridge-switch.wall-switch.plunger-control::before,
#bridge-switch.wall-switch.plunger-control::after {
  display: block;
  border-radius: 2px;
  border: 0;
  box-shadow: none;
}
#bridge-switch.wall-switch.plunger-control::before {
  inset: 29% 44% 27%;
  background: linear-gradient(90deg, #40545a, #bfcecb);
}
#bridge-switch.wall-switch.plunger-control::after {
  inset: 23% 21% 64%;
  background: #432a25;
  transition: transform 90ms ease-in;
}
#bridge-switch.wall-switch.plunger-control.depressed::after { transform: translateY(130%); }

#level-options button { position: relative; }
#level-options button:disabled { opacity: .51; cursor: default; }
.level-mark { position: absolute; top: 10%; right: 9%; font-size: .65em; }
.level-cleared .level-mark { color: #8af0b5; }
.release-notice { position: fixed; z-index: 9; inset: auto 10% 10%; padding: 16px; display: flex; gap: 16px; justify-content: center; border-radius: 12px; align-items: center; background: #1e3548; color: #fff; box-shadow: 0 0 0 2px #afcfdd; }

#main-menu {
  position: fixed;
  inset: 0;
  transform: translateY(-26px);
  width: min(84vw, 319px);
  max-height: calc(100dvh - 24px);
  padding: clamp(14px, 4vw, 28px);
  border: 1px solid #6d98b0;
  border-radius: 18px;
  text-align: center;
  color: #eefaff;
  background: #1d3043;
  box-shadow: 0 14px 40px #12253863;
}
#main-menu::backdrop { background: #12253838; }
#main-menu h2 { margin: 0 0 15px; font: 800 clamp(23px, 5.6vw, 35px)/1.1 system-ui, sans-serif; }
#main-menu form { margin: 0; }
#menu-play {
  width: 100%;
  min-height: 48px;
  border-color: #ffdb80;
  background: #ffde80;
  color: #192738;
  font-size: 1.18rem;
}
#menu-play:hover { background: #ffeaa7; }
#more-games {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 3px;
  padding: 0 10px;
  color: #d9edfa;
  text-underline-offset: .2em;
  font-size: .86rem;
}
#more-games:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#main-menu p { margin: 3px 0 0; color: #b7cddd; font-size: .72rem; }
main:has(#main-menu[open]) #start-walk { visibility: hidden; }
@media (max-height: 350px) {
  #main-menu { transform: none; padding-block: 12px; }
  #main-menu h2 { margin-bottom: 8px; }
}

#android-finale:not([hidden]) { display: grid; gap: .45rem; justify-items: center; margin-top: .8rem; }
#android-finale p { margin: 0; }
#android-finale a, #android-coming { padding: .45rem .7rem; border: 1px solid currentColor; border-radius: .45rem; color: #d7eeff; }
.menu-links { display: flex; align-items: center; justify-content: center; gap: .5rem; }
#menu-google-play { display: inline-grid; width: 44px; height: 44px; place-items: center; }
#menu-google-play[href] { cursor: pointer; }
#menu-google-play:focus-visible, #main-menu p a:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
#main-menu p a { color: inherit; text-underline-offset: .18em; }
