:root {
  color-scheme: light;
  --page: #f3f5f7;
  --paper: #fff;
  --ink: #18242e;
  --muted: #4d5c68;
  --accent: #195951;
  --accent-dark: #10433b;
  --edge: #dbe1e5;
  --soft: #edf1f3;
  --cut: #bf263d;
  --bleed: #8b6534;
  --error-text: #842132;
  --error-bg: #fff0f2;
  --error-border: #df8e9c;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body, h1, h2, p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

button, input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  color: inherit;
}

button:disabled, fieldset:disabled button {
  cursor: default;
}

:focus-visible {
  outline: 3px solid #298479;
  outline-offset: 3px;
}

.masthead {
  background: var(--paper);
  border-bottom: 1px solid var(--edge);
}

.masthead-inner, .workspace {
  width: min(100% - 48px, 1120px);
  margin-inline: auto;
}

.masthead-inner {
  min-height: 52px;
  display: flex;
  align-items: center;
}

.brand-name {
  font-size: 16px;
  font-weight: 740;
  letter-spacing: -.018em;
}

.workspace {
  padding-top: clamp(20px, 3vw, 34px);
  padding-bottom: 25px;
}

.intro {
  margin-bottom: 22px;
}

h1 {
  font-size: clamp(27px, 4vw, 40px);
  font-weight: 740;
  line-height: 1.12;
  letter-spacing: -.036em;
}

.intro p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.editor {
  display: grid;
  grid-template-columns: minmax(0, 1.53fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.preview-panel, .controls {
  min-width: 0;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: var(--paper);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 11px;
  padding: 12px 14px;
}

.preview-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.preview-heading .secondary {
  padding-inline: 10px;
  color: var(--accent);
}

.preview-header .status {
  flex-basis: 100%;
  margin-top: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
  font-weight: 680;
  letter-spacing: -.018em;
}

.view-toggle {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--soft);
  border-radius: 9px;
}

.view-toggle button {
  min-height: 36px;
  padding: 3px 12px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.view-toggle button[aria-pressed="true"] {
  color: var(--accent-dark);
  background: var(--paper);
  box-shadow: 0 1px 2px #18242e20;
}

.stage {
  display: grid;
  justify-items: center;
  margin: 0 12px;
  padding: 6px 10px 2px;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #eef1f3;
}

.stage.has-gap {
  border-color: var(--error-border);
}

.stage.is-over {
  border-color: var(--accent);
  background: #e4f2ed;
}

.board {
  position: relative;
  width: min(100%, 490px);
  aspect-ratio: 1;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
}

.stage.has-photo #preview {
  cursor: grab;
  touch-action: none;
}

.stage.has-photo #preview:active {
  cursor: grabbing;
}

.empty-state {
  position: absolute;
  inset: 40% 0 auto;
  display: grid;
  justify-items: center;
}

.empty-state p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.primary, .secondary, .text-button {
  min-height: 44px;
  border-radius: 7px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 670;
}

.primary {
  background: var(--accent);
  color: #fff;
}

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

.primary:disabled {
  color: #52606c;
  background: #e7ecf0;
}

.secondary {
  border: 1px solid var(--edge);
  background: var(--paper);
}

.secondary:hover:not(:disabled) {
  border-color: #adbbc5;
  background: var(--soft);
}

.text-button {
  padding-inline: 3px;
  color: var(--accent);
  background: transparent;
}

.text-button:hover:not(:disabled) {
  text-decoration: underline;
}

.preview-notes {
  padding: 12px 14px 14px;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-bottom: 8px;
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cut-key, .bleed-key {
  width: 16px;
  border-top: 2px solid var(--cut);
}

.bleed-key {
  border-top: 2px dashed var(--bleed);
}

.hole-key {
  width: 11px;
  height: 11px;
  margin-inline: 2px;
  border: 1.5px solid var(--cut);
  border-radius: 50%;
}

#crop-help {
  font-size: 13px;
  line-height: 1.45;
}

.coverage {
  margin-top: 9px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--error-bg);
  color: var(--error-text);
  font-weight: 620;
  font-size: 13px;
  line-height: 1.4;
}

.controls {
  padding-inline: 18px;
}

.photo-section, fieldset, .download-section {
  padding-block: 15px;
}

.photo-section, fieldset {
  border: 0;
  border-bottom: 1px solid var(--edge);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding-inline: 0;
}

fieldset:disabled {
  opacity: .65;
}

fieldset:disabled summary {
  pointer-events: none;
}

.muted, .status, .quality {
  font-size: 13px;
  line-height: 1.5;
}

.muted {
  margin-top: 6px;
  color: var(--muted);
}

