:root {
  color-scheme: light;
  --ink: #071643;
  --muted: #b8c8df;
  --blue: #238ce9;
  --soft-blue: #edf6ff;
  --danger: #ff3f3f;
  --panel: #ffffff;
  --page: #ffffff;
  --chip: #f4f8fd;
  --chip-strong: #e9f4ff;
  --shadow-soft: 0 10px 28px rgba(7, 22, 67, 0.08);
  --shadow-blue: 0 12px 30px rgba(35, 140, 233, 0.2), 0 2px 8px rgba(7, 22, 67, 0.08);
  --app-width: 100vw;
  --app-height: 100vh;
}

* {
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  user-select: none;
}

html,
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

.app-shell {
  display: grid;
  width: 100%;
  min-height: var(--app-height, 100vh);
  height: var(--app-height, 100vh);
  background: var(--panel);
}

.phone-frame {
  position: relative;
  width: var(--app-width, 100vw);
  height: var(--app-height, 100vh);
  max-width: 100vw;
  max-height: 100vh;
  overflow: hidden;
  background: transparent;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
  touch-action: none;
}

input,
textarea,
select {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

.hud {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.gamepush-loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
}

.gamepush-loading.is-hidden {
  display: none;
}

.gamepush-loading-panel {
  display: inline-grid;
  grid-auto-flow: column;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 0 18px;
  border: 1px solid rgba(109, 40, 217, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(7, 22, 67, 0.14);
  font-size: 16px;
  font-weight: 900;
}

.gamepush-loading-label.is-resolving-language {
  visibility: hidden;
}

.gamepush-loading-spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(109, 40, 217, 0.18);
  border-top-color: #6d28d9;
  border-radius: 50%;
  animation: gamepush-loading-spin 780ms linear infinite;
}

@keyframes gamepush-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.hud-top {
  --hint-offset: clamp(18px, 2.8vw, 34px);
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  width: min(calc(100% - 32px), 620px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(94px, 1fr) minmax(0, auto) minmax(112px, 1fr);
  align-items: center;
  gap: 10px;
}

.hud-top-left {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-start;
  justify-self: start;
  gap: 10px;
  transform: translateX(var(--hint-offset));
}

.hud-top-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-start;
  justify-self: start;
  gap: 10px;
}

.level-title {
  justify-self: center;
  min-width: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  transform: translateX(-6px);
  max-width: min(38vw, 220px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
  padding: 6px 10px;
  border-radius: 999px;
  transition: background 140ms ease, color 140ms ease;
}

.level-title:hover {
  color: var(--blue);
  background: rgba(237, 246, 255, 0.84);
}

.icon-button,
.round-button,
.hint-button,
.primary-button,
.text-button {
  border: 0;
  cursor: pointer;
  pointer-events: auto;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--blue);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 6px 18px rgba(35, 140, 233, 0.1);
  font-size: 28px;
  line-height: 1;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.icon-button:hover,
.round-button:hover,
.hint-button:hover,
.primary-button:hover {
  box-shadow: var(--shadow-blue);
}

.icon-button:active,
.round-button:active,
.hint-button:active,
.primary-button:active,
.text-button:active {
  transform: scale(0.96);
}

.icon-button:focus-visible,
.round-button:focus-visible,
.hint-button:focus-visible,
.primary-button:focus-visible,
.text-button:focus-visible,
.level-picker-reset:focus-visible,
.editor-button:focus-visible {
  outline: 3px solid rgba(35, 140, 233, 0.3);
  outline-offset: 3px;
}

.hint-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  max-width: min(44vw, 168px);
  min-height: 40px;
  border-radius: 8px;
  color: var(--blue);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 18px rgba(35, 140, 233, 0.1);
  font-size: 13px;
  font-weight: 900;
  padding: 0 14px;
  white-space: nowrap;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.hint-button.has-video::before {
  content: "";
  flex: 0 0 18px;
  display: inline-block;
  width: 18px;
  height: 15px;
  margin-right: 7px;
  border: 2px solid currentColor;
  border-radius: 2px;
  background:
    linear-gradient(135deg, currentColor 0 13%, transparent 13% 27%, currentColor 27% 40%, transparent 40% 54%, currentColor 54% 67%, transparent 67% 81%, currentColor 81% 94%, transparent 94%) 0 0 / 100% 6px no-repeat,
    linear-gradient(currentColor, currentColor) 0 6px / 100% 2px no-repeat,
    linear-gradient(currentColor, currentColor) 4px 11px / 9px 2px no-repeat;
  transform: rotate(-8deg);
}

.hint-button.is-loading {
  cursor: wait;
  opacity: 0.72;
}

.hud-stats {
  position: absolute;
  top: max(64px, calc(env(safe-area-inset-top) + 54px));
  left: 50%;
  width: min(calc(100% - 44px), 620px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center;
  gap: 10px;
}

#arrow-counter {
  justify-self: start;
}

#prev-level {
  justify-self: start;
}

#difficulty {
  display: none;
}

