* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 50%, #e8d5f5 100%);
}

#game-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

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

/* --- Screens --- */
.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.3s ease, visibility 0.3s;
}

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

/* --- Main Menu --- */
.menu-screen {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.menu-title {
  font-size: clamp(36px, 8vw, 72px);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 4px 20px rgba(0,0,0,0.3);
  margin-bottom: 10px;
  letter-spacing: -1px;
}

.menu-subtitle {
  font-size: clamp(14px, 3vw, 22px);
  color: rgba(255,255,255,0.85);
  margin-bottom: 40px;
  font-weight: 400;
}

/* --- Buttons --- */
.btn {
  min-height: 52px;
  min-width: 160px;
  padding: 14px 32px;
  border: none;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  letter-spacing: 0.5px;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  color: #fff;
  box-shadow: 0 4px 15px rgba(238,90,36,0.4);
}

.btn-primary:active {
  box-shadow: 0 2px 8px rgba(238,90,36,0.3);
}

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

.btn-small {
  min-height: 48px;
  min-width: 48px;
  padding: 10px 20px;
  font-size: 15px;
  border-radius: 12px;
}

.btn-icon {
  min-height: 48px;
  min-width: 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  font-size: 22px;
}

.btn-game {
  background: #fff;
  color: #5b4a9e;
  box-shadow: 0 3px 12px rgba(0,0,0,0.12);
}

.btn-game:active {
  box-shadow: 0 1px 6px rgba(0,0,0,0.1);
}

/* --- Categories Screen --- */
.categories-screen {
  background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 50%, #e8d5f5 100%);
  padding: 20px;
}

.screen-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  margin-bottom: 16px;
}

.screen-title {
  font-size: clamp(20px, 5vw, 32px);
  font-weight: 800;
  color: #3d3270;
}

.medal-counter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 700;
  color: #5b4a9e;
  background: rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: 12px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 600px;
  padding: 0 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
  max-height: calc(100vh - 120px);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.categories-grid::-webkit-scrollbar {
  display: none;
}

.category-card {
  background: #fff;
  border-radius: 20px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  border: 3px solid transparent;
}

.category-card:active {
  transform: scale(0.96);
}

.category-card.locked {
  opacity: 0.5;
  cursor: default;
  filter: grayscale(0.5);
}

.category-card.completed {
  border-color: #FFD700;
}

.category-icon {
  font-size: 40px;
  line-height: 1;
}

.category-name {
  font-size: 14px;
  font-weight: 700;
  color: #3d3270;
  text-align: center;
}

.category-progress {
  font-size: 12px;
  color: #8e82b0;
  font-weight: 600;
}

.category-lock-ad {
  font-size: 11px;
  color: #ee5a24;
  font-weight: 700;
  background: rgba(238, 90, 36, 0.1);
  padding: 4px 8px;
  border-radius: 8px;
}

.category-card.locked[data-action="unlockCategoryAd"] {
  opacity: 0.85;
  cursor: pointer;
  filter: none;
  border: 3px dashed #ee5a24;
}

/* --- Daily Challenge Card --- */
.daily-card {
  width: 100%;
  max-width: 600px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 20px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  margin-bottom: 10px;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.35);
  transition: transform 0.15s ease;
}

.daily-card:active {
  transform: scale(0.97);
}

.daily-card.daily-done {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  box-shadow: 0 4px 20px rgba(67, 233, 123, 0.35);
}

.daily-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.daily-icon {
  font-size: 36px;
  line-height: 1;
}

.daily-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.daily-title {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
}

.daily-status {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
}

.daily-streak {
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.2);
  padding: 5px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

.daily-streak:empty {
  display: none;
}

.daily-streak-result {
  font-size: 16px;
  font-weight: 700;
  color: #5b4a9e;
  background: #f0ecfa;
  padding: 6px 14px;
  border-radius: 10px;
}

