/* Layout: one narrow column on phones; the spin stage is the focal object.
   Brand (Twurn): deep plum ground, soft stone text, acid lime for the one thing to press.
   Lime is never used as text on light surfaces; warm gray is for secondary text on plum. */
:root {
  color-scheme: dark;
  --plum: #241335;        /* primary: page ground */
  --stone: #F3F1EC;       /* secondary: main text */
  --lime: #B8FF3B;        /* accent: main actions, highlights */
  --plum-2: #3B2D4A;      /* support dark: raised surfaces */
  --warm-gray: #B8B1C2;   /* muted: secondary text */
  --room: var(--plum);
  --panel: var(--plum-2);
  --line: rgba(184, 177, 194, .22);
  --text: var(--stone);
  --dim: var(--warm-gray);
  --mark: var(--lime);
  --mark-ink: var(--plum); /* text on lime */
  --bad: #ff8f80;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --logo: "Fredoka", "Arial Rounded MT Bold", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--room); color: var(--text); }
body {
  background:
    radial-gradient(90% 45% at 100% -5%, rgba(184, 255, 59, .10), transparent 65%),
    radial-gradient(110% 55% at 0% -10%, rgba(59, 45, 74, .9), transparent 70%),
    var(--room);
  background-attachment: fixed;
}
body {
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }

.top {
  padding-inline: 16px;
  padding-block: 14px;
  max-width: 1040px;
  margin-inline: auto;
}
.brand {
  font-family: var(--logo);
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--text);
  text-decoration: none;
}
.brand .tw { color: var(--lime); }

.wrap { max-width: 1040px; margin-inline: auto; padding-inline: 16px; padding-block: 8px 48px; }
.view { display: flex; flex-direction: column; gap: 18px; }

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(32px, 7vw, 52px);
  line-height: 1.02;
  letter-spacing: .01em;
  text-transform: uppercase;
  text-wrap: balance;
  margin: 12px 0 0;
  max-width: 16ch;
}
.lede { color: var(--dim); margin: 0; max-width: 46ch; font-size: 17px; }

/* Upload */
.upload { display: flex; flex-direction: column; gap: 16px; max-width: 480px; }
.drop {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 5;
  max-width: 100%;
  max-height: 46dvh;
  border: 2px dashed rgba(184, 255, 59, .45);
  border-radius: 18px;
  background: var(--panel);
  cursor: pointer;
  overflow: hidden;
}
.drop:hover, .drop.over { border-color: var(--dim); }
.drop:focus-within { outline: 2px solid var(--mark); outline-offset: 2px; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--panel); }
.drop-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; text-align: center; padding: 16px; }

/* Upload demo: photo goes up, a sprinkle of magic, then it turns all the way around (6 s loop) */
.demo { position: relative; width: 170px; height: 180px; margin-bottom: 10px; }
/* The outer card moves and fades; the inner one turns. Kept apart because a fading element
   flattens 3D, which would hide the back of the card. */
.demo-card {
  position: absolute; left: 37px; top: 6px; width: 96px; height: 120px;
  perspective: 520px;
  animation: demo-card 6s infinite;
}
.demo-spin {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  animation: demo-spin 6s infinite;
}
.demo-face {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border-radius: 10px; border: 3px solid var(--stone);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.demo-face.back { transform: rotateY(180deg); }
.demo-orbit {
  position: absolute; left: 5px; bottom: 6px; width: 160px; height: 40px;
  color: var(--mark); overflow: visible;
  animation: demo-orbit 6s infinite;
}
.demo-spark {
  position: absolute; width: 18px; height: 18px; background: var(--mark);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  opacity: 0; transform: scale(0);
  animation: demo-spark 6s infinite;
}
.demo-spark.s1 { left: 14px; top: 10px; }
.demo-spark.s2 { right: 12px; top: 30px; width: 14px; height: 14px; background: var(--stone); animation-delay: .12s; }
.demo-spark.s3 { left: 22px; top: 92px; width: 12px; height: 12px; background: var(--warm-gray); animation-delay: .24s; }
.demo-spark.s4 { right: 22px; top: 100px; width: 16px; height: 16px; background: var(--lime); animation-delay: .06s; }
@keyframes demo-card {
  0%   { transform: translateY(46px) scale(.9); opacity: 0; animation-timing-function: cubic-bezier(.2,.8,.3,1); }
  14%  { transform: translateY(0) scale(1); opacity: 1; }
  22%  { transform: translateY(0) scale(1.06); }
  30%  { transform: translateY(0) scale(1); }
  92%  { opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 0; }
}
@keyframes demo-spin {
  0%, 30% { transform: rotateY(0deg); animation-timing-function: cubic-bezier(.45,0,.25,1); }
  78%, 100% { transform: rotateY(360deg); }
}
@keyframes demo-spark {
  0%, 14% { opacity: 0; transform: scale(0) rotate(0deg); }
  21%     { opacity: 1; transform: scale(1.1) rotate(45deg); }
  32%, 100% { opacity: 0; transform: scale(0) rotate(90deg); }
}
@keyframes demo-orbit {
  0%, 26%  { opacity: 0; transform: scaleX(.7); }
  34%, 88% { opacity: 1; transform: scaleX(1); }
  100%     { opacity: 0; transform: scaleX(1); }
}
.drop-title { font-family: var(--display); font-weight: 600; font-size: 24px; letter-spacing: .06em; text-transform: uppercase; }
.drop-sub { color: var(--dim); font-size: 14px; }

.tips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--dim); font-size: 14px; }
.tips li::before { content: "·"; color: var(--mark); margin-right: 6px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-family: var(--display); font-weight: 500; font-size: 14px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); }
.field input {
  font: 16px var(--mono);
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 12px;
  border-radius: 12px;
  min-width: 0;
}
.field input:focus { outline: 2px solid var(--mark); outline-offset: 1px; border-color: transparent; }

