/* A quiet grey room with one light object in it: the palette. The chrome is
   deliberately colourless, because a warm brown interface makes the painting
   next to it read cooler and lighter than it really is -- the same reason
   galleries and every serious imaging tool use a neutral mid grey. The only
   colour in this interface is the paint you are holding. */

:root {
  /* the wall behind the painting */
  --stage: #3a3a3d;

  /* panels, darker than the wall so they recede behind the picture */
  --p0: #161618;
  --p1: #1e1e21;
  --p2: #27272b;
  --p3: #323237;
  --line: #101012;

  /* the palette board -- the one light surface */
  --board: #c9c2b4;
  --board-rim: #8c8375;
  --board-ink: #2a2621;

  --t1: #ebe9e5;
  --t2: #a6a39e;
  --t3: #75726e;

  --sel: #f2efe9;
  --focus: #7fb2c4;

  --pop: 0 10px 30px rgba(0, 0, 0, 0.5);
  --r: 8px;
  --r-sm: 5px;

  --ui: ui-sans-serif, -apple-system, "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --rail: 88px;
  --side: 344px;
  --top: 48px;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--p0);
  color: var(--t1);
  font: 13px/1.5 var(--ui);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail) 1fr var(--side);
  grid-template-rows: var(--top) 1fr;
  grid-template-areas:
    "top  top   top"
    "rail stage side";
}

:where(button, a, input, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--p1);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 500 17px/1 var(--display);
  color: var(--t1);
  letter-spacing: 0.01em;
  padding-right: 6px;
  white-space: nowrap;
}
.wordmark svg {
  width: 17px;
  height: 17px;
  fill: var(--t2);
  flex: none;
}

.bar-group {
  display: flex;
  gap: 4px;
}
.bar-spacer {
  flex: 1;
}

.btn {
  font: inherit;
  font-size: 12.5px;
  color: var(--t1);
  background: var(--p2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  height: 32px;
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease;
}
.btn:hover:not(:disabled) {
  background: var(--p3);
}
.btn:active:not(:disabled) {
  background: #202024;
}
.btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.btn.icon {
  padding: 0;
  width: 32px;
  font-size: 14px;
  line-height: 1;
}
.btn.small {
  height: 26px;
  padding: 0 9px;
  font-size: 11.5px;
}
.btn.ghost {
  background: transparent;
  border-color: #3a3a40;
  color: var(--t2);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--p2);
  color: var(--t1);
}
.btn.primary {
  background: #edeae4;
  color: #1a1a1c;
  border-color: #edeae4;
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) {
  background: #fff;
}
.btn.big {
  height: 44px;
  width: 100%;
  font-size: 14px;
}
.btn.zoom {
  min-width: 56px;
  font-variant-numeric: tabular-nums;
}
.narrow-only {
  display: none;
}

.menu {
  position: fixed;
  min-width: 240px;
  background: var(--p2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--pop);
  padding: 5px;
  z-index: 60;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 12.5px;
  color: var(--t1);
  background: none;
  border: 0;
  border-radius: var(--r-sm);
  padding: 8px 9px;
  cursor: pointer;
}
.menu button:hover {
  background: var(--p3);
}
.menu button small {
  display: block;
  color: var(--t3);
  font-size: 11px;
  margin-top: 2px;
}
.menu hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 5px 2px;
}

/* ------------------------------------------------------------- tool rail */

.rail {
  grid-area: rail;
  background: var(--p0);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 8px 0 16px;
  scrollbar-width: thin;
}

.rail-group-label {
  font-size: 9.5px;
  color: var(--t3);
  text-align: center;
  margin: 8px 0 2px;
}

.tool {
  position: relative;
  display: block;
  width: 76px;
  margin: 1px auto;
  padding: 3px 2px 2px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  cursor: pointer;
  color: var(--t2);
  text-align: center;
}
.tool:hover {
  background: var(--p2);
}
.tool[aria-pressed="true"] {
  background: var(--p3);
  border-color: var(--sel);
  color: var(--t1);
}
.tool[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-radius: 2px;
  background: var(--sel);
}
.tool canvas {
  display: block;
  width: 66px;
  height: 30px;
  margin: 0 auto;
}
.tool span {
  display: block;
  font-size: 10.5px;
  margin-top: 2px;
}
.tool kbd {
  position: absolute;
  top: 3px;
  left: 5px;
  font: inherit;
  font-size: 9px;
  color: var(--t3);
  opacity: 0;
  transition: opacity 0.12s;
}
.rail:hover kbd {
  opacity: 1;
}

