/* Colouring pad. Chooser: a grid of big picture tiles. Studio: tools | page | colours, all icon buttons.
   --btn is the tool/swatch size: as big as fits the screen height, never under the 64px tap minimum. */
:root { --cp-colour: #e8453c; }
.cp-main { --btn: clamp(64px, calc((100vh - 190px) / 8.4), 96px); --gap: clamp(6px, 1vh, 12px); padding-top: 12px; padding-bottom: 12px; }
.cp-main [hidden] { display: none !important; }

/* ---------- chooser ---------- */
.cp-chooser { width: min(100%, calc((100vh - 170px) * 16 / 9)); }
.cp-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(10px, 1.6vw, 22px); }
.cp-tile {
  display: grid; place-items: center; aspect-ratio: 4 / 3; min-height: var(--tap); padding: 6px;
  border: 0; border-radius: var(--radius); background: #fff; cursor: pointer; touch-action: manipulation;
  box-shadow: 0 0 0 3px var(--sand-deep), 0 8px 22px rgba(22,44,51,0.12);
}
.cp-tile svg { width: 100%; height: 100%; display: block; border-radius: 12px; }
.cp-tile:active { transform: scale(0.97); }
.cp-tile-blank { background: var(--sand); }
.cp-tile-blank svg { width: 46%; height: 46%; fill: none; stroke: var(--sea); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }

/* ---------- studio ---------- */
.cp-studio { display: flex; align-items: stretch; gap: clamp(10px, 1.6vw, 24px); width: 100%; height: 100%; min-height: 0; }

.cp-tools {
  flex: none; display: grid; grid-template-columns: repeat(2, var(--btn)); grid-auto-rows: var(--btn);
  gap: var(--gap); align-content: center;
}
.cp-tools > .cp-btn { grid-column: 1; }
.cp-sizes { grid-column: 2; grid-row: 3 / span 3; display: grid; grid-auto-rows: var(--btn); gap: var(--gap); transition: opacity 0.2s; }
.cp-sizes.is-off { opacity: 0.4; }
.cp-btn {
  display: grid; place-items: center; width: var(--btn); height: var(--btn); padding: 0;
  border: 0; border-radius: 18px; background: var(--sand-deep); color: var(--sea-deep); cursor: pointer;
  touch-action: manipulation; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.08);
}
.cp-btn svg { width: 58%; height: 58%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cp-btn svg .ink { fill: var(--cp-colour); stroke: currentColor; }
.cp-btn:active { transform: scale(0.94); }
.cp-btn[aria-pressed="true"] { background: var(--sea-deep); color: var(--cream); box-shadow: 0 0 0 4px var(--coral); }
.cp-btn[aria-disabled="true"] { opacity: 0.4; }
.cp-pictures { background: var(--sea); color: var(--cream); }
.cp-done { background: var(--coral); color: #fff; }
.cp-done svg { fill: #ffd23f; stroke: #fff; }
.cp-size span { display: block; border-radius: 50%; background: var(--cp-colour); box-shadow: 0 0 0 2px rgba(0,0,0,0.25); }
.cp-size[data-size="small"] span { width: 18%; height: 18%; }
.cp-size[data-size="medium"] span { width: 36%; height: 36%; }
.cp-size[data-size="large"] span { width: 62%; height: 62%; }

.cp-stage-wrap { flex: 1; min-width: 0; min-height: 0; display: grid; place-items: center; }
.cp-stage {
  position: relative; width: 100%; aspect-ratio: var(--ratio, 4 / 3); background: #fff; overflow: hidden;
  border-radius: 14px; box-shadow: 0 0 0 3px var(--sand-deep), 0 14px 36px rgba(22,44,51,0.18);
  touch-action: none; cursor: crosshair;
}
.cp-stage[data-tool="fill"] { cursor: pointer; }
.cp-stage > * { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cp-paint, .cp-lines { pointer-events: none; }
.cp-fills { pointer-events: none; }
.cp-fills path, .cp-fills rect { transition: fill 0.18s ease-out; }

.cp-palette {
  flex: none; display: grid; grid-template-columns: repeat(2, var(--btn)); grid-auto-rows: var(--btn);
  gap: var(--gap); align-content: center;
}
.cp-swatch {
  width: var(--btn); height: var(--btn); padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--swatch); touch-action: manipulation;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,0.14), 0 0 0 2px rgba(23,29,36,0.18);
  transition: transform 0.12s;
}
.cp-swatch:active { transform: scale(0.92); }
.cp-swatch[aria-pressed="true"] { transform: scale(1.06); box-shadow: inset 0 -5px 0 rgba(0,0,0,0.14), 0 0 0 4px #fff, 0 0 0 8px var(--sea-deep); }
.cp-palette.is-hint .cp-swatch { animation: cp-wiggle 0.5s ease 2; }
@keyframes cp-wiggle { 25% { transform: rotate(-12deg) scale(1.05); } 75% { transform: rotate(12deg) scale(1.05); } }

@media (prefers-reduced-motion: reduce) {
  .cp-palette.is-hint .cp-swatch { animation: none; }
  .cp-fills path, .cp-fills rect, .cp-swatch { transition: none; }
}
/* Portrait or narrow: palette goes to 4 columns so it stays tappable. */
@media (max-aspect-ratio: 5/4) {
  .cp-palette { grid-template-columns: repeat(4, var(--btn)); }
  .cp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cp-chooser { width: 100%; }
}
