/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Comic Neue', 'Comic Sans MS', 'Chalkboard SE', cursive, sans-serif;
  background: linear-gradient(135deg, #c3e8ff 0%, #ffd6e8 100%);
  color: #333;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ===== BUTTONS ===== */
.btn {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 16px;
  padding: 12px 24px;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  outline-offset: 3px;
}
.btn:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}
.btn:active:not(:disabled) {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn-primary {
  background: #4fc3f7;
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: #29b6f6; }

.btn-secondary {
  background: #fff;
  color: #555;
  border: 2px solid #ddd;
}
.btn-secondary:hover:not(:disabled) { background: #f5f5f5; }

.btn-accent {
  background: #ffb74d;
  color: #fff;
}
.btn-accent:hover:not(:disabled) { background: #ffa726; }

.btn-small {
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 12px;
  background: #e0e0e0;
  color: #555;
}
.btn-small:hover:not(:disabled) { background: #bdbdbd; }

/* ===== SPLASH SCREEN ===== */
.splash-content {
  text-align: center;
  animation: fadeInUp 0.6s ease;
}
.splash-logo {
  width: 120px;
  height: 120px;
  margin-bottom: 8px;
  animation: logoEntrance 0.8s ease;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.15));
}
.splash-title {
  font-size: 3.5rem;
  margin-bottom: 8px;
  color: #e91e63;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.08);
}
.splash-subtitle {
  font-size: 1.3rem;
  color: #666;
  margin-bottom: 32px;
}
.splash-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}
.splash-buttons .btn {
  width: 280px;
  font-size: 1.25rem;
}
.splash-help {
  margin-top: 24px;
}

/* ===== GALLERY SCREEN ===== */
#galleryScreen.active {
  justify-content: flex-start;
  padding-top: 30px;
  overflow-y: auto;
}

/* ===== HOW TO PLAY SCREEN ===== */
#howToScreen.active {
  justify-content: flex-start;
  padding-top: 30px;
  overflow-y: auto;
}
.howto-content {
  max-width: 620px;
  width: 100%;
  padding: 0 20px 40px;
  animation: fadeInUp 0.4s ease;
}
.howto-title {
  font-size: 2rem;
  color: #7b1fa2;
  text-align: center;
  margin-bottom: 24px;
}
.howto-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}
.howto-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: rgba(255,255,255,0.85);
  padding: 14px 18px;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.howto-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  margin-top: 2px;
}
.howto-step strong {
  font-size: 1.1rem;
  color: #333;
}
.howto-step p {
  font-size: 0.95rem;
  color: #555;
  margin-top: 4px;
  line-height: 1.4;
}
.gallery-content {
  text-align: center;
  max-width: 800px;
  width: 100%;
  padding: 0 20px 30px;
  animation: fadeInUp 0.4s ease;
}
.gallery-title {
  font-size: 2rem;
  color: #7b1fa2;
  margin-bottom: 24px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}
.gallery-card {
  background: #fff;
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.gallery-card:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}
.gallery-card img {
  width: 100%;
  height: 120px;
  object-fit: contain;
  border-radius: 8px;
  background: #fafafa;
}
.gallery-card .gallery-label {
  font-size: 1rem;
  font-weight: 700;
  color: #555;
}

/* ===== COLORING SCREEN ===== */
#coloringScreen.active {
  justify-content: stretch;
  align-items: stretch;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.9);
  border-bottom: 2px solid #e0e0e0;
  z-index: 10;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-group + .toolbar-group {
  border-left: 2px solid #e0e0e0;
  padding-left: 8px;
}

.tool-btn, .action-btn {
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 12px;
  background: #f5f5f5;
  color: #444;
}
.tool-btn.active {
  background: #4fc3f7;
  color: #fff;
  box-shadow: 0 2px 8px rgba(79,195,247,0.4);
}

/* Size buttons */
.size-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.size-btn.active {
  background: #ffe082;
  box-shadow: 0 2px 8px rgba(255,224,130,0.5);
}
.size-dot {
  border-radius: 50%;
  background: #333;
  display: block;
}
.size-small  { width: 8px;  height: 8px; }
.size-medium { width: 14px; height: 14px; }
.size-large  { width: 22px; height: 22px; }

/* Canvas */
.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #eaeaea;
  position: relative;
}
#drawingCanvas {
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
  cursor: crosshair;
  touch-action: none;
}

/* Palette */
.palette {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.92);
  border-top: 2px solid #e0e0e0;
  overflow-x: auto;
  z-index: 10;
}
.palette-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.swatch {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid #ccc;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  flex-shrink: 0;
}
.swatch:hover {
  transform: scale(1.15);
}
.swatch.active {
  border-color: #333;
  border-width: 4px;
  transform: scale(1.18);
  animation: swatchBounce 0.3s ease;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: #fff;
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 480px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  animation: fadeInUp 0.3s ease;
}
.modal-title {
  font-size: 1.6rem;
  color: #7b1fa2;
  margin-bottom: 16px;
}
.modal-text {
  font-size: 1.15rem;
  color: #555;
  margin-bottom: 20px;
}
.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
.modal-close {
  margin-top: 16px;
}
.modal-body {
  margin-bottom: 8px;
}

/* URL input */
.url-input {
  width: 100%;
  font-family: inherit;
  font-size: 1.05rem;
  padding: 12px 16px;
  border: 3px solid #ccc;
  border-radius: 14px;
  outline: none;
  margin-bottom: 8px;
  transition: border-color 0.2s ease;
}
.url-input:focus {
  border-color: #4fc3f7;
  box-shadow: 0 0 0 3px rgba(79,195,247,0.25);
}
.url-error {
  color: #e53935;
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
}

/* Save slot cards */
.slot-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid #e0e0e0;
  margin-bottom: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-align: left;
}
.slot-card:hover {
  background: #f0f7ff;
  border-color: #4fc3f7;
}
.slot-thumb {
  width: 64px;
  height: 48px;
  object-fit: contain;
  border-radius: 6px;
  background: #f5f5f5;
  border: 1px solid #ddd;
}
.slot-info {
  flex: 1;
}
.slot-name {
  font-weight: 700;
  font-size: 1rem;
  color: #333;
}
.slot-date {
  font-size: 0.85rem;
  color: #888;
}
.slot-empty {
  color: #aaa;
  font-style: italic;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes fadeInUp {
  from  { opacity: 0; transform: translateY(24px); }
  to    { opacity: 1; transform: translateY(0); }
}
@keyframes swatchBounce {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1.18); }
}
@keyframes logoEntrance {
  0%   { opacity: 0; transform: scale(0.3) rotate(-20deg); }
  60%  { transform: scale(1.15) rotate(5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 767px) {
  .splash-title { font-size: 2.4rem; }
  .splash-buttons .btn { width: 240px; font-size: 1.1rem; }

  .toolbar {
    gap: 4px;
    padding: 6px 8px;
  }
  .toolbar-group + .toolbar-group {
    border-left: none;
    padding-left: 0;
  }
  .tool-btn, .action-btn {
    font-size: 0.8rem;
    padding: 6px 8px;
    border-radius: 10px;
  }
  /* Hide text labels on small screens, keep emoji */
  .tool-btn span.btn-label,
  .action-btn span.btn-label {
    display: none;
  }

  .palette {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .palette-swatches {
    flex-wrap: nowrap;
  }
  .swatch {
    width: 36px;
    height: 36px;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }
}
