/* --------------------------------------------------------------------------
 * Kids' coloring book -- big targets, high contrast, no tiny text anywhere.
 * ----------------------------------------------------------------------- */

:root {
  --ink: #23262b;
  --paper: #fffdf7;
  --bg-1: #ffe9f2;
  --bg-2: #e6f2ff;
  --shadow: 0 6px 0 rgba(0, 0, 0, .12);
  --radius: 22px;

  /* A mouse has no crayon in its hand, so the pointer is the pen: nib at the
   * hotspot, barrel tinted by app.js with the color that is about to come out.
   * This copy is the plain one, in use until the first tint lands. */
  --pen-cursor: url("data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%2232%22%20height=%2232%22%20viewBox=%220%200%2032%2032%22%3E%3Cg%20stroke=%22%23ffffff%22%20stroke-linejoin=%22round%22%20paint-order=%22stroke%22%3E%3Cpath%20d=%22M2.5%2029.5%204.8%2023.3%2016.1%2012%2018.9%209.1%2022.9%2013.1%2020%2015.9%208.7%2027.2Z%22%20fill=%22%232b2b33%22%20stroke-width=%222.5%22/%3E%3Cpath%20d=%22M2.5%2029.5%204.8%2023.3%208.7%2027.2Z%22%20fill=%22%231b1b23%22%20stroke-width=%221.4%22/%3E%3Cpath%20d=%22M16.1%2012%2018.9%209.1%2022.9%2013.1%2020%2015.9Z%22%20fill=%22%231b1b23%22%20stroke-width=%221.4%22/%3E%3C/g%3E%3C/svg%3E") 2 30;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(150deg, var(--bg-1), var(--bg-2));
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ----------------------------------------------------------- picker screen */

.title {
  margin: 0;
  padding: 22px 16px 4px;
  text-align: center;
  font-size: clamp(26px, 5vw, 44px);
  letter-spacing: .5px;
}

.subtitle {
  margin: 0;
  padding: 0 16px 12px;
  text-align: center;
  font-size: clamp(16px, 2.6vw, 22px);
  opacity: .75;
}

/* holds the scrolling gallery and the rail that must NOT scroll with it */
.gallery-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.gallery {
  height: 100%;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 24px;
  padding: 10px 54px 30px 22px;   /* the wide right side is the rail's gutter */
  align-content: start;
  width: min(100%, 1240px);
  margin: 0 auto;
}

/* --------------------------------------------------------------- jump rail
 *
 * A hundred and twenty-four pictures is a long way to drag a finger, and the one
 * near the bottom is the one wanted twice a day. The numbers down the right edge
 * are the shortcut: tap one and the gallery goes there, or slide down them and
 * it follows. They brighten while the gallery is moving and dim again when it
 * stops, so they are findable without ever competing with the pictures.
 *
 * Each tick takes an equal share of the rail's height rather than only the room
 * its two digits need, so the thing a small finger has to hit is a tall box, not
 * a number. */
.jump-rail {
  position: absolute;
  top: 6px;
  bottom: 22px;
  right: 6px;
  width: 42px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  opacity: .35;
  transition: opacity .2s ease;
  touch-action: none;            /* sliding down the rail scrubs, never scrolls */
}

.jump-rail.showing { opacity: 1; }

.jump-tick {
  flex: 1;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: 15px;
  font-weight: bold;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 12px;
  padding: 0;
  cursor: pointer;
}

/* "Top" is three letters where the rest are two digits, so it takes the size it
   needs rather than making the rail wider for everything */
.jump-top { font-size: 13px; }

/* where the gallery is now */
.jump-tick.here {
  background: var(--paper);
  border: 3px solid var(--ink);
  box-shadow: var(--shadow);
}

/* Once there is work to come back to the gallery falls into two bands, and each
 * gets a label across the full width of the grid. */
.gallery-heading {
  grid-column: 1 / -1;
  margin: 4px 0 -8px 4px;
  font-size: clamp(20px, 2.4vw, 26px);
  opacity: .7;
}

.card {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: transform .12s ease;
}

.card:hover,
.card:focus-visible { transform: translateY(-5px) rotate(-1deg); outline: none; }
.card:active { transform: translateY(0); box-shadow: 0 2px 0 rgba(0, 0, 0, .12); }

.card svg { width: 100%; height: auto; display: block; }

.card-name {
  font-size: 22px;
  font-weight: bold;
}

/* Added to a home screen there is no address bar to reload from, so the way to a
 * newer version has to be on the page. It sits quietly in the corner: this is
 * for the grown-up who just changed something, not for the child. */
.refresh-btn {
  position: absolute;
  top: 14px;
  right: 16px;
  z-index: 2;
  font: inherit;
  font-size: 24px;
  line-height: 1;
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  opacity: .55;
  cursor: pointer;
}

.refresh-btn:hover { opacity: 1; }
.refresh-btn:active { transform: translateY(4px); box-shadow: none; opacity: 1; }


/* --------------------------------------------------------- coloring screen */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.toolbar-spacer { flex: 1; }

.drawing-name {
  font-size: 24px;
  font-weight: bold;
}

.tool-btn {
  font: inherit;
  font-size: 19px;
  padding: 12px 18px;
  min-height: 52px;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* the refresh in the bar is an icon on its own, so it does not need the width a
   text button wants */
#btn-refresh-bar { font-size: 25px; line-height: 1; padding: 10px 16px; }

.tool-btn:active { transform: translateY(4px); box-shadow: none; }
.tool-btn:disabled { opacity: .4; cursor: default; transform: none; }
.tool-btn-primary { background: #ffe066; }

.canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px 8px;
}

/* the frame is only there to hang the zoom buttons off the canvas corner */
.canvas-frame {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1;
  max-width: 100%;
}

.canvas {
  position: relative;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 100%;
  width: 100%;
  overflow: hidden;
  touch-action: none;            /* pinch/drag belong to us, not the browser */
}

/* The stage is what zoom and pan move. On a painting page it holds two layers --
 * the child's brushwork on a <canvas>, and the drawn outlines above it -- so the
 * paint can never cover a line no matter where it goes. Transforming the stage
 * rather than each layer keeps the two locked together. */
.stage {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;         /* app.js does the zoom/pan math in this corner space */
}

.stage svg,
.stage .paint-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage svg { pointer-events: none; }          /* re-enabled per region on fill pages */
.fill-mode .stage svg { pointer-events: auto; }

/* button-driven zoom glides; dragging and pinching must not lag behind the
 * finger, so app.js only adds .smooth for the button/keyboard path */
.stage.smooth { transition: transform .18s ease; }

.canvas.paint-mode { cursor: var(--pen-cursor), crosshair; }
.canvas.dropper-armed,
.canvas.dropper-armed .region { cursor: crosshair; }   /* waiting for a color to be tapped */

/* The gap between opening a picture and its file arriving. Usually too short to
 * see, so it is a word about what is happening rather than something spinning. */
.canvas .waiting {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #9aa0a6;
}

/* Being zoomed in does not change what a drag means -- it still paints on a
 * painting page, and on a fill page a click still colors -- so the pen stays.
 * Only a pan actually under way turns the pointer into a hand, and it has to
 * say so over the regions too, since those carry a cursor of their own. */
.canvas.panning,
.canvas.panning .region { cursor: grabbing; }

/* --------------------------------------------------------------- pan buttons
 *
 * A painting page gives one-finger drags to the brush, so dragging cannot also
 * pan -- and with a mouse there is no second finger to pan with at all. Hence a
 * pad: held down it pans continuously, and unlike a hand/pan mode it can never
 * be confused with painting, because it is a different control rather than a
 * different meaning for the same one. It appears only when there is somewhere to
 * pan to. */

.pan-pad {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: grid;
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: 4px;
}

.pan-up    { grid-area: up; }
.pan-left  { grid-area: left; }
.pan-right { grid-area: right; }
.pan-down  { grid-area: down; }

.pan-btn {
  font: inherit;
  font-size: 17px;
  line-height: 1;
  width: 48px;
  height: 48px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: none;            /* holding one must not scroll or select */
  user-select: none;
}

.pan-btn:active { transform: translateY(3px); box-shadow: none; }

/* ------------------------------------------------------------ zoom buttons */

.zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.zoom-btn {
  font: inherit;
  font-size: 26px;
  font-weight: bold;
  line-height: 1;
  width: 54px;
  height: 54px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.zoom-btn:active { transform: translateY(4px); box-shadow: none; }
.zoom-btn:disabled { opacity: .35; cursor: default; transform: none; }

.zoom-level { font-size: 17px; }

/* ------------------------------------------------------------- the drawing */

.region {
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linejoin: round;
  cursor: var(--pen-cursor), pointer;
}

.region:hover { filter: brightness(.93); }
.region:focus-visible { outline: none; stroke-width: 8; }

/* the background sheet: colorable, but it carries no outline of its own and
 * doesn't flash on hover -- a whole-page brightness shift is just noise */
.backdrop { stroke: none; }
.backdrop:hover { filter: none; }
.backdrop:focus-visible { stroke: var(--ink); stroke-width: 10; }

.ink  { fill: var(--ink); stroke: none; pointer-events: none; }

/* The blank sheet under a picture whose outlines are part of the art (see the
 * lion). It is not colorable, but it is NOT pointer-events:none either -- it is
 * what catches a tap that lands on an outline, so that tap quietly does nothing
 * instead of falling through and painting the whole background. */
.paper { fill: #ffffff; stroke: none; }

.line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: none;
}

/* a little pop when a region gets filled */
@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.popping {
  animation: pop .22s ease;
  transform-box: fill-box;
  transform-origin: center;
}

/* ----------------------------------------------------------------- brushes */

.brushes {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.brush {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
}

.brush span {                    /* the dot that shows how fat the brush is */
  display: block;
  background: var(--ink);
  border-radius: 50%;
}

.brush.selected {
  transform: scale(1.15);
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 9px var(--ink);
}

.card-art {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;           /* reserve the space before the picture is drawn */
}

.card-art canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.card-art svg {                  /* outlines stay above the brushwork */
  position: relative;
  z-index: 1;
}

.card-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 22px;
  line-height: 1;
}

/* ---------------------------------------------------------------- palette */

.palette-bar {
  position: relative;            /* the collapsed palette hangs off this */
  padding: 8px 16px 16px;
  flex: 0 0 auto;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.swatch {
  width: 58px;
  height: 58px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
  transition: transform .1s ease;
}

.swatch:hover { transform: scale(1.08); }

.swatch.selected {
  transform: scale(1.22);
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 9px var(--ink);
}

/* ------------------------------------------------------------ the ... menu
 *
 * Start Over and Save are the two rarest things on the bar and the two most
 * expensive to hit by accident, so on a small screen they fold away behind one
 * button. Everything keeps its id, so nothing else has to know. */

.tool-more { position: relative; display: contents; }
#btn-more { display: none; }

.tool-menu { display: contents; }

@media (max-width: 720px), (max-height: 620px) {
  .tool-more { display: block; }
  #btn-more { display: block; }

  .tool-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 6;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: var(--paper);
    border: 4px solid var(--ink);
    border-radius: 18px;
    box-shadow: var(--shadow);
  }

  .tool-menu.open { display: flex; }
  .tool-menu .tool-btn { width: 100%; white-space: nowrap; }
}

/* ------------------------------------------------- the collapsed color picker
 *
 * On a small screen sixteen swatches plus the brushes eat a third of the height,
 * and most of that is idle. There, the palette collapses to one button showing
 * the color in use, and opens as a sheet ON TOP of the picture -- never by
 * growing the bar, because resizing the canvas would mean re-rendering a
 * painting page's strokes every time it opened. A roomy screen keeps the
 * palette out where it is, since hiding it there costs a tap and buys nothing.
 */

.color-button {
  display: none;                 /* only on small screens; see the media query */
  width: 62px;
  height: 62px;
  margin: 0 auto;
  padding: 0;
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow), inset 0 0 0 4px var(--paper);
  cursor: pointer;
}

.color-button:active { transform: translateY(4px); box-shadow: inset 0 0 0 4px var(--paper); }

@media (max-width: 720px), (max-height: 620px) {
  .color-button { display: block; }

  .palette {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: calc(100% - 8px);
    z-index: 5;
    display: none;
    padding: 14px 12px;
    background: var(--paper);
    border: 4px solid var(--ink);
    border-radius: var(--radius);
    box-shadow: 0 -6px 0 rgba(0, 0, 0, .12);
  }

  .palette.open { display: flex; }
}

/* --------------------------------------------------------------- the mixer
 *
 * Sixteen fixed crayons cannot make a brown, a skin tone, or the muddy greens
 * these animals want, so there is a wheel as well. Hue runs around it and
 * saturation outwards; the strip underneath sets brightness, which is what
 * actually separates orange from brown. Four mixed colors are kept.
 */

.mixer {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% - 8px);
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 -6px 0 rgba(0, 0, 0, .12);
}

.wheel, .brightness {
  touch-action: none;
  cursor: crosshair;
  border-radius: 12px;
}

.wheel { border-radius: 50%; }
.brightness { border: 3px solid var(--ink); width: 240px; height: 34px; }

.mixer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.mix-preview {
  width: 52px;
  height: 52px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  box-shadow: var(--shadow);
}

.mix-slots { display: flex; gap: 8px; }

/* the slot the next color lands in wears the ring */
.mix-slots .swatch.target {
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 9px var(--ink);
}

/* an unused custom slot reads as an empty hole rather than a white crayon */
.swatch.empty {
  background: repeating-linear-gradient(45deg, #fff, #fff 6px, #e6e6e6 6px, #e6e6e6 12px);
}

/* the dropper: a blank crayon holding the pipette mark, so it reads as a tool
 * rather than as another color. Ringed while it waits for a tap on the picture,
 * the same ring a chosen crayon wears. */
.swatch.dropper {
  display: grid;
  place-items: center;
  background: var(--paper);
  color: var(--ink);
}

.swatch.dropper svg { width: 60%; height: 60%; display: block; }

.swatch.dropper.armed {
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 9px var(--ink);
}

/* on a phone the palette is a sheet that closes as the dropper arms, so the one
 * button still on screen has to say the dropper is waiting */
.color-button.armed {
  box-shadow: 0 0 0 5px var(--paper), 0 0 0 9px var(--ink),
              inset 0 0 0 4px var(--paper);
}

.swatch.mix {
  font-size: 26px;
  line-height: 1;
  background: conic-gradient(#e53935, #fdd835, #43a047, #29b6f6, #8e24aa, #e53935);
}

/* ------------------------------------------------------------ are you sure
 *
 * Start Over throws away everything on the page, and on a painting page there
 * is no undo that brings it back. The safe answer is the big coloured button,
 * because the person tapping may be three. */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(35, 38, 43, .45);
}

.modal-card {
  width: min(420px, 100%);
  padding: 24px 22px;
  text-align: center;
  background: var(--paper);
  border: 5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-title { margin: 0 0 6px; font-size: clamp(24px, 5vw, 32px); }
.modal-text { margin: 0 0 20px; font-size: 19px; opacity: .8; }

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-buttons .tool-btn { flex: 1 1 auto; min-width: 140px; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 20px;
  padding: 14px 24px;
  border-radius: 999px;
  z-index: 10;
}

/* --------------------------------------------------------------- phone-ish */

@media (max-width: 560px) {
  .swatch { width: 46px; height: 46px; }
  .zoom-btn { width: 46px; height: 46px; font-size: 22px; }
  .pan-btn { width: 40px; height: 40px; font-size: 14px; }
  .pan-pad { left: 8px; bottom: 8px; }
  .brush { width: 44px; height: 44px; }
  .brushes { gap: 9px; margin-bottom: 7px; }
  .zoom-level { font-size: 15px; }
  .zoom-controls { right: 8px; bottom: 8px; gap: 6px; }
  .palette { gap: 9px; }
  .tool-btn { font-size: 16px; padding: 10px 12px; min-height: 46px; }
  .drawing-name { display: none; }
}
