* {
  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%;
  overflow: hidden;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0a0a1a;
  color: #fff;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  z-index: 1;
  touch-action: none;
}

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

/* === Screen base === */
.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;
  transition: opacity 0.3s ease, visibility 0.3s;
  pointer-events: none;
}

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

/* === Buttons === */
.btn {
  min-width: 200px;
  min-height: 52px;
  padding: 14px 32px;
  border: none;
  border-radius: 16px;
  font-size: clamp(16px, 2.5vw, 20px);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-align: center;
  line-height: 1.2;
}

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

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
  box-shadow: 0 2px 10px rgba(102, 126, 234, 0.3);
}

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

.btn-small {
  min-width: 48px;
  min-height: 48px;
  padding: 10px 16px;
  font-size: clamp(13px, 2vw, 16px);
  border-radius: 12px;
}

.btn-icon {
  min-width: 48px;
  min-height: 48px;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

/* === Title Screen === */
.title-screen {
  background: linear-gradient(135deg, #0c0c2e 0%, #1a1a4e 50%, #0c0c2e 100%);
  gap: 24px;
  padding: 20px;
}

.title-logo {
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 900;
  background: linear-gradient(135deg, #fff 0%, #a8d8ff 30%, #fff 50%, #ffd4e8 70%, #fff 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  animation: shimmer 3s ease-in-out infinite;
  line-height: 1.2;
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.title-subtitle {
  font-size: clamp(14px, 2.5vw, 18px);
  color: rgba(255, 255, 255, 0.6);
  text-align: center;
  margin-bottom: 16px;
}

.title-diamonds {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.title-diamond {
  width: clamp(28px, 5vw, 44px);
  height: clamp(28px, 5vw, 44px);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  animation: float 2s ease-in-out infinite;
}

.title-diamond:nth-child(1) { background: #FF6B6B; animation-delay: 0s; }
.title-diamond:nth-child(2) { background: #4ECDC4; animation-delay: 0.2s; }
.title-diamond:nth-child(3) { background: #FFE66D; animation-delay: 0.4s; }
.title-diamond:nth-child(4) { background: #A78BFA; animation-delay: 0.6s; }
.title-diamond:nth-child(5) { background: #F472B6; animation-delay: 0.8s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.title-version {
  position: absolute;
  bottom: 12px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.2);
}

/* === Stars === */
.stars-display {
  display: flex;
  gap: 4px;
}

.star {
  font-size: 20px;
  color: rgba(255, 255, 255, 0.2);
}

.star.filled {
  color: #FFD700;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

/* === Category Screen === */
.category-screen {
  background: linear-gradient(135deg, #0c0c2e 0%, #1a1a4e 50%, #0c0c2e 100%);
  justify-content: flex-start;
  padding: 0;
}

.screen-header {
  width: 100%;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.screen-title {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 800;
  flex: 1;
}

.header-score {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.2);
  border-radius: 20px;
  padding: 6px 14px 6px 10px;
  flex-shrink: 0;
}

.header-score-icon {
  font-size: 18px;
  line-height: 1;
}

.header-score-value {
  font-size: 16px;
  font-weight: 800;
  color: #FFD700;
  line-height: 1;
}

.category-list {
  width: 100%;
  flex: 1;
  overflow-y: auto;
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.category-list::-webkit-scrollbar {
  display: none;
}

.category-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  min-height: 80px;
}

.category-card:active {
  transform: scale(0.98);
  background: rgba(255, 255, 255, 0.1);
}

.category-card.locked {
  opacity: 0.4;
  pointer-events: none;
}

.category-card.purchasable {
  border: 1px solid rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.06);
}

.btn-purchase {
  min-width: 80px;
  min-height: 40px;
  padding: 8px 16px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.3);
  transition: transform 0.15s ease;
}

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

.category-icon {
  font-size: 36px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  flex-shrink: 0;
}

.category-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.category-name {
  font-size: clamp(16px, 2.5vw, 20px);
  font-weight: 700;
}

.category-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
}

.progress-bar {
  flex: 1;
  max-width: 120px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.category-stars {
  font-size: 13px;
  color: #FFD700;
  flex-shrink: 0;
}

/* === Level Select Screen === */
.level-select-screen {
  background: linear-gradient(135deg, #0c0c2e 0%, #1a1a4e 50%, #0c0c2e 100%);
  justify-content: flex-start;
  padding: 0;
}

.level-grid {
  width: 100%;
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  align-content: start;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

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

.level-card {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px 4px;
  cursor: pointer;
  transition: transform 0.15s ease;
  position: relative;
  overflow: hidden;
}

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

.level-card.locked {
  opacity: 0.35;
  pointer-events: none;
}

.level-card.completed {
  border-color: rgba(102, 126, 234, 0.3);
  background: rgba(102, 126, 234, 0.08);
}

.level-thumbnail {
  flex: 1;
  min-height: 0;
  width: 80%;
  border-radius: 6px;
  object-fit: contain;
  image-rendering: pixelated;
}

.level-number {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  line-height: 1;
  flex-shrink: 0;
}

.level-stars {
  display: flex;
  gap: 1px;
  font-size: 10px;
  line-height: 1;
  flex-shrink: 0;
}

.level-lock {
  font-size: 22px;
  opacity: 0.5;
}

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

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

.gameplay-hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
  background: linear-gradient(to bottom, rgba(10, 10, 26, 0.8) 0%, transparent 100%);
}

.hud-progress {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
}

.hud-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4ECDC4, #44D7B6);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.hud-percent {
  font-size: 14px;
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}

.palette-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
  background: linear-gradient(to top, rgba(10, 10, 40, 0.95) 0%, rgba(10, 10, 40, 0.85) 70%, rgba(10, 10, 40, 0.4) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.palette-colors {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.palette-colors::-webkit-scrollbar {
  display: none;
}

.palette-color {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 10px;
  border: 3px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
  position: relative;
}

.palette-color.selected {
  border-color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

.palette-color.done {
  opacity: 0.3;
  pointer-events: none;
}

.palette-count {
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  padding: 1px 4px;
  line-height: 1;
}

.palette-tools {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* === Level Complete Screen === */
.level-complete-screen {
  background: rgba(10, 10, 26, 0.92);
  gap: 20px;
  padding: 20px;
  z-index: 30;
}

.complete-title {
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 900;
  background: linear-gradient(135deg, #FFD700, #FFA500, #FFD700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.complete-picture {
  width: clamp(140px, 40vw, 220px);
  height: clamp(140px, 40vw, 220px);
  border-radius: 16px;
  border: 3px solid rgba(255, 215, 0, 0.3);
  box-shadow: 0 0 30px rgba(255, 215, 0, 0.15);
  image-rendering: pixelated;
}

.complete-stars {
  display: flex;
  gap: 12px;
}

.complete-star {
  font-size: clamp(32px, 6vw, 48px);
  opacity: 0;
  transform: scale(0);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.complete-star.show {
  opacity: 1;
  transform: scale(1);
}

.complete-star.empty {
  opacity: 0.2;
  transform: scale(0.8);
}

.complete-score {
  font-size: clamp(20px, 3.5vw, 28px);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.8);
}

.complete-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.btn-reward {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #fff;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

/* === Pause Overlay === */
.pause-overlay {
  background: rgba(10, 10, 26, 0.92);
  gap: 16px;
  padding: 20px;
  z-index: 30;
}

.pause-title {
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 800;
  margin-bottom: 12px;
}

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 280px;
}

/* === Scrollable container helper === */
.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;
}

/* === Leaderboard Screen === */
.leaderboard-screen {
  background: linear-gradient(135deg, #0c0c2e 0%, #1a1a4e 50%, #0c0c2e 100%);
  justify-content: flex-start;
  padding: 0;
}

.leaderboard-content {
  width: 100%;
  flex: 1;
  padding: 0 20px 20px;
}

.leaderboard-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  min-height: 52px;
  transition: background 0.15s ease;
}

.leaderboard-entry.self {
  background: rgba(102, 126, 234, 0.15);
  border-color: rgba(102, 126, 234, 0.35);
  box-shadow: 0 0 12px rgba(102, 126, 234, 0.1);
}

.leaderboard-rank {
  min-width: 40px;
  font-size: 15px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  flex-shrink: 0;
}

.leaderboard-rank.top3 {
  font-size: 22px;
  color: #fff;
}

.leaderboard-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-entry.self .leaderboard-name {
  color: #a8d8ff;
}

.leaderboard-score {
  font-size: 15px;
  font-weight: 800;
  color: #FFD700;
  flex-shrink: 0;
}

.leaderboard-login-hint {
  margin-top: 16px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.4);
}

.leaderboard-login-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

/* === Background particles (title) === */
.bg-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bg-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  animation: particle-drift linear infinite;
}

@keyframes particle-drift {
  0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translateY(-20px) rotate(360deg); opacity: 0; }
}
