/* M.J. Artel Colouring Studio: a sheet of paper on the table, art supplies in a yellow crayon box.
   Same fonts, ink and crayons as the website (src/styles/global.css). */

@font-face {
  font-family: "Shantell Sans";
  src: url("fonts/shantell-800.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}
@font-face {
  font-family: "Shantell Sans";
  src: url("fonts/shantell-650.woff2") format("woff2");
  font-weight: 650;
  font-display: swap;
}
@font-face {
  font-family: "Andika";
  src: url("fonts/andika-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Andika";
  src: url("fonts/andika-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --table: #eef0f1;
  --paper: #ffffff;
  --ink: #161616;
  --muted: #4d4d4d;
  --line: 2px;
  --yellow: #fcd116;
  --sky: #8cd6f7;
  --blue: #197fe1;
  --orange: #f18f0c;
  --crayon: url("../assets/ui/crayon-specks.png") 0 0 / 256px 256px;
  --scribble: url("../assets/ui/scribble.png");
  --radius: 14px;
  --font-display: "Shantell Sans", "Trebuchet MS", system-ui, sans-serif;
  --font-ui: "Andika", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--table);
  color: var(--ink);
  font: 15px/1.45 var(--font-ui);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.studio {
  display: grid;
  height: 100vh;
  height: 100dvh;
  grid-template:
    "bar bar bar" auto
    "tray stage panel" minmax(0, 1fr)
    / 116px minmax(0, 1fr) 300px;
}

/* ---- top bar ---- */
.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--paper);
  border-bottom: 2.5px solid var(--ink);
  z-index: 2;
}
.brand {
  position: relative;
  z-index: 0;
  font: 800 21px/1 var(--font-display);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand > span {
  position: relative;
  z-index: 0;
}
.brand > span::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: .16em -.14em -.02em;
  background: var(--yellow);
  -webkit-mask: var(--scribble) center / 100% 100% no-repeat;
  mask: var(--scribble) center / 100% 100% no-repeat;
}
.brand small {
  font: 650 14px/1 var(--font-display);
  color: var(--ink);
  margin-left: 10px;
}
.page-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin: 0 auto;
  padding: 4px 6px 4px 4px;
  background: var(--paper);
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  text-align: left;
}
.page-btn:hover { background: #fff8d6; }
.page-btn img { width: 36px; height: 36px; border-radius: 6px; background: #fff; border: 1.5px solid var(--ink); object-fit: contain; }
.page-btn > span:nth-child(2) { display: flex; flex-direction: column; min-width: 0; }
#pageTitle { font: 650 15px/1.2 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#pageBook { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-btn-cta {
  margin-left: 6px;
  padding: 5px 10px;
  border: var(--line) solid var(--ink);
  border-radius: 9px;
  background: var(--crayon), var(--sky);
  color: var(--ink);
  font: 650 13px/1.2 var(--font-display);
  white-space: nowrap;
}
.actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 2px; height: 24px; background: var(--ink); opacity: .2; margin: 0 4px; }
.icon-btn, .text-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  border: var(--line) solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
}
.icon-btn { width: 40px; padding: 0; }
.text-btn { padding: 0 12px; font: 650 14px/1 var(--font-display); white-space: nowrap; }
.icon-btn svg, .text-btn svg { width: 20px; height: 20px; }
.icon-btn:hover:not(:disabled), .text-btn:hover { background: var(--crayon), var(--yellow); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.narrow-only { display: none; }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  padding: 6px;
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  box-shadow: 5px 5px 0 var(--ink);
  z-index: 10;
}
.menu-list button, .menu-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  text-align: left;
}
.menu-list button:hover, .menu-list a:hover { background: #fff3b8; }
.menu-list svg { width: 20px; height: 20px; }

/* ---- tool tray ---- */
.tray {
  grid-area: tray;
  overflow-y: auto;
  padding: 12px 10px;
  background: linear-gradient(rgb(252 209 22 / .45), rgb(252 209 22 / .45)), var(--crayon), var(--yellow);
  border-right: 2.5px solid var(--ink);
}
.tools { display: flex; flex-direction: column; gap: 8px; }
.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 4px 7px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  user-select: none;
  -webkit-user-select: none;
}
.tool input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tool .icon { display: block; color: var(--current, #e8772e); }
.tool svg { width: 46px; height: 46px; }
.tool .name { font: 650 11.5px/1.15 var(--font-display); text-align: center; }
.tool:hover { transform: translateY(-1px); }
.tool.is-on { background: var(--crayon), var(--sky); box-shadow: 4px 4px 0 var(--ink); transform: translate(-2px, -2px); }
.tool:focus-within { outline: 3px solid var(--blue); outline-offset: 2px; }
.tool kbd {
  position: absolute;
  top: 4px;
  right: 6px;
  font: 700 10px/1 var(--font-ui);
  color: var(--muted);
  opacity: .7;
}

/* ---- the page ---- */
.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--table);
  cursor: crosshair;
}
.stage.is-brush { cursor: none; }
.stage.is-panning, .stage.is-panning * { cursor: grab; }
.sheet {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgb(22 22 22 / .25), 0 18px 40px rgb(22 22 22 / .12);
  will-change: transform;
  visibility: hidden;
}
.sheet.is-ready { visibility: visible; }
.sheet canvas, .sheet img, .sheet .tooth {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.sheet img { mix-blend-mode: multiply; user-select: none; -webkit-user-drag: none; }
.sheet .tooth { mix-blend-mode: multiply; background-size: 512px 512px; }
.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(43, 38, 32, .8);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .85), inset 0 0 0 1px rgba(255, 255, 255, .85);
  pointer-events: none;
  will-change: transform;
}
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font: 650 20px var(--font-display);
  color: var(--muted);
  pointer-events: none;
}

