/* Neutral greys with no tint, so the photo's colours are judged fairly; one blue marks what is
   chosen, and Save. */
:root {
  --bg-workspace: #262626;
  --bg-bar: #1c1c1c;
  --bg-panel: #202020;
  --bg-control: #2e2e2e;
  --bg-hover: #3a3a3a;
  --line: #363636;
  --line-strong: #4a4a4a;
  --text: #ececec;
  --text-quiet: #a3a3a3;
  --text-faint: #787878;
  --accent: #3b82f6;
  --accent-hover: #2f6fe0;
  --accent-soft: rgba(59, 130, 246, 0.16);
  --danger: #b33a3a;
  --radius: 6px;
  --panel-width: 17rem;
  --tools-width: 5.75rem;
  --topbar-height: 3rem;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

/* The page itself never scrolls; only the tool column and a panel do, when short of height. */
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-workspace);
  color: var(--text);
}

.icons {
  display: none;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon .filled {
  fill: currentColor;
}

/* Buttons and fields */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  font: inherit;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-control);
  color: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--bg-hover);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  min-height: 2.25rem;
  font: inherit;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-workspace);
  color: inherit;
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 100%;
  height: 2.25rem;
  padding: 0.15rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-workspace);
}

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

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--topbar-height);
  flex: none;
  padding: 0 0.75rem;
  background: var(--bg-bar);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-right: 0.5rem;
  font-weight: 600;
  white-space: nowrap;
}

.brand .logo {
  width: 1.5rem;
  height: 1.5rem;
  flex: none;
}

.crop-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 auto;
}

.crop-bar .hint {
  margin-right: 0.5rem;
}

#crop-done {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#save-options {
  margin-left: auto;
}

.crop-bar:not([hidden]) + #save-options {
  margin-left: 0;
}

/* The tool column */

.workbench {
  display: flex;
  flex: 1;
  min-height: 0;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: var(--tools-width);
  flex: none;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--bg-bar);
  border-right: 1px solid var(--line);
}

.tools hr {
  width: 70%;
  margin: 0.25rem auto;
  border: 0;
  border-top: 1px solid var(--line-strong);
}

/* At least 56 px tall, for a fingertip. */
.tool {
  flex-direction: column;
  gap: 0.25rem;
  min-height: 3.5rem;
  flex: none;
  padding: 0.4rem 0.2rem;
  border-color: transparent;
  background: transparent;
  color: var(--text-quiet);
  font-size: 0.75rem;
  line-height: 1.15;
  text-align: center;
}

.tool .icon {
  width: 1.4rem;
  height: 1.4rem;
}

.tool:hover:not(:disabled) {
  color: var(--text);
}

.tool[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: #fff;
}

.tool[aria-pressed="true"] .icon {
  color: var(--accent);
}

/* The right-hand panel: one at a time, for the chosen tool. */

.strip {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.9rem;
  width: var(--panel-width);
  flex: none;
  overflow-y: auto;
  padding: 0.9rem 1rem 1rem;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
}

.strip h2 {
  margin: 0 0 0.1rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-quiet);
}

/* Labels sit above their full-width controls. */
.strip label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--text-quiet);
}

/* Two buttons side by side, each half the panel. */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.pair button {
  padding-inline: 0.4rem;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
  color: var(--text-quiet);
}

.slider input {
  grid-column: 1 / -1;
}

.slider output {
  min-width: 2.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.hint {
  color: var(--text-quiet);
  line-height: 1.4;
}

/* A small spinning ring before the hint, while a spot heals or a person is cut out. */
.hint.busy::before {
  content: "";
  display: inline-block;
  width: 0.9em;
  height: 0.9em;
  margin-right: 0.5em;
  vertical-align: -0.1em;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hint.busy::before {
    animation: none;
  }
}

.resize {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  border: 0;
}

.resize legend {
  margin-bottom: 0.6rem;
  padding: 0;
  color: var(--text-quiet);
  line-height: 1.4;
}

.resize:disabled {
  opacity: 0.4;
}

.max {
  margin-bottom: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-faint);
}

/* Layers */

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.layer-list li {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem;
  border-radius: var(--radius);
  background: var(--bg-control);
}

/* Long words are cut short, so a row never pushes its buttons out of reach. */
.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text);
}

.icon-button {
  width: 2.25rem;
  padding: 0;
  border-color: transparent;
  background: transparent;
}

/* Show, as an eye: open while the layer shows, struck through while it is hidden. The box itself
   is kept, unseen, so it can still be reached and pressed from the keyboard. */
.strip .eye {
  position: relative;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
}

.eye:hover {
  background: var(--bg-hover);
}

.eye input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.eye:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.eye input:checked ~ .icon-eye-off,
.eye input:not(:checked) ~ .icon-eye {
  display: none;
}

.eye input:not(:checked) ~ .icon-eye-off {
  color: var(--text-faint);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The workspace */

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-workspace);
}

/* With a photo open, the workspace's edge lights up while a file is held over it. */
.stage.dropping {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.placeholder {
  flex-direction: column;
  gap: 0.6rem;
  width: min(32rem, calc(100% - 4rem));
  padding: 3rem 2rem;
  border: 2px dashed var(--line-strong);
  border-radius: 12px;
  background: transparent;
  color: var(--text-quiet);
  text-align: center;
}

.placeholder .icon {
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.4rem;
  stroke-width: 1.25;
  color: var(--text-faint);
}

.placeholder-title {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
}

.placeholder-note {
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.placeholder:hover:not(:disabled),
.stage.dropping .placeholder {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.stage.dropping:has(.placeholder:not([hidden])) {
  box-shadow: none;
}

/* The error message, as a toast at the top of the workspace. */
.message {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  margin: 0;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius);
  background: var(--bg-bar);
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.zoom-bar {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(28, 28, 28, 0.92);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.zoom-bar button {
  min-width: 2.25rem;
  padding: 0.3rem 0.6rem;
  border-color: transparent;
  background: transparent;
}

.zoom-level {
  min-width: 3.75rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text-quiet);
}

/* Shows through wherever the photo is see-through, as a cutout leaves it. */
canvas {
  background: repeating-conic-gradient(#999 0 25%, #666 0 50%) 0 0 / 16px 16px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}

/* Only while cropping, placing text or tracing, so a finger drag moves the frame, the words or
   the line instead of scrolling the page. */
canvas.cropping,
canvas.drawing {
  touch-action: none;
}

canvas.drawing {
  cursor: crosshair;
}

/* Zoomed in with no tool that takes drags, a drag moves the photo, by finger too. */
canvas.pannable {
  touch-action: none;
  cursor: grab;
}

canvas.pannable.grabbing {
  cursor: grabbing;
}

/* Held down by finger, Before must not scroll the page or open the press-and-hold menu. */
#before {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.before-label {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  background: rgba(28, 28, 28, 0.92);
  color: var(--text);
  font-weight: 600;
  pointer-events: none;
}

/* Shows what a tap will cover; clicks pass through it to the photo. */
.spot-ring {
  position: absolute;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
