:root {
  color-scheme: light;
  --paper: #fff;
  --ink: #151515;
  --quiet: #575757;
  --signal: #f7ff00;
  --margin: clamp(18px, 4vw, 70px);
  --rail: clamp(280px, 30vw, 410px);
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color: var(--ink);
  background: var(--paper);
  font-family: "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; }
a, button { color: inherit; }
a { text-decoration: none; }
button { font: inherit; cursor: pointer; border: 0; background: transparent; }
button:disabled { opacity: .5; cursor: wait; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }
[hidden] { display: none !important; }

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

.masthead, .workbench {
  width: min(100% - 2 * var(--margin), 1440px);
  margin-inline: auto;
}

.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  padding-block: 22px 34px;
}

.masthead a { display: inline-flex; align-items: center; width: fit-content; min-height: 44px; }
.back { gap: .5em; font-size: 13px; }
.back span:first-child { font-size: 19px; line-height: 1; }
.masthead a:hover, .text-button:hover { text-decoration: underline; text-underline-offset: .22em; }
.masthead h1 {
  display: flex;
  align-items: baseline;
  font-size: clamp(30px, 5.9vw, 82px);
  line-height: .88;
  font-weight: 800;
  letter-spacing: -.09em;
  margin: 0;
  padding-right: .09em;
}

.title-mark {
  width: .3em;
  height: .46em;
  margin-inline: .08em .16em;
  background: var(--signal);
  clip-path: polygon(76% 0, 100% 0, 24% 100%, 0 100%);
}

.masthead-links { justify-self: end; display: flex; align-items: center; gap: clamp(14px, 2vw, 28px); }
.examples-link { font-size: 13px; }
.wordmark { font-size: 17px; font-weight: 750; letter-spacing: -.05em; }
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--rail);
  gap: clamp(28px, 5vw, 94px);
  align-items: start;
  padding-bottom: 28px;
}

.preview { display: grid; min-width: 0; }
.proof-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 3px;
  font-weight: 650;
  font-size: 13px;
  text-align: start;
}
.upload-mark { width: 28px; height: 24px; flex: none; }
#upload:hover .upload-mark { transform: rotate(-8deg); }
#original[aria-pressed="true"] { text-decoration: underline; text-underline-offset: .2em; }
.compare-mark {
  width: 15px;
  height: 15px;
  flex: none;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: linear-gradient(90deg, currentColor 50%, var(--paper) 50%);
}
#original[aria-pressed="true"] .compare-mark { background: var(--signal); }

.platen {
  --sheet-height: clamp(385px, calc(100svh - 210px), 880px);
  display: grid;
  place-items: center;
  min-height: calc(var(--sheet-height) + 44px);
  padding-block: 22px;
  position: relative;
  perspective: 1150px;
}

.scan-deck {
  width: min(100%, calc(var(--sheet-height) * var(--image-ratio, .8)));
  aspect-ratio: var(--image-ratio, .8);
  position: relative;
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: transform .2s ease-out;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 5px 10px #0002);
}

.scan-deck::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--signal);
  pointer-events: none;
  opacity: 0;
}
.platen.running .scan-deck::after { animation: scan 2.2s linear infinite; }
@keyframes scan {
  0%, 100% { opacity: 0; }
  12%, 85% { opacity: 1; }
  to { top: 100%; }
}

.drop-message {
  display: none;
  position: absolute;
  inset: 18px 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--signal);
  color: var(--ink);
  font-weight: 750;
  font-size: clamp(21px, 4vw, 44px);
  text-align: center;
  pointer-events: none;
}
.platen.dragging .drop-message { display: flex; }
.dimension { justify-self: center; color: var(--quiet); font: 12px / 1.5 var(--mono); }

