/* style.css — «Сортируй Плитки» */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0f0c29;
  font-family: 'Comic Relief', sans-serif;
  font-weight: 400;
  color: #fff;
  -webkit-text-stroke: 2px #000;
  paint-order: stroke fill;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

#gameCanvas {
  display: block;
  position: fixed;
  top: 0; left: 0;
  touch-action: manipulation;
}

img { -webkit-user-drag: none; }

body.loading #gameCanvas,
body.loading .screen,
body.loading #game-hud {
  visibility: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  -webkit-text-stroke: inherit;
  paint-order: inherit;
  text-shadow: inherit;
}

/* ==================== SCREENS ==================== */

.screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 20;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96);
}

.screen-overlay {
  background: rgba(10, 8, 30, 0.1);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ==================== PANEL ==================== */

.panel {
  background: rgba(20, 18, 50, 0.9);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 37px;
  padding: 48px 43px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 21px;
  box-shadow: 0 24px 100px rgba(0,0,0,0.5), inset 0 2px 0 rgba(255,255,255,0.05);
  max-width: 533px;
  width: 90%;
  animation: panelIn 0.4s ease;
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(48px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.panel h2 {
  font-size: 40px;
  font-weight: 700;
  color: #fff;
}

.panel p {
  font-size: 21px;
  color: #fff;
}

/* ==================== MAIN MENU ==================== */

#btn-levels { margin-top: 37px; }
#btn-leaderboard { margin-top: 37px; }
#leaderboard-img { width: auto; height: 37px; object-fit: contain; }
#btn-settings { margin-top: 37px; }

/* Main menu buttons — same style */
#btn-continue,
#btn-levels,
#btn-leaderboard,
#btn-settings {
  background: rgba(15, 12, 41, 0.55);
  border-color: rgba(255,255,255,0.08);
  box-shadow: 0 12px 48px rgba(0,0,0,0.4);
}

/* ==================== BUTTONS ==================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px 59px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 27px;
  font-family: 'Comic Relief', sans-serif;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  min-width: 320px;
  letter-spacing: 0.6px;
  outline: none;
  background: rgba(255,255,255,0.27);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.95); }

.btn.hidden { display: none; }

.btn img { width: 37px; height: 37px; opacity: 0.9; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, #7C3AED, #5B21B6);
  border-color: rgba(167,139,250,0.3);
  box-shadow: 0 12px 56px rgba(124,58,237,0.4);
  font-size: 27px;
  padding: 27px 69px;
}

.btn-primary img { width: 40px; height: 40px; }

.btn-primary:active { box-shadow: 0 8px 32px rgba(124,58,237,0.3); }

.btn-success {
  background: linear-gradient(135deg, #059669, #047857);
  border-color: rgba(52,211,153,0.25);
  box-shadow: 0 12px 56px rgba(5,150,105,0.35);
}

.btn-warning {
  background: linear-gradient(135deg, #D97706, #B45309);
  border-color: rgba(251,191,36,0.25);
  box-shadow: 0 12px 56px rgba(217,119,6,0.35);
}

.btn-danger {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.2);
  color: #fff;
  font-size: 19px;
  padding: 13px 27px;
  min-width: unset;
  gap: 11px;
}

.btn-danger img { width: 24px; height: 24px; opacity: 0.7; }

/* Icon-only buttons (pause, hint in HUD) — no background */
.btn-icon {
  position: relative;
  min-width: unset;
  width: 75px; height: 75px;
  padding: 0;
  border-radius: 24px;
  background: transparent;
  border: none;
}

.btn-icon img { width: 40px; height: 40px; }

/* ==================== HUD ==================== */

#game-hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

#game-hud.hidden { display: none; }

/* Pause — top-left */
.btn-pause {
  position: absolute;
  top: 19px; left: 19px;
  pointer-events: auto;
  width: 150px; height: 150px;
  border-radius: 48px;
}

.btn-pause img { width: 80px; height: 80px; }


/* Top-left: pause + hearts */


/* Right panel */



/* Hearts */
.hud-hearts {
  position: absolute;
  top: 69px; right: 40px;
  display: flex;
  gap: 5px;
  pointer-events: auto;
}

.hud-hearts img {
  width: 51px; height: 51px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.hud-hearts img.lost {
  opacity: 0.2;
  filter: grayscale(1) drop-shadow(0 4px 8px rgba(0,0,0,0.2));
  transform: scale(0.8);
}

/* Hamster counter */
.hud-counter {
  position: absolute;
  top: 148px; right: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

#hud-counter-img {
  width: 48px; height: 48px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4));
}

#hud-remaining {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 2px #000;
  paint-order: stroke fill;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
}