/* ---- side panel ---- */
.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding: 16px 18px 20px;
  background: var(--paper);
  border-left: 2.5px solid var(--ink);
}
.panel h2 { margin: 0; font: 800 18px/1.2 var(--font-display); }
.panel h3 { margin: 0 0 6px; font: 650 13px/1.2 var(--font-display); color: var(--muted); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
#palette {
  padding: 6px 28px 6px 10px;
  border: var(--line) solid var(--ink);
  border-radius: 9px;
  background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23161616' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 9px center / 11px;
  appearance: none;
  -webkit-appearance: none;
  font-weight: 700;
  font-size: 14px;
}
.swatch-row { display: grid; grid-template-columns: 1fr; gap: 8px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.swatch {
  position: relative;
  display: block;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 2px var(--ink);
  cursor: pointer;
  transition: transform .1s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.swatch.is-on { box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 2px var(--paper), 0 0 0 4.5px var(--ink); }
.swatch:focus-within { outline: 3px solid var(--blue); outline-offset: 4px; }
.swatch.custom {
  width: 100%;
  aspect-ratio: auto;
  height: 40px;
  border-radius: 12px;
  background: conic-gradient(from 180deg, #e5432f, #fcd116, #5cb83c, #197fe1, #7e3fa3, #e5432f);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.swatch.custom::after {
  content: "Mix your own";
  position: absolute;
  inset: 5px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--current, var(--paper));
  color: var(--current-ink, var(--ink));
  font: 650 13px/1 var(--font-display);
}
.swatch.custom input { inset: 0; width: 100%; height: 100%; }
.swatches.is-off, .recent.is-off { opacity: .35; pointer-events: none; }
.recent { display: flex; gap: 8px; flex-wrap: wrap; }
.recent .swatch { width: 28px; }
.recent-wrap { margin-top: 14px; }
.note { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

.settings { display: flex; flex-direction: column; gap: 14px; }
.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend { grid-column: 1 / -1; font: 650 14px/1.3 var(--font-display); padding: 0; }
.size-dot { width: 40px; height: 40px; display: grid; place-items: center; }
.size-dot::before {
  content: "";
  width: var(--d, 10px);
  height: var(--d, 10px);
  max-width: 40px;
  max-height: 40px;
  border-radius: 50%;
  background: var(--current, var(--ink));
  box-shadow: inset 0 0 0 1.5px var(--ink);
}
.pressure-hint { min-width: 52px; text-align: right; font-size: 13px; color: var(--muted); }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2.5px solid var(--ink);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--ink); }
input[type="range"]::-moz-range-thumb {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--yellow);
  border: 2.5px solid var(--ink);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; grid-column: 1 / -1; }
.chip {
  position: relative;
  padding: 6px 11px;
  border: var(--line) solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font: 650 13px/1.2 var(--font-display);
  cursor: pointer;
}
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip.is-on { background: var(--crayon), var(--sky); }
.chip:focus-within { outline: 3px solid var(--blue); outline-offset: 2px; }
.switch { display: flex; align-items: center; gap: 10px; font: 650 14px/1.3 var(--font-display); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: none;
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: #c9cdd0;
  box-shadow: inset 0 0 0 2px var(--ink);
  transition: background .15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--ink);
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--sky); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--blue); outline-offset: 2px; }

