/* ============================================================
   Trace — what this tool adds to the shell.
   ============================================================ */

/* Two columns: one picture, nothing to list. */
.workspace { grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1180px) { .workspace { grid-template-columns: minmax(0, 1fr) 300px; } }
@media (max-width: 960px) { .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: max(320px, 55dvh) auto; } }

@media (max-width: 620px) {
  .md-top-app-bar { gap: 2px; padding: 0 6px 0 10px; }
  .md-top-app-bar #btn-shortcuts { display: none; }
  .md-top-app-bar .md-button.has-icon { width: 40px; padding: 0; gap: 0; font-size: 0; }
  .md-top-app-bar .md-button.has-icon svg { width: 20px; height: 20px; }
}

/* The shell gives the dock display:flex, which outranks the hidden attribute. */
.viewport-dock[hidden] { display: none; }

/* ---------- The picture ---------- */
.surface { position: absolute; inset: 0; z-index: 1; overflow: hidden; cursor: grab; touch-action: none; }
.surface[data-drag="pan"] { cursor: grabbing; }
.surface[data-mode="split"] { cursor: ew-resize; }
.stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; --scale: 1; }
.stage > * { position: absolute; left: 0; top: 0; }
/* Every press belongs to the surface. Without this the picture and the traced
   SVG take the press themselves: the browser starts dragging the image, the
   surface stops hearing pointermove, and the divider is left behind. */
.stage, .stage * { pointer-events: none; user-select: none; -webkit-user-drag: none; }
.original { display: block; max-width: none; image-rendering: auto; }
.original[hidden], .ground[hidden] { display: none; }
.vector svg { display: block; overflow: visible; }

/* Checks one size at any zoom, since the stage scales everything in it. */
.ground {
  --check: calc(8px / var(--scale));
  background-color: #fff;
  background-image: conic-gradient(#e8e8e8 25%, transparent 0 50%, #e8e8e8 0 75%, transparent 0);
  background-size: calc(var(--check) * 2) calc(var(--check) * 2);
  outline: calc(1px / var(--scale)) solid var(--md-sys-color-outline-variant);
}
:root[data-theme="dark"] .ground {
  background-color: #2f3033;
  background-image: conic-gradient(#3a3b3e 25%, transparent 0 50%, #3a3b3e 0 75%, transparent 0);
}

/* Outlines: every path as a hairline, so the nodes and curves can be judged. */
.vector.outlines path,
.vector.outlines g { fill: none !important; }
.vector.outlines path {
  stroke: var(--md-sys-color-on-surface);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

/* ---------- Before a picture ---------- */
.empty {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 24px; text-align: center;
  color: var(--md-sys-color-on-surface-variant);
}
.empty[hidden] { display: none; }
.empty .empty-icon svg { width: 48px; height: 48px; fill: currentColor; opacity: 0.55; }
.empty h2 {
  margin: 8px 0 0; max-width: 32ch; text-wrap: balance;
  font: 400 24px/32px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface);
}
.empty p { margin: 0; font: 400 14px/20px var(--md-sys-typescale-plain-font); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }

/* ---------- Busy ---------- */
.progress {
  position: absolute; left: 50%; top: 50%; z-index: 6;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  padding: 14px 20px 14px 16px;
  border-radius: var(--md-sys-shape-corner-l);
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 90%, transparent);
  backdrop-filter: blur(16px);
  box-shadow: var(--app-hairline);
}
.progress[hidden] { display: none; }
.progress p { margin: 0; }
.progress-head { display: flex; align-items: center; gap: 12px; }
.progress-stage { font: 500 14px/20px var(--md-sys-typescale-plain-font); color: var(--md-sys-color-on-surface); white-space: nowrap; }
.progress-detail {
  margin: 8px 0 0 32px !important;
  font: 400 12px/16px var(--md-sys-typescale-plain-font);
  color: var(--md-sys-color-on-surface-variant);
}
.progress-detail:empty { display: none; }
.progress-spinner {
  flex: none; width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--md-sys-color-surface-container-highest);
  border-top-color: var(--md-sys-color-primary);
  animation: progress-spin 0.8s linear infinite;
}
@keyframes progress-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .progress-spinner { animation-duration: 2s !important; }
}

/* ---------- Compare ---------- */
.compare-line {
  position: absolute; top: 0; bottom: 0; z-index: 4; width: 0;
  pointer-events: none;
  border-left: 2px solid var(--md-sys-color-surface);
  outline: 1px solid color-mix(in srgb, var(--md-sys-color-on-surface) 30%, transparent);
  transform: translateX(-1px);
}
.compare-line[hidden] { display: none; }
.compare-knob {
  position: absolute; top: 50%; left: -1px;
  display: grid; place-items: center; width: 36px; height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--md-sys-color-surface);
  box-shadow: var(--app-hairline);
  color: var(--md-sys-color-on-surface);
}
.compare-knob svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- Inspector ---------- */
.colour-row { display: flex; align-items: center; gap: 4px; }
.colour-row .dial-row { flex: 1 1 auto; min-width: 0; }
.colour-row[data-hidden="true"] .dial-row { opacity: 0.45; }
.colour-row .eye { flex: none; }
.group-action {
  align-self: flex-start;
  padding: 6px 10px; border: none; border-radius: var(--md-sys-shape-corner-full);
  background: none; cursor: pointer;
  color: var(--md-sys-color-on-surface-variant);
  font: 500 12px/16px var(--md-sys-typescale-plain-font);
}
.group-action:disabled { opacity: 0.4; cursor: default; }
.export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.export-actions .md-button { justify-content: center; }
.engine-note { margin: 16px 4px 0 !important; }
.credits { margin: 6px 4px 16px !important; }
.credits a { color: inherit; }
.hint[hidden] { display: none; }

/* ---------- "Powered by" credit ----------
   Lives in the DOM on top of the canvas, never inside it, so it is present
   while you work and absent from every export. */
.viewport-credit {
  /* One number controls the whole badge: the artwork is 100x32 at scale 1. */
  --credit-scale: 2;
  position: absolute; top: 12px; right: 12px; z-index: 5;
  display: block; padding: 0; line-height: 0;
  border-radius: calc(9px * var(--credit-scale)); overflow: hidden;
  background: color-mix(in srgb, var(--md-sys-color-surface-container-high) 82%, transparent);
  backdrop-filter: blur(12px);
  box-shadow: var(--app-hairline);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-standard);
}
.viewport-credit:hover { background: var(--md-sys-color-surface-container-high); }
.viewport-credit svg {
  display: block;
  width: calc(100px * var(--credit-scale));
  height: calc(32px * var(--credit-scale));
}
.viewport-credit .credit-label { fill: var(--md-sys-color-on-surface-variant); }
.viewport-credit .credit-name,
.viewport-credit .credit-mark { fill: var(--md-sys-color-on-surface); }

/* Step it back on narrow viewports so it cannot run into the hint chip. */
@media (max-width: 1180px) { .viewport-credit { --credit-scale: 1.5; } }
@media (max-width: 960px)  { .viewport-credit { --credit-scale: 1.25; } }