/* --- Levels Screen --- */
.levels-screen {
  background: linear-gradient(135deg, #e0eafc 0%, #cfdef3 50%, #e8d5f5 100%);
  padding: 20px;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 500px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
  max-height: calc(100vh - 140px);
  scrollbar-width: none;
  -ms-overflow-style: none;
}

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

.level-btn {
  width: 70px;
  height: 70px;
  border-radius: 16px;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 700;
  font-size: 20px;
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: visible;
}

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

.level-btn.available {
  background: #fff;
  color: #5b4a9e;
  box-shadow: 0 3px 12px rgba(0,0,0,0.1);
}

.level-btn.locked {
  background: rgba(255,255,255,0.4);
  color: #b0a8c8;
  cursor: default;
}

.level-btn.locked::after {
  content: '\1F512';
  font-size: 14px;
  position: absolute;
  bottom: 6px;
}

.level-score {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 8px;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  line-height: 1.2;
  color: #fff;
  background: #b0a8c8;
}
.level-score.score-gold {
  background: linear-gradient(135deg, #FFD700, #FFA000);
  color: #fff;
}
.level-score.score-silver {
  background: linear-gradient(135deg, #a8a8a8, #7a7a7a);
  color: #fff;
}
.level-score.score-bronze {
  background: linear-gradient(135deg, #E8913A, #A0522D);
  color: #fff;
}

/* --- Gameplay Screen --- */
.gameplay-screen {
  background: transparent;
  pointer-events: none !important;
  padding: 0;
  justify-content: flex-start;
}

.gameplay-screen > * {
  pointer-events: auto;
}

.gameplay-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
}

.gameplay-level-name {
  font-size: 16px;
  font-weight: 700;
  color: #3d3270;
}

.gameplay-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex: 1;
  width: 100%;
  padding: 10px;
  pointer-events: none;
}

.reference-container {
  background: #fff;
  border-radius: 20px;
  padding: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.reference-label {
  font-size: 13px;
  font-weight: 600;
  color: #8e82b0;
}

.reference-canvas-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #e8e0f5;
}

.drawing-container {
  background: #fff;
  border-radius: 20px;
  padding: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.drawing-label {
  font-size: 13px;
  font-weight: 600;
  color: #8e82b0;
}

.drawing-canvas-wrap {
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #5b4a9e;
  position: relative;
  touch-action: none;
}

.tracing-overlay {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  opacity: 0.15;
  border-radius: 12px;
}

.gameplay-toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 20;
  flex-wrap: wrap;
}

.brush-sizes {
  display: flex;
  gap: 8px;
  align-items: center;
}

.brush-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #d0c8e8;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.brush-btn.active {
  border-color: #5b4a9e;
  background: #f0ecfa;
}

.brush-dot {
  border-radius: 50%;
  background: #333;
}

/* --- Result Screen --- */
.result-screen {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  justify-content: flex-start;
  padding-top: max(10vh, env(safe-area-inset-top, 0px));
}

.result-card {
  background: #fff;
  border-radius: 28px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 340px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.result-medal {
  font-size: 72px;
  line-height: 1;
  animation: medalBounce 0.6s ease;
}

@keyframes medalBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

.result-score {
  font-size: 42px;
  font-weight: 800;
  color: #3d3270;
}

.result-label {
  font-size: 16px;
  color: #8e82b0;
  font-weight: 600;
}

.result-status {
  font-size: 20px;
  font-weight: 700;
}

.result-status.gold { color: #FFD700; }
.result-status.silver { color: #A0A0A0; }
.result-status.bronze { color: #CD7F32; }
.result-status.fail { color: #e74c3c; }

.result-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.result-comparison {
  display: flex;
  gap: 12px;
  align-items: center;
}

.result-comparison canvas {
  border-radius: 8px;
  border: 2px solid #e8e0f5;
}

.result-vs {
  font-size: 14px;
  font-weight: 700;
  color: #b0a8c8;
}

/* --- Pause Overlay --- */
.pause-screen {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pause-card {
  background: #fff;
  border-radius: 28px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 300px;
  max-height: 90vh;
  overflow-y: auto;
  width: 85%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.pause-title {
  font-size: 28px;
  font-weight: 800;
  color: #3d3270;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  .gameplay-area {
    flex-direction: column;
    gap: 10px;
  }

  .categories-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .levels-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .result-card {
    padding: 20px 18px;
    gap: 10px;
    border-radius: 22px;
  }

  .result-medal {
    font-size: 52px;
  }

  .result-score {
    font-size: 34px;
  }

  .result-label {
    font-size: 14px;
  }

  .result-comparison canvas {
    width: 70px;
    height: 70px;
  }
}

@media (min-width: 601px) {
  .gameplay-area {
    flex-direction: row;
  }

  .levels-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

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

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

/* --- Confetti canvas --- */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 100;
  pointer-events: none;
}
