/* Thumb JPG
   Concept: a photographer's light table. Output frames are drawn as film frames.
   Palette: light table #e7e9ec, paper #f8f9fa, ink #16181c, film #1c1d21,
            proof blue #3340ff, edge amber #e2b05c. */

:root {
  --table: #e7e9ec;
  --paper: #f8f9fa;
  --ink: #16181c;
  --film: #1c1d21;
  --accent: #3340ff;
  --accent-dark: #2430e6;
  --edge: #e2b05c;
  --muted: #565c68;
  --hairline: rgba(22, 24, 28, 0.16);
  --ok: #0f7b57;
  --warn: #9a5b00;
  --danger: #c0213a;
  --display: "Bahnschrift", "DIN Condensed", "Roboto Condensed", "Arial Narrow", sans-serif-condensed, "Helvetica Neue", Arial, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--table);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.5;
}

h1, h2, p { margin: 0; }

button, input, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

kbd {
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 600;
  background: #fff;
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 0 6px;
}

/* ---------- page ---------- */

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding:
    calc(18px + env(safe-area-inset-top, 0px))
    max(20px, env(safe-area-inset-right, 0px))
    calc(56px + env(safe-area-inset-bottom, 0px))
    max(20px, env(safe-area-inset-left, 0px));
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
}

.mark img { display: block; border-radius: 7px; }

.privacy { color: var(--muted); font-size: 0.92rem; }

.hero { padding: clamp(36px, 7vw, 84px) 0 clamp(28px, 4vw, 48px); }

.hero h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(3rem, 10.5vw, 6.75rem);
  line-height: 0.92;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.lead {
  margin-top: 22px;
  max-width: 52ch;
  color: var(--muted);
  font-size: clamp(1.02rem, 1.6vw, 1.18rem);
  line-height: 1.55;
}

/* ---------- bench: dropzone + controls on one sheet ---------- */

.bench {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr);
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: clamp(36px, 6vw, 64px) clamp(24px, 5vw, 56px);
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: background 0.18s ease;
}

/* crop marks mark the frame area */
.dropzone::before {
  content: "";
  position: absolute;
  inset: 16px;
  pointer-events: none;
  --m: 26px;
  --t: 2px;
  --c: var(--ink);
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--m) var(--t),
    linear-gradient(var(--c), var(--c)) top left / var(--t) var(--m),
    linear-gradient(var(--c), var(--c)) top right / var(--m) var(--t),
    linear-gradient(var(--c), var(--c)) top right / var(--t) var(--m),
    linear-gradient(var(--c), var(--c)) bottom left / var(--m) var(--t),
    linear-gradient(var(--c), var(--c)) bottom left / var(--t) var(--m),
    linear-gradient(var(--c), var(--c)) bottom right / var(--m) var(--t),
    linear-gradient(var(--c), var(--c)) bottom right / var(--t) var(--m);
  background-repeat: no-repeat;
  transition: inset 0.2s ease;
}

.dropzone:hover::before,
.dropzone:focus-visible::before,
.dropzone.hot::before {
  inset: 10px;
  --c: var(--accent);
  --m: 34px;
}

.dropzone:hover { background: #fff; }
.dropzone.hot { background: #eceeff; }
.dropzone:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.dz-body { position: relative; max-width: 44ch; }

.dz-body h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2rem, 4.2vw, 2.9rem);
  line-height: 1;
  letter-spacing: -0.01em;
}

.dz-help { margin-top: 12px; color: var(--muted); }

.dz-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}

.dz-formats {
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:hover { background: var(--ink); color: #fff; }

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

.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn.sm { padding: 7px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- controls ---------- */

.controls {
  padding: 26px 24px 28px;
  border-left: 1.5px solid var(--ink);
}

.controls h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1;
  margin-bottom: 20px;
}

.field { padding: 16px 0; border-top: 1px solid var(--hairline); }
.field:first-of-type { padding-top: 0; border-top: 0; }

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.95rem;
  font-weight: 600;
}

.field-head output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }

.seg {
  display: flex;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
}

.seg button {
  flex: 1;
  appearance: none;
  padding: 9px 6px;
  border: 0;
  border-right: 1.5px solid var(--ink);
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg button:last-child { border-right: 0; }
.seg button:hover { background: rgba(22, 24, 28, 0.08); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.seg button:focus-visible { outline-offset: -4px; }

/* range */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --fill: 100%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill), rgba(22, 24, 28, 0.18) var(--fill));
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) var(--fill), rgba(22, 24, 28, 0.18) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
}

select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.bg-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

.swatches { display: flex; gap: 8px; }

.swatches button {
  appearance: none;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1.5px solid var(--hairline);
  border-radius: 4px;
  cursor: pointer;
}

.swatches button[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }

.name-group {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
}

.name-group input {
  flex: 1;
  min-width: 0;
  padding: 10px 4px 10px 12px;
  border: 0;
  background: transparent;
  outline: none;
}

.name-group span { padding: 0 12px 0 2px; color: var(--muted); font-weight: 600; }
.name-group:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 0.95rem;
  cursor: pointer;
}