.machine { min-width: 0; display: grid; row-gap: clamp(19px, 3vh, 33px); padding-top: 1px; }
.mode-group { border: 0; padding: 0; margin: 0; min-width: 0; }
.modes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.modes label { display: grid; cursor: pointer; position: relative; }
.modes input, .knob-range { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.modes label > span {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 7px;
  min-height: 59px;
  padding: 3px 3px 6px;
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  overflow-wrap: anywhere;
}
.modes input:checked + span { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.modes input:focus-visible + span, .knob-range:focus-visible + .knob-face { outline: 2px solid var(--ink); outline-offset: 2px; }
.mode-mark { display: block; width: 25px; height: 25px; background: var(--ink); }
.modes input:checked + span .mode-mark { background: var(--signal); }
.mark-carve { clip-path: polygon(0 0, 100% 0, 63% 50%, 100% 100%, 0 100%, 37% 50%); }
.mark-warp { clip-path: polygon(0 55%, 25% 7%, 42% 7%, 65% 51%, 100% 0, 100% 47%, 76% 97%, 57% 97%, 33% 54%, 0 100%); }
.mark-scan { clip-path: polygon(0 0, 87% 0, 87% 22%, 0 22%, 0 38%, 100% 38%, 100% 64%, 13% 64%, 13% 78%, 88% 78%, 88% 100%, 0 100%); }

.dial { position: relative; min-width: 0; }
.dial label { font-size: 13px; font-weight: 650; }
.dial output { font: 12px / 1 var(--mono); font-variant-numeric: tabular-nums; }
.rotaries { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.rotary {
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 4px;
  text-align: center;
}
.rotary label { grid-row: 2; overflow-wrap: anywhere; align-self: start; }
.rotary output { grid-row: 3; color: var(--quiet); }
.knob-face {
  grid-row: 1;
  display: grid;
  place-items: center;
  width: clamp(48px, 5vw, 68px);
  height: clamp(48px, 5vw, 68px);
  touch-action: none;
  cursor: grab;
  position: relative;
  isolation: isolate;
}
.knob-face:active { cursor: grabbing; }
.knob-face i {
  position: relative;
  width: 76%;
  height: 76%;
  background: var(--ink);
  transform: rotate(var(--turn, 0deg));
}
.knob-face i::after {
  content: "";
  position: absolute;
  top: 13%;
  left: calc(50% - 1.5px);
  width: 3px;
  height: 24%;
  background: var(--paper);
}
.knob-face:hover i::after, .knob-face:active i::after,
.knob-range:focus-visible + .knob-face i::after { background: var(--signal); }
.rotary-x i { clip-path: polygon(17% 0, 83% 0, 100% 18%, 100% 82%, 83% 100%, 17% 100%, 0 82%, 0 18%); }
.rotary-y i { border-radius: 50% 50% 45% 10%; }
.rotary-grain i { clip-path: polygon(50% 0, 62% 12%, 80% 6%, 86% 22%, 100% 29%, 94% 50%, 100% 69%, 86% 76%, 80% 94%, 62% 88%, 50% 100%, 37% 88%, 20% 94%, 14% 77%, 0 69%, 6% 50%, 0 30%, 14% 23%, 20% 7%, 37% 12%); }
.rotary-speed i { border-radius: 50%; clip-path: polygon(5% 0, 94% 0, 100% 55%, 81% 88%, 69% 88%, 67% 100%, 32% 100%, 32% 88%, 19% 88%, 0 55%); }

.tones { display: grid; gap: 13px; }
.tone {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 6px;
}
.tone label { font-size: 14px; }
.tone output { justify-self: end; }
.tone input {
  -webkit-appearance: none;
  appearance: none;
  grid-column: 1 / -1;
  height: 38px;
  width: 100%;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
  --track: linear-gradient(90deg, #eee, var(--ink));
}
.threshold input { --track: linear-gradient(90deg, #dedede, #999 44%, #303030 77%, #151515); }
.tone input::-webkit-slider-runnable-track { height: 5px; background: var(--track); }
.tone input::-moz-range-track { height: 5px; background: var(--track); }
.tone input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 24px;
  margin-top: -9.5px;
  background: var(--ink);
  clip-path: polygon(50% 0, 100% 30%, 100% 88%, 50% 100%, 0 88%, 0 30%);
}
.tone input::-moz-range-thumb {
  width: 14px;
  height: 24px;
  border: 0;
  background: var(--ink);
  clip-path: polygon(50% 0, 100% 30%, 100% 88%, 50% 100%, 0 88%, 0 30%);
}
.threshold input::-webkit-slider-thumb { background: var(--signal); }
.threshold input::-moz-range-thumb { background: var(--signal); }
.threshold > span { font-size: 11px; color: var(--quiet); }
.threshold > span:last-child { text-align: end; }

.finish summary {
  width: fit-content;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 7px;
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.finish summary::-webkit-details-marker { display: none; }
.finish summary::before { content: "+"; font: 20px / 1 var(--mono); }
.finish[open] summary::before { content: "−"; }
.finish summary:hover { text-decoration: underline; text-underline-offset: 4px; }
.finish .tones { margin-top: 8px; }

.operations {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.operations button {
  display: inline-flex;
  position: relative;
  isolation: isolate;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  min-height: 53px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: clamp(13px, 1.3vw, 16px);
  line-height: 1.02;
  text-align: start;
  overflow-wrap: anywhere;
}
.operations button:active { transform: translateY(1px); }
.operations .play { padding-right: 22px; }
.play::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--signal);
  clip-path: polygon(0 0, 87% 0, 100% 50%, 87% 100%, 0 100%, 5% 50%);
}
.play[aria-pressed="true"]::before { clip-path: polygon(5% 0, 95% 0, 95% 100%, 5% 100%); }
.run-mark, .save-mark { width: 16px; height: 16px; flex: none; background: currentColor; }
.run-mark { clip-path: polygon(14% 0, 100% 50%, 14% 100%); }
.play[aria-pressed="true"] .run-mark { clip-path: inset(13%); }
.save-mark { clip-path: polygon(36% 0, 64% 0, 64% 52%, 100% 52%, 50% 100%, 0 52%, 36% 52%); }
.save:hover span:last-child { text-decoration: underline; text-underline-offset: 4px; }
.machine-footer { display: flex; justify-content: flex-end; align-items: start; gap: 14px; }
.carve-hint { margin: 4px auto 0 0; color: var(--quiet); font-size: 12px; line-height: 1.35; }
.reset { min-height: 44px; margin-top: -10px; font-size: 12px; }
.notice { color: #9f2419; margin: 0; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }

@media (max-width: 720px) {
  .masthead { grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; padding-block: 4px 14px; }
  .masthead h1 { grid-column: 1/-1; grid-row: 2; justify-self: center; font-size: clamp(44px, 12vw, 68px); padding-block: 6px; }
  .workbench { grid-template-columns: minmax(0, 1fr); gap: 23px; padding-bottom: calc(98px + env(safe-area-inset-bottom, 0px)); }
  .machine { row-gap: 22px; }
  .platen { --sheet-height: clamp(227px, 45svh, 510px); min-height: calc(var(--sheet-height) + 26px); padding-block: 13px; }
  .operations {
    position: fixed;
    z-index: 2;
    inset: auto 0 0;
    grid-template-columns: 1fr 1fr;
    background: var(--paper);
    padding: 8px var(--margin) calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .operations button { font-size: 15px; }
  .rotary label { font-size: 12px; }
  .knob-face { width: 53px; height: 53px; }
  html { scroll-padding-bottom: 86px; }
}

@media (prefers-reduced-motion: reduce) {
  .scan-deck { transform: none; transition: none; }
  .platen.running .scan-deck::after { animation: none; }
  #upload:hover .upload-mark { transform: none; }
}
