:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #172033;
  font-family:
    Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: #172033;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.ui-layer {
  position: absolute;
  left: var(--game-left, 0px);
  top: var(--game-top, 0px);
  width: var(--game-width, 100%);
  height: var(--game-height, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  padding:
    max(clamp(8px, 1.5vw, 16px), var(--safe-top))
    max(clamp(8px, 1.5vw, 16px), var(--safe-right))
    max(clamp(8px, 1.5vw, 16px), var(--safe-bottom))
    max(clamp(8px, 1.5vw, 16px), var(--safe-left));
}

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(5px, 0.9vw, 10px);
  width: min(100%, 1120px);
  margin: 0 auto;
  color: #eef6ff;
  font-size: clamp(11px, 1vw, 13px);
  font-weight: 700;
  text-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}

.hud__left,
.hud__right,
.hud__center {
  display: contents;
}

.hud-pill,
.hint-button,
.ui-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 0.6vw, 6px);
  min-height: clamp(30px, 3.3vw, 34px);
  border: 1px solid rgb(255 255 255 / 0.16);
  border-radius: 8px;
  background: rgb(10 17 30 / 0.55);
  backdrop-filter: blur(10px);
  color: #eef6ff;
  font: inherit;
  line-height: 1;
  white-space: nowrap;
  min-width: 0;
  flex: 0 0 auto;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 0 clamp(7px, 1vw, 10px);
}

.level-counter {
  max-width: min(190px, 32vw);
}

