/* style.css — Global styles, themes, and animations */

/* 1. GLOBAL & RESET */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background-color: #f0e6ff;
  /* Safe area support for iPad notch */
  padding-bottom: env(safe-area-inset-bottom);
}

/* 2. CSS CUSTOM PROPERTIES */
:root {
  --lavender: #e8d5ff;
  --lavender-dark: #c9a8ff;
  --mint: #c8f0e0;
  --mint-dark: #8ee8c0;
  --peach: #ffd8c0;
  --yellow: #fff0b0;
  --yellow-dark: #ffd860;
  --text-dark: #4a3060;
  --text-mid: #7a5090;
  --shadow: rgba(120, 80, 180, 0.15);
}

/* 3. SCREENS */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

/* 4. HOME SCREEN */
#screen-home {
  background: linear-gradient(160deg, #e8d5ff 0%, #c8f0e0 60%, #ffd8c0 100%);
  justify-content: center;
}

.btn-home-back {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 10;
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 40px 24px;
}

.app-title {
  text-align: center;
}

.title-emoji {
  display: block;
  font-size: 94px;
  line-height: 1;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 8px 16px rgba(74, 48, 96, 0.15));
}

/* 5. BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 20px;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s ease;
  padding: 16px 32px;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  min-width: 62px;
  min-height: 62px;
}

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

.btn-play {
  background: linear-gradient(135deg, var(--lavender), var(--mint));
  color: var(--text-dark);
  width: 96px;
  height: 96px;
  padding: 0;
  font-size: 38px;
  border-radius: 30px;
  box-shadow: 0 8px 28px var(--shadow);
}

.btn-primary {
  background: linear-gradient(135deg, #c9a8ff, #a0c0ff);
  color: var(--text-dark);
  box-shadow: 0 4px 16px var(--shadow);
}

.btn-success {
  background: linear-gradient(135deg, #8ee8c0, #60d0a0);
  color: #2a6040;
}

.btn-outline {
  background: white;
  color: var(--text-mid);
  border: 3px solid var(--lavender-dark);
}

.btn-back {
  background: rgba(255, 255, 255, 0.75);
  color: var(--text-mid);
  padding: 0;
  width: 52px;
  height: 52px;
  font-size: 26px;
  border-radius: 16px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}

.btn-back-sm {
  background: rgba(255, 255, 255, 0.75);
  color: var(--text-mid);
  padding: 0;
  width: 46px;
  height: 46px;
  font-size: 22px;
  border-radius: 14px;
  border: none;
  font-weight: 700;
  cursor: pointer;
}

.btn-xl {
  width: 100%;
  max-width: 120px;
  padding: 0;
  height: 76px;
  font-size: 32px;
  border-radius: 24px;
}

/* 6. PICKER SCREEN */
#screen-picker {
  background: linear-gradient(160deg, #e8d5ff, #c8f0e0);
  overflow: hidden;
}

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

.screen-header h2 {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-dark);
}

/* Selected preview bar */
#selected-preview-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  margin: 0 auto 20px;
  box-shadow: 0 4px 16px var(--shadow);
  animation: fadeInUp 0.3s ease both;
  width: 100%;
  max-width: 380px;
}

#selected-preview-img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: 0 3px 12px var(--shadow);
  flex-shrink: 0;
}

#selected-preview-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#selected-preview-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
  flex: 1;
}

#selected-preview-bar .btn-success {
  display: inline-flex;
  padding: 10px 20px;
  font-size: 16px;
  border-radius: 16px;
  width: auto;
}

/* Category tabs */
#category-tabs {
  display: flex;
  gap: 10px;
  padding: 10px 18px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

#category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  border-radius: 16px;
  border: 3px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dark);
  flex-shrink: 0;
  transition: transform 0.12s, border-color 0.15s;
  box-shadow: 0 3px 10px var(--shadow);
}

.cat-tab:active { transform: scale(0.95); }

.cat-tab.active {
  border-color: var(--text-dark);
  transform: scale(1.06);
  box-shadow: 0 5px 18px var(--shadow);
}

.cat-emoji { font-size: 24px; }
.cat-label { font-size: 12px; }

/* Preset image grid */
#preset-grid-wrap {
  padding: 4px 18px 8px;
}

#preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.75);
  border: 3px solid transparent;
  border-radius: 18px;
  padding: 10px 6px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  box-shadow: 0 3px 10px var(--shadow);
}