.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.check .box {
  position: relative;
  flex: none;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--ink);
  border-radius: 3px;
  background: #fff;
}

.check input:checked + .box { background: var(--ink); }

.check input:checked + .box::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.check input:focus-visible + .box { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- results ---------- */

.results-section { margin-top: clamp(36px, 6vw, 64px); }

.results-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.results-bar h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1;
}

.stats { margin-top: 6px; color: var(--muted); }
.bar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 12px 16px;
  border-left: 4px solid var(--warn);
  background: var(--paper);
  color: var(--ink);
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr));
  gap: 22px;
}

/* a converted image is a film frame */
.frame {
  display: flex;
  flex-direction: column;
  background: var(--film);
  color: #f3f3f1;
  border-radius: 3px;
  animation: advance 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.frame.leaving { opacity: 0; transform: translateY(8px); }

@keyframes advance {
  from { opacity: 0; transform: translateX(-18px); }
  to { opacity: 1; transform: none; }
}

.perf {
  height: 24px;
  flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='24'%3E%3Crect x='8' y='7' width='14' height='10' rx='2.5' fill='%23e7e9ec'/%3E%3C/svg%3E") repeat-x center / 30px 24px;
}

.edge {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 2px 14px 8px;
  color: var(--edge);
  font-family: var(--display);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.edge .no { font-weight: 700; font-size: 1.15rem; }
.edge .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edge .state { flex: none; font-weight: 700; }
.edge .state.ok { color: #77e0ae; }
.edge .state.warn { color: #f4c36a; }
.edge .state.bad { color: #ff8da1; }

.window {
  position: relative;
  margin: 0 14px;
  width: auto;
  aspect-ratio: var(--ar, 4 / 3);
  max-height: 340px;
  background: #0d0e10;
  overflow: hidden;
  --pos: 50%;
}

.window img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition: filter 0.9s ease;
}

.cmp-src { clip-path: inset(0 calc(100% - var(--pos)) 0 0); }

/* "developing": the image sharpens in once the JPG is ready */
.frame.busy .window img { filter: blur(14px) grayscale(1) brightness(0.8); transition: none; }

.tag {
  position: absolute;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(13, 14, 16, 0.78);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  pointer-events: none;
}

.tag.l { left: 8px; }
.tag.r { right: 8px; }

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: #fff;
  pointer-events: none;
}

.knob {
  position: absolute;
  top: 50%;
  left: var(--pos);
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.05em;
  pointer-events: none;
}

.knob::before { content: "\2039 \203A"; }

.cmp-range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  touch-action: pan-y;
}

.window:focus-within { outline: 3px solid var(--edge); outline-offset: 2px; }

.frame.error .window,
.frame.error .tip-none { display: none; }

.err-box {
  margin: 0 14px;
  padding: 16px;
  border: 1.5px solid #ff8da1;
  color: #ffd5dc;
  font-size: 0.95rem;
  line-height: 1.45;
}

.frame-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 12px;
}

.frame-info { min-width: 0; font-size: 0.92rem; line-height: 1.45; }
.frame-info .dims { font-weight: 600; }
.frame-info .sizes { color: #b8bbc2; }
.frame-info .notes { color: var(--edge); font-size: 0.85rem; }

.frame-actions { display: flex; gap: 8px; flex: none; }

.frame .btn { border-color: rgba(255, 255, 255, 0.4); color: #fff; }
.frame .btn:hover { background: #fff; color: var(--ink); border-color: #fff; }
.frame .btn.primary { background: var(--accent); border-color: var(--accent); }
.frame .btn.primary:hover { background: #fff; color: var(--accent-dark); border-color: #fff; }
.frame :focus-visible { outline-color: var(--edge); }

.frame.error .btn.primary { display: none; }

/* ---------- footer, toasts, drag overlay ---------- */

.foot { margin-top: clamp(40px, 7vw, 72px); max-width: 74ch; color: var(--muted); font-size: 0.9rem; line-height: 1.6; }

.toasts {
  position: fixed;
  left: max(16px, env(safe-area-inset-left, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  right: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(440px, 100%);
  padding: 12px 16px;
  border-radius: 4px;
  background: var(--ink);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.4;
  box-shadow: 0 6px 24px rgba(22, 24, 28, 0.25);
  animation: toast-in 0.2s ease;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(6px); }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s;
}

.drag-overlay p { font-family: var(--display); font-weight: 700; font-size: clamp(2.6rem, 9vw, 5.5rem); line-height: 1; }
.drag-overlay span { font-size: 1.1rem; opacity: 0.9; }

body.dragging .drag-overlay { opacity: 0.96; visibility: visible; }

/* ---------- responsive + motion ---------- */

@media (max-width: 860px) {
  .bench { grid-template-columns: minmax(0, 1fr); }
  .controls { border-left: 0; border-top: 1.5px solid var(--ink); }
  .dropzone { min-height: 300px; }
}

@media (max-width: 480px) {
  .dz-actions .btn { flex: 1 1 100%; }
  .frame-foot { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
