* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Nunito", Arial, sans-serif;
  color: #3b2a6b;
  background: linear-gradient(#bfe9ff, #fff3c4 60%, #ffd9ec);
  background-attachment: fixed;
}

/* Home */
.hero {
  text-align: center;
  padding: 28px 12px 8px;
}

.hero h1 {
  margin: 0;
  font-size: clamp(44px, 9vw, 90px);
  font-weight: 900;
  background: linear-gradient(90deg, #ff3b30, #ff9500, #f5c400, #34c759, #00a2ff, #af52de, #ff2d92);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: bounce 2.5s ease-in-out infinite;
}

.hero p {
  margin: 6px 0;
  font-size: clamp(18px, 3vw, 26px);
}

@keyframes bounce {
  50% {
    transform: translateY(-8px) rotate(-1.5deg);
  }
}

#gallery {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px 50px;
}

#gallery h2 {
  margin: 30px 0 12px;
  font-size: 34px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 20px;
}

.card {
  position: relative;
  padding: 12px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  color: #3b2a6b;
  background: #fff;
  border: 6px solid #c9c9d1;
  border-radius: 28px;
  box-shadow: 0 6px 0 #a8a8b3;
  transition: transform 0.15s;
}

.card:hover {
  transform: translateY(-6px) rotate(-2deg);
}

/* Thumbnail: the child's colors at the bottom, the outline on top */
.thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 6px;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb .thumb-outline {
  mix-blend-mode: multiply;
}

/* Pictures that were already colored get a star and a green frame */
.card.done {
  border-color: #34c759;
  box-shadow: 0 6px 0 #1f9a40, 0 0 0 6px rgba(52, 199, 89, 0.35);
}

.badge {
  position: absolute;
  top: -14px;
  right: -10px;
  z-index: 2;
  padding: 4px 12px;
  font-size: 18px;
  font-weight: 900;
  color: #fff;
  background: #34c759;
  border: 4px solid #fff;
  border-radius: 999px;
  transform: rotate(8deg);
}

/* ---------- Paint view ---------- */
#paint {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  height: 100dvh;
  padding: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar h2 {
  margin: 0;
  font-size: clamp(20px, 4vw, 34px);
  text-align: center;
}

.big-btn {
  padding: 10px 22px;
  font-family: inherit;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 700;
  color: #fff;
  border: 5px solid;
  border-radius: 20px;
  cursor: pointer;
}

.big-btn:active {
  transform: scale(0.95);
}

.back {
  background: #2d9cdb;
  border-color: #1b6fa3;
}

.reset {
  background: #ff5a5f;
  border-color: #b3282d;
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-wrap {
  position: relative;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--ratio, 1);
  overflow: hidden;
  background: #fff;
  border: 6px solid #7c4dff;
  border-radius: 24px;
  box-shadow: 0 8px 0 #5b34c7;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: manipulation;
}

/* The outline sits on top; "multiply" keeps the colors visible through the white parts */
#outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* ---------- Palette ---------- */
.palette-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff;
  border: 5px solid #ffb703;
  border-radius: 28px;
}

#current-color {
  flex: none;
  width: 64px;
  height: 64px;
  border: 6px solid #3b2a6b;
  border-radius: 50%;
}

#palette {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.swatch {
  width: clamp(34px, 5vw, 48px);
  height: clamp(34px, 5vw, 48px);
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  outline: 2px solid #bbb;
  cursor: pointer;
}

.swatch.selected {
  outline: 5px solid #3b2a6b;
  transform: scale(1.2);
}

.rainbow {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  font-size: 40px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 4px #000, 0 0 4px #000;
  background: conic-gradient(red, orange, yellow, lime, cyan, blue, magenta, red);
  border: 5px solid #3b2a6b;
  border-radius: 16px;
  cursor: pointer;
}

/* The real color input is invisible and covers the whole rainbow square */
.rainbow input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

@media (max-width: 600px) {
  .big-btn {
    padding: 8px 12px;
  }

  .palette-bar {
    flex-wrap: wrap;
  }
}