/* ----------------------------------------------------------------- stage */

.stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
}

.easel {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  cursor: none;
  outline: none;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
}
.easel.panning {
  cursor: grabbing;
}

/* A true-size outline of the tool, so you can see what you are about to lay
   down before you lay it down. The cheapest thing that makes a pointer feel
   like an object you are holding. */
.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 3;
  border: 1px solid rgba(255, 255, 255, 0.75);
  outline: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 2px;
  transform-origin: 50% 50%;
}
.brush-cursor.round {
  border-radius: 50%;
}
/* On the palette a finger covers the paint it is mixing, so the mark has to
   read from under it: bright, and visible against both the board and dark
   pigment. */
#palette-cursor {
  border-color: rgba(255, 255, 255, 0.95);
  outline-color: rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 80%);
  background: rgba(22, 22, 24, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--t1);
  box-shadow: var(--pop);
  z-index: 8;
  opacity: 1;
  transition: opacity 0.35s ease;
}
.toast[hidden] {
  display: none;
}
.toast.fading {
  opacity: 0;
}

.firstrun {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 22, 24, 0.34);
  backdrop-filter: blur(2px);
  z-index: 10;
}
.firstrun[hidden] {
  display: none;
}
.firstrun .card {
  width: min(420px, 84%);
  background: var(--p1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px 26px 20px;
  box-shadow: var(--pop);
  text-align: center;
}
.firstrun h1 {
  margin: 0 0 10px;
  font: 500 22px/1.25 var(--display);
  color: var(--t1);
}
.firstrun p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--t2);
}
.firstrun-alts {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.firstrun-alts .btn {
  flex: 1;
}
.linkish {
  display: block;
  width: 100%;
  margin-top: 16px;
  background: none;
  border: 0;
  font: inherit;
  font-size: 13px;
  color: var(--t2);
  cursor: pointer;
}
.linkish:hover {
  color: var(--t1);
}
.linkish.quiet {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--t3);
}

/* ------------------------------------------------------------ side panel */

.side {
  grid-area: side;
  background: var(--p1);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 12px 12px 24px;
}

/* the palette board */

.board {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr;
  grid-template-rows: 44px 1fr;
  gap: 4px;
  padding: 7px;
  background: var(--board);
  border: 1px solid var(--board-rim);
  border-radius: 14px 14px 10px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.dabs {
  display: grid;
  gap: 3px;
  place-items: center;
}
.dabs.lights {
  grid-area: 1 / 2;
  grid-auto-flow: column;
}
.dabs.darks {
  grid-area: 2 / 1;
  grid-auto-flow: row;
}

/* Squeezed paint, not a colour chip. The specular highlight is what lets
   seven near-black pigments tell each other apart -- on the old dark panel
   they were a row of identical black squares. */
.dab {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  background:
    radial-gradient(42% 38% at 33% 26%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 62%),
    radial-gradient(74% 74% at 50% 56%, var(--c) 36%, color-mix(in oklab, var(--c) 72%, #000) 100%);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.45),
    inset 0 -3px 5px rgba(0, 0, 0, 0.35),
    inset 0 2px 3px rgba(255, 255, 255, 0.16);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.dab:hover {
  transform: translateY(-2px) scale(1.07);
  z-index: 2;
}
.dab[aria-pressed="true"] {
  box-shadow:
    0 0 0 2px var(--board-ink),
    0 3px 8px rgba(0, 0, 0, 0.5),
    inset 0 -3px 5px rgba(0, 0, 0, 0.35);
}
/* Transparent pigments read as glazes: the board shows through them. */
.dab[data-glaze] {
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.3),
    inset 0 -2px 4px rgba(0, 0, 0, 0.22),
    inset 0 2px 4px rgba(255, 255, 255, 0.26);
  opacity: 0.9;
}

.palette-slot {
  grid-area: 2 / 2;
  position: relative;
  height: 236px;
  border-radius: var(--r-sm);
  overflow: hidden;
  pointer-events: auto;
  touch-action: none;
  cursor: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
#palette-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.board-hint {
  position: absolute;
  inset: auto 8px 7px 8px;
  text-align: center;
  font-size: 10.5px;
  color: rgba(42, 38, 33, 0.5);
  pointer-events: none;
  transition: opacity 0.3s;
}
.board-hint.gone {
  opacity: 0;
}
.board-wipe {
  position: absolute;
  right: 10px;
  bottom: 8px;
  width: 24px;
  height: 22px;
  border: 0;
  border-radius: var(--r-sm);
  background: rgba(42, 38, 33, 0.12);
  color: var(--board-ink);
  font-size: 12px;
  cursor: pointer;
  z-index: 3;
}
.board-wipe:hover {
  background: rgba(42, 38, 33, 0.24);
}

/* what's on the brush */

.brush-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 12px 0 4px;
}
.current-dab {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: none;
  background: #555;
  box-shadow:
    inset 0 -3px 5px rgba(0, 0, 0, 0.35),
    inset 0 2px 3px rgba(255, 255, 255, 0.18),
    0 1px 3px rgba(0, 0, 0, 0.45);
}
.load {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}
.load-bar {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: #0e0e10;
  overflow: hidden;
}
.load-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--t2);
  transition: width 0.15s;
}
.load-text {
  font-size: 11px;
  color: var(--t3);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* blocks & disclosures */

.block {
  padding: 14px 0 4px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.block h2 {
  margin: 0 0 4px;
  font: 500 15px/1.25 var(--display);
  color: var(--t1);
}
.blurb {
  margin: 0 0 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--t2);
}
.field-label {
  display: block;
  font-size: 11px;
  color: var(--t3);
  margin-bottom: 7px;
}
.mediums {
  display: flex;
  gap: 6px;
}
.mediums .btn {
  flex: 1;
  padding: 0 4px;
  font-size: 11.5px;
}

.disclosure {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 10px;
}
.disclosure summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--t2);
  list-style: none;
  padding: 2px 0;
}
.disclosure summary::-webkit-details-marker {
  display: none;
}
.disclosure summary::before {
  content: "▸ ";
  color: var(--t3);
}
.disclosure[open] summary::before {
  content: "▾ ";
}
.disclosure summary:hover {
  color: var(--t1);
}
.disclosure .sliders {
  padding-top: 10px;
}