.error { color: var(--bad); margin: 0; }

button, .button {
  font-family: var(--display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}
button:hover, .button:hover { border-color: var(--dim); }
button:focus-visible, .button:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
.primary { background: var(--mark); border-color: var(--mark); color: var(--mark-ink); font-weight: 600; font-size: 20px; min-height: 52px; }
.primary:hover { border-color: var(--stone); }
.primary:disabled:hover { border-color: var(--mark); }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.primary.small { font-size: 16px; min-height: 40px; }

/* The main call to action: lime pill with plum lettering */
.spin-cta {
  font-family: var(--display);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--plum);
  background: var(--lime);
  border: 0;
  border-radius: 999px;
  min-height: 60px;
  padding: 10px 24px;
  box-shadow: 0 8px 24px rgba(184, 255, 59, .22);
  transition: transform .12s ease-out, box-shadow .12s ease-out, filter .2s, opacity .2s;
}
.spin-cta:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(184, 255, 59, .32); border: 0; }
.spin-cta:active { transform: translateY(2px); box-shadow: 0 4px 12px rgba(184, 255, 59, .2); }
.spin-cta:focus-visible { outline: 3px solid var(--stone); outline-offset: 3px; }
.spin-cta:disabled { opacity: .38; cursor: not-allowed; transform: none; box-shadow: none; }
.ghost { align-self: flex-start; }