#hud-hint-count {
  position: absolute;
  bottom: 0px; right: 0px;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 2px #000;
  paint-order: stroke fill;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
  line-height: 1;
  pointer-events: none;
}

#btn-hint {
  position: absolute;
  top: 175px; left: 44px;
  width: 90px; height: 90px;
  border-radius: 50%;
  background: rgba(255,255,255,0);
  pointer-events: auto;
}

#btn-hint img { width: 48px; height: 48px; }

/* ==================== WIN SCREEN ==================== */

#win-stars {
  display: flex;
  gap: 13px;
  margin: 5px 0;
}

#win-stars img {
  width: 69px; height: 69px;
  animation: starPop 0.5s ease backwards;
}

#win-stars img:nth-child(1) { animation-delay: 0.1s; }
#win-stars img:nth-child(2) { animation-delay: 0.3s; }
#win-stars img:nth-child(3) { animation-delay: 0.5s; }

#win-stars img.empty {
  visibility: visible;
  opacity: 0.45;
  filter: brightness(0);
  animation: none;
}

@keyframes starPop {
  from { transform: scale(0) rotate(-30deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

#win-moves {
  font-size: 23px;
  color: #fff;
  margin-bottom: 5px;
}

/* ==================== LEVEL SELECT — CHAPTER CARDS ==================== */

/* Chapter carousel - centered in screen overlay */
#chapters-carousel {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  gap: 48px;
  padding: 24px max(24px, calc(50% - 305px));
  width: 100%;
  max-width: 100vw;
}

#chapters-carousel::-webkit-scrollbar { display: none; }
#chapters-carousel.hidden { display: none; }

/* Each chapter is its own panel/card — glassmorphism panel as base */
.chapter-slide {
  flex: 0 0 610px;
  width: 610px;
  height: 436px;
  scroll-snap-align: center;
  border-radius: 24px;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
  box-shadow: 0 12px 48px rgba(0,0,0,0.35);
  background: rgba(20, 18, 45, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chapter-slide:active { transform: scale(0.93); }

/* Centered card — larger, elevated */
.chapter-slide.centered,
.level-card.centered {
  transform: scale(1.1);
  z-index: 2;
  box-shadow: 0 20px 80px rgba(0,0,0,0.5);
}

.chapter-slide.centered:active { transform: scale(0.93); }
.level-card.centered:active { transform: scale(0.93); }

/* Background image — sits ON TOP of the panel */
.chapter-slide-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 1;
  border-radius: inherit;
}

/* Text overlay — on top of image */
.chapter-slide-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,0.15);
}

.chapter-slide-title {
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
}

.chapter-slide-subtitle {
  font-size: 16px;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
}

/* Levels view */
#levels-view {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 25;
}

#levels-view.hidden { display: none; }

.btn-back {
  position: absolute;
  top: 19px; left: 19px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 21px;
  font-family: 'Comic Relief', sans-serif;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255,255,255,0.07);
  color: #fff;
  transition: transform 0.15s ease;
  z-index: 30;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.btn-back:active { transform: scale(0.95); }
.btn-back img { width: auto; height: 28px; object-fit: contain; }
.settings-back-mobile { display: none; }

/* Level cards row */
#levels-grid {
  display: flex;
  gap: 32px;
  padding: 80px max(24px, calc(50% - 152px)) 40px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  max-width: 100vw;
  scroll-behavior: smooth;
}

#levels-grid::-webkit-scrollbar { display: none; }

.level-card {
  flex: 0 0 304px;
  height: 436px;
  scroll-snap-align: center;
  border-radius: 22px;
  border: 2px solid rgba(255,255,255,0.12);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.level-card:active { transform: scale(0.95); }

.level-card-bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  border-radius: 22px;
}

.level-card-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.55);
  border-radius: 14px;
  padding: 10px 16px;
  width: 100%;
  backdrop-filter: blur(4px);
}

