:root {
  --bg: #fff8f0;
  --text: #3d3d3d;
  --primary: #ff8fab;
  --primary-dark: #ff5c8a;
  --secondary: #a0e7e5;
  --accent: #ffe156;
  --card: #ffffff;
  --border: #ffdac1;
  --shadow: rgba(0, 0, 0, 0.08);
  --radius: 18px;
  --header-height: 200px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

.hero {
  text-align: center;
  padding: 32px 16px 20px;
}

.hero h1 {
  font-size: clamp(2rem, 6vw, 3.2rem);
  margin: 0 0 10px;
  color: #ff5c8a;
  text-shadow: 2px 2px 0 #fff;
}

.hero p {
  font-size: 1.15rem;
  margin: 0 0 20px;
}

.search-bar {
  display: flex;
  gap: 10px;
  justify-content: center;
  max-width: 520px;
  margin: 0 auto 18px;
}

.search-bar input {
  flex: 1;
  padding: 14px 18px;
  border: 3px solid var(--border);
  border-radius: 999px;
  font-size: 1rem;
  outline: none;
  background: #fff;
}

.search-bar input:focus {
  border-color: var(--primary);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  font-family: inherit;
  font-weight: 700;
  min-height: 44px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 0 var(--primary-dark);
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  color: #2c5f5d;
}

.btn-tool {
  background: #fff;
  border: 3px solid var(--border);
  color: var(--text);
  width: 100%;
}

.categories {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.chip {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
  border: 3px solid var(--border);
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
}

.chip:hover,
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  margin-top: 10px;
}

.loading,
.error,
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  font-size: 1.1rem;
}

.error {
  color: #d32f2f;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s;
  cursor: pointer;
  border: 4px solid #fff;
}

.card:hover {
  transform: translateY(-6px);
}

.card-thumb {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #fff;
  padding: 12px;
}

.card-body {
  padding: 14px;
  text-align: center;
}

.card-title {
  font-size: 1rem;
  margin: 0 0 10px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-btn {
  width: 100%;
  padding: 10px;
  font-size: 0.95rem;
}

.footer {
  text-align: center;
  padding: 30px 0 0;
  font-size: 0.9rem;
  color: #888;
}

/* Coloring view */
.coloring-view {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow: auto;
}

.coloring-view[hidden] {
  display: none;
}

.coloring-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.coloring-header h2 {
  flex: 1;
  text-align: center;
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  color: var(--primary-dark);
}

.spacer {
  flex: 1;
}

.workspace {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 16px;
  min-height: 0;
}

@media (min-width: 800px) {
  .workspace {
    flex-direction: row;
  }
}

.palette-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

@media (min-width: 800px) {
  .palette-panel {
    width: 140px;
    flex-shrink: 0;
  }
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, 44px);
  gap: 10px;
  justify-content: center;
}

@media (min-width: 800px) {
  .palette {
    grid-template-columns: repeat(2, 44px);
  }
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 3px 6px var(--shadow);
  cursor: pointer;
  transition: transform 0.15s;
}

.color-swatch:hover,
.color-swatch.active {
  transform: scale(1.15);
  border-color: #3d3d3d;
}

.tools {
  display: flex;
  flex-direction: row;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

@media (min-width: 800px) {
  .tools {
    flex-direction: column;
    width: 100%;
  }
}

.color-picker-label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}

.color-picker-label input[type="color"] {
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
}

.canvas-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border-radius: var(--radius);
  border: 4px solid var(--border);
  padding: 16px;
  min-height: 0;
  overflow: auto;
}

.svg-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.svg-wrapper svg {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  width: auto;
  touch-action: manipulation;
}

.svg-wrapper svg * {
  cursor: pointer;
  transition: fill 0.15s;
}

.hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff9c4;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 2px 8px var(--shadow);
}

.canvas-area {
  position: relative;
}
