/* ----- HAKUDŌ Try-On — typography from auto-google-font (Inter, scale: minor-third) ----- */

:root {
  --color-bg: #f4f1eb;
  --color-surface: #fffcf6;
  --color-ink: #2c2721;
  --color-ink-soft: #4f4738;
  --color-muted: #8a8174;
  --color-line: #d8d0c3;
  --color-gold: #b69667;
  --color-gold-soft: #d9c198;
  --color-bad: #b14a3a;

  --font-display: "Fraunces", "Times New Roman", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --font-size-xs:   0.6944rem;
  --font-size-sm:   0.8333rem;
  --font-size-base: 1rem;
  --font-size-lg:   1.2rem;
  --font-size-xl:   1.44rem;
  --font-size-2xl:  1.728rem;
  --font-size-3xl:  2.0736rem;
  --font-size-4xl:  2.4883rem;

  --lh-base: 1.5;
  --lh-tight: 1.1;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(44, 39, 33, 0.06), 0 12px 28px rgba(44, 39, 33, 0.07);
  --shadow-button: 0 1px 2px rgba(44, 39, 33, 0.08), 0 6px 18px rgba(44, 39, 33, 0.12);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 252, 246, 0.95), rgba(244, 241, 235, 0) 60%),
    radial-gradient(80% 40% at 90% 100%, rgba(182, 150, 103, 0.18), rgba(244, 241, 235, 0) 60%),
    linear-gradient(180deg, #f7f4ef 0%, var(--color-bg) 60%, #ebe3d7 100%);
  background-attachment: fixed;
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: var(--lh-base);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

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

img, svg { display: block; max-width: 100%; }

/* ----- App shell ----- */

.app {
  min-height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 20px env(safe-area-inset-bottom, 24px);
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 18px 0 6px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.topbar__logo {
  height: 22px;
  width: auto;
  opacity: 0.96;
}

.frame-mosaic {
  position: relative;
  width: calc(100% + 40px);
  margin: 4px -20px 14px;
  height: 260px;
  overflow: hidden;
  isolation: isolate;
  perspective: 900px;
  perspective-origin: 50% 35%;

  /* Soft-edged alpha mask (Gaussian-ish falloff via multi-stop gradients) on both axes,
     composited so only where horizontal AND vertical mask are opaque is the mosaic visible. */
  -webkit-mask-image:
    linear-gradient(90deg,
      transparent 0%,
      rgba(0,0,0,0.18) 6%,
      rgba(0,0,0,0.55) 10%,
      rgba(0,0,0,0.85) 14%,
      #000 20%,
      #000 80%,
      rgba(0,0,0,0.85) 86%,
      rgba(0,0,0,0.55) 90%,
      rgba(0,0,0,0.18) 94%,
      transparent 100%),
    linear-gradient(180deg,
      transparent 0%,
      rgba(0,0,0,0.35) 6%,
      rgba(0,0,0,0.8) 12%,
      #000 18%,
      #000 70%,
      rgba(0,0,0,0.8) 82%,
      rgba(0,0,0,0.35) 92%,
      transparent 100%);
  -webkit-mask-composite: source-in;
          mask-image:
    linear-gradient(90deg,
      transparent 0%,
      rgba(0,0,0,0.18) 6%,
      rgba(0,0,0,0.55) 10%,
      rgba(0,0,0,0.85) 14%,
      #000 20%,
      #000 80%,
      rgba(0,0,0,0.85) 86%,
      rgba(0,0,0,0.55) 90%,
      rgba(0,0,0,0.18) 94%,
      transparent 100%),
    linear-gradient(180deg,
      transparent 0%,
      rgba(0,0,0,0.35) 6%,
      rgba(0,0,0,0.8) 12%,
      #000 18%,
      #000 70%,
      rgba(0,0,0,0.8) 82%,
      rgba(0,0,0,0.35) 92%,
      transparent 100%);
          mask-composite: intersect;
}

.frame-mosaic__stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 0;
  transform: rotateX(22deg) translateZ(-6px);
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  will-change: transform;
}

.frame-row {
  display: flex;
  flex-shrink: 0;
  flex: 1 1 auto;
  gap: 10px;
  width: max-content;
  animation-name: frameDrift;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}

.frame-row--a { animation-duration: 32s; animation-direction: normal; }
.frame-row--b { animation-duration: 44s; animation-direction: reverse; }
.frame-row--c { animation-duration: 36s; animation-direction: normal; }

.frame-row img {
  flex-shrink: 0;
  width: 96px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border: 1px solid rgba(216, 208, 195, 0.7);
  border-radius: 12px;
  box-shadow:
    0 1px 1px rgba(44, 39, 33, 0.04),
    0 8px 18px rgba(44, 39, 33, 0.08);
  padding: 6px 8px;
}

@keyframes frameDrift {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-50%, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .frame-row { animation: none !important; }
}

/* ----- Step state machine ----- */

.step {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 8px 0 28px;
  gap: 14px;
  animation: fadeUp 280ms ease-out;
}

.step[hidden] { display: none; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Hero on welcome ----- */

.hero {
  padding: 8px 0 14px;
}

h1, h2 {
  font-family: var(--font-display);
  font-feature-settings: "ss01", "ss02";
  color: var(--color-ink);
}

h1 {
  font-size: var(--font-size-4xl);
  line-height: var(--lh-tight);
  letter-spacing: -0.022em;
  font-weight: 600;
  margin: 0 0 12px;
}

h2 {
  font-size: var(--font-size-2xl);
  line-height: var(--lh-tight);
  letter-spacing: -0.015em;
  font-weight: 600;
  margin: 4px 0 8px;
}

.hero p {
  margin: 0;
  font-size: var(--font-size-lg);
  color: var(--color-ink-soft);
  max-width: 28ch;
}

/* ----- Big buttons (tap targets ~ 60px) ----- */

.big-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 60px;
  padding: 0 22px;
  background: var(--color-surface);
  color: var(--color-ink);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--font-size-lg);
  letter-spacing: -0.005em;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-button);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.big-button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(44, 39, 33, 0.08);
}