/* sliders */

.sliders {
  display: grid;
  gap: 11px;
}
.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: center;
}
.slider label {
  font-size: 11.5px;
  color: var(--t2);
}
.slider output {
  font-size: 11px;
  color: var(--t3);
  font-variant-numeric: tabular-nums;
}
.slider input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  height: 16px;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  cursor: pointer;
}
.slider input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: #0e0e10;
}
.slider input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: #0e0e10;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--t1);
  border: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.slider input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--t1);
  border: 0;
}
.checkrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--t2);
}
.checkrow input {
  accent-color: var(--t1);
}

/* --------------------------------------------------------------- lessons */

.lessons {
  position: absolute;
  top: var(--top);
  right: 0;
  bottom: 0;
  width: var(--side);
  background: var(--p1);
  border-left: 1px solid var(--line);
  box-shadow: -14px 0 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  z-index: 30;
}
.lessons[hidden] {
  display: none;
}
.lessons header {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.lessons header h2 {
  margin: 0;
  flex: 1;
  font: 500 15px/1.25 var(--display);
  color: var(--t1);
}
.lesson-picker {
  display: flex;
  gap: 5px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.lesson-picker .btn.active {
  border-color: var(--sel);
  color: var(--t1);
}
.lesson-steps {
  margin: 0;
  padding: 6px 10px 24px;
  overflow-y: auto;
  list-style: none;
  counter-reset: step;
}
.lesson-steps li {
  counter-increment: step;
  position: relative;
  padding: 10px 10px 11px 34px;
  border-radius: var(--r);
  cursor: pointer;
  border: 1px solid transparent;
}
.lesson-steps li::before {
  content: counter(step);
  position: absolute;
  left: 8px;
  top: 10px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  background: var(--p3);
  color: var(--t2);
}
.lesson-steps li:hover {
  background: var(--p2);
}
.lesson-steps li.active {
  background: var(--p2);
  border-color: #45454b;
}
.lesson-steps b {
  display: block;
  font: 500 13.5px/1.3 var(--display);
  margin-bottom: 3px;
  color: var(--t1);
}
.lesson-steps p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--t2);
}
.lesson-steps .chips {
  display: flex;
  gap: 5px;
  margin-top: 7px;
  flex-wrap: wrap;
  align-items: center;
}
.lesson-steps .chips i {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.4);
}
.lesson-steps .chips em {
  font-style: normal;
  font-size: 10.5px;
  color: var(--t3);
}

/* ----------------------------------------------------------------- fatal */