.level-counter span {
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.hint-button {
  pointer-events: auto;
  min-width: 112px;
  max-width: 150px;
  padding: 0 clamp(7px, 1vw, 9px);
  cursor: pointer;
}

.ui-button {
  pointer-events: auto;
  min-width: 72px;
  padding: 0 clamp(7px, 1vw, 9px);
  cursor: pointer;
}

.ui-button[hidden],
.skip-button[hidden] {
  display: none;
}

.ui-button--icon {
  width: 38px;
  min-width: 38px;
  max-width: 38px;
  padding: 0;
}

.level-menu-button {
  min-width: 78px;
}

.skip-button {
  min-width: 94px;
}

.ui-icon {
  width: clamp(18px, 2.4vw, 22px);
  height: clamp(18px, 2.4vw, 22px);
  display: block;
  flex: 0 0 auto;
  object-fit: contain;
}

.ui-icon--hard {
  width: 20px;
  height: 20px;
}

.ui-icon--ultra-hard {
  width: 22px;
  height: 22px;
}

.hint-button .ui-icon {
  width: 20px;
  height: 20px;
}

.hint-button:active,
.ui-button:active {
  transform: translateY(1px);
}

.status {
  position: static;
  width: min(780px, calc(100% - 36px));
  transform: none;
  margin-top: clamp(4px, 0.8vw, 8px);
  min-height: 22px;
  color: rgb(238 246 255 / 0.86);
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 700;
  text-align: center;
  text-shadow: 0 2px 8px rgb(0 0 0 / 0.35);
}

.status:empty {
  display: none;
}

.victory {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding:
    max(14px, var(--safe-top))
    max(14px, var(--safe-right))
    max(14px, var(--safe-bottom))
    max(14px, var(--safe-left));
  overflow: hidden;
  background: rgb(6 10 18 / 0.62);
}

.victory[hidden] {
  display: none;
}

.level-menu {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding:
    max(14px, var(--safe-top))
    max(14px, var(--safe-right))
    max(14px, var(--safe-bottom))
    max(14px, var(--safe-left));
  overflow: hidden;
  background: rgb(6 10 18 / 0.58);
}

.level-menu[hidden] {
  display: none;
}

.tutorial {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding:
    max(14px, var(--safe-top))
    max(14px, var(--safe-right))
    max(14px, var(--safe-bottom))
    max(14px, var(--safe-left));
  overflow: hidden;
  background: rgb(6 10 18 / 0.58);
}

.tutorial[hidden] {
  display: none;
}

.tutorial__panel {
  width: min(350px, calc(100vw - 36px - var(--safe-left) - var(--safe-right)), calc((100svh - 28px - var(--safe-top) - var(--safe-bottom)) * 0.72));
  max-height: calc(100svh - 28px - var(--safe-top) - var(--safe-bottom));
  padding: clamp(12px, 2.7vw, 22px) clamp(12px, 3.2vw, 20px);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 8px;
  background: rgb(17 28 46 / 0.96);
  color: #eef6ff;
  text-align: center;
  box-shadow: 0 22px 70px rgb(0 0 0 / 0.34);
}

.tutorial__demo {
  display: grid;
  place-items: center;
  min-height: clamp(82px, 21svh, 170px);
  margin-bottom: clamp(7px, 1.8svh, 16px);
}

.tutorial__title {
  margin-bottom: clamp(5px, 1.2svh, 8px);
  font-size: clamp(17px, 4.9vw, 22px);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.tutorial__text {
  color: rgb(238 246 255 / 0.78);
  font-size: clamp(12px, 3.4vw, 15px);
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.tutorial__close {
  width: 100%;
  margin-top: clamp(12px, 2.8svh, 18px);
  background: #58d6c4;
  color: #102033;
}

.tutorial-arrow-shape,
.tutorial-frozen-shape,
.tutorial-wood-shape,
.tutorial-mixed-shape,
.tutorial-water-shape {
  position: relative;
  width: 136px;
  height: 136px;
  border-radius: 32px;
  background: rgb(69 104 158 / 0.72);
  box-shadow: inset 0 0 0 6px rgb(238 246 255 / 0.12);
}

.tutorial-arrow-shape {
  width: 174px;
  height: 98px;
  border: 8px solid #2f8cff;
  border-radius: 26px;
}

.tutorial-arrow-line {
  position: absolute;
  left: 36px;
  right: 36px;
  top: 50%;
  height: 7px;
  border-radius: 0;
  background: rgb(238 246 255 / 0.78);
  transform: translateY(-50%);
}

.tutorial-arrow-head {
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  transform: translateY(-50%);
}

.tutorial-arrow-head--left {
  left: 25px;
  border-top: 13px solid transparent;
  border-bottom: 13px solid transparent;
  border-right: 18px solid rgb(238 246 255 / 0.78);
}

.tutorial-arrow-head--right {
  right: 25px;
  border-top: 13px solid transparent;
  border-bottom: 13px solid transparent;
  border-left: 18px solid rgb(238 246 255 / 0.78);
}

.tutorial-arrow-seam {
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 50%;
  width: 6px;
  height: auto;
  border-radius: 999px;
  background: rgb(238 246 255 / 0.12);
  transform: translateX(-50%);
}

.tutorial__demo--frozen {
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  min-height: 116px;
}

.tutorial-frozen-shape {
  border: 6px solid rgb(218 244 255 / 0.86);
  background:
    repeating-linear-gradient(135deg, rgb(238 250 255 / 0.28) 0 8px, rgb(120 183 218 / 0.16) 8px 17px),
    rgb(69 104 158 / 0.78);
}

.tutorial__demo--frozen .tutorial-frozen-shape,
.tutorial__demo--frozen .tutorial-water-shape {
  width: 92px;
  height: 92px;
  border-radius: 24px;
}

.tutorial-frozen-shape span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #eefaff;
  font-size: 34px;
  font-weight: 900;
  text-shadow: 0 2px 0 rgb(39 70 98 / 0.7);
}

.tutorial-plus {
  color: #58d6c4;
  font-size: 26px;
  font-weight: 900;
}

.tutorial-water-shape {
  border: 6px solid #50df8b;
  background: linear-gradient(to top, #50df8b 0 58%, rgb(67 199 120 / 0.18) 58% 100%);
}

.tutorial__demo--wood {
  grid-template-columns: 1fr;
  min-height: 132px;
}

.tutorial-wood-shape {
  width: 112px;
  height: 112px;
  border: 8px solid #4c2d1a;
  border-radius: 30px;
  background: #5b3520;
  box-shadow:
    inset 0 0 0 5px rgb(255 238 203 / 0.16),
    0 9px 0 rgb(54 31 18 / 0.28);
}

.tutorial-wood-shape::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: 32px;
  height: 4px;
  border-radius: 0;
  background: #24150d;
  box-shadow:
    0 18px 0 #24150d,
    0 36px 0 #24150d;
}

.tutorial__demo--layered {
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  min-height: 132px;
}

.tutorial-layered-shape {
  position: relative;
  width: 118px;
  height: 118px;
  border: 7px solid #ff8a2f;
  border-radius: 28px;
  background: rgb(255 138 47 / 0.2);
  box-shadow: inset 0 0 0 6px rgb(255 255 255 / 0.08);
}

.tutorial-layered-inner {
  position: absolute;
  inset: 9px;
  border: 7px solid #ff5cb8;
  border-radius: 22px;
  background: rgb(255 92 184 / 0.38);
}

.tutorial-layered-shape--outer {
  background: linear-gradient(to top, #ff8a2f 0 72%, rgb(255 138 47 / 0.18) 72% 100%);
}

.tutorial__demo--mixed {
  min-height: 146px;
}

.tutorial-mixed-shape {
  display: grid;
  grid-template-rows: 1fr 1fr;
  width: 92px;
  height: 154px;
  overflow: hidden;
  border: 7px solid rgb(238 246 255 / 0.1);
  border-radius: 28px;
  background: rgb(69 104 158 / 0.2);
  box-shadow: 5px 7px 0 rgb(4 10 22 / 0.28);
}

.tutorial-mixed-part {
  display: block;
  margin: 0;
  border: 0;
  background: color-mix(in srgb, currentColor 22%, transparent);
}

.tutorial-mixed-part--blue {
  color: #2f8cff;
  border-top: 7px solid currentColor;
  border-right: 7px solid currentColor;
  border-bottom: 3px solid rgb(238 246 255 / 0.66);
  border-left: 7px solid currentColor;
  border-radius: 21px 21px 0 0;
}

.tutorial-mixed-part--green {
  color: #43c778;
  border-right: 7px solid currentColor;
  border-bottom: 7px solid currentColor;
  border-left: 7px solid currentColor;
  border-radius: 0 0 21px 21px;
}

.tutorial__demo--key {
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  min-height: 132px;
}

.tutorial-key-shape {
  position: relative;
  width: 104px;
  height: 104px;
  border: 7px solid #774ee5;
  border-radius: 28px;
  background: rgb(119 78 229 / 0.34);
  box-shadow:
    inset 0 0 0 5px rgb(255 255 255 / 0.08),
    0 9px 0 rgb(4 10 22 / 0.28);
}

.tutorial-key-icon {
  position: absolute;
  left: 41px;
  top: 44px;
  width: 40px;
  height: 0;
  border-radius: 999px;
  background: none;
  border-top: 6px solid rgb(238 246 255 / 0.92);
}

.tutorial-key-icon::before {
  content: "";
  position: absolute;
  left: -24px;
  top: -13px;
  width: 16px;
  height: 16px;
  border: 5px solid rgb(238 246 255 / 0.92);
  border-radius: 50%;
}

.tutorial-key-icon::after {
  content: "";
  position: absolute;
  left: 21px;
  top: 0;
  width: 5px;
  height: 13px;
  background: rgb(238 246 255 / 0.92);
  box-shadow: 9px 0 0 rgb(238 246 255 / 0.92);
}

.tutorial-lock-pipe {
  position: relative;
  width: 34px;
  height: 126px;
  border: 6px solid #10213f;
  border-radius: 22px;
  background: #e3aa1d;
  box-shadow: 0 9px 0 rgb(4 10 22 / 0.28);
}

.tutorial-lock-pipe span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 42px;
  border: 5px solid #071225;
  border-radius: 8px;
  background: #10213f;
  box-shadow:
    inset 0 0 0 2px rgb(255 255 255 / 0.06),
    0 5px 0 rgb(4 10 22 / 0.24);
  transform: translate(-50%, -50%);
}

.tutorial-lock-pipe span::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 22px;
  width: 16px;
  height: 12px;
  border-radius: 3px;
  background: rgb(238 246 255 / 0.72);
  transform: translate(-50%, -50%);
}

.tutorial-lock-pipe span::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 5px;
  width: 13px;
  height: 11px;
  border: 4px solid rgb(238 246 255 / 0.72);
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
  transform: translateX(-50%);
}