.big-button--primary {
  background: var(--color-ink);
  color: #fff8ed;
  border-color: var(--color-ink);
}

.big-button input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.big-button[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  background: transparent;
  border: 0;
  color: var(--color-ink-soft);
  font-size: var(--font-size-base);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  position: relative;
}

.link-button input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.link-button:active { color: var(--color-ink); }

/* ----- Trust line on welcome ----- */

.trust {
  margin: 4px 0 0;
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  text-align: center;
}

/* ----- Camera step ----- */

.step--camera {
  align-items: stretch;
  padding-top: 12px;
}

.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #1a140e;
  box-shadow: var(--shadow-card);
}

.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #1a140e;
}

.camera-stage__guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(60% 64% at 50% 48%, rgba(0,0,0,0) 0%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.55) 100%);
}

.camera-stage__guide::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 48%;
  width: 60%;
  aspect-ratio: 3 / 4;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 248, 237, 0.6);
  border-radius: 50%;
}

.big-button--shutter {
  background: var(--color-ink);
  color: #fff8ed;
  border-color: var(--color-ink);
  gap: 12px;
  font-weight: 700;
}

.shutter-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff8ed;
  box-shadow: inset 0 0 0 3px var(--color-ink), 0 0 0 2px #fff8ed;
}

/* ----- Photo preview ----- */

.preview {
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #e7ded1;
  box-shadow: var(--shadow-card);
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ----- Loader ----- */

.step--working {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-top: 24px;
}

.loader {
  width: min(280px, 78vw);
  margin: 4px 0;
}

.loader g { fill: none; stroke: var(--color-ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

.loader__macron line { stroke-width: 3.5; }

@keyframes frameFade {
  0%, 22%       { opacity: 1; }
  28%, 100%     { opacity: 0; }
}

.loader__frame {
  opacity: 0;
  animation: frameFade 6s ease-in-out infinite;
}

.loader__frame--1 { animation-delay: 0s; }
.loader__frame--2 { animation-delay: 1.5s; }
.loader__frame--3 { animation-delay: 3s; }
.loader__frame--4 { animation-delay: 4.5s; }

@keyframes macronPulse {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 1; }
}

.loader__macron { animation: macronPulse 1.5s ease-in-out infinite; }

.status {
  margin: 6px 0 0;
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-ink);
  min-height: 1.6em;
}

.hint {
  margin: 4px 0 0;
  font-size: var(--font-size-sm);
  color: var(--color-muted);
}

.progress__bar {
  width: 100%;
  max-width: 320px;
  height: 6px;
  margin: 14px auto 0;
  background: rgba(216, 208, 195, 0.7);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress__bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-gold), var(--color-ink));
  border-radius: var(--radius-pill);
  transition: width 600ms ease;
}

/* ----- Result ----- */

.step--result h2 {
  text-align: center;
}

.result-image {
  width: 100%;
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-card);
  margin: 6px 0 4px;
}

/* ----- Error ----- */

.step--error {
  align-items: center;
  text-align: center;
  padding-top: 36px;
}

.error-mark {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(177, 74, 58, 0.12);
  color: var(--color-bad);
  font-size: 32px;
  font-weight: 800;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
}

/* ----- Desktop nicety (not the primary target, but tidy) ----- */

@media (min-width: 720px) {
  .app { max-width: 520px; }
  .preview { aspect-ratio: 4 / 5; }
}

@media (prefers-reduced-motion: reduce) {
  .step,
  .loader__scan,
  .loader__dot,
  .loader__frame,
  .loader__badge {
    animation: none !important;
  }
  .progress__bar span { transition: none !important; }
}
