:root {
  color-scheme: light;
  --bg: #ece7dc;
  --paper: #f6f2e9;
  --ink: #1b1814;
  --muted: #6f675c;
  --line: #c4bbae;
  --red: #d41c3a;
  --radius: 1.1rem;
}

* {
  box-sizing: border-box;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100vh;
  padding: max(1rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(1.25rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.masthead h1,
.slot h2,
.result h2 {
  margin: 0;
  line-height: 1.15;
  text-wrap: balance;
}

.masthead h1 {
  font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.slot h2,
.result h2 {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.sources {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex: 1 1 22rem;
  min-height: 18rem;
}

.slot,
.result {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
  min-height: 0;
}

.drop,
.result-frame {
  flex: 1;
  min-height: 16rem;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.drop {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.drop:hover,
.drop.is-drag {
  border-color: var(--red);
}

.drop:focus-visible {
  border-color: var(--red);
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.preview {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.crop {
  position: absolute;
  border: 3px dashed var(--red);
  box-shadow: 0 0 0 9999px rgba(27, 24, 20, 0.45);
  pointer-events: none;
}

.slot-meta,
.result-status {
  margin: 0;
  min-height: 1.4em;
  max-width: 75ch;
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.drop.is-error + .slot-meta {
  color: var(--red);
}

.drop.is-error {
  border-color: var(--red);
}

.result {
  flex: 1 1 18rem;
}

.result-frame {
  position: relative;
  display: grid;
  place-items: center;
  overflow: auto;
  background-color: var(--paper);
  background-image:
    linear-gradient(45deg, #e4ddd0 25%, transparent 25%),
    linear-gradient(-45deg, #e4ddd0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e4ddd0 75%),
    linear-gradient(-45deg, transparent 75%, #e4ddd0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.result.has-diff .result-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  border-style: solid;
}

.result-empty {
  margin: 0;
  padding: 1rem;
  max-width: 36ch;
  color: var(--muted);
  text-align: center;
  text-wrap: balance;
}

.result canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

@media (max-width: 40rem) {
  .sources {
    grid-template-columns: 1fr;
    flex-basis: auto;
  }

  .drop,
  .result-frame {
    min-height: 14rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .drop,
  .result-frame {
    transition: none;
  }
}
