:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73; /* 5.1:1 on white */
  --accent: #0071e3; /* 4.6:1 on white */
  --accent-hover: #0077ed;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --line: rgba(0, 0, 0, 0.08);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* Header */
.top { padding: 28px 32px 8px; }
.brand { display: flex; align-items: center; gap: 14px; max-width: 1440px; margin: 0 auto; }
.brand__mark { flex: none; width: 40px; height: 40px; color: var(--text); }
.brand h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--text-2); font-size: 14px; }

/* Layout */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 32px 24px;
}

/* Stage */
.stage-wrap { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; gap: 12px; min-width: 0; height: min(calc(100vh - 128px), 820px); }
.stage {
  --stage-bg: #f5f5f7;
  position: relative;
  flex: 1;
  min-height: 420px;
  border-radius: 24px;
  background: var(--stage-bg);
  box-shadow: 0 0 0 1px var(--line) inset, 0 1px 2px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stage.is-transparent {
  background: repeating-conic-gradient(#e8e8ed 0 25%, #ffffff 0 50%) 0 0 / 20px 20px;
}
.stage:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage.is-busy { cursor: progress; }

.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stage-bar__actions { display: flex; gap: 8px; }
.hint { margin: 0; color: var(--text-2); font-size: 14px; }

/* Export progress sheet, covers the stage while frames render */
.sheet {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(245, 245, 247, 0.82);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  backdrop-filter: blur(20px) saturate(1.4);
  cursor: default;
}
.sheet__card {
  display: grid;
  gap: 10px;
  justify-items: center;
  width: min(320px, 86%);
  padding: 24px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--line);
  text-align: center;
}
.sheet__card strong { font-size: 17px; }
.sheet__card small { color: var(--text-2); font-variant-numeric: tabular-nums; }
.progress { width: 100%; height: 6px; border-radius: 99px; background: var(--fill); overflow: hidden; }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--accent); }

/* Inspector */
.inspector {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.group {
  padding: 18px 18px 20px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, 0.03);
}
.group h2 { margin: 0 0 12px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.group > * + * { margin-top: 12px; }
.group h2 + * { margin-top: 0; }
.note { margin: 0; color: var(--text-2); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > * { margin: 0; }
.label { font-size: 14px; font-weight: 500; }
.label small, .dim { color: var(--text-2); font-size: 13px; font-weight: 400; }
.label small::before { content: ' · '; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }

/* Drop zones */
.drop { position: relative; }
.drop input[type='file'] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop__area {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  border-radius: 12px;
  background: var(--fill);
  outline: 1.5px dashed rgba(0, 0, 0, 0.18);
  outline-offset: -1.5px;
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  transition: background 0.15s, outline-color 0.15s;
}
.drop__area b { color: var(--accent); font-weight: 600; }
.drop__area:hover, .drop.is-over .drop__area { background: rgba(0, 113, 227, 0.08); outline-color: var(--accent); }
.drop input:focus-visible + .drop__area { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop--portrait .drop__area { aspect-ratio: 1 / 1.4142; max-height: 200px; }
.drop--landscape .drop__area { aspect-ratio: 1.4142 / 1; }
.drop.has-image .drop__area { outline-style: solid; outline-color: transparent; background: #000; }
.drop.has-image .drop__text { display: none; }
.drop__area img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop__clear {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.drop__clear:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.drop--portrait { width: fit-content; margin-inline: auto; }
.drop--portrait .drop__area { width: auto; height: 200px; }
.halves { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.halves .drop--portrait { width: auto; margin: 0; }
.halves .drop--portrait .drop__area { width: 100%; height: auto; max-height: none; }

/* Segmented control */
.segmented { display: flex; padding: 2px; border-radius: 9px; background: var(--fill); }
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span {
  display: block;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
}
.segmented input:checked + span { background: var(--panel); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04); }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Swatches */
.swatches { display: flex; gap: 10px; }
.swatches label { position: relative; display: block; }
.swatches input { position: absolute; opacity: 0; }
.swatches span {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sw);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14) inset;
  cursor: pointer;
}
.swatches input:checked + span { box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.14) inset, 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.swatches input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 4px; }
.color { position: relative; display: block; width: 28px; height: 28px; border-radius: 50%; background: conic-gradient(#ff3b30, #ffcc00, #34c759, #00c7be, #007aff, #af52de, #ff3b30); cursor: pointer; }
.color.is-active { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.color input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

/* Switch */
.switch { cursor: pointer; }
.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 99px;
  background: var(--fill-2);
  cursor: pointer;
  transition: background 0.2s;
}
.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}
.switch input:checked { background: #34c759; }
.switch input:checked::after { transform: translateX(18px); }
.switch input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 16px;
  border: 0;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn--secondary { background: var(--fill); color: var(--text); }
.btn--secondary:hover:not(:disabled) { background: var(--fill-2); }
.btn--plain { background: none; color: var(--accent); padding-inline: 10px; }
.btn--wide { width: 100%; min-height: 44px; font-size: 15px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Buy me a coffee, shown after a download */
.coffee {
  width: min(360px, calc(100vw - 32px));
  padding: 28px 24px 16px;
  border: 0;
  border-radius: 22px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18), 0 0 0 1px var(--line);
  text-align: center;
}
.coffee::backdrop { background: rgba(0, 0, 0, 0.2); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.coffee[open] { animation: coffee-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes coffee-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } }
.coffee__cup { font-size: 44px; line-height: 1; }
.coffee h2 { margin: 12px 0 6px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.coffee p { margin: 0 0 20px; color: var(--text-2); font-size: 15px; }
.coffee__actions { display: grid; gap: 4px; }
.coffee a.btn { text-decoration: none; }

.toast { min-height: 1.4em; margin: 0; padding: 0 4px; color: var(--text-2); font-size: 13px; }
.toast.is-error { color: #d70015; }

/* Footer */
.foot { display: flex; justify-content: space-between; gap: 8px 24px; flex-wrap: wrap; max-width: 1440px; width: 100%; margin: 0 auto; padding: 8px 32px 28px; color: var(--text-2); font-size: 13px; }
.foot p { margin: 0; }
.foot a { color: var(--text); text-decoration: none; }
.foot a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .top { padding: 20px 16px 4px; }
  .app { grid-template-columns: 1fr; padding: 12px 16px 20px; }
  .stage { min-height: 0; aspect-ratio: 4 / 3; flex: none; }
  .stage-wrap { position: static; height: auto; }
  .foot { padding: 8px 16px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