.pill {
  display: inline-flex;
  min-width: 0;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: #526984;
  background: var(--chip);
  box-shadow: inset 0 0 0 1px rgba(7, 22, 67, 0.03);
  font-size: 13px;
  font-weight: 800;
  padding: 0 8px;
  white-space: nowrap;
}

.level-progress {
  --level-progress: 0%;
  position: absolute;
  top: max(110px, calc(env(safe-area-inset-top) + 100px));
  left: 56px;
  right: 56px;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf3fa;
  box-shadow: inset 0 0 0 1px rgba(7, 22, 67, 0.03);
}

.level-progress::before {
  content: "";
  display: block;
  width: var(--level-progress);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #36a3f5, #16c7b7);
  transition: width 220ms ease;
}

.hearts {
  grid-column: 2;
  display: flex;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  font-size: 28px;
  line-height: 1;
}

.heart {
  color: var(--danger);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.04));
}

.heart.is-empty {
  color: #d6e0eb;
}

.bottom-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(26px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 18px;
}

.round-button {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  color: var(--blue);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-blue);
  font-size: 24px;
  font-weight: 800;
  transition: box-shadow 140ms ease, transform 140ms ease;
}

.sound-button.is-muted {
  color: #8fa2ba;
  background: #f4f8fd;
  box-shadow: 0 8px 22px rgba(7, 22, 67, 0.08);
}

.error-flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: rgba(255, 63, 63, 0.07);
  box-shadow: inset 0 0 90px 25px rgba(255, 63, 63, 0.74);
  transition: opacity 180ms ease;
}

.error-flash.is-active {
  opacity: 1;
}

.tutorial {
  --tutorial-character-drop: 28px;
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: max(96px, calc(env(safe-area-inset-top) + 86px)) 18px 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.9));
  pointer-events: auto;
}

.tutorial.is-hidden {
  display: none;
}

.tutorial-panel {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: minmax(112px, 190px) minmax(0, 1fr);
  gap: 12px;
  align-items: end;
}

.tutorial-character {
  width: 100%;
  max-height: min(48vh, 340px);
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 24px rgba(7, 22, 67, 0.16));
  pointer-events: none;
  transform: translateY(var(--tutorial-character-drop));
}

.tutorial-bubble {
  align-self: center;
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border: 2px solid rgba(109, 40, 217, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(7, 22, 67, 0.14);
}

.tutorial-bubble p {
  margin: 0;
  font-size: 16px;
  font-weight: 850;
  line-height: 1.35;
  text-wrap: balance;
}

.tutorial-next {
  justify-self: start;
  min-width: 132px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: #6d28d9;
  box-shadow: 0 12px 28px rgba(109, 40, 217, 0.26);
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.tutorial-next:hover,
.tutorial-next:focus-visible {
  background: #7c3aed;
  box-shadow: 0 16px 32px rgba(109, 40, 217, 0.32);
  outline: none;
  transform: translateY(-1px);
}

.tutorial-next:active {
  transform: translateY(1px) scale(0.99);
}

#game-canvas.is-hint-pulse {
  animation: canvas-hint-pulse 380ms ease-out both;
}

.phone-frame.is-danger-shake {
  animation: danger-shake 280ms ease-out both;
}

@keyframes canvas-hint-pulse {
  0%,
  100% {
    filter: none;
  }

  50% {
    filter: drop-shadow(0 0 18px rgba(35, 140, 233, 0.24));
  }
}

@keyframes danger-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  22% {
    transform: translate3d(-4px, 0, 0);
  }

  46% {
    transform: translate3d(4px, 0, 0);
  }

  70% {
    transform: translate3d(-2px, 0, 0);
  }
}

