/* ==========================================================================
   Coloring Page Generator — the interface stays quiet so the artwork leads.
   ========================================================================== */

:root {
  --paper: #ffffff; /* the sheet */
  --desk: #eceae4; /* soft neutral desk behind the sheet */
  --desk-2: #e4e1d9;
  --ink: #1a1a19; /* UI text */
  --ink-soft: #8a877f; /* quiet labels */
  --line: #d8d5cc; /* hairlines */
  --focus: #3b6ea5; /* keyboard focus ring */
  /* Also bounded by the viewport height, so a much larger wordmark cannot
     push the sheet off the bottom of the screen. */
  --sheet-w: min(86vmin, 720px, calc((100dvh - 265px) * 0.7727));
}

* {
  box-sizing: border-box;
}

/* A class selector beats the UA stylesheet's [hidden] rule, so .controls and
   .toolbar stayed visible even when hidden was set — both menus showed at
   once. This puts the attribute back in charge. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

/* While marking up, the page itself must not move: on a touch screen a drag
   would otherwise scroll and rubber-band the whole site instead of drawing. */
html.editing,
body.editing {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}
body.editing {
  position: fixed;
  inset: 0;
  width: 100%;
}

/* The stage is built to fit the viewport, so a visible scrollbar only ever
   shows up as an empty gutter on the right. Hide it on every engine while
   keeping the page scrollable if something does overflow. */
html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

body {
  margin: 0;
  background: radial-gradient(
    120% 80% at 50% -10%,
    var(--desk) 0%,
    var(--desk-2) 100%
  );
  color: var(--ink);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

.stage {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 3.2vh, 34px);
  padding-top: max(clamp(20px, 4vh, 48px), env(safe-area-inset-top));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-bottom: max(clamp(20px, 4vh, 48px), env(safe-area-inset-bottom));
  padding-left: max(20px, env(safe-area-inset-left));
}

/* The wordmark is a name now, not a label, so it gets real typographic
   treatment: a serif, set at reading size. Still tuned to sit under the
   artwork in the visual hierarchy rather than compete with it. */
.wordmark {
  margin: 0;
  font-family:
    "Fraunces", "Didot", "Bodoni 72", "Bodoni MT", Baskerville,
    "Iowan Old Style", Georgia, ui-serif, serif;
  font-size: clamp(44px, 6.4vh, 74px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: #3b3833;
  user-select: none;
}

/* The sheet reads as a physical piece of paper resting on the desk. */
/* The sheet is a fixed-size stage. Pages are layered inside it and absolutely
   positioned, so swapping artwork cannot move anything on the page. */
.sheet {
  position: relative;
  contain: layout paint;
  width: var(--sheet-w);
  aspect-ratio: 816 / 1056; /* US Letter */
  background: var(--paper);
  border-radius: 6px;
  box-shadow:
    0 1px 1px rgba(30, 28, 24, 0.04),
    0 10px 24px -8px rgba(30, 28, 24, 0.22),
    0 30px 60px -30px rgba(30, 28, 24, 0.28);
  overflow: hidden;
}

.sheet svg,
.sheet .ink {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* The markup layer only accepts input while editing, so it never gets in the
   way of normal use — and it always sits above the artwork so it prints. */
.ink {
  pointer-events: none;
  touch-action: none;
}
/* Handles are decoration only: input always goes to the ink layer. */
.ui {
  pointer-events: none !important;
}
.editing .ink {
  pointer-events: auto;
  cursor: crosshair;
}
.editing .stage {
  touch-action: none;
}

/* Incoming page starts transparent and is faded up over the outgoing one. */
.sheet svg.enter {
  opacity: 0;
}
.sheet svg.fade {
  transition: opacity 260ms ease;
  opacity: 1;
}

/* Simple spinner shown while a page generates on the main thread. */
.loader {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--paper);
}
.loader.is-on {
  display: flex;
}
.loader::before {
  content: "";
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .loader::before {
    animation: none;
    border-top-color: var(--line);
    border-color: var(--ink);
    border-top-color: transparent;
  }
}

/* Two controls, nothing else. */
.controls {
  display: flex;
  gap: 12px;
}

/* Icon-only controls: square-ish pills with no labels, which keeps the row
   compact and lets the artwork carry the page. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 44px;
  height: 40px;
  padding: 0;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
  box-shadow: none;
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.ico {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------- markup -- */
/* Both rows live in a dock of constant height. Floating the toolbar kept the
   layout still but made it sit on top of the artwork; reserving the space
   instead keeps the sheet clear AND stops it shifting. */
.dock {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  width: 100%;
  padding: 0 8px;
}

/* Never let a row run off the side of the screen. */
.controls,
.toolbar {
  max-width: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(6px);
}

/* A cell that can raise a popover above itself. */
.cell {
  position: relative;
  display: inline-flex;
}

.pop {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 22px -10px rgba(30, 28, 24, 0.4);
  z-index: 30;
}

.sep {
  width: 1px;
  height: 22px;
  margin: 0 2px;
  background: var(--line);
}

.sep-tall {
  height: 26px;
  margin: 0 4px;
}

.tool,
.swatch,
.size {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease;
}

/* Only devices with a real pointer get hover. On a touch screen the hover
   state sticks after a tap, which made action buttons look permanently
   selected. */
@media (hover: hover) {
  .tool:hover,
  .swatch:hover,
  .size:hover {
    background: rgba(0, 0, 0, 0.05);
  }
  .btn:hover {
    background: #fff;
    border-color: #c7c3b9;
    box-shadow: 0 4px 12px -6px rgba(30, 28, 24, 0.3);
  }
}

.tool.is-on,
.swatch.is-on,
.size.is-on {
  background: #fff;
  border-color: #c7c3b9;
  box-shadow: 0 1px 3px rgba(30, 28, 24, 0.14);
}

.tool:focus-visible,
.swatch:focus-visible,
.size:focus-visible,
.btn-sm:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

#undo,
#reset,
#done {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* Solid state fills the icon, so the button shows what it will draw. */
#fillBtn.is-on .ico {
  fill: currentColor;
}

.dot {
  display: block;
  width: 17px;
  height: 17px;
  border-radius: 50%;
}
/* Thickness shows as a stroke sample, not a filled dot — two black circles
   side by side read as two colour swatches. */
.dot-size {
  width: 19px;
  border-radius: 99px;
  background: var(--ink);
}
.dot-black {
  background: #000;
}
.dot-white {
  background: #fff;
  border: 1px solid #b9b5ab;
}

.size span {
  display: block;
  background: var(--ink);
  border-radius: 50%;
}

.btn-sm {
  padding: 6px 13px;
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .sheet svg.fade {
    transition: none;
  }
  .btn {
    transition: none;
  }
}

/* ==========================================================================
   Print — only the artwork, at true US Letter size, centered.
   ========================================================================== */
@page {
  size: letter;
  margin: 0;
}

@media print {
  body {
    background: #fff;
  }
  .wordmark,
  .controls,
  .toolbar,
  .dock,
  .ui {
    display: none !important;
  }
  .stage {
    min-height: auto;
    padding: 0;
    gap: 0;
  }
  .sheet {
    width: 8.5in;
    height: 11in;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Eight cells must fit one row on a narrow phone without wrapping. */
@media (max-width: 420px) {
  .tool,
  .swatch,
  .size {
    width: 33px;
    height: 32px;
  }
  .toolbar {
    padding: 4px 5px;
    gap: 1px;
  }
  .ico {
    width: 15px;
    height: 15px;
  }
  .btn {
    width: 42px;
    height: 38px;
  }
  .controls {
    gap: 8px;
  }
}