.level-card-title {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.level-card-stars {
  display: flex;
  gap: 4px;
}

.level-card-stars img {
  width: 26px;
  height: 26px;
}

.level-card-stars img.empty {
  opacity: 0.25;
  filter: grayscale(1);
}

.level-card.completed {
  border-color: rgba(52,211,153,0.4);
}

.level-card.unlocked {
  border-color: rgba(129,140,248,0.3);
}

.level-card.locked {
  cursor: not-allowed;
  opacity: 0.5;
  filter: grayscale(0.5);
}

.level-card.locked .level-card-content {
  background: rgba(0,0,0,0.7);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 600px) {
  .panel {
    padding: 32px 24px;
    border-radius: 29px;
    gap: 16px;
  }
  .panel h2 { font-size: 32px; }
  .panel p { font-size: 17px; }
  .btn {
    padding: 19px 43px;
    font-size: 19px;
    min-width: 253px;
    border-radius: 21px;
  }
  .btn-primary {
    padding: 21px 53px;
    font-size: 21px;
  }
  .btn-icon {
    width: 60px; height: 60px;
    border-radius: 19px;
  }
  .btn-icon img { width: 32px; height: 32px; }
  .btn-pause {
    width: 100px; height: 100px;
    border-radius: 32px;
  }
  .btn-pause img { width: 53px; height: 53px; }
  .btn-pause { top: 13px; left: 13px; }
  #btn-hint {
    width: 75px; height: 75px;
    top: 127px; left: 13px;
    border-radius: 24px;
  }
  #btn-hint img { width: 40px; height: 40px; }
  
  .hud-hearts img { width: 34px; height: 34px; }
  #hud-counter-img { width: 20px; height: 20px; }
  #hud-remaining { font-size: 16px; }
  .level-btn { width: 48px; height: 55px; }
}

/* ==================== TUTORIAL ==================== */

.tutorial-panel {
  background: rgba(20, 18, 50, 0.95);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 37px;
  padding: 32px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 21px;
  box-shadow: 0 24px 100px rgba(0,0,0,0.5);
  max-width: 533px;
  width: 90%;
  animation: panelIn 0.4s ease;
}

.tutorial-panel h2 {
  font-size: 40px;
  font-weight: 700;
  color: #fff;
  text-align: center;
}

.tutorial-visual-wrap {
  width: 240px;
  height: 160px;
  border-radius: 16px;
  overflow: visible;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#tutorial-canvas {
  display: block;
  position: static;
  width: 100%;
  height: 100%;
  touch-action: auto;
}

#tutorial-text {
  font-size: 21px;
  color: #fff;
  text-align: center;
  line-height: 1.5;
  white-space: pre-line;
}

@media (max-width: 600px) {
  .tutorial-panel { padding: 24px 24px; gap: 16px; border-radius: 29px; }
  .tutorial-panel h2 { font-size: 32px; }
  .tutorial-visual-wrap { width: 200px; height: 134px; }
  #tutorial-canvas { width: 200px; height: 134px; }
  #tutorial-text { font-size: 17px; }
  #hud-time { font-size: 40px; }
}