.level-menu__panel {
  display: flex;
  flex-direction: column;
  width: min(430px, calc(100vw - 28px - var(--safe-left) - var(--safe-right)), calc((100svh - 28px - var(--safe-top) - var(--safe-bottom)) * 0.92));
  max-height: calc(100svh - 28px - var(--safe-top) - var(--safe-bottom));
  padding: clamp(12px, 3.2vw, 18px);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 8px;
  background: rgb(17 28 46 / 0.94);
  box-shadow: 0 22px 70px rgb(0 0 0 / 0.34);
}

.level-menu__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: clamp(7px, 1.8svh, 14px);
}

.level-menu__title {
  min-width: 0;
  color: #eef6ff;
  font-size: clamp(18px, 4.8vw, 20px);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.level-menu__close {
  min-width: 88px;
}

.level-menu__list {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: clamp(4px, 1.4vw, 9px);
  min-height: 0;
  overflow: visible;
}

.level-menu__pager {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: clamp(7px, 1.8svh, 14px);
}

.level-menu__arrow {
  position: relative;
  width: 46px;
  min-width: 46px;
  height: 42px;
  padding: 0;
  border-color: rgb(88 214 196 / 0.42);
  background: linear-gradient(180deg, rgb(88 214 196 / 0.22), rgb(47 140 255 / 0.16));
  box-shadow:
    inset 0 0 0 1px rgb(255 255 255 / 0.08),
    0 8px 18px rgb(0 0 0 / 0.18);
}

.level-menu__arrow::before {
  content: "";
  position: absolute;
  top: 50%;
  width: 0;
  height: 0;
  transform: translateY(-50%);
}

.level-menu__arrow[data-direction="prev"]::before {
  left: 15px;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 14px solid #eef6ff;
}

.level-menu__arrow[data-direction="next"]::before {
  right: 15px;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 14px solid #eef6ff;
}

.level-menu__arrow:disabled {
  cursor: default;
  opacity: 0.35;
  background: rgb(10 17 30 / 0.5);
  box-shadow: none;
}

.level-menu__arrow:disabled::before {
  border-left-color: rgb(238 246 255 / 0.55);
  border-right-color: rgb(238 246 255 / 0.55);
}

.level-menu__page {
  min-width: 54px;
  color: rgb(238 246 255 / 0.82);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
}

.level-menu__item {
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: clamp(34px, calc((100svh - 190px) / 5), 44px);
  padding: 0 clamp(2px, 0.8vw, 7px);
  border-radius: 8px;
  font-size: clamp(12px, 3.7vw, 18px);
  font-weight: 900;
}

.ui-button.level-menu__item {
  min-width: 0;
}

.level-menu__item .ui-icon {
  width: 20px;
  height: 20px;
}

.level-menu__item--special .ui-icon {
  width: 26px;
  height: 26px;
}

.level-menu__item--active {
  border-color: #58d6c4;
  background: rgb(88 214 196 / 0.16);
  box-shadow: inset 0 0 0 2px rgb(88 214 196 / 0.55);
  color: #eef6ff;
}

.level-menu__item--locked {
  cursor: default;
  opacity: 0.38;
  filter: grayscale(0.45);
}

.level-menu__item:disabled {
  pointer-events: none;
}

.level-menu__item--numbered::after {
  content: "";
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-radius: 50%;
  background: rgb(174 187 207 / 0.65);
}

.level-menu__item--numbered.level-menu__item--completed::after {
  background: #50df8b;
  opacity: 1;
}

.victory__panel {
  width: min(340px, calc(100vw - 36px - var(--safe-left) - var(--safe-right)), calc((100svh - 28px - var(--safe-top) - var(--safe-bottom)) * 0.74));
  max-height: calc(100svh - 28px - var(--safe-top) - var(--safe-bottom));
  padding: clamp(14px, 3.4vw, 26px) clamp(14px, 3.8vw, 22px);
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: 8px;
  background: rgb(17 28 46 / 0.92);
  color: #eef6ff;
  text-align: center;
  box-shadow: 0 22px 70px rgb(0 0 0 / 0.34);
}

.victory__check {
  width: clamp(46px, 14vw, 76px);
  height: clamp(46px, 14vw, 76px);
  margin: 0 auto clamp(7px, 2svh, 14px);
  border-radius: 50%;
  background: #58d6c4;
  color: #102033;
  font-size: clamp(32px, 10.5vw, 54px);
  font-weight: 900;
  line-height: clamp(46px, 14vw, 76px);
}

.victory__title {
  margin-bottom: clamp(6px, 1.6svh, 12px);
  font-size: clamp(18px, 5.1vw, 24px);
  font-weight: 900;
  overflow-wrap: anywhere;
}

.victory__text {
  margin: clamp(4px, 1.2svh, 7px) 0;
  color: rgb(238 246 255 / 0.8);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.victory__next {
  width: 100%;
  margin-top: clamp(9px, 2.4svh, 18px);
  background: #58d6c4;
  color: #102033;
}

@media (max-width: 760px) {
  .ui-layer {
    padding: max(8px, var(--safe-top)) 8px 8px;
  }

  .hud {
    width: 100%;
    gap: 6px;
  }

  .level-counter {
    max-width: min(260px, calc(100vw - 24px));
  }

  .level-menu__panel {
    width: min(390px, calc(100vw - 20px - var(--safe-left) - var(--safe-right)), calc((100svh - 20px - var(--safe-top) - var(--safe-bottom)) * 0.96));
  }

  .level-menu__item {
    min-height: clamp(36px, calc((100svh - 160px) / 4), 46px);
  }

  .tutorial__panel {
    width: min(320px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)), calc((100svh - 20px - var(--safe-top) - var(--safe-bottom)) * 0.68));
    padding: 12px;
  }

  .tutorial__demo {
    min-height: clamp(72px, 18svh, 112px);
    margin-bottom: 7px;
  }

  .tutorial__demo > * {
    transform: scale(0.78);
  }

  .tutorial__title {
    font-size: clamp(16px, 4.4vw, 19px);
  }

  .tutorial__text {
    font-size: clamp(11px, 3.2vw, 13px);
    line-height: 1.25;
  }

  .tutorial__close {
    min-height: 30px;
    margin-top: 8px;
  }

}

