/* ==========================================================================
   Drawing panel — loaded only by draw.html

   The canvas owns the screen. Every control lives in a floating dock on top
   of it, so nothing but the artwork takes vertical space.
   ========================================================================== */

.draw-page main { padding-bottom: 32px; }

/* Header: the "back home" button must never crowd the wordmark */
.draw-page .site-header__inner { flex-wrap: wrap; row-gap: 8px; }
.draw-page .site-header .tool-btn { white-space: nowrap; }

@media (max-width: 430px) {
  .draw-page #backHome span { display: none; }
  .draw-page #backHome { padding-inline: 12px; }
}

/* Runs the full width of the workspace below it, so the page does not look
   like it has a narrow column of text over a wide canvas. */
.draw-intro {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--muted-2);
}

.text-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.text-link:hover { color: #ddc6ff; }

/* --- Workspace ---------------------------------------------------------- */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

/* The untransformed frame. Docks and the cursor are positioned against it. */
.stage-wrap {
  position: relative;
  overflow: hidden;
  height: clamp(420px, calc(100svh - 235px), 880px);
  background: #16141c;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
}

@media (max-width: 700px) {
  .stage-wrap { height: clamp(380px, calc(100svh - 185px), 760px); }
}

/* Only this element carries the zoom / rotation / pan transform. */
.stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  will-change: transform;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
  border-radius: 8px;
  background: #fff;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: #fff;
  touch-action: none;
}

/* The DOM cursor overlay replaces the native pointer while painting. */
.stage-wrap[data-cursor="none"] { cursor: none; }
.stage-wrap[data-cursor="fill"] { cursor: crosshair; }
.stage-wrap[data-cursor="pick"] { cursor: crosshair; }
.stage-wrap[data-cursor="lasso"] { cursor: crosshair; }
.stage-wrap[data-cursor="move"] { cursor: move; }
.stage-wrap[data-cursor="grab"] { cursor: grabbing; }
.stage-wrap .dock, .stage-wrap .view-chip { cursor: default; }
.stage-wrap .pop { cursor: default; }
.stage-wrap .hexrow input { cursor: text; }

/* --- Brush / eraser cursor ---------------------------------------------- */
.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 4;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: left, top, width, height;
}
.brush-cursor[hidden] { display: none; }

/* Brush: a solid dot in the chosen colour, hairline ring so it stays
   visible when you paint white on white. */
.brush-cursor--brush {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), 0 0 0 2px rgba(255, 255, 255, .5);
}

/* Eraser: hollow black ring showing exactly what will be wiped. */
.brush-cursor--eraser {
  background: transparent;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .65) inset, 0 0 0 1px rgba(255, 255, 255, .65);
}

/* --- Docks --------------------------------------------------------------- */
.dock {
  position: absolute;
  z-index: 6;
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: var(--radius-pill);
  background: rgba(18, 16, 24, .74);
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}

.dock--tools {
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
  align-items: center;
}

.dock--actions {
  right: 12px;
  top: 12px;
  flex-direction: row;
}

.dock-sep {
  width: 20px;
  height: 1px;
  margin: 3px auto;
  background: rgba(255, 255, 255, .16);
}

.dock-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color .16s var(--ease), color .16s var(--ease);
}
.dock-btn:hover { background: rgba(255, 255, 255, .12); }
.dock-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dock-btn .icon { width: 21px; height: 21px; }

.dock-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.dock-btn[aria-expanded="true"] { background: rgba(255, 255, 255, .16); }

.dock-btn--accent { color: var(--accent); }
.dock-btn--accent:hover { background: rgba(201, 166, 255, .2); }
.dock-btn:disabled { opacity: .5; cursor: progress; }

/* Colour swatch button */
.dock-btn--swatch:hover { background: rgba(255, 255, 255, .12); }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #c9a6ff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35), 0 0 0 3px rgba(0, 0, 0, .35);
}

