:root {
  --bg: #fffefa;
  --ink: #000;
  --ink-soft: rgba(0, 0, 0, 0.86);
  --dash: rgba(0, 0, 0, 0.37);
  --panel: #d9d9d9;
  --muted: #777670;
  --line: #111;
  --err: #a02c2c;
  /* one canvas unit (Figma frame is 1914px wide) in CSS px, capped at a 975px column */
  --u: calc(min(975px, 100vw - 32px) / 1914);
  --hand: "Patrick Hand SC", "Comic Sans MS", cursive;
  --sans: "Kumbh Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --pridi: "Pridi", Georgia, serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  background: #000;
  color: #fff;
  padding: 8px 12px;
  border-radius: 6px;
  z-index: 10;
  text-decoration: none;
}
.skip-link:focus { top: 8px; }

/* ---------- Page tokens (mobile defaults) ---------- */
.page {
  --brand: clamp(56px, 16vw, 76px);
  --lead: 17px;
  --prompt: 19px;
  --foot: 30px;
  --zone-empty: 220px;
  --zone-row: 112px;
  --btn: 60px;
  --thumb-w: 56px;
  --thumb-h: 72px;
  --thumb-gap: 12px;
  --pad-x: 16px;
  --pad-r: 14px;
  --zone-border: 2px;
  --x-size: 24px;
  --stage-h: 340px;
  --tb-w: 46px;
  --tb-h: 140px;
  --tb-r: 10px;
  --tb-t: 10px;
  --dl-w: 60px;
  --dl-h: 52px;
  --dl-r: 10px;
  --dl-b: 10px;

  position: relative;
  max-width: 975px;
  margin: 0 auto;
  padding: 28px 16px 48px;
  overflow: hidden;
}

/* ---------- Shared blocks ---------- */
.brand {
  margin: 8px 0 0;
  font-family: var(--hand);
  font-weight: 400;
  font-size: var(--brand);
  line-height: 1;
  text-align: center;
  letter-spacing: 0.01em;
}

.block { margin: 36px 0 0; }
.block-c { margin-top: 44px; }

.lead {
  margin: 0 auto 18px;
  max-width: 34ch;
  font-family: var(--sans);
  font-size: var(--lead);
  line-height: 1.5;
  text-align: center;
  color: var(--ink-soft);
}
.lead-b { color: var(--ink); margin: 18px auto 0; }

.art {
  margin: 0 auto;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
}
.art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.art-a img {
  transform-origin: 50% 70%;
}
@media (prefers-reduced-motion: no-preference) {
  .art-a img { animation: sketch-float 7s ease-in-out infinite; }
}
@keyframes sketch-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-9px) rotate(-0.8deg); }
}

.prompt {
  margin: 0 0 22px;
  font-family: var(--pridi);
  font-weight: 400;
  font-size: var(--prompt);
  line-height: 1.3;
  text-align: center;
}

/* ---------- Upload zone ---------- */
.dropzone {
  --zone-h: var(--zone-empty);
  position: relative;
  width: 100%;
  height: var(--zone-h);
  border: var(--zone-border) dashed var(--dash);
  border-radius: 0;
  background: transparent;
  transition: height 0.6s cubic-bezier(0.65, 0, 0.35, 1), border-color 0.2s, background-color 0.2s;
  cursor: default;
}
.dropzone[data-mode="empty"] { cursor: pointer; }
.dropzone[data-mode="row"] {
  --zone-h: var(--zone-row);
  height: var(--zone-row);
}
.dropzone.is-drag {
  border-color: rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.03);
}

