/* ============================================================
   HodgePodge Helpers — Interactive Coloring Book
   Mobile-first stylesheet
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --purple:  #4E1E3D;
  --gold:    #ECB358;
  --green:   #063E20;
  --bg:      #F8F4F1;
  --dark:    #110610;
  --red:     #E63946;
  --radius:  10px;
  --shadow:  0 4px 16px rgba(17, 6, 16, 0.18);
}

/* ---------- Reset ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  /* Kid-friendly rounded font stack */
  font-family: 'Nunito', 'Comic Sans MS', 'Chalkboard SE', system-ui, sans-serif;
  color: var(--dark);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- Screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.screen.active {
  display: flex;
}

/* ============================================================
   COVER SCREEN
   ============================================================ */
.cover-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 24px;
  gap: 20px;
}

#cover-img {
  max-width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: var(--shadow), 0 0 0 4px var(--gold);
}

.btn-start {
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 15px 36px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.3px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(78, 30, 61, 0.45);
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn-start:active {
  transform: scale(0.95);
  box-shadow: 0 2px 6px rgba(78, 30, 61, 0.3);
}

/* ============================================================
   APP HEADER
   ============================================================ */
.app-header {
  flex-shrink: 0;
  background: var(--purple);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  min-height: 48px;
  gap: 8px;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  width: 40px;
  height: 38px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s;
}
.nav-btn:active    { background: rgba(255, 255, 255, 0.28); }
.nav-btn:disabled  { opacity: 0.3; cursor: default; pointer-events: none; }

.page-info {
  flex: 1;
  text-align: center;
  min-width: 0;
}
.page-title {
  display: block;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-num {
  display: block;
  font-size: 11px;
  opacity: 0.75;
}

/* ============================================================
   ART AREA
   ============================================================ */
.art-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: var(--bg);
  overflow: hidden;
}

/* Canvas wrapper — width + height set by JS */
.canvas-wrapper {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 2px rgba(78, 30, 61, 0.12);
}

/* Base image layer — always visible, no blend, sized by JS via wrapper */
.line-art-base {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Coloring canvas — transparent by default, sits on top of image.
   mix-blend-mode:multiply makes user colors blend with the image:
   colored region × white image area = color shown
   colored region × dark line        = line stays visible (darkens) */
#coloring-canvas {
  display: block;
  position: relative;  /* stays in normal flow so wrapper sizes to it */
  z-index: 2;
  mix-blend-mode: multiply;
  touch-action: none;
  cursor: crosshair;
  /* no background — transparent so image shows through uncolored areas */
}

/* Loading indicator shown while an image loads */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(248, 244, 241, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--purple);
  border-radius: 6px;
  z-index: 20;
}

/* ============================================================
   TOOLBAR
   ============================================================ */
.toolbar {
  flex-shrink: 0;
  background: var(--purple);
  padding: 7px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.tools-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  flex-wrap: nowrap;
}

/* Generic tool button */
.tool-btn {
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
  border: 2px solid transparent;
  border-radius: var(--radius);
  width: 44px;
  height: 40px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.tool-btn.active {
  background: var(--gold);
  color: var(--dark);
  border-color: rgba(255, 255, 255, 0.45);
}
.tool-btn:active { transform: scale(0.93); }

.btn-clear { background: rgba(230, 57, 70, 0.32); }
.btn-clear:active { background: rgba(230, 57, 70, 0.55); }

/* Color picker label wraps a hidden <input type=color> */
.color-pick-wrap {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}
.color-pick-wrap input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
}

/* ===== Heart Button ===== */
.heart-btn {
  background: linear-gradient(135deg, #ff6b9d 0%, var(--red) 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(230, 57, 70, 0.42);
  transition: transform 0.15s, box-shadow 0.15s;
  /* Visually separate from the tool group */
  margin-left: 6px;
}
.heart-btn:active {
  transform: scale(1.18);
  box-shadow: 0 5px 16px rgba(230, 57, 70, 0.55);
}

/* ===== Color Palette ===== */
.palette-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s, border-color 0.1s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.swatch.selected {
  border-color: #fff;
  transform: scale(1.22);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.swatch:active { transform: scale(1.1); }
/* White swatch needs an inner border so it's visible */
.swatch[data-color="#FFFFFF"],
.swatch[data-color="#ffffff"] {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18), 0 1px 3px rgba(0,0,0,0.2);
}

/* ============================================================
   CELEBRATION
   ============================================================ */

/* Full-screen pointer-events-none overlay for floating hearts */
#celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

/* Individual floating hearts / sparkles */
.floating-heart {
  position: absolute;
  pointer-events: none;
  line-height: 1;
  animation: floatUp var(--dur, 2.8s) ease-out var(--delay, 0s) forwards;
}

@keyframes floatUp {
  0%   { transform: translateY(0)    rotate(-6deg) scale(1);   opacity: 1; }
  40%  { transform: translateY(-30vh) rotate(6deg)  scale(1.1); opacity: 0.95; }
  100% { transform: translateY(-78vh) rotate(-4deg) scale(0.5); opacity: 0; }
}

/* Celebration text message — fades in, pauses, fades out */
#celebration-msg {
  position: fixed;
  top: 28%;
  left: 50%;
  transform: translateX(-50%) scale(0.85);
  background: var(--purple);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  padding: 13px 26px;
  border-radius: 50px;
  border: 3px solid var(--gold);
  box-shadow: 0 8px 28px rgba(78, 30, 61, 0.5);
  pointer-events: none;
  z-index: 201;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s ease;
}
#celebration-msg.show {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* ============================================================
   RESPONSIVE — tablet / desktop
   ============================================================ */
@media (min-width: 520px) {
  .app-header       { padding: 8px 16px; }
  .page-title       { font-size: 15px; }
  .tool-btn         { width: 50px; height: 44px; font-size: 20px; }
  .heart-btn        { width: 50px; height: 50px; font-size: 22px; }
  .swatch           { width: 32px; height: 32px; }
  .toolbar          { padding: 8px 20px 10px; gap: 8px; }
  .tools-row        { gap: 10px; }
  .palette-row      { gap: 9px; }
  .btn-start        { font-size: 22px; padding: 16px 42px; }
}

@media (min-width: 800px) {
  /* On desktop, cap the coloring screen width and center it */
  #coloring-screen {
    max-width: 720px;
    margin: 0 auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.15);
  }
  #celebration-layer { max-width: 720px; left: 50%; transform: translateX(-50%); }
  #cover-img { max-height: 60vh; }
}
