/* style.css — a colouring book. The picture gets nearly all the screen; the
   colours sit under your thumb. */
:root { color-scheme: light; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; user-select: none;
  font-family: "Baloo 2", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #3a3340; background: #fdf6ee;
}
body { display: flex; flex-direction: column; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

#loading {
  position: fixed; inset: 0; z-index: 900; display: flex; align-items: center; justify-content: center;
  background: #f4703a; color: #fff; font-size: 20px; font-weight: 800;
}
#loading[hidden] { display: none; }

#top {
  flex: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: #f4703a; color: #fff;
}
.title { font-weight: 800; font-size: clamp(15px, 4vw, 20px); margin-right: auto; }
#nowcolour {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,.25); flex: none;
}
#top button {
  background: rgba(255,255,255,.22); border-radius: 999px; padding: 7px 12px;
  font-size: clamp(11px, 2.8vw, 14px); font-weight: 800; white-space: nowrap;
}
#top button:disabled { opacity: .4; }
#top button:active:not(:disabled) { transform: translateY(2px); }
@media (max-width: 560px) {
  .title { width: calc(100% - 40px); margin-right: 0; }
  #top button { flex: 1 1 auto; text-align: center; padding: 8px 6px; }
}

#paper {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  padding: 8px;
  background:
    linear-gradient(180deg, #fffdf8, #fdf3e6);
}
/* The pages are square. CSS aspect-ratio kept losing to the flex sizing on
   tall screens, so the frame is measured in script instead — one line, and it
   is right on every shape of screen. It also gives the zoom something to move. */
#paper { overflow: hidden; touch-action: none; }
#frame {
  flex: 0 0 auto; align-self: center;
  background: #fff; border: 4px solid #e8d6c2; border-radius: 14px;
  box-shadow: 0 6px 0 rgba(0,0,0,.06); overflow: hidden;
  transform-origin: center center; will-change: transform;
}
#art { width: 100%; height: 100%; display: block; }
#art .fill { cursor: pointer; transition: fill .12s ease; }
/* The whiskers, the cherry stalk, the icing lines: they are decoration drawn
   on top, and they were swallowing taps meant for the area underneath. */
#art path:not(.fill), #art line:not(.fill) { pointer-events: none; }
#art .fill.splash { animation: splash .3s ease; }
@keyframes splash { 0% { opacity: .35 } 100% { opacity: 1 } }

#palette {
  flex: none; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  padding: 8px 10px; background: #fff; border-top: 3px solid #f0dcc6;
}
.swatch {
  width: clamp(34px, 9vw, 44px); height: clamp(34px, 9vw, 44px); border-radius: 50%;
  border: 3px solid rgba(0,0,0,.12); box-shadow: 0 3px 0 rgba(0,0,0,.12);
  display: flex; align-items: center; justify-content: center; font-size: 17px;
}
.swatch.on { border-color: #2e2a33; transform: translateY(-3px); box-shadow: 0 5px 0 rgba(0,0,0,.18); }
.swatch:active { transform: translateY(1px); }
.swatch.rubber { background: #fff; }

#picker {
  flex: none; display: flex; gap: 6px; overflow-x: auto;
  padding: 7px 10px calc(9px + env(safe-area-inset-bottom));
  background: #fff8ef; border-top: 3px solid #f0dcc6;
}
.pic {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: #fff; border: 3px solid #f0dcc6; border-radius: 12px;
  padding: 5px 10px; min-width: 58px; box-shadow: 0 3px 0 rgba(0,0,0,.07);
}
.pic.on { border-color: #f4703a; background: #fff1e8; }
.picic { font-size: clamp(20px, 5.5vw, 26px); line-height: 1.1; }
.picnm { font-size: 9.5px; font-weight: 700; opacity: .6; }

/* “Just the picture” — the page gets out of the way */
body.showing #palette, body.showing #picker, body.showing #btn-undo,
body.showing #btn-clear, body.showing #nowcolour, body.showing .title { display: none; }
body.showing #top { background: transparent; }
body.showing #btn-show { background: rgba(0,0,0,.14); color: #3a3340; opacity: .55; margin-left: auto; }
body.showing #paper { padding: 0; }
body.showing #art { border-radius: 0; border-width: 0; max-width: none; }

/* the pages are fetched when you pick them, so there is a moment of nothing */
#paper.loading::after {
  content: '✏️'; font-size: 40px; opacity: .3; animation: tick 1s ease-in-out infinite;
}
@keyframes tick { 0%,100%{ transform: rotate(-8deg) } 50%{ transform: rotate(8deg) } }
#art .ink { pointer-events: none; }

/* ---------------------------------------------------------- the zoom bar -- */
#zoombar {
  flex: none; display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 6px 10px; background: #fff6ed; border-top: 3px solid #f0dcc6;
}
#zoombar button {
  background: #fff; border: 3px solid #f0dcc6; border-radius: 999px;
  padding: 6px 14px; font-size: clamp(13px, 3.2vw, 16px); font-weight: 800;
  box-shadow: 0 3px 0 rgba(0,0,0,.08);
}
#zoombar button:disabled { opacity: .35; }
#zoombar button:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
#z-level { font-weight: 800; font-size: clamp(12px, 3vw, 15px); min-width: 4ch; text-align: center; opacity: .7; }
.zhint { font-size: 11px; opacity: .5; font-weight: 700; }
@media (max-width: 560px) { .zhint { display: none; } }
body.zoomed #frame { cursor: grab; }
body.showing #zoombar { display: none; }

/* ------------------------------------------------------------- printing -- */
@media print {
  #top, #palette, #picker, #zoombar, #loading { display: none !important; }
  html, body { height: auto; overflow: visible; background: #fff; }
  #paper { padding: 0; background: #fff; overflow: visible; }
  #frame {
    width: 18cm !important; height: 18cm !important;
    border: none; box-shadow: none; border-radius: 0;
    transform: none !important; margin: 0 auto;
  }
  #art { width: 100%; height: 100%; }
  /* an unfilled area must print as white paper, not as nothing */
  #art .fill[fill="#ffffff"] { fill: #fff; }
  @page { margin: 1.2cm; }
}