@media (max-height: 700px) {
  .level-menu__panel {
    width: min(390px, calc(100vw - 20px - var(--safe-left) - var(--safe-right)), calc((100svh - 20px - var(--safe-top) - var(--safe-bottom)) * 0.96));
  }

  .level-menu__item {
    min-height: clamp(36px, calc((100svh - 160px) / 4), 46px);
  }

  .tutorial__panel {
    width: min(320px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)), calc((100svh - 20px - var(--safe-top) - var(--safe-bottom)) * 0.68));
    padding: 12px;
  }

  .tutorial__demo {
    min-height: clamp(70px, 18svh, 110px);
    margin-bottom: 7px;
  }

  .tutorial__demo > * {
    transform: scale(0.78);
  }

  .tutorial__title {
    font-size: clamp(16px, 4.4vw, 19px);
  }

  .tutorial__text {
    font-size: clamp(11px, 3.2vw, 13px);
    line-height: 1.25;
  }

  .tutorial__close {
    min-height: 30px;
    margin-top: 8px;
  }
}

@media (max-width: 520px) {
  .hud {
    width: 100%;
    gap: 6px;
  }

  .hud__left,
  .hud__right,
  .hud__center {
    justify-content: center;
  }

  .hud--special .hud-pill:first-child {
    min-width: 0;
    padding: 0 8px;
  }

  .hud--special .hud-pill:first-child .ui-icon {
    width: 20px;
    height: 20px;
  }

}

