:root {
  --eazo-safe-area-top: max(56px, env(safe-area-inset-top, 0px));
  --eazo-safe-area-bottom: max(34px, env(safe-area-inset-bottom, 0px));
  --paper: #f6f0e8;
  --paper-deep: #ebe1d6;
  --ink: #2d2925;
  --warm-ink: #6e645b;
  --hairline: rgba(45, 41, 37, .18);
  --accent: #b66d62;
  --accent-soft: #ead0ca;
  --shadow: 0 20px 60px rgba(70, 54, 43, .18);
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(182, 109, 98, .13), transparent 28%),
    linear-gradient(135deg, #fbf7f0 0%, var(--paper) 48%, #e8dccf 100%);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

button {
  font: inherit;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
  width: 100%;
  padding-top: var(--eazo-safe-area-top);
  padding-bottom: var(--eazo-safe-area-bottom);
  display: flex;
  justify-content: center;
  overflow-x: hidden;
}

.sheet {
  width: min(100%, 460px);
  min-height: calc(100dvh - var(--eazo-safe-area-top) - var(--eazo-safe-area-bottom));
  display: flex;
  flex-direction: column;
  padding: 10px 18px 12px;
  gap: 10px;
  position: relative;
}

.sheet::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(45, 41, 37, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 41, 37, .025) 1px, transparent 1px);
  background-size: 22px 22px, 22px 22px;
  -webkit-mask-image: radial-gradient(circle at center, black, transparent 75%);
  mask-image: radial-gradient(circle at center, black, transparent 75%);
  opacity: .55;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  flex: 0 0 auto;
  min-width: 0;
}

.brandline { display: flex; flex-direction: column; min-width: 0; }

.eyebrow {
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

h1 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -.045em;
  font-size: clamp(28px, 8.5vw, 42px);
  line-height: .92;
  margin: 2px 0 0;
}

.language {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: rgba(255, 252, 247, .62);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.85);
  flex: 0 0 auto;
}
.lang-btn {
  min-height: 38px;
  min-width: 48px;
  border-radius: 999px;
  background: transparent;
  color: var(--warm-ink);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
}
.lang-btn.active { background: var(--ink); color: var(--paper); }