.hud-timer {
  position: absolute;
  top: 200px; right: 19px;
  transform: none;
  justify-content: flex-end;
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
#hud-timer.hidden { display: none; }
#hud-time {
  font-size: 60px;
  font-weight: 700;
  color: #fff;
  -webkit-text-stroke: 2px #000;
  paint-order: stroke fill;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
}
/* Language buttons */
.lang-btn {
  background: rgba(255,255,255,0.1) !important;
  border: 3px solid transparent !important;
  transition: border-color 0.2s ease, background 0.2s ease !important;
}
.lang-btn.active {
  border-color: #60A5FA !important;
  background: rgba(96,165,250,0.2) !important;
}
.settings-slider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
}
.settings-slider span {
  font-size: 24px;
  font-weight: 700;
}
.settings-slider input {
  width: min(240px, 52vw);
  accent-color: #60A5FA;
}
/* Leaderboard */
#leaderboard-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 80px;
}
.leader-panel {
  background: rgba(20, 18, 50, 0.9);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 37px;
  padding: 32px 24px;
  max-width: 533px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.leader-panel h2 {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
}
.leader-sub {
  font-size: 14px;
  color: #fff;
  text-align: center;
  margin-bottom: 8px;
}
.leader-entries {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 400px;
  overflow-y: auto;
}
.leader-row {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  gap: 8px;
}
.leader-rank {
  width: 30px;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: #fff;
}
.leader-name {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.leader-score {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
}
.leader-star-icon {
  width: 16px;
  height: 16px;
}
.leader-player {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-top: 8px;
  background: rgba(96,165,250,0.15);
  border: 2px solid #60A5FA;
  border-radius: 12px;
  gap: 8px;
}
.leader-loading {
  color: #fff;
  text-align: center;
  padding: 20px;
}
.leader-no-data {
  color: #fff;
  text-align: center;
  padding: 20px;
}

body, body *:not(canvas):not(img):not(svg):not(path) {
  -webkit-text-stroke: 2px #000;
  paint-order: stroke fill;
  text-shadow: 0 2px 8px rgba(0,0,0,0.9);
}

canvas, img, svg {
  -webkit-text-stroke: 0 transparent;
  text-shadow: none;
}

/* ==================== ADAPTIVE OVERRIDES ==================== */

.screen,
#game-hud {
  height: 100dvh;
  min-height: 0;
}

.panel,
.tutorial-panel,
.leader-panel {
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
}

.btn {
  max-width: calc(100vw - 32px);
}

@media (max-width: 700px), (max-height: 560px) {
  body, body *:not(canvas):not(img):not(svg):not(path) {
    -webkit-text-stroke: 1.5px #000;
  }

  .screen {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  }

  .panel,
  .tutorial-panel {
    width: min(92vw, 430px);
    padding: 24px 20px;
    gap: 14px;
    border-radius: 24px;
  }

  .panel h2,
  .tutorial-panel h2,
  .leader-panel h2 {
    font-size: clamp(26px, 7vw, 34px);
    text-align: center;
    line-height: 1.12;
  }

  .panel p,
  #tutorial-text {
    font-size: clamp(15px, 4.2vw, 18px);
    line-height: 1.35;
  }

  .btn {
    width: min(100%, 320px);
    min-width: 0;
    min-height: 54px;
    padding: 14px 20px;
    gap: 10px;
    border-radius: 18px;
    font-size: clamp(17px, 4.7vw, 21px);
    letter-spacing: 0;
  }

  .btn img,
  #leaderboard-img {
    width: 30px;
    height: 30px;
  }

  .btn-primary {
    padding: 16px 22px;
    font-size: clamp(18px, 5vw, 22px);
  }

  #btn-levels,
  #btn-leaderboard,
  #btn-settings {
    margin-top: 18px;
  }

  .btn-back {
    top: calc(10px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 17px;
    gap: 6px;
  }

  .btn-back img {
    height: 22px;
  }

  .btn-pause {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(8px + env(safe-area-inset-left));
    width: clamp(68px, 18vw, 92px);
    height: clamp(68px, 18vw, 92px);
    border-radius: 24px;
  }

  .btn-pause img {
    width: clamp(38px, 10vw, 52px);
    height: clamp(38px, 10vw, 52px);
  }

  #btn-hint {
    top: calc(86px + env(safe-area-inset-top));
    left: calc(10px + env(safe-area-inset-left));
    width: clamp(58px, 15vw, 74px);
    height: clamp(58px, 15vw, 74px);
  }

  #btn-hint img {
    width: clamp(34px, 9vw, 42px);
    height: clamp(34px, 9vw, 42px);
  }

  #hud-hint-count {
    font-size: clamp(17px, 4.8vw, 22px);
  }

  .hud-hearts {
    top: calc(18px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
    gap: 3px;
  }

  .hud-hearts img {
    width: clamp(28px, 8.5vw, 38px);
    height: clamp(28px, 8.5vw, 38px);
  }

  .hud-counter {
    top: calc(58px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
    gap: 5px;
  }

  #hud-counter-img {
    width: clamp(24px, 7vw, 34px);
    height: clamp(24px, 7vw, 34px);
  }

  #hud-remaining {
    font-size: clamp(20px, 6vw, 28px);
  }

  .hud-timer {
    top: calc(92px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
  }

  #hud-time {
    font-size: clamp(30px, 9vw, 44px);
  }

  #chapters-carousel {
    gap: 20px;
    padding: 72px max(16px, calc(50% - min(42vw, 230px))) 32px;
  }

  .chapter-slide {
    flex-basis: min(84vw, 460px);
    width: min(84vw, 460px);
    height: min(60vw, 320px);
    min-height: 220px;
    border-radius: 20px;
  }

  .chapter-slide.centered,
  .level-card.centered {
    transform: scale(1.04);
  }

  .chapter-slide-title {
    font-size: clamp(23px, 6vw, 30px);
  }

  .chapter-slide-subtitle {
    font-size: clamp(14px, 3.7vw, 17px);
  }

  #levels-grid {
    gap: 18px;
    padding: 72px max(16px, calc(50% - min(37vw, 132px))) 28px;
  }

  .level-card {
    flex-basis: min(74vw, 264px);
    height: min(105vw, 380px);
    min-height: 300px;
    padding: 16px;
    border-radius: 18px;
  }

  .level-card-bg-canvas {
    border-radius: 18px;
  }

  .level-card-content {
    padding: 8px 12px;
    border-radius: 12px;
  }

  .level-card-title {
    font-size: clamp(21px, 5.8vw, 25px);
  }

  .level-card-stars img {
    width: 23px;
    height: 23px;
  }

  .tutorial-visual-wrap {
    width: min(58vw, 220px);
    height: min(38vw, 148px);
  }

  #tutorial-canvas {
    width: 100%;
    height: 100%;
  }

  #leaderboard-screen {
    justify-content: flex-start;
    padding-top: calc(62px + env(safe-area-inset-top));
  }

  .leader-panel {
    width: min(92vw, 460px);
    padding: 22px 16px;
    border-radius: 24px;
  }

  .leader-entries {
    max-height: calc(100dvh - 260px);
  }

  .leader-row,
  .leader-player {
    padding: 8px 10px;
    gap: 6px;
  }

  .leader-rank {
    width: 28px;
    font-size: 16px;
  }

  .leader-name,
  .leader-score {
    font-size: 15px;
  }
}