@media (max-width: 480px) {
  .hud {
    align-content: flex-start;
  }

  .hud-pill,
  .hint-button,
  .ui-button {
    max-width: calc(50vw - 14px);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .level-counter {
    flex: 1 1 100%;
    max-width: calc(100vw - 18px);
  }

  .level-menu,
  .tutorial,
  .victory {
    padding:
      max(9px, var(--safe-top))
      max(9px, var(--safe-right))
      max(9px, var(--safe-bottom))
      max(9px, var(--safe-left));
  }

  .level-menu__panel {
    width: min(340px, calc(100vw - 18px - var(--safe-left) - var(--safe-right)));
    padding: 9px;
  }

  .level-menu__header {
    justify-content: center;
    gap: 7px;
  }

  .level-menu__title {
    flex: 1 1 100%;
    text-align: center;
  }

  .level-menu__close {
    min-width: 74px;
    max-width: 120px;
  }

  .level-menu__item {
    min-width: 0;
    max-width: none;
    padding: 0 3px;
    min-height: clamp(34px, calc((100svh - 142px) / 4), 44px);
    font-size: clamp(12px, 3.9vw, 16px);
  }

  .tutorial__panel,
  .victory__panel {
    width: min(300px, calc(100vw - 18px - var(--safe-left) - var(--safe-right)));
  }

  .tutorial__demo {
    min-height: clamp(62px, 16svh, 96px);
  }

  .tutorial__demo > * {
    transform: scale(0.7);
  }

  .tutorial__title {
    font-size: clamp(15px, 4.8vw, 18px);
  }

  .tutorial__text,
  .victory__text {
    font-size: clamp(11px, 3.5vw, 13px);
    line-height: 1.25;
  }

  .victory__title {
    font-size: clamp(17px, 5.2vw, 21px);
  }
}

@media (max-width: 420px) {
  .ui-layer {
    padding: max(7px, var(--safe-top)) 7px 7px;
  }

  .hud-pill,
  .hint-button,
  .ui-button {
    min-height: 29px;
    font-size: 12px;
  }

  .hud-pill {
    min-width: 54px;
    padding: 0 7px;
  }

  .level-counter {
    flex: 1 1 100%;
    max-width: calc(100vw - 14px);
    font-size: 11px;
  }

  .level-menu-button {
    min-width: 60px;
  }

  .hint-button {
    min-width: 90px;
    max-width: 112px;
  }

  .hud--special .hud-pill:first-child span {
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }

  .ui-button {
    min-width: 52px;
    padding: 0 7px;
  }

  .ui-button.level-menu__item {
    min-width: 0;
    padding: 0 3px;
  }

  .ui-button--icon {
    width: 31px;
    min-width: 31px;
    max-width: 31px;
  }

  .ui-icon {
    width: 18px;
    height: 18px;
  }

  .status {
    margin-top: 6px;
    font-size: 13px;
  }
}

@media (max-width: 340px) {
  .hud {
    gap: 5px;
  }

  .hud__left,
  .hud__right,
  .hud__center {
    gap: 5px;
  }

  .hud-pill,
  .hint-button,
  .ui-button {
    min-height: 27px;
    font-size: 11px;
  }

  .hint-button {
    min-width: 82px;
  }
}

@media (max-width: 380px), (max-height: 520px) {
  .victory,
  .level-menu,
  .tutorial {
    padding:
      max(8px, var(--safe-top))
      max(8px, var(--safe-right))
      max(8px, var(--safe-bottom))
      max(8px, var(--safe-left));
  }

  .tutorial__panel {
    width: min(288px, calc(100vw - 18px - var(--safe-left) - var(--safe-right)), calc((100svh - 16px - var(--safe-top) - var(--safe-bottom)) * 0.68));
    max-height: calc(100svh - 16px - var(--safe-top) - var(--safe-bottom));
    padding: 11px;
  }

  .tutorial__demo {
    min-height: clamp(58px, 15svh, 92px);
    margin-bottom: 6px;
  }

  .tutorial__demo > * {
    transform: scale(0.66);
  }

  .tutorial__title {
    font-size: clamp(15px, 4.7vw, 18px);
  }

  .tutorial__text {
    font-size: clamp(11px, 3.3vw, 14px);
    line-height: 1.25;
  }

  .tutorial__close {
    margin-top: 8px;
    min-height: 30px;
  }

  .level-menu__panel {
    width: min(330px, calc(100vw - 18px - var(--safe-left) - var(--safe-right)), calc((100svh - 16px - var(--safe-top) - var(--safe-bottom)) * 0.9));
    max-height: calc(100svh - 16px - var(--safe-top) - var(--safe-bottom));
    padding: 8px;
  }

  .level-menu__header {
    gap: 8px;
    margin-bottom: 7px;
  }

  .level-menu__close {
    min-width: 64px;
  }

  .level-menu__list {
    gap: 4px;
  }

  .level-menu__item {
    min-width: 0;
    max-width: none;
    padding: 0 2px;
    min-height: clamp(34px, calc((100svh - 136px) / 4), 44px);
  }

  .level-menu__pager {
    margin-top: 7px;
  }

  .level-menu__arrow {
    width: 38px;
    min-width: 38px;
    height: 34px;
  }

  .level-menu__arrow[data-direction="prev"]::before {
    left: 12px;
    border-top-width: 8px;
    border-bottom-width: 8px;
    border-right-width: 12px;
  }

  .level-menu__arrow[data-direction="next"]::before {
    right: 12px;
    border-top-width: 8px;
    border-bottom-width: 8px;
    border-left-width: 12px;
  }

  .victory__panel {
    width: min(288px, calc(100vw - 18px - var(--safe-left) - var(--safe-right)), calc((100svh - 16px - var(--safe-top) - var(--safe-bottom)) * 0.7));
    max-height: calc(100svh - 16px - var(--safe-top) - var(--safe-bottom));
    padding: 12px;
  }

  .victory__next {
    min-height: 30px;
  }
}

@media (max-height: 560px) and (min-width: 521px) {
  .ui-layer {
    padding: 6px;
  }

  .hud {
    width: min(100%, 900px);
    gap: 5px;
    font-size: 11px;
  }

  .hud-pill,
  .hint-button,
  .ui-button {
    min-height: 27px;
    padding: 0 7px;
  }

  .hud-pill {
    min-width: 60px;
  }

  .level-menu-button {
    min-width: 66px;
  }

  .skip-button {
    min-width: 78px;
  }

  .hint-button {
    min-width: 94px;
  }

  .ui-button--icon {
    width: 30px;
    min-width: 30px;
    max-width: 30px;
  }

  .status {
    margin-top: 3px;
    font-size: 12px;
  }
}

@media (min-width: 900px) {
  body {
    background: #172033;
  }
}