.client-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  flex: 0 0 auto;
}
.client-tab {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 8px 6px 6px;
  border-radius: 999px;
  background: rgba(255, 252, 247, .58);
  border: 1px solid var(--hairline);
  color: var(--warm-ink);
  min-width: 0;
}
.client-tab.active {
  color: var(--ink);
  border-color: rgba(182, 109, 98, .58);
  background: #fff9f4;
  box-shadow: 0 10px 26px rgba(120, 80, 65, .10);
}
.thumb {
  width: 42px; height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(45, 41, 37, .16);
  background: #dad2c9 center/cover no-repeat;
  flex: 0 0 auto;
  overflow: hidden;
}
.client-meta { display: flex; flex-direction: column; min-width: 0; }
.client-name {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.portrait-plate {
  flex: 1 1 auto;
  min-height: 300px;
  max-height: min(58dvh, 560px);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid var(--hairline);
  border-radius: 28px;
  background:
    linear-gradient(#fffaf5, #f4ece2) padding-box,
    linear-gradient(135deg, rgba(255,255,255,.8), rgba(182,109,98,.32)) border-box;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.portrait-plate::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(45, 41, 37, .09);
  border-radius: 22px;
  pointer-events: none;
  z-index: 20;
}

.portrait {
  height: auto;
  width: 100%;
  max-width: min(100%, 56dvh);
  max-height: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  background: #d8d4ce;
  box-shadow: inset 0 0 0 1px rgba(45, 41, 37, .14);
  touch-action: none;
  isolation: isolate;
}

.photo-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
.photo-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 3;
  clip-path: inset(0 calc(100% - var(--wipe, 100%)) 0 0);
}
.photo-layer.crossfade { animation: editorialFade 520ms ease both; }
@keyframes editorialFade {
  from { opacity: .12; filter: blur(5px) saturate(.85); transform: scale(1.015); }
  to   { opacity: 1; filter: blur(0) saturate(1); transform: scale(1); }
}

.photo-fallback {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #e4ddd4, #cfc6bb);
  color: var(--warm-ink);
  font-size: 13px;
  letter-spacing: .04em;
  text-align: center;
  padding: 20px;
}
.photo-fallback[hidden] { display: none; }

.stage-tags {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.tag {
  border: 1px solid rgba(45,41,37,.14);
  background: rgba(246,240,232,.78);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(45,41,37,.72);
  font-weight: 800;
}
.closest-tag {
  color: #fff7ef;
  background: rgba(182,109,98,.9);
  border-color: rgba(182,109,98,.2);
}
.closest-tag[hidden] { display: none; }

.slider-handle {
  position: absolute;
  top: 0; bottom: 0;
  left: var(--wipe, 100%);
  width: 46px;
  transform: translateX(-23px);
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.slider-handle::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 1px;
  background: rgba(255,250,245,.94);
  box-shadow: 0 0 0 1px rgba(45,41,37,.13);
}
.slider-knob {
  position: relative;
  width: 40px; height: 40px;
  border-radius: 999px;
  background: rgba(255, 250, 245, .92);
  border: 1px solid rgba(45,41,37,.18);
  box-shadow: 0 8px 22px rgba(45,41,37,.22);
  display: grid;
  place-items: center;
  font-size: 15px;
  color: var(--accent);
}

.anim-layer {
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
  opacity: 0;
}
.anim-layer.play { animation: fadeOverlay 620ms ease both; }
@keyframes fadeOverlay { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }

.anim-layer.cut::before, .anim-layer.cut::after {
  content: "";
  position: absolute;
  left: 24%; top: 32%;
  width: 52%; height: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(182,109,98,.7);
  transform-origin: left center;
  animation: snip 620ms ease both;
}
.anim-layer.cut::after { top: 40%; transform: rotate(-12deg); }
@keyframes snip { 0% { clip-path: inset(0 100% 0 0); } 55%,100% { clip-path: inset(0); } }

.anim-layer.dye { background: linear-gradient(180deg, transparent 6%, rgba(182,109,98,.32), transparent 74%); }
.anim-layer.dye.play { animation: wash 620ms ease both; }
@keyframes wash { from { opacity: 0; transform: translateY(-30%); } 45% { opacity: 1; } to { opacity: 0; transform: translateY(20%); } }

.anim-layer.curl::before {
  content: ""; position: absolute; left: 36%; top: 22%; width: 28%; height: 24%;
  border: 3px solid var(--accent); border-left-color: transparent; border-radius: 50%;
  box-shadow: 0 0 10px rgba(182,109,98,.4);
  animation: spinLine 620ms ease both;
}
@keyframes spinLine { from { transform: scale(.4) rotate(-90deg); } to { transform: scale(1.5) rotate(280deg); } }

.anim-layer.braid::before {
  content: ""; position: absolute; left: 28%; top: 24%; width: 44%; height: 30%;
  background: repeating-linear-gradient(135deg, transparent 0 9px, rgba(182,109,98,.7) 10px 13px, transparent 14px 22px);
  clip-path: inset(0 100% 0 0);
  animation: weave 620ms ease both;
}
@keyframes weave { to { clip-path: inset(0); } }

.anim-layer.shave::before {
  content: ""; position: absolute; left: 22%; top: 30%; width: 56%; height: 4px;
  border-radius: 10px; background: #2d2925;
  box-shadow: 0 9px 0 rgba(45,41,37,.3), 0 -9px 0 rgba(45,41,37,.16), 0 0 10px rgba(0,0,0,.3);
  animation: clipper 620ms cubic-bezier(.2,.8,.2,1) both;
}
@keyframes clipper { from { transform: translateX(-34%) rotate(-8deg); opacity: 0; } 30% { opacity: 1; } to { transform: translateX(36%) rotate(7deg); opacity: 0; } }

.anim-layer.grow::before {
  content: ""; position: absolute; inset: 10%;
  background: radial-gradient(circle, rgba(255,255,255,.9), rgba(182,109,98,.2) 35%, transparent 66%);
  transform: scale(.5);
  animation: shimmer 620ms ease both;
}
@keyframes shimmer { to { transform: scale(1.3); opacity: 0; } }

.instruction {
  margin: 0;
  width: 100%;
  text-align: center;
  color: var(--warm-ink);
  font-size: 12.5px;
  line-height: 1.35;
  max-width: 40em;
}

.controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  z-index: 3;
}
.tools { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.tool {
  min-width: 0;
  height: 56px;
  padding: 5px 2px;
  border-radius: 18px;
  border: 1px solid rgba(45,41,37,.14);
  background: rgba(255,252,247,.62);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink);
  transition: background .18s ease, border-color .18s ease, transform .1s ease;
}
.tool:active { transform: scale(.96); }
.tool.active { background: var(--accent-soft); border-color: rgba(182,109,98,.56); }
.tool svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tool span { font-size: 10px; font-weight: 800; letter-spacing: .02em; }

.swatches {
  display: grid;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  gap: 8px;
  padding: 6px 8px;
  border-radius: 22px;
  border: 1px solid var(--hairline);
  background: rgba(255,252,247,.66);
}
.swatches[hidden] { display: none; }
.swatch {
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(45,41,37,.16);
  background: var(--swatch);
  color: transparent;
  position: relative;
  overflow: hidden;
}
.swatch.active::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px solid rgba(255,250,245,.94);
  border-radius: inherit;
  box-shadow: 0 0 0 1px rgba(45,41,37,.22);
}

