:root {
  --ground: #f3f3ef;
  --surface: #e7e7e1;
  --surface-2: #dbdbd3;
  --ink: #141614;
  --ink-soft: #4f534e;
  --accent: #e9a41b;      /* marigold */
  --accent-press: #d1900c;
  --on-accent: #141614;
  --error: #b3261e;
  --frame: #141614;
  --on-frame: #f3f3ef;

  --margin: clamp(16px, 2.4vw, 32px);
  --gap: clamp(16px, 2vw, 28px);
  --radius-pill: 999px;

  --size-display: clamp(2.6rem, 5vw, 4.75rem);
  --size-text: 1.0625rem;
  --size-small: 0.9375rem;

  --ease: cubic-bezier(.2, .7, .2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #121412;
    --surface: #1d201d;
    --surface-2: #2a2e2a;
    --ink: #ecece6;
    --ink-soft: #a9ada6;
    --accent: #f0b429;
    --accent-press: #f7c652;
    --on-accent: #121412;
    --error: #ff8a80;
    --frame: #2a2e2a;
    --on-frame: #ecece6;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: var(--size-text);
  line-height: 1.5;
}

img { display: block; max-width: 100%; }

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- bar ---------- */

.bar {
  padding: 20px var(--margin);
}

.wordmark, .foot-mark {
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-decoration: none;
}

.wordmark span, .foot-mark span { color: var(--accent); }

/* ---------- layout ---------- */

.studio {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(24px, 4vw, 64px);
  align-items: start;
  padding: clamp(8px, 2vw, 24px) var(--margin) clamp(64px, 8vw, 120px);
}

/* ---------- controls ---------- */

h1 {
  margin: 0;
  font-size: var(--size-display);
  font-weight: 650;
  line-height: 0.95;
  letter-spacing: -0.045em;
  max-width: 11ch;
}

.lede {
  margin: 24px 0 0;
  max-width: 38ch;
  font-size: 1.25rem;
  line-height: 1.45;
}

.slots {
  margin-top: clamp(28px, 3vw, 40px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.slot {
  position: relative;
  display: block;
  height: clamp(220px, 36vh, 480px);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  transition: background-color .2s var(--ease), transform .2s var(--ease);
}

.slot:hover { background: var(--surface-2); }
.slot:active { transform: scale(.99); }
.slot:focus-within { outline: 3px solid var(--accent); outline-offset: 3px; }
.slot.is-over { background: var(--accent); }
.slot.is-over .slot-empty { color: var(--on-accent); }

.slot input {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
}

.slot img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
  background: var(--surface);
  pointer-events: none;
}

.slot-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-end;
  gap: 6px;
  padding: clamp(16px, 2vw, 24px);
  pointer-events: none;
}

.slot-empty svg {
  width: 38%;
  max-width: 120px;
  margin: auto auto 24px;
  fill: var(--surface-2);
  transition: fill .2s var(--ease);
}

.slot:hover .slot-empty svg { fill: var(--ground); }

.slot-empty strong { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
.slot-empty span { font-size: var(--size-small); color: var(--ink-soft); }

/* Name tag shown on top of a chosen photo; tap to change it. */
.slot-name {
  position: absolute; left: 12px; bottom: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--ground);
  font-size: var(--size-small);
  font-weight: 600;
  pointer-events: none;
  display: none;
}

.slot.has-image .slot-empty { display: none; }
.slot.has-image .slot-name { display: block; }

.hint {
  margin: 12px 0 0;
  font-size: var(--size-small);
  color: var(--ink-soft);
}

.slot.is-invalid { background: color-mix(in srgb, var(--error) 18%, var(--surface)); }

/* ---------- camera button on each slot ---------- */

.slot-wrap { position: relative; }

.cam-btn {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px;
  padding: 8px 16px 8px 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--ground);
  color: var(--ink);
  font: inherit;
  font-size: var(--size-small);
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
}

.cam-btn svg { width: 18px; height: 18px; fill: currentColor; }
.cam-btn:hover { background: var(--accent); color: var(--on-accent); }
.cam-btn:active { transform: scale(.96); }

/* ---------- steps slider ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: clamp(24px, 3vw, 48px);
  margin-top: 32px;
}

.steps { flex: 1; min-width: 0; }

.steps-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 1.25rem; font-weight: 600;
}

.steps-head output { font-variant-numeric: tabular-nums; }

.steps input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  margin: 8px 0 0;
  background: transparent;
  cursor: pointer;
}

.steps input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: var(--radius-pill);
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 6%) 100% no-repeat, var(--surface-2);
}
.steps input[type="range"]::-moz-range-track {
  height: 8px; border-radius: var(--radius-pill); background: var(--surface-2);
}
.steps input[type="range"]::-moz-range-progress {
  height: 8px; border-radius: var(--radius-pill); background: var(--accent);
}
.steps input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px; height: 28px; margin-top: -10px;
  border-radius: 50%; border: 0;
  background: var(--ink);
  transition: transform .15s var(--ease);
}
.steps input[type="range"]::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%; border: 0; background: var(--ink);
}
.steps input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

.steps-ends {
  display: flex; justify-content: space-between;
  font-size: var(--size-small); color: var(--ink-soft);
}

/* ---------- button ---------- */

.go {
  flex: none;
  width: clamp(200px, 30%, 280px);
  min-height: 64px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color .2s var(--ease), transform .15s var(--ease);
}