.add-btn {
  position: absolute;
  z-index: 2;
  width: var(--btn);
  height: var(--btn);
  top: calc((var(--zone-h) - var(--btn)) / 2);
  left: calc(50% - var(--btn) / 2);
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: left 0.6s cubic-bezier(0.65, 0, 0.35, 1), top 0.6s cubic-bezier(0.65, 0, 0.35, 1), background-color 0.2s, transform 0.15s;
}
.dropzone[data-mode="row"] .add-btn {
  left: calc(100% - var(--pad-r) - var(--zone-border) - var(--btn));
}
.add-btn:hover { background: #c9c9c9; }
.add-btn:active { transform: scale(0.96); }
.add-btn[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; }

.plus {
  width: 42%;
  height: 42%;
  background:
    linear-gradient(#000, #000) center / 100% 2px no-repeat,
    linear-gradient(#000, #000) center / 2px 100% no-repeat;
}

.thumbs {
  position: absolute;
  left: var(--pad-x);
  top: calc((var(--zone-h) - var(--thumb-h)) / 2);
  z-index: 1;
  display: flex;
  gap: var(--thumb-gap);
  margin: 0;
  padding: 0;
  list-style: none;
  transition: top 0.6s cubic-bezier(0.65, 0, 0.35, 1);
}
.thumb {
  position: relative;
  flex: 0 0 auto;
  width: var(--thumb-w);
  height: var(--thumb-h);
  margin: 0;
  border-radius: 10px;
  background: var(--panel);
  animation: thumb-in 0.45s ease both;
}
.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
}
/* Hand-drawn cross at the top-right corner, centred just outside the corner like frame 402. */
.thumb-x {
  position: absolute;
  top: calc(var(--x-size) * -0.5 + 6px);
  right: calc(var(--x-size) * -0.5 + 6px);
  width: var(--x-size);
  height: var(--x-size);
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.6) rotate(-6deg);
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.thumb:hover .thumb-x,
.thumb:focus-within .thumb-x,
.thumb-x:focus-visible {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}
.thumb-x:hover { background: rgba(255, 255, 255, 0.7); }
.thumb-x:focus-visible { outline-offset: 2px; }
.thumb-x svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: #141414;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Touch devices have no hover: keep the cross always visible. */
@media (hover: none) {
  .thumb-x { opacity: 1; transform: none; }
}

@keyframes thumb-in {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.zone-error {
  min-height: 1.4em;
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  color: var(--err);
}

/* ---------- 3D viewer panel ---------- */
.viewer {
  position: relative;
  margin-top: 18px;
  height: var(--stage-h);
  background: var(--panel);
  overflow: hidden;
  isolation: isolate;
}
.viewer.is-in { animation: viewer-in 0.6s ease both; }
@keyframes viewer-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

.viewer-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.viewer-canvas canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.viewer-canvas canvas:active { cursor: grabbing; }
.viewer[data-view="photo"] .viewer-canvas { visibility: hidden; }

.photo-view {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 7% 7%;
  background: var(--panel);
}
.viewer[data-view="photo"] .photo-view { display: flex; }
.photo-view img {
  flex: 1 1 30%;
  min-width: 0;
  max-width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.35);
}

.viewer-status {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  background: rgba(217, 217, 217, 0.78);
}
.viewer-status:has(.status-card) { background: rgba(217, 217, 217, 0.6); }

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.voxels {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  gap: 5px;
  transform: rotate(45deg);
}
.voxels i {
  display: block;
  width: 14px;
  height: 14px;
  background: #3b3b3b;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.25);
  animation: voxel 1.2s ease-in-out infinite both;
}
.voxels i:nth-child(1) { animation-delay: 0s; }
.voxels i:nth-child(2) { animation-delay: 0.12s; }
.voxels i:nth-child(3) { animation-delay: 0.24s; }
.voxels i:nth-child(4) { animation-delay: 0.12s; }
.voxels i:nth-child(5) { animation-delay: 0.24s; }
.voxels i:nth-child(6) { animation-delay: 0.36s; }
.voxels i:nth-child(7) { animation-delay: 0.24s; }
.voxels i:nth-child(8) { animation-delay: 0.36s; }
.voxels i:nth-child(9) { animation-delay: 0.48s; }
@keyframes voxel {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-7px); }
}
.loader p {
  margin: 0;
  font-family: var(--hand);
  font-size: 26px;
  letter-spacing: 0.02em;
}