/* "Hide tools" leaves only its own button behind. */
.stage-wrap.ui-hidden .dock--tools,
.stage-wrap.ui-hidden .pop,
.stage-wrap.ui-hidden .dock--actions .dock-btn:not(#toggleTools) {
  display: none;
}
.stage-wrap.ui-hidden .dock--actions { background: rgba(18, 16, 24, .5); }

/* --- View chip ----------------------------------------------------------- */
/* Zoom over rotation on two lines: keeps the pill narrow enough to sit beside
   the action dock on a phone, and the same height as it. */
.view-chip {
  position: absolute;
  z-index: 6;
  left: 12px;
  top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 13px 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(18, 16, 24, .74);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.view-chip[hidden] { display: none; }
.view-chip:hover { border-color: rgba(255, 255, 255, .3); }
.view-chip .icon { width: 17px; height: 17px; color: var(--muted); }

.view-chip__vals {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  line-height: 1.1;
}
.view-chip__vals span:last-child { font-size: 11.5px; color: var(--muted); }

/* --- Status toast -------------------------------------------------------- */
.toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: 16px;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(18, 16, 24, .88);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* --- Popovers ------------------------------------------------------------ */
.pop {
  position: absolute;
  z-index: 7;
  left: 64px;
  top: 50%;
  transform: translateY(-50%);
  width: 246px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(22, 20, 28, .94);
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .5);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.pop[hidden] { display: none; }

.pop__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.pop__head--sub { margin-top: 12px; }

.pop__head-actions { display: inline-flex; align-items: center; gap: 2px; }

.pop__close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin: -4px -4px -4px 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.pop__close:hover { background: rgba(255, 255, 255, .1); color: var(--text); }
.pop__close .icon { width: 15px; height: 15px; }
.pop__close[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Saturation / brightness field */
.sv {
  position: relative;
  height: 132px;
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
  background:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, var(--hue-color, #c9a6ff));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.sv__knob,
.hue__knob {
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 1px 4px rgba(0, 0, 0, .5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Hue strip */
.hue {
  position: relative;
  height: 14px;
  margin-top: 12px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  touch-action: none;
  background: linear-gradient(to right,
    #f00 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .14);
}
.hue__knob { top: 50%; }

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-top: 12px;
}
.swatches button {
  aspect-ratio: 1;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18);
}
.swatches button:hover { box-shadow: inset 0 0 0 1px #fff, 0 0 0 2px rgba(255, 255, 255, .25); }
.swatches button[aria-pressed="true"] { box-shadow: inset 0 0 0 1px #fff, 0 0 0 2px var(--accent); }

.hexrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.hexrow input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #16141c;
  color: var(--text);
  font: 600 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}

/* Size preview + slider */
.size-preview {
  display: grid;
  place-items: center;
  height: 92px;
  border-radius: 10px;
  background: #fff;
  background-image:
    linear-gradient(45deg, #eceaf0 25%, transparent 25%, transparent 75%, #eceaf0 75%),
    linear-gradient(45deg, #eceaf0 25%, transparent 25%, transparent 75%, #eceaf0 75%);
  background-size: 14px 14px;
  background-position: 0 0, 7px 7px;
}
.size-preview__dot {
  border-radius: 50%;
  background: #c9a6ff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
}

.pop input[type="range"] {
  width: 100%;
  height: 30px;
  margin-top: 10px;
  accent-color: var(--accent);
  background: transparent;
  cursor: pointer;
}

.size-readout {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Symmetry axes read as a short list rather than a row of pills. */
.chips--stack { flex-direction: column; }
.chips--stack .chip-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
}
.chips--stack .chip-btn .icon { width: 19px; height: 19px; }

.pop--mirror { width: 214px; }
.chip-btn {
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn:hover { border-color: rgba(255, 255, 255, .3); }
.chip-btn[aria-pressed="true"] {
  background: rgba(201, 166, 255, .2);
  border-color: var(--accent);
  color: #f1e6ff;
}

/* --- Phones: the tool rail becomes a bottom pill ------------------------- */
@media (max-width: 700px) {
  .dock--tools {
    left: 50%;
    top: auto;
    bottom: 12px;
    flex-direction: row;
    /* Wrap to a second row on narrow phones rather than hiding tools
       behind a horizontal scroll nobody notices. */
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
    padding: 4px;
    transform: translateX(-50%);
    /* Anchored at left:50%, shrink-to-fit would only see half the frame and
       wrap far too early — ask for the full row, then cap it. */
    width: max-content;
    max-width: calc(100% - 24px);
    border-radius: 24px;
  }
  .dock--tools .dock-btn { flex: 0 0 auto; width: 36px; height: 36px; }
  .dock--tools .dock-btn .icon { width: 20px; height: 20px; }

  /* Seven tools plus dividers will not fit one row on a phone, and a single
     row matters more than the grouping hint. */
  .dock--tools .dock-sep { display: none; }

  .dock-sep { width: 1px; height: 20px; margin: auto 2px; }

  /* Narrow enough that the chip still fits beside it on a ~350px phone. */
  .dock--actions { gap: 2px; }
  .dock--actions .dock-btn { width: 36px; height: 36px; }
  .dock--actions .dock-btn .icon { width: 19px; height: 19px; }

  /* Same height as the action dock (36px buttons + 5px padding + border),
     sitting beside it rather than under it. */
  .view-chip {
    height: 48px;
    gap: 6px;
    padding: 0 10px 0 8px;
    font-size: 12px;
  }
  .view-chip .icon { width: 15px; height: 15px; }
  .view-chip__vals span:last-child { font-size: 11px; }

  /* Clear the bottom tool rail. */
  .toast { bottom: 72px; }

  /* Popovers dock above the bottom rail instead of beside it */
  .pop {
    left: 50%;
    right: auto;
    top: auto;
    bottom: 66px;
    transform: translateX(-50%);
    width: min(288px, calc(100vw - 32px));
  }

  /* Android shows its own "to exit full screen" notice along the bottom edge
     for about ten seconds. Ride above it, then settle back down. */
  .dock--tools, .toast, .pop { transition: bottom .32s var(--ease); }
  .stage-wrap.fs-notice .dock--tools { bottom: 86px; }
  .stage-wrap.fs-notice .pop { bottom: 140px; }
  .stage-wrap.fs-notice .toast { bottom: 146px; }
}

/* Below roughly 340px the chip and the action dock genuinely cannot share a
   line, so the chip drops underneath instead of colliding. */
@media (max-width: 340px) {
  .view-chip { top: 66px; }
  /* Keeps the tool rail on one row down to a 320px screen. */
  .dock--tools .dock-btn { width: 36px; height: 36px; }
}

/* --- Fullscreen ---------------------------------------------------------- */
.workspace:fullscreen {
  width: 100vw;
  height: 100vh;
  gap: 0;
  margin: 0;
  background: var(--bg);
}
.workspace:fullscreen .stage-wrap {
  height: 100%;
  border: 0;
  border-radius: 0;
}

/* --- Info dialog --------------------------------------------------------- */
.info-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 20px 22px 24px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-3);
  color: var(--text);
}
.info-dialog::backdrop { background: rgba(6, 5, 9, .68); }

.info-dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.info-dialog__head h2 { font-size: 18px; line-height: 1.3; }

.info-list { margin: 0; }
.info-list dt {
  margin-top: 14px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
}
.info-list dt:first-child { margin-top: 0; }
.info-list dd {
  margin: 5px 0 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.info-dialog--ask { width: min(420px, calc(100vw - 32px)); }

.info-dialog__text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.btn-ghost,
.btn-danger {
  min-height: 42px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-ghost {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
}
.btn-ghost:hover { border-color: rgba(255, 255, 255, .32); background: rgba(255, 255, 255, .05); }

.btn-danger {
  border: 1px solid #ff6b6b;
  background: rgba(255, 107, 107, .16);
  color: #ffd9d9;
}
.btn-danger:hover { background: rgba(255, 107, 107, .28); }

/* --- Legacy buttons still used in the page header ------------------------ */
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .05);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease);
}
.tool-btn:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .28); }