.level-picker {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  align-items: end;
  padding: 0 10px max(12px, env(safe-area-inset-bottom));
  pointer-events: auto;
  background: linear-gradient(180deg, transparent 0 32%, rgba(7, 22, 67, 0.1));
}

.level-picker.is-hidden {
  display: none;
}

.level-picker-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  max-height: min(52vh, calc(var(--app-height, 100vh) - 24px), 420px);
  overflow: hidden;
  padding: 14px;
  border: 1px solid rgba(7, 22, 67, 0.07);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 18px 42px rgba(7, 22, 67, 0.16);
}

.level-picker-head {
  display: grid;
  grid-template-columns: 1fr 40px;
  align-items: center;
  gap: 12px;
}

.level-picker-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0;
}

.level-picker-close {
  justify-self: end;
  font-size: 22px;
}

.level-picker-meta {
  min-height: 18px;
  color: #526984;
  font-size: 12px;
  font-weight: 800;
}

.level-picker-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 4px;
}

.level-picker-actions {
  display: grid;
  justify-items: center;
  padding-top: 2px;
}

.level-picker-reset {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  color: #526984;
  background: transparent;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  padding: 0 14px;
  transition: color 140ms ease, background 140ms ease, transform 140ms ease;
}

.level-picker-reset:hover {
  color: var(--blue);
  background: var(--soft-blue);
}

.level-picker-reset:active {
  transform: scale(0.96);
}

