:root {
  color-scheme: light;
  --ink: #102243;
  --blue: #126fc4;
  --yellow: #ffd535;
  --green: #41c96b;
  --panel: rgba(255, 255, 255, 0.92);
  --control-shadow: rgba(9, 80, 142, 0.35);
  /* The page is viewport-fit=cover, so everything chrome-adjacent has to inset. */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-width: 320px;
  background: #bfe9ff;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; }

#game-shell {
  height: 100svh;
  isolation: isolate;
  /* clip, not hidden: `hidden` still scrolls programmatically, and focusing the
     start button on a short screen used to shove the whole HUD off the top. */
  overflow: clip;
  position: relative;
}

#game {
  display: block;
  height: 100svh;
  outline: none;
  touch-action: none;
  width: 100%;
}

/* One flow column for every top-of-screen chip, so the objective text can wrap to
   any height without ever landing on the level dots. */
.hud-stack {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  left: calc(var(--safe-l) + clamp(12px, 3vw, 34px));
  pointer-events: none;
  position: absolute;
  right: calc(var(--safe-r) + clamp(12px, 3vw, 34px));
  top: calc(var(--safe-t) + clamp(12px, 3vw, 28px));
  z-index: 2;
}

.hud {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.player-card, .status-card, .round-button, .objective {
  border: 3px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 5px 0 rgba(14, 73, 134, 0.25);
}

.player-card {
  align-items: center;
  background: var(--panel);
  border-radius: 18px;
  display: flex;
  gap: 10px;
  padding: 8px 13px 8px 8px;
}

.portrait {
  align-items: center;
  background: #f6c54d;
  border: 2px solid #0e579d;
  border-radius: 50%;
  display: flex;
  font-size: 27px;
  height: 48px;
  justify-content: center;
  width: 48px;
}

.player-card p, .status-card span {
  color: #315778;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  margin: 0 0 2px;
}

.player-card strong { font-size: clamp(12px, 2.2vw, 16px); }

.hud-right { align-items: center; display: flex; gap: 10px; pointer-events: auto; }

.status-card {
  background: #123560;
  border-color: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  color: white;
  padding: 8px 12px;
  text-align: center;
}

.status-card span { color: #bbdcff; display: block; }
.status-card strong { color: #ff6663; font-size: 17px; letter-spacing: 0.08em; white-space: nowrap; }

.round-button {
  background: #fff;
  border-radius: 50%;
  color: var(--blue);
  cursor: pointer;
  font-size: 23px;
  font-weight: 900;
  height: 47px;
  width: 47px;
}

.objective {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  display: flex;
  font-size: clamp(12px, 2.3vw, 16px);
  font-weight: 800;
  gap: 9px;
  max-width: min(480px, 100%);
  padding: 9px 15px;
  position: relative;
  text-align: center;
}

.objective-dot { background: var(--green); border: 3px solid #0d8140; border-radius: 50%; height: 14px; width: 14px; }
.objective-count { background: #e8f4ff; border-radius: 999px; color: #154f82; font-size: 11px; line-height: 1; padding: 6px 8px; white-space: nowrap; }
.objective.door-ready { background: #efffdc; }
.objective.door-ready .objective-dot { background: var(--yellow); border-color: #cf9613; }
.objective.door-ready .objective-count { background: #2d9958; color: #fff; }

.level-progress {
  align-items: center;
  display: flex;
  gap: 5px;
  justify-content: center;
  list-style: none;
  margin: 0;
  max-width: 100%;
  padding: 0;
}

.level-progress li {
  align-items: center;
  background: rgba(255,255,255,.84);
  border: 2px solid rgba(25,96,156,.22);
  border-radius: 50%;
  color: #52708c;
  display: flex;
  font-size: 10px;
  font-weight: 900;
  height: 22px;
  justify-content: center;
  width: 22px;
}
.level-progress li.current { background: var(--yellow); border-color: #d69616; color: var(--ink); transform: scale(1.15); }
.level-progress li.done { background: var(--green); border-color: #168747; color: #fff; }

.screen-card {
  background: rgba(255, 255, 255, 0.96);
  border: 4px solid #fff;
  border-radius: 18px;
  box-shadow: 0 14px 0 rgba(10, 67, 120, 0.25), 0 24px 58px rgba(10, 61, 103, 0.38);
  left: 50%;
  max-height: calc(100svh - 24px);
  max-width: min(460px, calc(100vw - 38px));
  overflow-y: auto;
  padding: clamp(24px, 4.5vw, 38px);
  position: absolute;
  text-align: center;
  top: 50%;
  transform: translate(-50%, -42%);
  transition: opacity 180ms ease, transform 180ms ease;
  width: 100%;
  z-index: 4;
}

.screen-card.hidden { opacity: 0; pointer-events: none; transform: translate(-50%, -38%) scale(.96); }
.badge { color: #287ac3; font-size: 12px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.screen-card h1 { color: #164a81; font-size: clamp(34px, 7vw, 56px); letter-spacing: -.035em; line-height: .92; margin: 12px 0 16px; text-wrap: balance; }
.screen-card p { color: #3a5573; font-size: 16px; font-weight: 700; line-height: 1.45; margin: 0 auto 20px; max-width: 34ch; }

.how-to { background: #e6f3ff; border-radius: 14px; display: grid; font-size: 13px; gap: 8px 10px; grid-template-columns: 22px 1fr; margin: 0 auto 21px; padding: 13px; text-align: left; }
.step-number { align-items: center; background: #287ac3; border-radius: 50%; color: #fff; display: flex; font-size: 11px; font-weight: 900; height: 21px; justify-content: center; width: 21px; }
.how-to b { color: #184a7b; line-height: 1.3; }

.primary-button {
  background: linear-gradient(180deg, #ffd94e, #f5b928);
  border: 3px solid #fff;
  border-radius: 15px;
  box-shadow: 0 5px 0 #bd7910;
  color: #183657;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  padding: 13px 22px;
}
.primary-button:active { box-shadow: 0 2px 0 #bd7910; transform: translateY(3px); }
.primary-button span { font-size: 24px; line-height: 0; margin-left: 5px; }

.touch-controls { align-items: flex-end; bottom: calc(var(--safe-b) + clamp(16px, 4vw, 35px)); display: flex; justify-content: space-between; left: calc(var(--safe-l) + clamp(16px, 4vw, 38px)); pointer-events: none; position: absolute; right: calc(var(--safe-r) + clamp(16px, 4vw, 38px)); z-index: 3; }
.d-pad { height: 136px; position: relative; width: 136px; }
.move-button, .squeak-button, .tool-button { -webkit-tap-highlight-color: transparent; border: 3px solid rgba(255, 255, 255, 0.92); box-shadow: 0 5px 0 var(--control-shadow); cursor: pointer; pointer-events: auto; touch-action: none; transition: filter 150ms ease, transform 150ms ease, box-shadow 150ms ease; }
.move-button { align-items: center; background: rgba(20, 120, 200, .91); border-radius: 50%; color: #fff; display: flex; font-size: 23px; height: 55px; justify-content: center; position: absolute; width: 55px; }
.move-button.up { left: 40px; top: 0; }
.move-button.left { left: 0; top: 40px; }
.move-button.right { right: 0; top: 40px; }
.move-button.down { bottom: 0; left: 40px; }
.move-button:active, .squeak-button:active, .tool-button:active { box-shadow: 0 2px 0 var(--control-shadow); transform: translateY(3px); }
.tool-row { align-items: flex-end; display: flex; gap: 12px; pointer-events: auto; }
.squeak-button { align-items: center; background: linear-gradient(180deg, #ffdf4e, #f7b928); border-radius: 50%; color: #173a5d; display: flex; flex-direction: column; height: 104px; justify-content: center; width: 104px; }
.squeak-button span { font-size: 34px; line-height: .9; }
.squeak-button b, .tool-button b { font-size: 10px; letter-spacing: .035em; line-height: 1.1; margin-top: 2px; text-transform: uppercase; }
.squeak-button small { background: rgba(255,255,255,.55); border-radius: 999px; font-size: 10px; font-weight: 900; line-height: 1; margin-top: 4px; padding: 3px 6px; }
.tool-button { align-items: center; border-radius: 50%; color: #173a5d; display: flex; flex-direction: column; height: 78px; justify-content: center; width: 78px; }
.bubble-button { background: linear-gradient(180deg, #9cecff, #53bce5); }
.tool-button span { font-size: 27px; line-height: .9; }
.tool-button small { background: rgba(255,255,255,.54); border-radius: 999px; font-size: 10px; font-weight: 900; line-height: 1; margin-top: 3px; padding: 3px 6px; }
.squeak-button:disabled, .tool-button:disabled { cursor: default; filter: grayscale(1); opacity: .62; }

button:focus-visible { outline: 4px solid #102243; outline-offset: 3px; }
@media (hover: hover) { .move-button:hover, .squeak-button:hover, .tool-button:hover, .round-button:hover, .primary-button:hover { filter: brightness(1.06); transform: translateY(-1px); } }

.toast { background: #fff9ce; border: 3px solid #fff; border-radius: 15px; box-shadow: 0 4px 0 rgba(115, 87, 0, 0.2); color: #533e00; font-size: 15px; font-weight: 900; left: 50%; max-width: min(420px, 80vw); opacity: 0; padding: 10px 15px; pointer-events: none; position: absolute; text-align: center; top: 42%; transform: translate(-50%, -4px); transition: opacity 160ms ease, transform 160ms ease; z-index: 3; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.keyboard-hint { bottom: calc(var(--safe-b) + 14px); color: rgba(255,255,255,.96); font-size: 12px; font-weight: 800; left: 50%; margin: 0; position: absolute; text-shadow: 0 1px 2px #15517e; transform: translateX(-50%); z-index: 2; }

@media (max-width: 640px), (max-height: 620px) {
  .player-card { padding: 6px 9px 6px 6px; }
  .portrait { font-size: 20px; height: 38px; width: 38px; }
  .player-card p { display: none; }
  .hud-stack { gap: 6px; top: calc(var(--safe-t) + 10px); }
  /* The chip wraps to 2-3 lines at this width, so a pill radius reads wrong. */
  .objective { border-radius: 18px; font-size: 13px; padding: 8px 12px; }
  .level-progress li { font-size: 9px; height: 20px; width: 20px; }
  .keyboard-hint { display: none; }
  /* Was transform: scale(.86), which shrank the hit targets along with the art. */
  .d-pad { height: 124px; width: 124px; }
  .move-button { font-size: 21px; height: 50px; width: 50px; }
  .move-button.up { left: 37px; top: 0; }
  .move-button.left { left: 0; top: 37px; }
  .move-button.right { right: 0; top: 37px; }
  .move-button.down { bottom: 0; left: 37px; }
  .squeak-button { height: 84px; width: 84px; }
  .squeak-button span { font-size: 28px; }
  .squeak-button b, .tool-button b { font-size: 8px; }
  .tool-button { height: 64px; width: 64px; }
}

/* Phone held sideways: almost no vertical room, so drop the dots and tighten. */
@media (orientation: landscape) and (max-height: 480px) {
  .level-progress { display: none; }
  .objective { font-size: 12px; padding: 6px 10px; }
  /* Keep the start/win cards inside a 393px-tall screen so nothing has to scroll. */
  .screen-card { padding: 16px 22px; }
  .screen-card h1 { font-size: 30px; margin: 6px 0 10px; }
  .screen-card p { font-size: 13px; margin-bottom: 12px; }
  .how-to { font-size: 11px; gap: 5px 8px; margin-bottom: 13px; padding: 9px; }
  .step-number { height: 18px; width: 18px; font-size: 10px; }
  .primary-button { font-size: 16px; padding: 10px 18px; }
  .d-pad { height: 112px; width: 112px; }
  .move-button { font-size: 18px; height: 46px; width: 46px; }
  .move-button.up { left: 33px; top: 0; }
  .move-button.left { left: 0; top: 33px; }
  .move-button.right { right: 0; top: 33px; }
  .move-button.down { bottom: 0; left: 33px; }
  .squeak-button { height: 74px; width: 74px; }
  .squeak-button span { font-size: 25px; }
  .tool-button { height: 58px; width: 58px; }
}

@media (pointer: fine) and (min-width: 740px) { .touch-controls { opacity: .78; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.001ms !important; } }