.preset-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
}

.preset-card:active { transform: scale(0.93); }

.preset-card.selected {
  border-color: var(--lavender-dark);
  box-shadow: 0 6px 22px rgba(150, 100, 255, 0.35);
  transform: scale(1.04);
}

.preset-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-mid);
}

/* Upload own row */
#upload-row {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 10px 18px 16px;
}

.btn-upload {
  background: rgba(255, 255, 255, 0.8);
  color: var(--text-mid);
  border: 2.5px dashed var(--lavender-dark);
  border-radius: 18px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s;
  width: 100%;
  max-width: 380px;
}

.btn-upload:active { transform: scale(0.97); }
.btn-upload:hover  { background: rgba(255,255,255,0.95); }

/* 7. LEVEL SELECT SCREEN */
#screen-level {
  background: linear-gradient(160deg, #c8f0e0, #ffd8c0);
}

.level-select-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 24px 32px;
  width: 100%;
  gap: 16px;
}

.level-options {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 420px;
}



.diff-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  border-radius: 20px;
  border: none;
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-dark);
  box-shadow: 0 4px 16px var(--shadow);
  transition: transform 0.12s;
  text-align: left;
  width: 100%;
}

.diff-btn:active {
  transform: scale(0.96);
}

.diff-btn.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

.diff-icon {
  font-size: 28px;
}

.diff-label {
  flex: 1;
}

.diff-count {
  font-size: 13px;
  opacity: 0.65;
  font-weight: 500;
}

.lock-icon {
  font-size: 22px;
}

.diff-easy { background: linear-gradient(135deg, #c8f0e0, #a0e0c0); }
.diff-medium { background: linear-gradient(135deg, #fff0b0, #ffe080); }
.diff-hard { background: linear-gradient(135deg, #ffd8c0, #ffb890); }
.diff-super { background: linear-gradient(135deg, #e8d5ff, #c0a0ff); }

/* 8. GAME SCREEN */
#screen-game {
  background: linear-gradient(160deg, #dde8ff 0%, #e8d5ff 100%);
}

#game-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 54px;
}

#progress-display {
  min-width: 76px;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: var(--text-dark);
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 14px;
  border-radius: 18px;
  box-shadow: 0 2px 8px var(--shadow);
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: block;
}

/* 9. CELEBRATION */
#screen-celebrate {
  background: linear-gradient(160deg, #fff0b0, #ffd8c0, #e8d5ff);
  justify-content: center;
}

.celebrate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 24px;
  z-index: 2;
  text-align: center;
}

.celebrate-content h1 {
  font-size: 78px;
  font-weight: 900;
  line-height: 1;
  color: var(--text-dark);
  animation: bounce 0.7s ease;
}

.celebrate-stars {
  font-size: 38px;
  letter-spacing: 10px;
  animation: fadeInUp 0.5s 0.4s both;
}

.celebrate-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 360px;
  margin-top: 8px;
  align-items: center;
  justify-content: center;
}

#confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  animation: confettiFall linear forwards;
}

/* 10. SIDEKICK */
.sidekick-emoji {
  display: inline-block;
  font-size: 48px;
  line-height: 1;
}

.sidekick-idle {
  animation: sidekickFloat 3s ease-in-out infinite;
}

.sidekick-happy {
  animation: sidekickBounce 0.5s ease;
}

.sidekick-celebrate {
  animation: sidekickCelebrate 1s ease-in-out infinite;
  font-size: 80px;
}

.sidekick-encourage {
  animation: sidekickWave 0.8s ease 2;
}

/* 11. KEYFRAME ANIMATIONS */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}

@keyframes sidekickFloat {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-10px) rotate(4deg); }
}

@keyframes sidekickBounce {
  0%, 100% { transform: scale(1) translateY(0); }
  35% { transform: scale(1.35) translateY(-22px); }
  65% { transform: scale(0.88) translateY(5px); }
}

@keyframes sidekickCelebrate {
  0%, 100% { transform: scale(1) rotate(-12deg); }
  25% { transform: scale(1.25) rotate(12deg) translateY(-18px); }
  50% { transform: scale(1) rotate(-8deg); }
  75% { transform: scale(1.18) rotate(8deg) translateY(-12px); }
}

@keyframes sidekickWave {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-22deg) translateY(-5px); }
  75% { transform: rotate(22deg) translateY(-5px); }
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.12); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