.level-picker-item {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: #526984;
  background: var(--chip);
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.level-picker-number {
  line-height: 1;
}

.level-picker-rating {
  min-height: 11px;
  color: #ffbf2f;
  font-size: 10px;
  line-height: 1;
  letter-spacing: 0;
}

.level-picker-item:hover {
  color: var(--blue);
  background: var(--chip-strong);
}

.level-picker-item:active {
  transform: scale(0.96);
}

.level-picker-item.is-current {
  color: #fff;
  background: linear-gradient(135deg, #168eea, #0fb6aa);
  box-shadow: var(--shadow-blue);
}

.level-picker-item.is-current .level-picker-rating {
  color: rgba(255, 255, 255, 0.88);
}

.level-picker-item.is-locked {
  color: #afbfd2;
  background: #f6f8fb;
  cursor: default;
  box-shadow: none;
}

.level-picker-item.is-locked:hover {
  color: #afbfd2;
  background: #f6f8fb;
}

.level-picker-item.is-locked:active {
  transform: none;
}

.level-picker-item.is-locked .level-picker-rating {
  color: #cbd6e3;
}

.victory {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-rows: minmax(96px, 1fr) auto auto auto minmax(76px, 1fr);
  justify-items: center;
  gap: 24px;
  padding: max(42px, env(safe-area-inset-top)) 28px max(30px, env(safe-area-inset-bottom));
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(233, 246, 255, 0.95), rgba(255, 255, 255, 0.98) 48%),
    #fff;
}

.victory.is-hidden {
  display: none;
}

.victory h1 {
  grid-row: 2;
  z-index: 2;
  margin: 0;
  max-width: 320px;
  color: var(--ink);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
  text-wrap: balance;
}

.victory-stars {
  grid-row: 3;
  z-index: 2;
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #ffbf2f;
  font-size: 72px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 8px 20px rgba(255, 191, 47, 0.28);
}

.victory-stars .star {
  display: inline-block;
  animation: star-pop 520ms cubic-bezier(0.2, 1.24, 0.28, 1) both;
}

.victory-stars .star:nth-child(2) {
  animation-delay: 80ms;
}

.victory-stars .star:nth-child(3) {
  animation-delay: 160ms;
}

.star.is-empty {
  color: #d6e0eb;
  text-shadow: none;
}

.primary-button {
  grid-row: 4;
  z-index: 2;
  display: grid;
  min-width: 260px;
  min-height: 58px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #168eea, #0fb6aa);
  font-weight: 900;
  box-shadow: var(--shadow-blue);
  transition: box-shadow 140ms ease, transform 140ms ease;
}

.primary-button.is-celebrating {
  animation:
    victory-button-rise 420ms ease both,
    victory-button-breathe 1800ms ease-in-out 520ms infinite;
}

.primary-button small {
  margin-top: -8px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 800;
}

.text-button {
  z-index: 2;
  min-height: 36px;
  color: #526984;
  background: transparent;
  font-weight: 900;
  transition: color 140ms ease, transform 140ms ease;
}

.text-button:hover {
  color: var(--blue);
}

.confetti {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image:
    radial-gradient(circle, #238ce9 0 2px, transparent 2px),
    radial-gradient(circle, #ffca2f 0 2px, transparent 2px),
    radial-gradient(circle, #ff6d9c 0 2px, transparent 2px),
    radial-gradient(circle, #0fb6aa 0 2px, transparent 2px);
  opacity: 0.38;
  background-position: 10% 10%, 24% 0, 70% 8%, 88% 2%;
  background-size: 76px 104px, 92px 86px, 84px 112px, 118px 96px;
  animation: confetti-fall 5200ms linear infinite;
  will-change: background-position;
}

@keyframes confetti-fall {
  from {
    background-position: 10% 0, 24% -24px, 70% -52px, 88% -12px;
  }

  to {
    background-position: 10% 104px, 24% 62px, 70% 60px, 88% 84px;
  }
}

@keyframes star-pop {
  0% {
    opacity: 0;
    transform: scale(0.42) rotate(-10deg);
  }

  64% {
    opacity: 1;
    transform: scale(1.14) rotate(4deg);
  }

  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes victory-button-rise {
  from {
    transform: translateY(10px) scale(0.96);
  }

  to {
    transform: translateY(0) scale(1);
  }
}

@keyframes victory-button-breathe {
  0%,
  100% {
    transform: translateY(0);
    box-shadow: var(--shadow-blue);
  }

  50% {
    transform: scale(1.035);
    box-shadow: 0 18px 34px rgba(35, 140, 233, 0.3);
  }
}

@media (prefers-reduced-motion: reduce) {
  .confetti,
  .victory-stars .star,
  .primary-button.is-celebrating,
  .gamepush-loading-spinner,
  #game-canvas.is-hint-pulse,
  .phone-frame.is-danger-shake {
    animation: none;
  }
}

.is-editor .hud-top,
.is-editor .hud-stats,
.is-editor .level-progress,
.is-editor .tutorial,
.is-editor .bottom-actions,
.is-editor .level-picker {
  display: none;
}

.level-editor {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 4;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(7, 22, 67, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(7, 22, 67, 0.16);
}

.level-editor.is-hidden {
  display: none;
}

.editor-toolbar,
.editor-controls,
.editor-paths {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor-toolbar {
  display: grid;
  grid-template-columns: repeat(6, 38px);
  justify-content: start;
}

.editor-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--ink);
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.editor-controls,
.editor-generator {
  display: grid;
  grid-template-columns: 1fr 1fr 1.25fr;
}

.editor-generator {
  grid-template-columns: 1.35fr 1fr 1.15fr 0.8fr;
}

.editor-controls label,
.editor-generator label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #6b7d94;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.editor-controls input,
.editor-controls select,
.editor-generator input,
.editor-generator select {
  width: 100%;
  min-height: 34px;
  border: 1px solid #d7e2ef;
  border-radius: 6px;
  color: var(--ink);
  background: #f8fbff;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 0 8px;
}

.editor-paths {
  min-height: 34px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.editor-path-tab {
  flex: 0 0 auto;
  min-width: 54px;
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  color: #65768d;
  background: #edf3fa;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.editor-path-tab.is-active {
  color: #fff;
  background: var(--blue);
}

.editor-status {
  min-height: 18px;
  color: #65768d;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.editor-status.is-invalid {
  color: var(--danger);
}

.editor-solution {
  min-height: 17px;
  overflow: hidden;
  color: #238ce9;
  font-size: 11px;
  font-weight: 900;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-output {
  width: 100%;
  height: 86px;
  resize: none;
  border: 1px solid #d7e2ef;
  border-radius: 6px;
  color: #23324f;
  background: #f8fbff;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  padding: 8px;
}

@media (max-width: 360px) {
  .hud-top {
    --hint-offset: clamp(6px, 2vw, 10px);
    width: min(calc(100% - 24px), 620px);
    grid-template-columns: minmax(86px, 1fr) minmax(0, auto) minmax(94px, 1fr);
    gap: 6px;
  }

  .hud-top-left,
  .hud-top-actions {
    gap: 6px;
  }

  .level-title {
    max-width: min(31vw, 150px);
    transform: translateX(-4px);
  }

  .hint-button {
    min-width: 94px;
    max-width: min(34vw, 118px);
    padding: 0 8px;
  }

  .hint-button.has-video::before {
    margin-right: 4px;
    flex-basis: 16px;
    width: 16px;
    height: 13px;
  }

  .hud-stats {
    width: min(calc(100% - 32px), 620px);
    grid-template-columns: minmax(58px, 1fr) auto minmax(58px, 1fr);
    gap: 8px;
  }

  .pill {
    font-size: 12px;
  }

  .hearts {
    gap: 5px;
    font-size: 24px;
  }

  .level-progress {
    left: 44px;
    right: 44px;
  }

  .tutorial {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tutorial-panel {
    grid-template-columns: 108px minmax(0, 1fr);
    gap: 8px;
  }

  .tutorial-bubble {
    padding: 13px;
  }

  .tutorial-bubble p {
    font-size: 14px;
  }

  .tutorial-next {
    min-width: 112px;
    min-height: 40px;
    font-size: 14px;
  }

  .level-picker {
    padding-left: 8px;
    padding-right: 8px;
  }

  .level-picker-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .level-editor {
    left: 8px;
    right: 8px;
  }

  .editor-output {
    height: 74px;
  }

  .editor-generator {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-height: 700px) {
  .hud-top {
    --hint-offset: clamp(8px, 2.5vw, 18px);
    top: max(10px, env(safe-area-inset-top));
    width: min(calc(100% - 24px), 620px);
    grid-template-columns: minmax(86px, 1fr) minmax(0, auto) minmax(98px, 1fr);
    gap: 8px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    font-size: 24px;
  }

  .level-title {
    font-size: 14px;
    padding-top: 5px;
    padding-bottom: 5px;
    transform: translateX(-5px);
  }

  .hud-top-left,
  .hud-top-actions {
    gap: 8px;
  }

  .hint-button {
    min-width: 94px;
    min-height: 36px;
    font-size: 12px;
    padding: 0 10px;
  }

  .hud-stats {
    top: max(54px, calc(env(safe-area-inset-top) + 44px));
    width: min(calc(100% - 32px), 620px);
    grid-template-columns: minmax(60px, 1fr) auto minmax(60px, 1fr);
    gap: 8px;
  }

  .pill {
    min-height: 30px;
    font-size: 12px;
  }

  .hearts {
    gap: 5px;
    min-width: 90px;
    font-size: 24px;
  }

  .level-progress {
    top: max(94px, calc(env(safe-area-inset-top) + 84px));
    left: 44px;
    right: 44px;
  }

  .tutorial {
    padding-top: max(82px, calc(env(safe-area-inset-top) + 72px));
  }

  .tutorial-character {
    max-height: min(44vh, 260px);
  }

  .tutorial-bubble {
    gap: 10px;
  }

  .tutorial-bubble p {
    font-size: 14px;
  }

  .tutorial-next {
    min-height: 40px;
  }

  .level-picker {
    padding: 0 8px max(8px, env(safe-area-inset-bottom));
  }

  .level-picker-panel {
    max-height: min(64vh, calc(var(--app-height, 100vh) - 18px), 370px);
    gap: 10px;
    padding: 12px;
  }

  .level-picker-item {
    min-height: 38px;
  }

  .victory {
    grid-template-rows: minmax(68px, 1fr) auto auto auto minmax(54px, 1fr);
    gap: 18px;
    padding: max(28px, env(safe-area-inset-top)) 22px max(22px, env(safe-area-inset-bottom));
  }

  .victory h1 {
    font-size: 24px;
  }

  .victory-stars {
    min-height: 72px;
    gap: 10px;
    font-size: 54px;
  }

  .primary-button {
    min-width: 236px;
    min-height: 54px;
  }
}

@media (max-height: 520px) {
  .hud-top {
    --hint-offset: clamp(8px, 2vw, 16px);
    top: max(6px, env(safe-area-inset-top));
    width: min(calc(100% - 16px), 760px);
    grid-template-columns: minmax(78px, 1fr) minmax(0, auto) minmax(92px, 1fr);
    gap: 6px;
  }

  .hud-top-left,
  .hud-top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    font-size: 22px;
  }

  .level-title {
    max-width: min(34vw, 190px);
    font-size: 13px;
    padding: 4px 7px;
    transform: translateX(-4px);
  }

  .hint-button {
    min-width: 92px;
    max-width: min(32vw, 126px);
    min-height: 34px;
    font-size: 11px;
    padding: 0 8px;
  }

  .hud-stats {
    top: max(44px, calc(env(safe-area-inset-top) + 38px));
    width: min(calc(100% - 24px), 760px);
    grid-template-columns: minmax(52px, 1fr) auto minmax(52px, 1fr);
    gap: 6px;
  }

  .pill {
    min-height: 26px;
    font-size: 11px;
    padding: 0 7px;
  }

  .hearts {
    gap: 4px;
    min-width: 76px;
    font-size: 22px;
  }

  .level-progress {
    top: max(78px, calc(env(safe-area-inset-top) + 70px));
    left: 28px;
    right: 28px;
    height: 4px;
  }

  .tutorial {
    --tutorial-character-drop: 0px;
    padding: max(50px, calc(env(safe-area-inset-top) + 44px)) 10px 0;
  }

  .tutorial-panel {
    width: min(100%, 620px);
    max-height: calc(var(--app-height, 100vh) - 50px);
    grid-template-columns: minmax(78px, 150px) minmax(0, 1fr);
    gap: 8px;
  }

  .tutorial-character {
    max-height: min(52vh, 210px);
  }

  .tutorial-bubble {
    align-self: end;
    gap: 8px;
    padding: 10px 12px;
  }

  .tutorial-bubble p {
    font-size: 12px;
    line-height: 1.25;
    text-wrap: auto;
  }

  .tutorial-next {
    min-width: 94px;
    min-height: 34px;
    font-size: 13px;
  }

  .level-picker {
    align-items: center;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    background: rgba(7, 22, 67, 0.08);
  }

  .level-picker-panel {
    width: min(100%, 620px);
    max-height: calc(var(--app-height, 100vh) - 16px);
    gap: 8px;
    padding: 10px;
  }

  .level-picker-head {
    grid-template-columns: 1fr 34px;
    gap: 8px;
  }

  .level-picker-head h2 {
    font-size: 15px;
  }

  .level-picker-meta {
    font-size: 11px;
  }

  .level-picker-list {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

  .level-picker-item {
    min-height: 34px;
    font-size: 12px;
  }

  .victory {
    grid-template-rows: minmax(24px, 0.7fr) auto auto auto minmax(20px, 0.7fr);
    gap: 9px;
    padding: max(14px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
  }

  .victory h1 {
    max-width: 420px;
    font-size: 20px;
  }

  .victory-stars {
    min-height: 46px;
    gap: 8px;
    font-size: 40px;
  }

  .primary-button {
    min-width: 212px;
    min-height: 44px;
    font-size: 14px;
  }
}

@media (hover: none) {
  .icon-button:hover {
    box-shadow: 0 6px 18px rgba(35, 140, 233, 0.1);
  }

  .round-button:hover,
  .primary-button:hover {
    box-shadow: var(--shadow-blue);
  }
}
