/* =========================
   Base reset
   ========================= */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

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

/* =========================================================
   FULL-WIDTH BREAKOUT
   Wrap app in: <div class="coloring-breakout">...</div>
   ========================================================= */
.coloring-breakout{
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);

  padding-left: 12px;
  padding-right: 12px;
  padding-top: 12px;
  padding-bottom: 12px;

  background: #fff;
}

/* =========================
   App shell
   ========================= */
.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px;
}

.header {
  text-align: center;
  margin-bottom: 10px;
}

.header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  line-height: 1.2;
}

.header p {
  margin: 0;
  color: #555;
  font-size: 0.95rem;
}

/* =========================
   Main layout
   ========================= */
:root {
  --header-offset: 180px; /* adjust once */
}

.workarea {
  display: flex;
  gap: 12px;
  align-items: stretch;

  height: calc(100vh - var(--header-offset, 120px));
  overflow: hidden;
}

/* =========================
   Sidebar
   ========================= */
.sidebar {
  width: 300px;
  flex: 0 0 300px;

  display: flex;
  flex-direction: column;

  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 10px;

  overflow: hidden;
}

/* =========================
   Palette
   ========================= */
.coloringsheet-app .palette {
  flex: 0 0 auto;
  height: min(56vh, 520px);
  overflow-y: auto;
  overflow-x: hidden;

  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;

  padding: 10px;
  border: 1px solid #e6e6e6;
  border-radius: 10px;
  background: #fafafa;
}

.coloringsheet-app .color-cell,
.coloringsheet-app .swatch {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 3px solid #e0e0e0;
  cursor: pointer;
  background: #fff;
  user-select: none;

  min-width: 38px;
  max-width: 56px;
  justify-self: center;
}

.coloringsheet-app .color-cell.selected,
.coloringsheet-app .swatch.selected {
  border-color: #111;
  outline: 3px solid rgba(0, 0, 0, 0.12);
  outline-offset: 0;
}

/* =========================
   Controls
   ========================= */
.controls {
  flex: 0 0 auto;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #eee;

  display: flex;
  flex-direction: column;
  gap: 10px;
}

.controls .row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.controls strong {
  font-size: 1rem;
}

.current-color-swatch,
.current {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid #111;
  background: #000;
}

.controls button {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: #eee;
  cursor: pointer;
  font-size: 1rem;
}

.controls button:hover { background: #ddd; }

.controls input[type="color"] {
  width: 48px;
  height: 38px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

/* =========================
   Canvas Area (KEY FIX)
   ========================= */
.canvas-wrapper,
.canvas {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;

  background: #fff;
  border: 1px solid #ddd;
  border-radius: 12px;
  padding: 10px;

  overflow: hidden;

  display: flex;
  align-items: center;
  justify-content: center;
}

/* SVG fits container completely */
#svg-holder,
#svg-holder svg,
#coloring-svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

#svg-holder svg,
#coloring-svg {
  object-fit: contain;
}

/* Make shapes clickable */
#coloring-svg path,
#coloring-svg rect,
#coloring-svg circle,
#coloring-svg ellipse,
#coloring-svg polygon,
#coloring-svg polyline {
  cursor: pointer;
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 900px) {

  .workarea {
    flex-direction: column;
    height: auto;
  }

  .sidebar {
    width: auto;
    flex: 0 0 auto;
  }

  .palette {
    grid-template-columns: repeat(8, 1fr);
  }

  .color-cell,
  .swatch {
min-width: 22px;
max-width: 34px;
  }

  .canvas-wrapper,
  .canvas {
    height: 70vh;
  }

  .controls button {
    width: auto;
  }
}

/* =========================
   Print
   ========================= */
@media print {
  body { background: #fff; }
  .sidebar, .header { display: none; }

  .canvas-wrapper,
  .canvas {
    border: 0;
    padding: 0;
    height: auto;
    overflow: visible;
  }
}

/* =========================
   Small UI helpers
   ========================= */
.coloringsheet-app .current-row{
  position: relative; /* anchor for the hidden picker */
}

.coloringsheet-app .picker-hidden{
  position: absolute;
  left: 90px;    /* tweak if you want */
  top: 50%;
  transform: translateY(-50%);

  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.coloringsheet-app .current{
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid #111;
}

.coloringsheet-app .swatch-custom{
  border: 3px solid #e0e0e0;
  background: conic-gradient(
    red, orange, yellow, lime, cyan, blue, magenta, red
  );
}

/* Sidebar must be allowed to shrink and manage internal scrolling */
.sidebar{
  height: 100%;
  min-height: 0;     /* CRITICAL: allows flex children to shrink */
  overflow: hidden;  /* keep rail clean; palette will scroll */
}

/* Palette should take remaining space and scroll */
.coloringsheet-app .palette{
  flex: 1 1 auto;    /* was flex: 0 0 auto */
  min-height: 0;     /* CRITICAL: enables overflow scrolling in flex layouts */
  height: auto;      /* remove the min(56vh,520px) cap behavior */
  overflow-y: auto;
}

/* Controls stay visible at the bottom */
.controls{
  flex: 0 0 auto;
}