#fatal {
  position: fixed;
  inset: 0;
  z-index: 99;
  display: grid;
  place-items: center;
  background: var(--p0);
  padding: 24px;
}
#fatal[hidden] {
  display: none;
}
.fatal-card {
  max-width: 520px;
  background: var(--p1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px 26px;
}
.fatal-card h1 {
  margin: 0 0 10px;
  font: 500 18px/1.25 var(--display);
  color: var(--t1);
}
.fatal-card p {
  margin: 0;
  color: var(--t2);
  line-height: 1.6;
  white-space: pre-wrap;
  font-size: 12.5px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1180px) {
  :root {
    --side: 320px;
    --rail: 80px;
  }
  .tool {
    width: 66px;
  }
  .tool canvas {
    width: 58px;
    height: 38px;
  }
}

@media (max-width: 900px) {
  :root {
    --rail: 62px;
    --side: 0px;
  }
  #ui {
    grid-template-columns: var(--rail) 1fr;
    grid-template-areas:
      "top  top"
      "rail stage";
  }
  .wordmark {
    font-size: 0;
    gap: 0;
  }
  .wordmark svg {
    width: 20px;
    height: 20px;
  }
  .narrow-only {
    display: inline-block;
  }
  /* The bar wraps onto a second row instead of scrolling sideways. A bar you
     have to swipe hides Save and Lessons off the right-hand end, and a
     sideways-scrolling bar over the GL canvas also left an unpainted strip
     along the bottom of the screen in some browsers. Wrapping avoids both. */
  #ui {
    grid-template-rows: auto 1fr;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
    min-height: var(--top);
  }
  .topbar .btn {
    height: 44px;
    flex: none;
  }
  .topbar .btn.icon {
    width: 44px;
    font-size: 16px;
  }
  /* A palette is naturally held low, and a bottom sheet is thumb-reachable. */
  .side {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--sheet, 62vh);
    border-left: 0;
    border-top: 1px solid var(--line);
    transform: translateY(100%);
    transition: transform 0.22s ease;
    z-index: 25;
  }
  .side.open {
    transform: none;
  }
  .lessons {
    top: 0;
    width: min(340px, 100%);
    z-index: 40;
  }
  .tool {
    width: 54px;
  }
  .tool canvas {
    width: 46px;
    height: 32px;
  }
}

/* The tool paints itself; say so while it is working. */
.btn.busy {
  background: var(--accent, #c8743a);
  color: #fff;
}
.btn.busy::after {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* ------------------------------------------------ what is on the bristles */

/* A picture of the bed, not a flat swatch: a tool can carry two colours and
   you cannot use that if you cannot see it. */
.current-dab {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, #2a2a2c 25%, transparent 25%, transparent 75%, #2a2a2c 75%) 0 0 / 8px 8px,
    linear-gradient(45deg, #2a2a2c 25%, #323234 25%, #323234 75%, #2a2a2c 75%) 4px 4px / 8px 8px;
  flex: none;
  image-rendering: auto;
}

.dip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 10px;
}
.dip-choices {
  display: flex;
  gap: 3px;
  background: var(--p0);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
}
.dip {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--t2);
  font: 500 11px/1 var(--ui);
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.dip:hover {
  color: var(--t1);
}
.dip[aria-pressed='true'] {
  background: var(--p2);
  color: var(--t1);
}

/* ------------------------------------------------- reaching the palette */

/* On a phone the top bar scrolls, and a button you have to scroll to find is a
   button that does not exist. The palette is the one thing you cannot paint
   without, so it gets a thumb-reachable place of its own. */
@media (max-width: 900px) {
  .btn.narrow-only#btn-panels {
    position: fixed;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    padding: 12px 18px;
    border-radius: 24px;
    font-weight: 600;
    background: var(--accent, #c8743a);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.45);
  }
  .side.open ~ .stage .btn.narrow-only#btn-panels,
  body:has(.side.open) .btn.narrow-only#btn-panels {
    bottom: calc(var(--sheet, 62vh) + 14px);
  }
  .dip-row {
    padding-bottom: 14px;
  }
}

/* The dropper's cursor. It points at one pixel rather than covering an area,
   so it is a crosshair at a fixed size, not a footprint that tracks the size
   slider. The base .brush-cursor sets a border and an outline, which would
   draw a box around the crosshair, so both are cleared here. */
.brush-cursor.picking {
  border: 0;
  outline: 0;
  border-radius: 0;
  background:
    linear-gradient(#fff, #fff) center / 1.5px 100% no-repeat,
    linear-gradient(#fff, #fff) center / 100% 1.5px no-repeat;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.9));
}

/* --------------------------------------------------- touch-sized controls */

/* Below 900px wide this is almost always a phone or a tablet held in a hand,
   so every control gets a finger-sized target (44px or more). The desktop
   layout above is left exactly as it was. */
@media (max-width: 900px) {
  .btn.small,
  .mediums .btn,
  .lesson-picker .btn,
  .firstrun-alts .btn {
    height: 44px;
    font-size: 12.5px;
  }
  .lessons header .btn.icon {
    width: 44px;
    height: 44px;
  }
  .dab {
    width: 44px;
    height: 44px;
  }
  .board {
    grid-template-columns: 52px 1fr;
    grid-template-rows: 52px 1fr;
  }
  .palette-slot {
    height: auto;
    min-height: 236px;
  }
  .board-wipe {
    width: 44px;
    height: 44px;
    font-size: 15px;
  }
  .dip {
    min-height: 44px;
    padding: 0 12px;
    font-size: 12px;
  }
  .disclosure summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    font-size: 13px;
  }
  .disclosure summary::before {
    margin-right: 4px;
  }
  .slider input[type="range"] {
    height: 44px;
  }
  .slider input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
    margin-top: -10.5px;
  }
  .slider input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }
  .checkrow {
    min-height: 44px;
  }
  .checkrow input {
    width: 22px;
    height: 22px;
  }
  .linkish {
    min-height: 44px;
    margin-top: 8px;
  }
  .linkish.quiet {
    margin-top: 0;
  }
  .menu button {
    min-height: 44px;
    padding: 10px 12px;
  }
}

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

