/* ============================================
   ColorBook Master — style.css
   Mobile-first, Android-ready
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #FF6B9D;
  --primary-dk: #e05585;
  --accent:     #FFD93D;
  --accent-dk:  #f0c520;
  --green:      #6BCB77;
  --blue:       #4D96FF;
  --purple:     #9B59B6;
  --bg:         #FFF9F0;
  --card-bg:    #FFFFFF;
  --text:       #333333;
  --text-muted: #888888;
  --border:     #E8E0F0;
  --locked-bg:  #F0F0F0;
  --shadow:     0 4px 16px rgba(0,0,0,0.10);
  --radius:     16px;
  --banner-h:   56px;
}

body {
  font-family: 'Nunito', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== TOP BANNER AD ===== */
#banner-ad {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--banner-h);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#banner-ad span {
  color: white;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  opacity: 0.9;
}

/* ===== MAIN APP WRAPPER ===== */
#app {
  padding-top: var(--banner-h);
  min-height: 100vh;
}

/* ===== SCREENS ===== */
.screen { display: none; }
.screen.active { display: block; }

/* ===== HEADER ===== */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, #FF8E53 100%);
  padding: 16px 20px 20px;
  color: white;
  position: sticky;
  top: var(--banner-h);
  z-index: 100;
}
.header-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-back {
  background: rgba(255,255,255,0.25);
  border: none;
  color: white;
  width: 38px; height: 38px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.btn-back:hover { background: rgba(255,255,255,0.35); }
.header-title { font-size: 20px; font-weight: 800; flex: 1; }
.header-subtitle { font-size: 12px; opacity: 0.85; margin-top: 4px; font-weight: 600; }

/* ===== HOME SCREEN ===== */
#home-screen {
  padding: 20px 16px 32px;
}
.home-hero {
  text-align: center;
  padding: 24px 0 20px;
}
.home-hero h1 {
  font-size: 28px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.home-hero p {
  color: var(--text-muted);
  margin-top: 8px;
  font-size: 14px;
  font-weight: 600;
}
.section-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  margin: 16px 0 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== BOOK CARDS ===== */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.book-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  border: 2px solid transparent;
}
.book-card:active { transform: scale(0.97); }
.book-card.free { border-color: var(--green); }
.book-card.locked { opacity: 0.85; }

.book-thumb {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, #f8f8ff, #ffe8f5);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.book-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.book-thumb .lock-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
}
.book-thumb .emoji-placeholder {
  font-size: 50px;
}
.book-info {
  padding: 10px 12px 12px;
}
.book-info h3 {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-info .book-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  font-weight: 600;
}
.free-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--green);
  color: white;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 20px;
  text-transform: uppercase;
}
.ad-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--accent);
  color: #333;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 20px;
}

/* ===== BOOK SCREEN (page selection) ===== */
#book-screen { padding-bottom: 32px; }
.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  padding: 16px;
}
.page-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
  position: relative;
}
.page-card:active { transform: scale(0.96); }
.page-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: #f5f5f5;
}
.page-num {
  text-align: center;
  padding: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.page-card.colored::after {
  content: '✓';
  position: absolute;
  top: 6px; right: 6px;
  background: var(--green);
  color: white;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== COLORING SCREEN ===== */
#color-screen {
  display: none;
  flex-direction: column;
  height: calc(100vh - var(--banner-h));
}
#color-screen.active {
  display: flex;
}
.color-header {
  background: var(--primary);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.color-header .btn-back {
  flex-shrink: 0;
}
.color-header-title {
  color: white;
  font-weight: 800;
  font-size: 15px;
  flex: 1;
}
.canvas-container {
  flex: 1;
  overflow: hidden;
  background: #f0f0f0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
#coloring-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
}
.tools-panel {
  background: white;
  padding: 10px 14px;
  flex-shrink: 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tool-row + .tool-row { margin-top: 8px; }

/* Color palette */
.palette {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}
.color-swatch {
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.color-swatch:active { transform: scale(0.9); }
.color-swatch.selected {
  border-color: #333;
  transform: scale(1.15);
}

/* Tool buttons */
.tool-btn {
  background: var(--border);
  border: none;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.tool-btn:active { transform: scale(0.95); }
.tool-btn.active { background: var(--primary); color: white; }
.tool-btn.danger { background: #ffe5e5; color: #e53935; }

/* Brush size */
.brush-sizes {
  display: flex;
  gap: 6px;
  align-items: center;
}
.brush-dot {
  background: #555;
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s;
  border: 2px solid transparent;
}
.brush-dot.selected { border-color: var(--primary); transform: scale(1.2); }
.brush-dot:nth-child(1) { width: 10px; height: 10px; }
.brush-dot:nth-child(2) { width: 16px; height: 16px; }
.brush-dot:nth-child(3) { width: 22px; height: 22px; }
.brush-dot:nth-child(4) { width: 28px; height: 28px; }

/* ===== AD REWARD OVERLAY ===== */
#ad-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#ad-overlay.hidden { display: none; }
.ad-box {
  background: white;
  border-radius: 24px;
  padding: 32px 28px;
  max-width: 320px;
  width: 90%;
  text-align: center;
}
.ad-box h2 { font-size: 22px; margin-bottom: 8px; }
#ad-mock-msg {
  color: var(--text-muted);
  font-size: 14px;
  margin: 12px 0 24px;
  font-weight: 600;
  line-height: 1.5;
}
.ad-mock-visual {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 14px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  font-size: 36px;
}
.ad-counter {
  font-size: 40px;
  font-weight: 900;
  color: var(--primary);
  margin: 0 0 8px;
}
.ad-counter-label { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; font-weight: 600; }
#ad-skip-btn {
  background: var(--border);
  color: var(--text);
  padding: 10px 24px;
  border: none;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}

/* ===== UNLOCK SUCCESS TOAST ===== */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%; transform: translateX(-50%);
  background: var(--green);
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-weight: 800;
  font-size: 14px;
  z-index: 3000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  transition: opacity 0.4s;
  white-space: nowrap;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ===== UTILITIES ===== */
.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