@media (max-width: 700px), (max-width: 1000px) and (max-height: 500px) {
  #btn-settings-back {
    display: none;
  }

  .settings-back-mobile {
    display: inline-flex;
  }

  #hud-hint-count {
    font-size: clamp(13.6px, 3.84vw, 17.6px);
  }

  .hud-hearts img {
    width: clamp(19.6px, 5.95vw, 26.6px);
    height: clamp(19.6px, 5.95vw, 26.6px);
  }

  #hud-counter-img {
    width: clamp(16.8px, 4.9vw, 23.8px);
    height: clamp(16.8px, 4.9vw, 23.8px);
  }

  #hud-remaining {
    font-size: clamp(14px, 4.2vw, 19.6px);
  }

  .level-card-title {
    font-size: clamp(16.8px, 4.64vw, 20px);
  }

  .tutorial-panel {
    scale: 0.85;
  }

  #settings-screen .panel {
    scale: 0.8;
  }
}

@media (max-height: 430px) and (orientation: landscape) {
  .screen {
    justify-content: center;
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .panel,
  .tutorial-panel {
    gap: 10px;
    padding: 14px 18px;
  }

  .panel h2,
  .tutorial-panel h2,
  .leader-panel h2 {
    font-size: 24px;
  }

  .btn {
    min-height: 44px;
    padding: 9px 16px;
    font-size: 16px;
  }

  .btn img,
  #leaderboard-img {
    width: 24px;
    height: 24px;
  }

  #chapters-carousel,
  #levels-grid {
    padding-top: 50px;
    padding-bottom: 18px;
  }

  .chapter-slide {
    flex-basis: min(58vw, 360px);
    width: min(58vw, 360px);
    height: min(56vh, 230px);
    min-height: 170px;
  }

  .level-card {
    flex-basis: min(36vw, 220px);
    height: min(72vh, 300px);
    min-height: 210px;
  }

  .btn-pause {
    width: 58px;
    height: 58px;
    border-radius: 18px;
  }

  .btn-pause img {
    width: 34px;
    height: 34px;
  }

  #btn-hint {
    top: calc(70px + env(safe-area-inset-top));
    width: 52px;
    height: 52px;
  }

  #btn-hint img {
    width: 30px;
    height: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .panel,
  .tutorial-panel,
  .btn,
  .chapter-slide,
  .level-card,
  .hud-hearts img,
  #win-stars img {
    animation: none;
    scroll-behavior: auto;
    transition: none;
  }
}