/* On a phone the tool rail moves under the canvas as a row you can swipe, so
   the painting gets the full width of the screen, and the palette opens as a
   shorter sheet that leaves the top of the picture in view. */
@media (max-width: 640px) {
  :root {
    --rail: 0px;
    --railh: 68px;
    --sheet: min(52vh, 440px);
  }
  #ui {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "top"
      "stage"
      "rail";
  }

  /* Two tidy rows: what you do to the painting, then undo, view, lessons and
     save. The first group is stretched so the rest always starts a new row. */
  .topbar .bar-group:first-of-type {
    flex: 1 1 calc(100% - 40px);
  }
  .topbar .bar-group:first-of-type .btn {
    flex: 1 1 auto;
    padding: 0 8px;
  }
  .topbar .btn {
    padding: 0 11px;
  }
  .btn.zoom {
    min-width: 50px;
  }

  .rail {
    grid-area: rail;
    display: flex;
    align-items: stretch;
    gap: 2px;
    height: calc(var(--railh) + env(safe-area-inset-bottom, 0px));
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-top: 1px solid var(--line);
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }
  .rail::-webkit-scrollbar {
    display: none;
  }
  .rail-group-label {
    flex: none;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    margin: 0 1px 0 4px;
    text-align: center;
  }
  .tool {
    flex: none;
    width: 56px;
    margin: 0;
    padding: 4px 2px 2px;
  }
  .tool canvas {
    width: 50px;
    height: 32px;
  }
  .tool[aria-pressed="true"]::after {
    top: auto;
    bottom: -1px;
    left: 12px;
    right: 12px;
    width: auto;
    height: 3px;
  }

  .btn.narrow-only#btn-panels {
    right: 12px;
    bottom: calc(var(--railh) + 12px + env(safe-area-inset-bottom, 0px));
    height: 48px;
    padding: 0 20px;
  }

  /* The palette sheet: colours in two rows of finger-sized dabs across the
     top, the mixing area under them at the board's own proportions. */
  .side {
    padding: 8px 6px 20px;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.45);
  }
  .board {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    gap: 4px;
    padding: 4px;
  }
  .dabs.lights,
  .dabs.darks {
    grid-area: auto;
    grid-auto-flow: column;
    gap: 2px;
  }
  .dabs.lights {
    grid-template-columns: repeat(5, minmax(0, 52px));
    justify-content: space-evenly;
  }
  .dabs.darks {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }
  .dab {
    width: 100%;
    max-width: 48px;
    height: auto;
    aspect-ratio: 1;
  }
  .palette-slot {
    grid-area: auto;
    min-height: 0;
    aspect-ratio: 900 / 520;
  }
  .brush-row {
    margin: 10px 4px 6px;
  }
  .dip-row {
    padding: 0 4px 12px;
  }
  .block,
  .disclosure {
    margin-left: 4px;
    margin-right: 4px;
  }

  .lessons {
    width: 100%;
    border-left: 0;
  }
}