.go:hover { background: var(--accent-press); }
.go:active { transform: scale(.985); }
.go:disabled { cursor: progress; background: var(--surface-2); color: var(--ink-soft); }

/* ---------- result ---------- */

.result {
  position: sticky;
  top: 24px;
  display: flex;
  justify-content: flex-end;
}

/* Sized by the frame, so the status line lines up with the picture. */
.result-inner { width: fit-content; max-width: 100%; }

.frame {
  position: relative;
  aspect-ratio: 2 / 3;
  height: min(calc(100vh - 190px), 1000px);
  min-height: 420px;
  max-width: 100%;
  background: var(--frame);
  color: var(--on-frame);
  overflow: hidden;
}

.frame img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
  background: var(--surface);
}

.frame-empty, .frame-busy {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; justify-content: flex-end;
  padding: clamp(20px, 2.4vw, 32px);
}

.frame-empty p, .frame-busy p {
  margin: 0;
  font-size: clamp(1.5rem, 2.4vw, 2.25rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 12ch;
}

.frame-busy p { max-width: none; font-variant-numeric: tabular-nums; }

.frame[data-state="empty"] .frame-empty,
.frame[data-state="busy"] .frame-busy { display: flex; }

.progress {
  height: 8px;
  margin-bottom: 20px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--on-frame) 18%, transparent);
  overflow: hidden;
}

.progress span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: sweep 1.4s var(--ease) infinite;
}

@keyframes sweep {
  from { transform: translateX(-100%); }
  to   { transform: translateX(250%); }
}

.frame.reveal img { animation: reveal .6s var(--ease); }

@keyframes reveal {
  from { opacity: 0; transform: scale(1.03); }
  to   { opacity: 1; transform: none; }
}

.result-foot {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px;
  min-height: 56px;
  margin-top: 16px;
}

#status { margin: 0; font-size: var(--size-text); }
#status.error { color: var(--error); font-weight: 600; }

.download {
  flex: none;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  background: var(--ink);
  color: var(--ground);
  font-weight: 600;
  text-decoration: none;
  transition: transform .15s var(--ease), background-color .2s var(--ease);
}
.download:hover { background: var(--ink-soft); }
.download:active { transform: scale(.97); }

/* ---------- footer ---------- */

.foot {
  display: flex; justify-content: space-between; align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 32px;
  padding: 28px var(--margin);
  background: var(--surface);
}

.foot p { margin: 0; }
.foot p:last-child { max-width: 60ch; font-size: var(--size-small); }

/* ---------- entrance ---------- */

@media (prefers-reduced-motion: no-preference) {
  .studio > * > *, .result { animation: rise .6s var(--ease) both; }
  h1 { animation-delay: 0s; }
  .lede { animation-delay: .07s; }
  .slots { animation-delay: .14s; }
  .hint { animation-delay: .21s; }
  .actions { animation-delay: .28s; }
  .result { animation-delay: .2s; }
  .result > * { animation: none; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .progress span { animation: none; width: 100%; opacity: .6; }
}

/* ---------- smaller screens ---------- */

@media (max-width: 900px) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  .slot { height: auto; aspect-ratio: 3 / 4; }
  .result { position: static; }
  .result-inner { width: 100%; }
  .frame { height: auto; min-height: 0; width: 100%; }
  h1 { max-width: 12ch; }
}

@media (max-width: 480px) {
  .lede { font-size: 1.125rem; margin-top: 20px; }
  .slot-empty strong { font-size: 1.0625rem; }
  .slot-empty svg { margin-bottom: 12px; }
  .actions { flex-direction: column; align-items: stretch; gap: 24px; }
  .go { width: 100%; }
}

/* ---------- webcam dialog ---------- */

.camera {
  width: min(880px, calc(100vw - 2 * var(--margin)));
  max-height: calc(100vh - 2 * var(--margin));
  padding: clamp(16px, 2.4vw, 28px);
  border: 0;
  background: var(--ground);
  color: var(--ink);
  overflow: auto;
}

.camera::backdrop { background: rgb(10 11 10 / .8); }

.camera h2 {
  margin: 0 0 16px;
  font-size: clamp(1.5rem, 2.6vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.viewfinder {
  position: relative;
  background: var(--frame);
  aspect-ratio: 4 / 3;
  max-height: calc(100vh - 300px);
  margin: 0 auto;
}

.viewfinder video {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}

/* Mirror the front camera so it moves like a mirror; the photo itself is not flipped. */
.viewfinder.is-mirrored video { transform: scaleX(-1); }

.countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  margin: 0;
  font-size: clamp(5rem, 16vw, 10rem);
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.viewfinder.flash::after {
  content: ""; position: absolute; inset: 0;
  background: #fff;
  animation: flash .35s var(--ease) forwards;
}

@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

.camera-msg { margin: 12px 0 0; min-height: 1.5em; }
.camera-msg.error { color: var(--error); font-weight: 600; }

.camera-actions {
  display: flex; flex-wrap: wrap; gap: 12px;
  margin-top: 12px;
}

.camera-actions .go { width: auto; min-height: 56px; padding: 0 32px; }

.ghost {
  min-height: 56px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s var(--ease), transform .15s var(--ease);
}

.ghost:hover { background: var(--surface-2); }
.ghost:active { transform: scale(.97); }
.camera button:disabled { opacity: .5; cursor: not-allowed; }

#close-cam { margin-left: auto; }

@media (max-width: 480px) {
  .camera-actions .go, .camera-actions .ghost { flex: 1 1 100%; }
  #close-cam { margin-left: 0; }
}
