:root {
  color-scheme: light;
  --teal: #168d8c;
  --teal-dark: #0d7476;
  --card: #fffdfb;
  --ink: #183b4b;
  --muted: #58717c;
  --cell: min(68px, calc((100vw - 46px) / 6));
  --grid-line: #9c7b79;
  --floor: #dff1f5;
  --floor-alt: #d8edf2;
  --pink: #f47dab;
  --pink-dark: #d72f7b;
  --yellow: #efbf16;
  --brown: #71371e;
  --shadow: 0 22px 60px rgb(10 74 77 / 22%);
  font-family: Inter, ui-rounded, "Nunito Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: clip;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, rgb(255 255 255 / 11%) 0 7%, transparent 7.3%),
    linear-gradient(145deg, var(--teal), var(--teal-dark));
}

button, a { font: inherit; }
button { touch-action: manipulation; }

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 56px;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 0 4px 22px;
  color: white;
}

.eyebrow {
  margin: 0 0 6px;
  color: #bff2ed;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1 { margin: 0; font-size: clamp(1.55rem, 3vw, 2.35rem); line-height: 1.08; }

.source-link {
  flex: 0 0 auto;
  padding: 10px 16px;
  border: 1px solid rgb(255 255 255 / 65%);
  border-radius: 7px;
  color: white;
  font-weight: 700;
  text-decoration: none;
  transition: background .2s, transform .2s;
}

.source-link:hover { background: rgb(255 255 255 / 13%); transform: translateY(-1px); }

.puzzle-card, .help-card {
  border: 1px solid rgb(255 255 255 / 65%);
  border-radius: 17px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.puzzle-card { padding: clamp(20px, 4vw, 44px); }
.instructions { max-width: 920px; margin: 0 auto 32px; font-size: clamp(.95rem, 1.5vw, 1.08rem); line-height: 1.55; }
.instructions p { margin: 0; }
.sticky-rule { margin-top: 8px !important; color: var(--pink-dark); font-weight: 800; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 240px);
  align-items: center;
  gap: clamp(30px, 7vw, 90px);
  max-width: 920px;
  margin: 0 auto;
}

.board-wrap { display: grid; justify-items: center; min-width: 0; }
.board { position: relative; width: calc(6 * var(--cell)); height: calc(5 * var(--cell)); }
.pieces { position: absolute; inset: 0; pointer-events: none; }

.floor-cell, .hole, .goal-outline, .gum, .robot { position: absolute; }
.floor-cell {
  width: var(--cell);
  height: var(--cell);
  background: var(--floor);
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
}

.floor-cell.edge-top { border-top: 1px solid var(--grid-line); }
.floor-cell.edge-left { border-left: 1px solid var(--grid-line); }
.floor-cell:nth-child(even) { background: var(--floor-alt); }

.goal-outline {
  z-index: 2;
  left: calc(4 * var(--cell));
  top: calc(2 * var(--cell));
  width: calc(2 * var(--cell));
  height: calc(2 * var(--cell));
  border: 4px solid var(--pink-dark);
  pointer-events: none;
}

.hole {
  z-index: 3;
  left: var(--cell);
  top: calc(2 * var(--cell));
  width: var(--cell);
  height: var(--cell);
  border: 4px solid var(--brown);
  background: var(--card);
}

.gum {
  z-index: 5;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell)));
  transition: transform 150ms ease;
}

