* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: #f4f6f8;
  color: #1f2937;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  padding: 16px 20px;
  background: white;
  border-bottom: 1px solid #dbe2ea;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0 0 6px 0;
  font-size: 1.5rem;
}

.topbar p {
  margin: 0;
  color: #5b6470;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hidden {
  display: none !important;
}

.gallery-view {
  padding: 20px;
}

.gallery-intro {
  max-width: 900px;
  margin: 0 auto 18px auto;
}

.gallery-intro h2 {
  margin: 0 0 6px 0;
  font-size: 1.5rem;
}

.gallery-intro p {
  margin: 0;
  color: #5b6470;
}

.gallery {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.card {
  border: 1px solid #dbe2ea;
  border-radius: 18px;
  background: white;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.card:hover {
  transform: translateY(-2px);
  border-color: #b9c6d3;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  display: block;
  background: #ffffff;
  border-bottom: 1px solid #edf1f5;
}

.card-body {
  padding: 14px;
}

.card h3 {
  margin: 0 0 6px 0;
  font-size: 1.1rem;
}

.card-meta {
  margin: 0 0 10px 0;
  color: #5b6470;
  font-size: 0.93rem;
}

.progress-bar {
  height: 9px;
  background: #e8edf3;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: #0a84ff;
}

.progress-text {
  margin: 0;
  color: #5b6470;
  font-size: 0.9rem;
}

.coloring-view {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 16px;
  padding: 16px;
  flex: 1;
}

.sidebar,
.canvas-wrap {
  background: white;
  border: 1px solid #dbe2ea;
  border-radius: 16px;
  padding: 16px;
}

.sidebar h2 {
  margin-top: 0;
}

.palette {
  display: grid;
  gap: 10px;
}

.palette-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 2px solid #d7dde5;
  background: white;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 1rem;
}

.palette-btn.selected {
  border-color: #0a84ff;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.12);
}

.palette-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary-btn {
  border: 1px solid #c9d2dc;
  background: white;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}

.secondary-btn:hover,
.palette-btn:hover:not(:disabled) {
  background: #f8fafc;
}

.color-chip {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(0,0,0,0.18);
  flex: 0 0 auto;
}

.palette-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.count {
  font-size: 0.9rem;
  color: #5b6470;
}

.canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70vh;
}

.canvas {
  width: 100%;
  max-width: 900px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.color-region {
  fill: #ffffff;
  cursor: pointer;
  transition: fill 0.2s ease, stroke 0.2s ease;
}

.color-region.matching {
  stroke: #0a84ff !important;
  stroke-width: 6 !important;
}

.color-region.wrong {
  stroke: #dc2626 !important;
  stroke-width: 7 !important;
}

.region-label {
  font-size: 22px;
  font-weight: 700;
  fill: #6b7280;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

.hint {
  margin-top: 16px;
  color: #5b6470;
  font-size: 0.95rem;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .coloring-view {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    min-height: auto;
  }
}

@media (max-width: 520px) {
  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .gallery-view {
    padding: 14px;
  }

  .coloring-view {
    padding: 12px;
  }
}
