/* ===== ROOT & RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --yellow:    #FFE135;
  --orange:    #FF7B3A;
  --pink:      #FF5FA0;
  --purple:    #9B5DE5;
  --blue:      #3A86FF;
  --cyan:      #00C8FF;
  --green:     #06D6A0;
  --bg:        #FFF8F0;
  --card-bg:   #FFFFFF;
  --text:      #2D2D2D;
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow:    0 8px 32px rgba(0,0,0,.10);
  --shadow-hover: 0 16px 48px rgba(0,0,0,.18);
}

html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
  animation: fadeIn .4s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== APP HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 40px;
  background: linear-gradient(135deg, var(--purple) 0%, var(--blue) 100%);
  color: #fff;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 4px 20px rgba(58,134,255,.3);
  flex-wrap: wrap;
}

.logo {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  letter-spacing: 1px;
  text-shadow: 2px 3px 0 rgba(0,0,0,.2);
}

.tagline {
  font-size: 1rem;
  opacity: .9;
  flex: 1;
}

.category-label {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  background: rgba(255,255,255,.2);
  padding: 6px 18px;
  border-radius: 50px;
}

/* ===== BACK BUTTON ===== */
.btn-back {
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.5);
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: .95rem;
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 50px;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.btn-back:hover {
  background: rgba(255,255,255,.35);
  transform: translateX(-3px);
}

/* ===== FLOATING BUBBLES BACKGROUND ===== */
.bubbles-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.bubble {
  position: absolute;
  border-radius: 50%;
  opacity: .08;
  animation: floatUp linear infinite;
}
@keyframes floatUp {
  from { transform: translateY(110vh) scale(.8); }
  to   { transform: translateY(-20vh) scale(1.1); }
}

/* ===== CATEGORIES SCREEN ===== */
#screen-categories main {
  position: relative; z-index: 1;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 28px;
  padding: 40px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.category-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
}
.category-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .3s;
  border-radius: var(--radius-lg);
}
.category-card:hover {
  transform: translateY(-8px) scale(1.03);
  box-shadow: var(--shadow-hover);
}
.category-card:hover::before { opacity: 1; }

.category-card .cat-icon {
  font-size: 3.5rem;
  display: block;
  margin-bottom: 14px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.15));
  transition: transform .3s ease;
}
.category-card:hover .cat-icon { transform: scale(1.15) rotate(-5deg); }

.category-card .cat-name {
  font-family: 'Fredoka One', cursive;
  font-size: 1.4rem;
  color: var(--text);
}

.category-card .cat-count {
  font-size: .85rem;
  color: #888;
  margin-top: 6px;
}

/* Card color themes */
.category-card:nth-child(1) { border-color: var(--yellow); }
.category-card:nth-child(1)::before { background: linear-gradient(135deg, rgba(255,225,53,.08), rgba(255,123,58,.06)); }
.category-card:nth-child(2) { border-color: var(--orange); }
.category-card:nth-child(2)::before { background: linear-gradient(135deg, rgba(255,123,58,.08), rgba(255,95,160,.06)); }
.category-card:nth-child(3) { border-color: var(--pink); }
.category-card:nth-child(3)::before { background: linear-gradient(135deg, rgba(255,95,160,.08), rgba(155,93,229,.06)); }
.category-card:nth-child(4) { border-color: var(--purple); }
.category-card:nth-child(4)::before { background: linear-gradient(135deg, rgba(155,93,229,.08), rgba(58,134,255,.06)); }
.category-card:nth-child(5) { border-color: var(--blue); }
.category-card:nth-child(5)::before { background: linear-gradient(135deg, rgba(58,134,255,.08), rgba(0,200,255,.06)); }
.category-card:nth-child(6) { border-color: var(--cyan); }
.category-card:nth-child(6)::before { background: linear-gradient(135deg, rgba(0,200,255,.08), rgba(6,214,160,.06)); }
.category-card:nth-child(7) { border-color: var(--green); }
.category-card:nth-child(8) { border-color: var(--yellow); }

/* ===== DRAWINGS SCREEN ===== */
.drawings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 24px;
  padding: 36px 40px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.drawing-card {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
  border: 3px solid #eee;
}
.drawing-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: var(--shadow-hover);
  border-color: var(--blue);
}

.drawing-thumb {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f8f8;
  padding: 12px;
  overflow: hidden;
}
.drawing-thumb svg, .drawing-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.drawing-label {
  padding: 12px 14px;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  text-align: center;
  color: var(--text);
  border-top: 2px solid #eee;
}

/* ===== PAINT SCREEN ===== */
#screen-paint {
  background: #f0f4ff;
}

.paint-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
  flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
}

.drawing-name {
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  flex: 1;
}

.paint-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-action {
  background: rgba(255,255,255,.2);
  border: 2px solid rgba(255,255,255,.4);
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: .9rem;
  padding: 8px 16px;
  border-radius: 50px;
  cursor: pointer;
  transition: background .2s, transform .15s;
}
.btn-action:hover {
  background: rgba(255,255,255,.35);
  transform: translateY(-2px);
}

.btn-download {
  background: var(--green);
  border-color: rgba(255,255,255,.6);
}
.btn-download:hover { background: #04b888; }

.btn-fullscreen {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.35);
}
.btn-fullscreen:hover { background: rgba(255,255,255,.28); }