.status-card {
  max-width: min(92%, 360px);
  padding: 18px 20px;
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}
.status-card p {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.45;
}
.retry {
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.retry:hover { background: #000; color: #fff; }

/* toolbar + download */
.toolbar {
  position: absolute;
  z-index: 2;
  top: var(--tb-t);
  right: var(--tb-r);
  width: var(--tb-w);
  height: var(--tb-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
}
.toolbar button {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--line);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.toolbar button + button { border-top: 2px solid var(--line); }
.toolbar button:hover { background: rgba(0, 0, 0, 0.07); }
.toolbar button[aria-pressed="true"] { background: rgba(0, 0, 0, 0.16); }

.icon {
  width: 56%;
  height: 56%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.download {
  position: absolute;
  z-index: 2;
  right: var(--dl-r);
  bottom: var(--dl-b);
  width: var(--dl-w);
  height: var(--dl-h);
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--line);
  text-decoration: none;
}
.download:hover { background: rgba(0, 0, 0, 0.07); }
.download[aria-disabled="true"] {
  opacity: 0.35;
  pointer-events: none;
}
.download .icon { width: 50%; height: 50%; }

/* footer */
.foot {
  margin: 56px 0 0;
  font-family: var(--hand);
  font-size: var(--foot);
  line-height: 1.2;
  text-align: center;
  color: var(--muted);
}

/* ---------- Desktop: absolute layout matching the Figma frame ---------- */
@media (min-width: 761px) {
  .page {
    --brand: calc(128 * var(--u));
    --lead: calc(36 * var(--u));
    --prompt: calc(36 * var(--u));
    --foot: calc(64 * var(--u));
    --zone-empty: calc(900 * var(--u));
    --zone-row: calc(219 * var(--u));
    --btn: calc(100 * var(--u));
    --thumb-w: calc(134 * var(--u));
    --thumb-h: calc(172 * var(--u));
    --thumb-gap: calc(24 * var(--u));
    --pad-x: calc(49 * var(--u));
    --pad-r: calc(40 * var(--u));
    --zone-border: calc(5 * var(--u));
    --x-size: calc(29 * var(--u));
    --stage-h: calc(779 * var(--u));
    --tb-w: calc(107 * var(--u));
    --tb-h: calc(266 * var(--u));
    --tb-r: calc(20 * var(--u));
    --tb-t: calc(15 * var(--u));
    --dl-w: calc(126 * var(--u));
    --dl-h: calc(109 * var(--u));
    --dl-r: calc(26 * var(--u));
    --dl-b: calc(14 * var(--u));

    width: calc(1914 * var(--u));
    height: calc(3926 * var(--u));
    max-width: none;
    padding: 0;
    overflow: visible;
  }

  .block { display: contents; }

  .brand {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(40 * var(--u));
    margin: 0;
  }

  .lead {
    position: absolute;
    margin: 0;
    max-width: none;
  }
  .lead-a {
    left: calc(176 * var(--u));
    top: calc(708 * var(--u));
    width: calc(689 * var(--u));
  }
  .lead-b {
    left: calc(1119 * var(--u));
    top: calc(1603 * var(--u));
    width: calc(593 * var(--u));
  }

  .art {
    position: absolute;
    margin: 0;
    max-width: none;
    width: calc(755 * var(--u));
    height: calc(755 * var(--u));
  }
  .art-a { left: calc(957 * var(--u)); top: calc(406 * var(--u)); }
  .art-b { left: calc(170 * var(--u)); top: calc(1292 * var(--u)); }

  .prompt {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(2252 * var(--u));
    margin: 0;
  }

  .dropzone {
    position: absolute;
    left: calc(170 * var(--u));
    top: calc(2493 * var(--u));
    width: calc(1541 * var(--u));
  }

  .zone-error {
    position: absolute;
    left: calc(170 * var(--u));
    width: calc(1541 * var(--u));
    top: calc(2418 * var(--u));
    margin: 0;
    font-size: calc(28 * var(--u));
  }

  .viewer {
    position: absolute;
    left: calc(170 * var(--u));
    top: calc(2764 * var(--u));
    width: calc(1541 * var(--u));
    margin: 0;
  }

  .foot {
    position: absolute;
    left: calc(648 * var(--u));
    top: calc(3794 * var(--u));
    width: calc(618 * var(--u));
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .voxels i { animation: none; opacity: 0.7; transform: none; }
}

/* ---------------------------------------------------------------- step-by-step build (v5) */
.steps {
  margin: 14px auto 0;
  max-width: 640px;
  padding: 12px 16px 14px;
  font-family: var(--hand);
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: 14px 18px 12px 16px / 16px 12px 18px 14px;
  box-sizing: border-box;
}
.steps[hidden] { display: none; }
.steps-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 14px;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  line-height: 1.2;
  color: var(--muted);
  border-radius: 10px;
  padding: 2px 4px;
  min-width: 0;
}
.step-text { overflow-wrap: anywhere; }
.step-mark {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border: 2px solid var(--dash);
  border-radius: 50% 46% 52% 48%;
  position: relative;
  box-sizing: border-box;
}
.step.is-active { color: var(--ink); }
.step.is-active .step-mark {
  border-color: var(--ink);
  animation: step-pulse 1.4s ease-in-out infinite;
}
.step.is-done { color: var(--ink); }
.step.is-done .step-mark { border-color: var(--ink); }
.step.is-done .step-mark::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 0px;
  width: 7px;
  height: 13px;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: rotate(40deg);
  border-radius: 1px 3px 2px 1px;
}
.step.is-skip { text-decoration: line-through; opacity: 0.5; }
@keyframes step-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.55; }
}
.step-detail {
  margin: 10px 0 0;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink-soft);
  min-height: 1.2em;
}
.verdict {
  margin: 8px 0 0;
  font-family: var(--pridi);
  font-size: 16px;
  line-height: 1.35;
  color: var(--ink);
}
.verdict[hidden] { display: none; }
.scrub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
  font-family: var(--sans);
  font-size: 14px;
}
.scrub[hidden] { display: none; }
.scrub button {
  width: 34px;
  height: 34px;
  font: inherit;
  font-size: 20px;
  line-height: 1;
  background: var(--bg);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.scrub button:disabled { opacity: 0.35; cursor: default; }
@media (max-width: 520px) {
  .steps-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .step.is-active .step-mark { animation: none; }
}

/* steps as an overlay card inside the grey 3D panel (bottom-left, clear of the toolbar and download) */
.viewer .steps {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: min(430px, calc(100% - 120px));
  margin: 0;
  max-width: none;
  padding: 10px 12px 10px;
  z-index: 4;
  background: rgba(255, 254, 250, 0.94);
}
.viewer .steps-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.viewer .step { font-size: 15px; }
.viewer .step-detail { font-size: 13px; }
.viewer .verdict { font-size: 14px; }
@media (max-width: 520px) {
  .viewer .steps { width: calc(100% - 28px); left: 14px; right: 14px; bottom: 60px; }
  .viewer .steps-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}