.gum::before {
  width: 56%;
  aspect-ratio: 1;
  border: 2px solid rgb(207 43 113 / 35%);
  border-radius: 50% 47% 52% 48%;
  background:
    radial-gradient(circle at 29% 25%, white 0 7%, rgb(255 255 255 / 65%) 8% 15%, transparent 16%),
    linear-gradient(145deg, #ffb9d0, var(--pink));
  box-shadow: inset -4px -5px 7px rgb(170 26 91 / 18%), 0 3px 5px rgb(93 39 66 / 18%);
  content: "";
}

.gum-bridge {
  position: absolute;
  z-index: -1;
  background: rgb(244 125 171 / 45%);
}
.gum-bridge.right { left: 68%; width: 64%; height: 22%; }
.gum-bridge.down { top: 68%; width: 22%; height: 64%; }
.gum-bridge[hidden] { display: none; }

.robot {
  z-index: 7;
  display: grid;
  place-items: center;
  width: var(--cell);
  height: var(--cell);
  padding: 7%;
  transform: translate(calc(var(--x) * var(--cell)), calc(var(--y) * var(--cell)));
  transition: transform 150ms ease;
}
.robot svg { width: 82%; filter: drop-shadow(0 3px 2px rgb(25 55 69 / 25%)); }
.board.blocked { animation: nudge 180ms ease; }

.board-caption { display: flex; align-items: center; gap: 7px; margin: 12px 0 0; color: var(--muted); font-size: .78rem; }
.legend-hole { width: 15px; height: 15px; border: 2px solid var(--brown); background: white; }

.control-panel { display: grid; justify-items: stretch; gap: 14px; }
.dpad { display: grid; grid-template: repeat(2, 58px) / repeat(3, 58px); justify-content: center; gap: 7px; }
.move-button, .utility-button {
  border: 0;
  border-radius: 8px;
  color: white;
  cursor: pointer;
  font-size: 2rem;
  font-weight: 900;
  box-shadow: 0 4px 0 rgb(145 99 0 / 35%);
  transition: filter .15s, transform .08s, box-shadow .08s;
}
.move-button { background: linear-gradient(#f6ca27, var(--yellow)); color: #4b2a10; }
.move-button.up { grid-area: 1 / 2; }
.move-button.left { grid-area: 2 / 1; }
.move-button.down { grid-area: 2 / 2; }
.move-button.right { grid-area: 2 / 3; }
.move-button:hover, .utility-button:hover { filter: brightness(1.06); }
.move-button:active, .utility-button:active { transform: translateY(3px); box-shadow: 0 1px 0 rgb(80 40 10 / 35%); }
.move-button.hinted { animation: hintPulse 850ms ease infinite; outline: 4px solid rgb(244 125 171 / 40%); }
.move-button:disabled { cursor: wait; filter: grayscale(.45); opacity: .58; box-shadow: none; }
.move-button:disabled:hover { filter: grayscale(.45); }

.utility-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.utility-button { min-height: 48px; background: var(--brown); box-shadow: 0 4px 0 rgb(52 24 12 / 45%); }
.utility-button:disabled { cursor: default; filter: grayscale(.6); opacity: .45; box-shadow: none; }

.status-card { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-radius: 9px; background: #edf7f6; color: var(--muted); font-size: .88rem; }
.status-card strong { color: var(--teal-dark); font-size: 1.35rem; }

.text-button {
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  cursor: pointer;
  font-weight: 800;
}
.text-button.secondary { border: 2px solid var(--teal); background: transparent; color: var(--teal-dark); }
.text-button:disabled { cursor: wait; opacity: .55; }

.message { min-height: 1.5em; margin: 30px auto 0; color: var(--muted); text-align: center; }
.message.error { color: #ad3e2e; }
.message.success { color: var(--teal-dark); font-weight: 800; }

.help-card { margin-top: 22px; padding: 25px clamp(22px, 4vw, 42px); }
.help-card h2 { margin: 0 0 12px; font-size: 1.2rem; }
.help-card ol { display: grid; gap: 7px; margin: 0; padding-left: 1.35rem; line-height: 1.45; }
.help-card p { margin: 15px 0 0; color: var(--muted); font-size: .9rem; }

.win-dialog {
  width: min(430px, calc(100% - 32px));
  padding: 34px;
  border: 0;
  border-radius: 18px;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 30px 90px rgb(13 59 62 / 40%);
}
.win-dialog::backdrop { background: rgb(9 63 65 / 65%); backdrop-filter: blur(4px); }
.win-dialog h2 { margin: 12px 0 7px; }
.win-dialog p { margin: 0 0 22px; color: var(--muted); }
.win-gum { display: grid; place-items: center; width: 72px; aspect-ratio: 1; margin: auto; border-radius: 50%; background: linear-gradient(145deg, #ffb9d0, var(--pink)); color: white; font-size: 2.3rem; font-weight: 900; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid white; outline-offset: 2px; box-shadow: 0 0 0 6px #124d5a; }

@keyframes nudge { 30% { transform: translateX(-5px); } 65% { transform: translateX(5px); } }
@keyframes hintPulse { 50% { transform: translateY(-3px) scale(1.05); filter: brightness(1.12); } }

@media (max-width: 760px) {
  .page-shell { width: min(100% - 20px, 620px); padding-top: 18px; }
  .page-header { align-items: start; flex-direction: column; gap: 14px; }
  .source-link { padding: 7px 11px; font-size: .84rem; }
  .puzzle-card { padding-inline: 12px; }
  .instructions { padding-inline: 7px; }
  .game-layout { grid-template-columns: 1fr; gap: 26px; }
  .control-panel { width: min(310px, 100%); margin: auto; }
  .utility-buttons { width: 180px; margin: auto; }
}

@media (max-width: 400px) {
  .page-header { padding-left: 3px; }
  .puzzle-card { border-radius: 12px; }
  .instructions { font-size: .9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
