@font-face {
  font-family: 'Comfortaa';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/comfortaa-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Comfortaa';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/comfortaa-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Comfortaa';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/comfortaa-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: var(--app-height, 100%);
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
  font-family: 'Comfortaa', sans-serif;
  background: #0a0a2e;
}

body {
  position: fixed;
  top: 0;
  left: 0;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: var(--app-height, 100%);
  touch-action: none;
  z-index: 1;
}

#ui-root {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  height: var(--app-height, 100%);
  z-index: 10;
  pointer-events: none;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.4s ease, visibility 0.4s;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ===== MAIN MENU ===== */
.menu-screen {
  background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0.9) 0%, rgba(10, 10, 46, 0.95) 100%);
}

.menu-title {
  font-size: clamp(32px, 8vw, 64px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 30px rgba(0, 255, 255, 0.6), 0 0 60px rgba(255, 0, 255, 0.3);
  margin-bottom: 40px;
  text-align: center;
  line-height: 1.2;
  white-space: pre-line;
}

.btn {
  min-width: 200px;
  min-height: 56px;
  padding: 14px 32px;
  border: none;
  border-radius: 28px;
  font-family: 'Comfortaa', sans-serif;
  font-size: clamp(16px, 3vw, 20px);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  pointer-events: auto;
}

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

.btn-primary {
  background: linear-gradient(135deg, #00e5ff, #7c4dff);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0, 229, 255, 0.4);
}

.btn-primary:hover {
  box-shadow: 0 6px 30px rgba(0, 229, 255, 0.6);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-small {
  min-width: 48px;
  min-height: 48px;
  padding: 10px 16px;
  font-size: 14px;
  border-radius: 16px;
}

/* ===== WORLD MAP ===== */
.worlds-screen {
  background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0.92) 0%, rgba(10, 10, 46, 0.97) 100%);
  padding: 20px;
}

.worlds-title {
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 700;
  color: #fff;
  margin-bottom: 24px;
}

.worlds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  max-width: 500px;
  width: 100%;
  padding: 0 10px;
}

.world-card {
  aspect-ratio: 1;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
  min-height: 120px;
  pointer-events: auto;
}

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

.world-card.locked {
  opacity: 0.4;
  cursor: default;
  filter: grayscale(0.7);
}

.world-card-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.world-card-name {
  font-size: clamp(12px, 2.5vw, 16px);
  font-weight: 600;
  color: #fff;
  text-align: center;
}

.world-card-stars {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 4px;
}

.world-card-lock {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 16px;
  opacity: 0.7;
}

/* ===== LEVEL SELECT ===== */
.levels-screen {
  background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0.92) 0%, rgba(10, 10, 46, 0.97) 100%);
  padding: 20px;
}

.levels-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
  max-width: 400px;
  padding: 0 10px;
}

.levels-title {
  font-size: clamp(18px, 4vw, 28px);
  font-weight: 700;
  color: #fff;
  flex: 1;
  text-align: center;
}

.levels-scroll {
  width: 100%;
  max-width: 380px;
  max-height: calc(var(--app-height, 100vh) - 140px);
  padding: 0 10px 20px;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
}

.level-btn {
  aspect-ratio: 1;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-family: 'Comfortaa', sans-serif;
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.2s, background 0.2s;
  min-width: 48px;
  min-height: 48px;
  pointer-events: auto;
}

.level-btn:active {
  transform: scale(0.9);
}

.level-btn.locked {
  opacity: 0.3;
  cursor: default;
}

.level-btn.completed {
  background: rgba(0, 229, 255, 0.15);
  border-color: rgba(0, 229, 255, 0.3);
}

.level-stars {
  font-size: 11px;
  letter-spacing: 1px;
}

/* ===== GAMEPLAY HUD ===== */
.hud-screen {
  justify-content: flex-start;
  pointer-events: none;
}

.hud-screen.active {
  pointer-events: none;
}

.hud-top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 20px 16px;
  pointer-events: auto;
}

