/* =======================================================================
   WP COLORING — STYLESHEET v5.3.5 (Unified Responsive Engine)
   ======================================================================= */

/* --- Reset & Variables --- */
:root {
  --swatch-size: 40px;
  --swatch-inner: 24px;
  --action-size: 60px;
  --action-radius: 14px;
  --action-font: 30px;
  --canvas-radius: 12px;
}
.wp-coloring-shell *,
.wp-coloring-shell *::before,
.wp-coloring-shell *::after {
  box-sizing: border-box;
}
.wp-coloring-shell button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
}
.wp-coloring-shell :focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.45);
  outline-offset: 2px;
}

/* --- Shell & Grid Layout --- */
.wp-coloring-shell {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding: 16px;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}
.wp-coloring-grid {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 100px;
  gap: 16px;
  align-items: stretch;
}

/* --- Sidebars (PC) --- */
.wp-coloring-sidebar {
  border: 1px solid #e0e7ff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 12px;
  position: sticky;
  top: 40px;
}

/* --- Palette --- */
.palette-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(44px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 2px;
  list-style: none;
}
.palette-btn {
  width: var(--swatch-size);
  height: var(--swatch-size);
  border-radius: 50%;
  border: 1px solid #e6ebf2;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  transition: all 0.2s;
}
.palette-btn::before {
  content: "";
  width: var(--swatch-inner);
  height: var(--swatch-inner);
  border-radius: 50%;
  background: var(--clr);
}
.palette-btn:hover {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}
.palette-btn.active {
  border-color: #000;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #000;
}

/* --- Main Canvas Area --- */
.wp-coloring-main {
  border: 1px solid #e0e7ff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 12px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.wp-coloring-status {
  flex-shrink: 0;
  text-align: center;
  color: #64748b;
  font-weight: 500;
  padding: 8px;
  min-height: 20px;
}

/* Vùng chứa canvas sẽ co giãn linh hoạt */
.wp-coloring-canvas-outer {
  position: relative;
  overflow: hidden;
  touch-action: none;
  flex-grow: 1; /* Quan trọng: làm cho nó lấp đầy không gian dọc */
  width: 100%;
  min-height: 250px;
  border: 1px dashed #e0e7ff;
  border-radius: var(--canvas-radius);
  background: #fff;
}
/* Các canvas con sẽ được JS định vị tuyệt đối bên trong */
.wp-coloring-canvas-outer .bg-canvas,
.wp-coloring-canvas-outer .paint-canvas {
  position: absolute;
  display: none;
}
.wp-coloring-canvas-outer.ready .bg-canvas,
.wp-coloring-canvas-outer.ready .paint-canvas {
  display: block;
}

/* --- Actions (Right Sidebar) --- */
.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.action-btn {
  width: var(--action-size);
  height: var(--action-size);
  border-radius: var(--action-radius);
  border: 1px solid #e6ebf2;
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--action-font);
  line-height: 1;
  font-weight: bold;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
  transition: all 0.2s;
}
.action-btn:hover {
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
  color: #4f46e5;
}
.action-btn:active {
  transform: translateY(1px);
}

/* --- Mobile / Responsive --- */
.wp-coloring-mobile-sidebar {
  display: none;
}
@media (max-width: 900px) {
  .wp-coloring-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    /* Thêm thuộc tính này để grid trên mobile chiếm đủ chiều cao */
    height: 100%;
    display: flex;
    flex-direction: column;
  }
  .wp-coloring-sidebar.right,
  .wp-coloring-sidebar.left {
    display: none;
  }

  .wp-coloring-shell {
    height: 80vh;
    display: flex;
    flex-direction: column;
  }

  .wp-coloring-main {
    flex-grow: 1;
    min-height: 0;
  }

  .wp-coloring-mobile-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px solid #e0e7ff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 12px;
    margin-top: 12px;
    flex-shrink: 0;
  }
  .mobile-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 5px;
  }
  .mobile-actions .action-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
    border-radius: 12px;
    flex-shrink: 0;
  }
  .mobile-palette {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 5px;
  }
  .mobile-palette .palette-btn {
    --swatch-size: 44px;
    --swatch-inner: 28px;
    flex-shrink: 0;
  }
}

.wp-coloring-error {
  color: #dc2626;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
}