/* Fullscreen: compact header so canvas fills the screen */
:fullscreen .paint-header  { padding: 8px 16px; }
:fullscreen .drawing-name  { font-size: 1rem; }
:fullscreen .paint-workspace { height: calc(100vh - 56px); }

/* ===== PAINT WORKSPACE ===== */
.paint-workspace {
  display: flex;
  flex: 1;
  gap: 0;
  overflow: hidden;
  min-height: 0;
}

/* ===== PALETTE PANEL ===== */
.palette-panel {
  width: 180px;
  min-width: 160px;
  background: #fff;
  border-right: 3px solid #e0e8ff;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  box-shadow: 4px 0 16px rgba(0,0,0,.06);
}

.palette-title {
  font-family: 'Fredoka One', cursive;
  font-size: .95rem;
  color: var(--purple);
  margin-bottom: 4px;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: transform .15s, border-color .15s, box-shadow .15s;
  position: relative;
}
.swatch:hover {
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.swatch.active {
  border-color: #333;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #333;
}

.tool-section { display: flex; flex-direction: column; gap: 6px; }

.size-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.size-btn {
  flex: 1;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid #ddd;
  background: #f5f5f5;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background .15s, border-color .15s, transform .15s;
  color: #333;
}
.size-btn:hover { background: #e0e8ff; border-color: var(--blue); transform: scale(1.1); }
.size-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ===== TOOL BUTTONS (brush / bucket / eraser) ===== */
.tools-row {
  display: flex;
  gap: 6px;
}

.tool-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 2px solid #dde4ff;
  background: #f5f7ff;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s, box-shadow .15s;
}
.tool-btn:hover {
  background: #e6ebff;
  border-color: var(--blue);
  transform: translateY(-2px);
}
.tool-btn.active {
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-color: var(--purple);
  box-shadow: 0 4px 12px rgba(155,93,229,.35);
  transform: translateY(-2px);
}
.tool-btn .tool-icon { font-size: 1.4rem; line-height: 1; }
.tool-btn .tool-label { font-family: 'Nunito', sans-serif; font-size: .7rem; font-weight: 800; color: #555; }
.tool-btn.active .tool-label { color: #fff; }

/* ===== TOLERANCE SLIDER ===== */
.tolerance-slider { width: 100%; accent-color: var(--purple); cursor: pointer; }
.tolerance-hint { text-align: center; font-size: .8rem; font-weight: 800; color: var(--purple); margin-top: 2px; }

/* ===== FILL INDICATOR ===== */
.fill-indicator {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  padding: 10px 28px;
  border-radius: 50px;
  box-shadow: 0 4px 20px rgba(155,93,229,.4);
  z-index: 10;
  animation: pulseIndicator .6s ease infinite alternate;
  pointer-events: none;
}
@keyframes pulseIndicator {
  from { opacity: .8; transform: translateX(-50%) scale(1); }
  to   { opacity: 1;  transform: translateX(-50%) scale(1.04); }
}


.current-color-preview {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 3px solid #ddd;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.1);
  transition: background-color .2s;
}

input[type="color"] {
  display: none;
}
.custom-color-label {
  display: block;
  background: linear-gradient(135deg, var(--orange), var(--pink));
  color: #fff;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: .85rem;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: opacity .2s, transform .15s;
}
.custom-color-label:hover { opacity: .85; transform: scale(1.03); }

/* ===== CANVAS CONTAINER ===== */
.canvas-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: auto;
  background: repeating-conic-gradient(#e0e8ff 0% 25%, #f0f4ff 0% 50%) 0 0/40px 40px;
}

#paint-canvas, #drawing-layer {
  position: absolute;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 40px rgba(0,0,0,.18), 0 0 0 4px #fff;
}

#paint-canvas {
  background: #ffffff;
  z-index: 1;
}

#drawing-layer {
  z-index: 2;
  pointer-events: none;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .categories-grid { grid-template-columns: repeat(2, 1fr); padding: 20px; gap: 16px; }
  .drawings-grid { grid-template-columns: repeat(2, 1fr); padding: 16px; gap: 14px; }
  .paint-workspace { flex-direction: column; }
  .palette-panel { width: 100%; min-width: unset; flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 3px solid #e0e8ff; }
  .color-swatches { grid-template-columns: repeat(10, 32px); width: max-content; }
}

/* ===== TOAST NOTIFICATION ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--purple);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  padding: 14px 32px;
  border-radius: 50px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  z-index: 10000;
  transition: transform .4s cubic-bezier(.175,.885,.32,1.275);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ===== LOADING / EMPTY STATES ===== */
.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 60px 20px;
  opacity: .5;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
}

/* Thumbnail states while SVG loads */
.thumb-loading,
.thumb-missing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 6px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  color: #ccc;
  text-align: center;
  animation: thumbPulse 1.2s ease infinite alternate;
}
.thumb-loading { color: var(--purple); opacity: .5; }
.thumb-missing  { font-size: 1.3rem; opacity: .45; }
.thumb-missing small { font-family: 'Nunito', sans-serif; font-size: .75rem; font-weight: 700; }
@keyframes thumbPulse { from { opacity: .3; } to { opacity: .7; } }

/* Custom color picker — now sits right below the palette grid */
.custom-color-section { margin-top: -4px; }
.custom-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