.hud-level-info {
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  max-width: 55vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-intersections {
  font-size: clamp(14px, 3vw, 18px);
  font-weight: 600;
  color: #ff6b6b;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hud-moves {
  font-size: clamp(12px, 2.5vw, 16px);
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hud-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  transition: background 0.2s;
  pointer-events: auto;
}

.hud-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.hud-bottom {
  margin-top: auto;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  pointer-events: auto;
}

/* ===== LEVEL COMPLETE ===== */
.complete-screen {
  background: rgba(10, 10, 46, 0.85);
  backdrop-filter: blur(12px);
}

.complete-title {
  font-size: clamp(28px, 7vw, 48px);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 30px rgba(0, 255, 255, 0.6);
  margin-bottom: 16px;
}

.complete-stars {
  font-size: clamp(36px, 8vw, 56px);
  margin-bottom: 8px;
  letter-spacing: 8px;
}

.complete-stats {
  font-size: clamp(14px, 3vw, 18px);
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 32px;
  text-align: center;
  line-height: 1.8;
}

.complete-buttons {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ===== HINT BUTTON ===== */
.hint-btn {
  position: relative;
}

.hint-btn-sub {
  font-size: 11px;
  opacity: 0.7;
  display: block;
  margin-top: 2px;
}

/* ===== PAUSE OVERLAY ===== */
.pause-screen {
  background: rgba(10, 10, 46, 0.9);
  backdrop-filter: blur(16px);
  gap: 16px;
}

.pause-title {
  font-size: clamp(24px, 6vw, 40px);
  font-weight: 700;
  color: #fff;
  margin-bottom: 24px;
}

/* ===== DAILY CHALLENGE ===== */
.daily-badge {
  background: linear-gradient(135deg, #ff6b35, #f7c948);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  font-family: 'Comfortaa', sans-serif;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== SETTINGS ===== */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 300px;
  padding: 12px 0;
  color: #fff;
  font-size: 16px;
}

.toggle {
  width: 52px;
  height: 28px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
  pointer-events: auto;
}

.toggle.on {
  background: #00e5ff;
}

.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.3s;
}

.toggle.on::after {
  transform: translateX(24px);
}

/* ===== SCROLLABLE ===== */
.scrollable-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
  overscroll-behavior-x: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scrollable-container::-webkit-scrollbar {
  display: none;
}

/* ===== RESPONSIVE ===== */
/* ===== SOUND TOGGLE (Menu) ===== */
.menu-bottom-btns {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  right: max(24px, env(safe-area-inset-right, 0px));
  display: flex;
  gap: 12px;
}

.sound-toggle-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  pointer-events: auto;
}

.sound-toggle-btn:active {
  background: rgba(255, 255, 255, 0.25);
}

.sound-toggle-btn.muted {
  opacity: 0.4;
}

/* ===== LEADERBOARD ===== */
.leaderboard-screen {
  background: radial-gradient(ellipse at center, rgba(20, 10, 60, 0.95) 0%, rgba(10, 10, 46, 0.98) 100%);
  padding: 20px;
}

.leaderboard-title {
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 700;
  color: #fff;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
}

.leaderboard-list {
  width: 100%;
  max-width: 400px;
  max-height: 60vh;
  padding: 0 10px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: background 0.2s;
}

.leaderboard-me {
  background: rgba(0, 229, 255, 0.12);
  border-color: rgba(0, 229, 255, 0.3);
}

.leaderboard-rank {
  font-size: 16px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.6);
  width: 50px;
  flex-shrink: 0;
}

.leaderboard-name {
  flex: 1;
  font-size: 14px;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  font-size: 16px;
  font-weight: 700;
  color: #ffd700;
  margin-left: 12px;
}

.leaderboard-empty,
.leaderboard-loading {
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 16px;
  padding: 40px 0;
}

/* ===== TUTORIAL ===== */
.tutorial-screen {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

.tutorial-card {
  background: rgba(20, 20, 60, 0.95);
  border-radius: 24px;
  padding: 32px 24px;
  max-width: 320px;
  width: 85%;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.tutorial-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.tutorial-text {
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(14px, 3.5vw, 17px);
  line-height: 1.6;
  margin-bottom: 24px;
  white-space: pre-line;
}

@media (max-width: 400px) {
  .worlds-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .levels-grid {
    gap: 8px;
  }
}

/* ===== LANDSCAPE ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .hud-top {
    padding: max(6px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
  }

  .hud-bottom {
    padding: 6px max(12px, env(safe-area-inset-right, 0px)) max(6px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    gap: 8px;
  }

  .levels-scroll {
    max-height: calc(var(--app-height, 100vh) - 90px);
  }

  .levels-grid {
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
  }

  .levels-header {
    margin-bottom: 12px;
  }

  .worlds-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }

  .world-card {
    min-height: 80px;
  }

  .world-card-icon {
    font-size: 24px;
    margin-bottom: 4px;
  }

  .leaderboard-list {
    max-height: 45vh;
  }

  .menu-title {
    font-size: clamp(24px, 6vw, 48px);
    margin-bottom: 20px;
  }

  .pause-title {
    margin-bottom: 12px;
  }

  .pause-screen {
    gap: 10px;
  }

  .complete-title {
    margin-bottom: 8px;
  }

  .complete-stats {
    margin-bottom: 16px;
  }

  .tutorial-card {
    padding: 20px 20px;
  }

  .tutorial-icon {
    font-size: 32px;
    margin-bottom: 8px;
  }

  .tutorial-text {
    margin-bottom: 16px;
  }
}