.actions { display: grid; grid-template-columns: 1fr 1fr 1.15fr; gap: 8px; }
.action {
  border-radius: 999px;
  border: 1px solid rgba(45,41,37,.16);
  background: rgba(255,252,247,.72);
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: transform .1s ease, opacity .18s ease;
}
.action:active { transform: scale(.97); }
.action.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.action:disabled { opacity: .42; cursor: default; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--eazo-safe-area-top) + 6px) 16px calc(var(--eazo-safe-area-bottom) + 6px);
  background: rgba(45,41,37,.28);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  overflow-y: auto;
}
.modal[hidden] { display: none; }

.result-card {
  width: min(100%, 460px);
  max-height: 100%;
  overflow: auto;
  background: #fffaf4;
  border: 1px solid rgba(45,41,37,.16);
  border-radius: 30px;
  box-shadow: 0 28px 80px rgba(45,41,37,.30);
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}
.result-head {
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 12px;
}
.result-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  line-height: .98;
  font-weight: 500;
  letter-spacing: -.035em;
}
.status-pill {
  border-radius: 999px;
  background: var(--accent-soft);
  color: #6d3832;
  font-size: 11px;
  padding: 8px 10px;
  white-space: nowrap;
  font-weight: 800;
  align-self: center;
}
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}
.result-actions button {
  border-radius: 999px;
  background: rgba(246,240,232,.9);
  border: 1px solid var(--hairline);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  min-height: 46px;
  color: var(--ink);
}
.result-actions .share { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.result-actions button:disabled { opacity: .5; cursor: default; }

.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.mini-result {
  margin: 0;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(45,41,37,.13);
  background: #d8d4ce;
  aspect-ratio: 1 / 1;
}
.mini-result img { width: 100%; height: 100%; object-fit: cover; object-position: center center; display: block; }
.mini-label {
  position: absolute;
  left: 8px; bottom: 8px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 10px;
  background: rgba(255,250,245,.86);
  color: var(--warm-ink);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 800;
}
.note {
  margin: 14px 0 0;
  padding: 14px;
  border-left: 2px solid var(--accent);
  background: linear-gradient(90deg, rgba(182,109,98,.1), transparent);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.35;
}
.detail { margin-top: 12px; color: var(--warm-ink); font-size: 13px; line-height: 1.45; }
.close-modal {
  margin-top: 14px;
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--warm-ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--eazo-safe-area-bottom) + 14px);
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  padding: 12px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease, transform 240ms ease;
  font-size: 13px;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 780px) {
  .sheet {
    width: min(100%, 1040px);
    display: grid;
    grid-template-columns: minmax(280px, .82fr) minmax(360px, 1fr);
    grid-template-rows: auto auto 1fr;
    column-gap: 34px;
    row-gap: 14px;
    padding-inline: 28px;
  }
  .topbar { grid-column: 1 / -1; }
  .client-strip { grid-column: 1; align-self: start; grid-template-columns: 1fr; }
  .stage-wrap { grid-column: 2; grid-row: 2 / 4; }
  .controls { grid-column: 1; grid-row: 3; align-self: end; }
  .portrait-plate { max-height: min(72dvh, 700px); }
}

@media (max-height: 720px) {
  .sheet { gap: 7px; padding-inline: 14px; }
  .portrait-plate { min-height: 235px; max-height: 48dvh; padding: 8px; border-radius: 24px; }
  .tool { height: 50px; border-radius: 16px; }
  .tool svg { width: 16px; height: 16px; }
  .instruction { font-size: 11.5px; line-height: 1.25; }
  h1 { font-size: 28px; }
  .client-tab { padding: 5px; }
  .thumb { width: 30px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