.free-note { margin: -4px 0 0; text-align: center; font-weight: 600; color: var(--lime); }
.free-note.out { color: var(--dim); font-weight: 500; }
#human-check:empty { display: none; }
#human-check { display: flex; justify-content: center; }
button.code-link, button.code-link:hover {
  align-self: center;
  background: none;
  border: 0;
  box-shadow: none;
  padding: 2px 4px;
  font: 14px var(--body, inherit);
  text-transform: none;
  letter-spacing: 0;
  color: var(--dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* While the spin is being made: the photo fills the viewer, with progress along the bottom */
.pending {
  position: absolute; inset: 0;
  background: var(--panel);
  overflow: hidden;
  transition: opacity .35s ease-out;
  z-index: 2;
}
.pending.fading { opacity: 0; pointer-events: none; }
.pending img { width: 100%; height: 100%; object-fit: contain; }
.sphere { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Example spin on the home page */
.example { margin: 0; display: flex; flex-direction: column; gap: 8px; max-width: 480px; }
.ex-stage {
  position: relative; aspect-ratio: 1; border-radius: 18px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  cursor: ew-resize; touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
.ex-stage img, .ex-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ex-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: rgba(29,16,48,.68); padding: 6px 14px; border-radius: 999px;
  pointer-events: none; transition: opacity .4s;
}
.ex-hint::before, .ex-hint::after { content: "‹"; margin-right: 8px; opacity: .8; }
.ex-hint::after { content: "›"; margin: 0 0 0 8px; }
.ex-hint.gone { opacity: 0; }
.example figcaption { font-size: 16px; font-weight: 600; color: var(--lime); }

/* Your spins */
.mine { display: flex; flex-direction: column; gap: 10px; }
.mine h2 {
  font-family: var(--display); font-weight: 600; font-size: 20px;
  letter-spacing: .06em; text-transform: uppercase; margin: 8px 0 0;
}
.mine-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px;
}
.mine-grid a {
  display: block; position: relative; aspect-ratio: 3 / 4;
  background: var(--panel); border: 1px solid var(--line); overflow: hidden; border-radius: 12px;
}
.mine-grid a:hover { border-color: var(--dim); }
.mine-grid a:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
.mine-grid img { width: 100%; height: 100%; object-fit: cover; }
.mine-grid time {
  position: absolute; left: 0; right: 0; bottom: 0;
  font: 11px var(--mono); color: #ffffff; padding: 3px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.6));
}
.mine-note { margin: 0; font-size: 13px; color: var(--dim); }
.progress {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px 12px;
  width: 100%;
}
.pending-title {
  grid-column: 1 / -1;
  font-family: var(--display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text);
}
.pct { font-family: var(--mono); font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.bar { position: relative; height: 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--mark); transition: width .6s ease-out; }
.bar .fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.6), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* Result */
.stage {
  position: relative;
  width: 100%;
  max-height: 72dvh;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  border-radius: 18px;
  touch-action: none;
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
  margin-inline: auto;
}
.stage:focus-visible { outline: 2px solid var(--mark); outline-offset: 2px; }
.stage canvas { display: block; width: 100%; height: 100%; }
.hint-chip {
  position: absolute; left: 10px; top: 10px;
  font: 12px var(--mono);
  background: rgba(29,16,48,.68);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
  transition: opacity .4s;
}
.hint-chip.gone { opacity: 0; }
.badges { position: absolute; right: 10px; top: 10px; display: flex; align-items: center; gap: 6px; pointer-events: none; }
.globe { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: rgba(0,0,0,.5); }
.globe svg { width: 20px; height: 20px; fill: none; stroke: rgba(255,255,255,.85); stroke-width: 1.1; }
.hd-chip {
  font: 600 12px var(--mono);
  letter-spacing: .06em;
  background: rgba(0,0,0,.5);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 8px;
  line-height: 18px;
}
.hd-chip.working { animation: pulse 1.4s ease-in-out infinite; }
.hd-chip.done { animation: pop .35s ease-out; } /* same 50% black badge as other apps use */
@keyframes pulse { 50% { opacity: .45; } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.controls { display: flex; flex-direction: column; gap: 10px; }
.controls.waiting { display: none; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.grow { flex: 1 1 0; }
.share { gap: 8px; padding-inline: 22px; font-size: 18px; min-height: 48px; box-shadow: 0 6px 18px rgba(184, 255, 59, .2); }
.share svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.share:active { transform: translateY(2px); box-shadow: none; }
.text-link {
  color: var(--dim); font-size: 15px; text-decoration: underline; text-underline-offset: 3px;
  padding: 8px 10px;
}
.text-link:hover { color: var(--text); }

.toast {
  border-radius: 999px;
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--room);
  font-family: var(--display); font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  padding: 8px 14px;
}

@media (min-width: 860px) {
  #view-upload { display: grid; grid-template-columns: 1fr 440px; column-gap: 48px; align-items: start; }
  #view-upload[hidden] { display: none !important; }
  #view-upload h1, #view-upload .lede, #view-upload .example, #view-upload .mine { grid-column: 1; }
  #view-upload .example { margin-top: 18px; max-width: 420px; }
  #view-upload .mine { margin-top: 24px; }
  #view-upload .upload { grid-column: 2; grid-row: 1 / span 4; }
}

/* Phones: the viewer fills the screen height. Spins are wide, so the sides are cropped;
   the person stays centred throughout the orbit, so nothing important is lost.
   Zoom buttons are hidden because pinching does the same. */
@media (max-width: 700px) {
  .wrap { padding-block: 4px 12px; }
  #view-result { gap: 12px; }
  .stage {
    aspect-ratio: auto !important;
    max-width: none !important;
    max-height: none;
    height: calc(100dvh - 150px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-height: 320px;
  }
  .stage canvas { object-fit: cover; }
  .pending img { object-fit: cover; }
  #b-in, #b-out { display: none; }
  .row { flex-wrap: nowrap; }
  .row .grow { display: none; }
  .row > * { white-space: nowrap; }
  .row .share { flex: 1 1 auto; }
  .row .text-link { flex: none; font-size: 14px; padding-inline: 4px; }
  .demo { transform: scale(.85); margin: -12px 0 -4px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar .fill::after, .hd-chip.working, .hd-chip.done { animation: none; }
  .demo-card { animation: none; }
  .demo-spin { animation: none; transform: rotateY(-28deg); }
  .demo-orbit { animation: none; }
  .demo-spark { display: none; }
}