.photo-actions, .rotation {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.status {
  margin-top: 8px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status[data-error="true"] {
  color: var(--error-text);
}

.section-title {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title .text-button {
  margin-block: -7px;
}

.position-control, .move-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.position-control {
  justify-content: space-between;
  margin-top: 12px;
  font-size: 14px;
  font-weight: 630;
}

.move-buttons button {
  width: 44px;
  padding-inline: 0;
  font-size: 19px;
  color: var(--accent);
}

.range-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 10px;
  margin-top: 15px;
  font-size: 14px;
}

.range-control label {
  font-weight: 630;
}

.range-control output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.range-control input {
  grid-column: 1 / -1;
  width: 100%;
  height: 27px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-control input:disabled {
  cursor: default;
}

.rotation button {
  flex: 1;
  white-space: nowrap;
}

.rotation span {
  margin-right: 4px;
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  vertical-align: -.05em;
}

details {
  margin-top: 12px;
  border-top: 1px solid var(--edge);
}

summary {
  padding-top: 12px;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
}

summary::marker {
  color: var(--accent);
}

.download-button {
  width: 100%;
  min-height: 47px;
  font-size: 15px;
}

.download-icon {
  margin-right: 4px;
  font-size: 20px;
  line-height: .7;
}

.download-button[data-needs-fit="true"] {
  border: 1px solid var(--error-border);
  color: var(--error-text);
  background: var(--paper);
}

.download-button[data-needs-fit="true"]:hover {
  background: var(--error-bg);
}

.download-button[data-needs-fit="true"] .download-icon {
  display: none;
}

.blocking-alert {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--error-border);
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 15px;
  line-height: 1.4;
}

.blocking-alert p {
  margin-top: 4px;
  font-size: 14px;
}

.alert-icon {
  flex: 0 0 21px;
  display: grid;
  place-items: center;
  height: 21px;
  border-radius: 50%;
  background: var(--error-text);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.download-section .muted {
  margin-top: 9px;
}

.quality {
  margin-bottom: 11px;
  padding: 8px 11px;
  border-radius: 7px;
  color: #66431e;
  background: #f5ebd8;
}

.review {
  width: min(700px, 100% - 24px);
  max-width: none;
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: clamp(13px, 3vw, 24px);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 18px 60px #15232b35;
  overscroll-behavior: contain;
}

.review::backdrop {
  background: #142330a6;
}

.review-header h2 {
  font-size: clamp(21px, 3.5vw, 25px);
}

.review-header h2:focus {
  outline: none;
}

.review-header p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.proof-comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-block: 14px 11px;
}

.proof {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--edge);
  border-radius: 8px;
}

.proof figcaption {
  display: grid;
  padding: 8px 10px;
  gap: 3px;
  font-size: 14px;
  line-height: 1.3;
}

.proof figcaption span {
  color: var(--muted);
  font-size: 12px;
}

.proof canvas {
  display: block;
  width: 100%;
  height: auto;
  border-top: 1px solid var(--edge);
  background: #eef1f3;
}

.review-note {
  padding: 9px 11px;
  border-radius: 7px;
  background: var(--soft);
  font-size: 14px;
  line-height: 1.5;
}

.review-consent {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  margin-block: 8px 6px;
  font-size: 14px;
  font-weight: 620;
  cursor: pointer;
}

.review-consent input {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

footer {
  margin-top: 17px;
  color: var(--muted);
  font-size: 12px;
}

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

@media (max-width: 805px) {
  .masthead-inner, .workspace {
    width: min(100% - 32px, 620px);
  }

  .editor {
    display: block;
  }

  .controls {
    margin-top: 13px;
  }
}

@media (max-width: 805px) and (min-height: 630px) {
  .preview-panel:has(.has-photo) {
    position: sticky;
    top: 8px;
    z-index: 1;
  }

  .has-photo .board {
    width: min(100%, 36svh, 408px);
  }
}

@media (max-width: 440px) {
  .masthead-inner {
    min-height: 51px;
  }

  .preview-header {
    padding: 11px 11px 10px;
    gap: 7px;
  }

  .preview-header h2 {
    font-size: 15px;
  }

  .preview-header:has(#replace:not([hidden])) .preview-heading {
    width: 100%;
    justify-content: space-between;
  }

  .preview-header:has(#replace:not([hidden])) .view-toggle {
    flex: 1;
  }

  .preview-header:has(#replace:not([hidden])) .view-toggle button {
    flex: 1;
  }

  .view-toggle button {
    padding-inline: 8px;
    min-height: 38px;
    font-size: 12px;
  }

  .stage {
    margin-inline: 7px;
    padding: 5px 5px 2px;
  }

  .preview-notes, .controls {
    padding-inline: 13px;
  }

  .legend {
    gap: 6px 10px;
    font-size: 11px;
  }

  .empty-state {
    inset-block-start: 36%;
  }

  .proof-comparison {
    gap: 7px;
  }

  .proof figcaption {
    padding-inline: 7px;
    font-size: 13px;
  }

  .review-actions button {
    flex: 1;
    padding-inline: 8px;
  }
}