.book-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  margin-top: auto;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--paper);
  border: var(--line) solid var(--ink);
}
.book-card img { width: 84px; height: auto; border-radius: 6px; border: 1.5px solid var(--ink); transform: rotate(-2deg); }
.book-card .eyebrow { margin: 0; font-size: 12.5px; color: var(--muted); }
.book-card h2 { margin: 2px 0 4px; font-size: 16px; }
.book-card p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.buy {
  display: inline-block;
  padding: 6px 12px;
  border: var(--line) solid var(--ink);
  border-radius: 10px;
  background: var(--crayon), var(--yellow);
  color: var(--ink);
  font: 650 13px/1.25 var(--font-display);
  text-decoration: none;
}
.buy:hover { background: var(--crayon), #ffe25a; }
.see-inside {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  text-decoration-color: var(--sky);
  text-decoration-thickness: 2.5px;
  text-underline-offset: .2em;
}
.small-print { margin: 0; font-size: 11.5px; color: var(--muted); }

/* ---- page picker ---- */
.picker {
  width: min(960px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 8px 8px 0 var(--ink);
}
.picker::backdrop { background: rgb(22 22 22 / .45); }
.picker-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--paper);
  border-bottom: 2.5px solid var(--ink);
  z-index: 1;
}
.picker-head h2 { margin: 0; font: 800 22px/1.2 var(--font-display); }
#pickerBody { padding: 8px 20px 24px; }
.picker-book { margin-top: 18px; }
.picker-book-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.picker-book-head img { width: 44px; height: 44px; border-radius: 6px; border: 1.5px solid var(--ink); object-fit: cover; }
.picker-book-head h3 { margin: 0; font: 800 18px var(--font-display); }
.picker-book-head a { margin-left: auto; font-weight: 700; font-size: 14px; color: var(--ink); text-decoration-color: var(--sky); text-decoration-thickness: 2.5px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.picker-page {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: #fff;
  text-align: left;
  font: 650 14px/1.25 var(--font-display);
}
.picker-page:hover { box-shadow: 4px 4px 0 var(--ink); transform: translate(-2px, -2px); }
.picker-page.is-current { background: var(--crayon), var(--sky); }
.picker-page img { width: 100%; aspect-ratio: 1; object-fit: contain; }
.picker-page .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font: 650 11px/1.3 var(--font-display);
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .25);
  z-index: 20;
}
.toast a { color: var(--yellow); font-weight: 700; }

.print-sheet { display: none; }

/* ---- tablets and phones: tray along the bottom, colours above it ---- */
@media (max-width: 999px) {
  .studio {
    grid-template:
      "bar" auto
      "stage" minmax(0, 1fr)
      "panel" auto
      "tray" auto
      / 100%;
  }
  .bar { gap: 8px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand { font-size: 18px; }
  .brand small, .page-btn-cta, .wide-only { display: none; }
  .narrow-only { display: block; }
  .page-btn { margin: 0; flex: 1; }
  .actions { margin-left: auto; }

  .tray {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 2.5px solid var(--ink);
  }
  .tools { flex-direction: row; gap: 8px; width: max-content; }
  .tool { flex: 0 0 70px; padding: 4px 2px 6px; }
  .tool svg { width: 38px; height: 38px; }
  .tool .name { font-size: 10.5px; }
  .tool kbd { display: none; }

  .panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-areas:
      "swatches swatches swatches swatches"
      "palette size pressure clip";
    align-items: center;
    gap: 6px 14px;
    padding: 8px 12px;
    overflow: visible;
    border-left: 0;
    border-top: 2.5px solid var(--ink);
  }
  .colours, .panel-head, .settings { display: contents; }
  .panel-head h2, .recent-wrap, .note, .book-card, .small-print { display: none !important; }
  #palette { grid-area: palette; font-size: 13px; }
  .swatch-row {
    grid-area: swatches;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 6px;
    scrollbar-width: none;
  }
  .swatch-row::-webkit-scrollbar { display: none; }
  .swatches { display: flex; gap: 8px; }
  .swatch { flex: 0 0 34px; width: 34px; }
  .swatch.custom { flex: 0 0 34px; height: 34px; border-radius: 50%; }
  .swatch.custom::after { content: ""; inset: 6px; border-radius: 50%; }
  #sizeField { grid-area: size; }
  #pressureField { grid-area: pressure; }
  #lookField { grid-area: size / size / pressure / pressure; grid-column: 2 / 4; }
  .switch { grid-area: clip; font-size: 13px; }
  .field { grid-template-columns: auto minmax(0, 1fr) auto; }
  .field > label, .field > legend { grid-column: auto; font-size: 13px; }
  .size-dot { width: 28px; height: 28px; }
  .size-dot::before { max-width: 28px; max-height: 28px; }
  .pressure-hint { display: none; }
  .chips { flex-wrap: nowrap; overflow-x: auto; grid-column: auto; }
  .chip { white-space: nowrap; }
}

@media (max-width: 560px) {
  .panel {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "swatches swatches"
      "size pressure"
      "palette clip";
  }
  #lookField { grid-column: 1 / -1; grid-row: 2; }
  .switch { justify-self: end; }
  #pageBook { display: none; }
}

@media (max-width: 999px) {
  /* Messages drop in under the top bar, clear of the colours and tools. */
  .toast { top: calc(64px + env(safe-area-inset-top)); bottom: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .studio, .picker, .toast { display: none !important; }
  .print-sheet { display: block; }
  .print-sheet img { display: block; width: 100%; height: auto; }
  @page { margin: 10mm; }
}
