:root {
  --carta: #F7F1FF;
  --punti: #DCCCF0;
  --ink: #3B1F5C;
  --ink-soft: #6E5A8A;
  --fucsia: #FF3D8B;
  --metro: #FFD23F;
  --menta: #3FBF9F;
  --bianco: #FFFFFF;
  --pinked: none;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--carta);
  color: var(--ink);
  font-family: 'Lexend', ui-rounded, system-ui, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--fucsia); outline-offset: 2px; }
[hidden] { display: none !important; }

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

/* Metro da sarta */
.tape {
  position: relative;
  background: var(--metro);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(8px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 20px calc(22px + env(safe-area-inset-left));
}
.tape::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 14px;
  pointer-events: none;
  opacity: .6;
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 50px) left bottom / 100% 14px no-repeat,
    repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px 10px) left bottom / 100% 7px no-repeat;
}
.logo {
  margin: 0;
  font-family: 'Shrikhand', 'Lexend', serif;
  font-weight: 400;
  font-size: clamp(24px, 3.3vw, 38px);
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-2deg);
}
.actions { display: flex; gap: 2px; }
.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 66px;
  min-height: 56px;
  padding: 6px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  font-size: 12.5px;
  font-weight: 500;
}
.act svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.act svg .dot { fill: currentColor; stroke: none; }
.act:active { background: rgba(59, 31, 92, .12); }
.act-main { background: var(--ink); color: var(--metro); }
.act-main:active { background: #2a1543; }
.act:disabled { opacity: .35; }

/* Studio */
.studio {
  display: grid;
  grid-template-columns: 1fr minmax(340px, 420px);
  min-height: 0;
}
.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background-color: var(--carta);
  background-image: radial-gradient(var(--punti) 1.5px, transparent 1.7px);
  background-size: 22px 22px;
}
#model { position: absolute; inset: 12px 12px 8px; display: flex; justify-content: center; }
#model svg { height: 100%; width: 100%; display: block; overflow: visible; }
.stage.drawing { cursor: crosshair; }

.hint {
  position: absolute;
  left: 18px; top: 14px;
  margin: 0;
  max-width: 260px;
  font-size: 14px;
  line-height: 1.35;
  color: var(--ink-soft);
  pointer-events: none;
}

.sticker-bar {
  position: absolute;
  left: 0; right: 0; bottom: 16px;
  width: max-content;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--bianco);
  border: 2.5px solid var(--ink);
  border-radius: 30px;
  box-shadow: 0 6px 0 rgba(59, 31, 92, .15);
  max-width: calc(100% - 24px);
  flex-wrap: wrap;
  justify-content: center;
}

.g-pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { opacity: .35; } 100% { opacity: 1; } }

/* Pannello */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bianco);
  border-left: 3px solid var(--ink);
}
.tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border-bottom: 2px dashed var(--punti);
  padding: 4px 4px 0;
}
.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 66px;
  padding: 10px 0 10px;
  border: 0;
  background: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
}
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 600; }
.tab[aria-selected="true"]::after {
  content: '';
  position: absolute;
  left: 20%; right: 20%; bottom: -2px;
  height: 5px;
  border-radius: 3px;
  background: var(--fucsia);
}
.panel-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px calc(40px + env(safe-area-inset-bottom));
}
.group { margin-bottom: 24px; }
.group h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.group p.note { margin: 0 0 12px; font-size: 14px; line-height: 1.4; color: var(--ink-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 46px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 23px;
  background: var(--bianco);
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
}
.chip:active { transform: translateY(1px); }
.chip[aria-pressed="true"], .chip-on { background: var(--ink); color: var(--bianco); }
.chip:disabled { opacity: .35; }
.chip.worn::before {
  content: '';
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--fucsia);
  vertical-align: 1px;
}

.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.pieces .chip { padding: 0 10px; }

/* Bottoni colore */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 10px; }
.btn-color {
  position: relative;
  aspect-ratio: 1;
  min-height: 42px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  padding: 0;
  background: var(--c);
}
.btn-color::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 40% 40%, rgba(59,31,92,.45) 0 6%, transparent 7%),
    radial-gradient(circle at 60% 40%, rgba(59,31,92,.45) 0 6%, transparent 7%),
    radial-gradient(circle at 40% 60%, rgba(59,31,92,.45) 0 6%, transparent 7%),
    radial-gradient(circle at 60% 60%, rgba(59,31,92,.45) 0 6%, transparent 7%),
    radial-gradient(circle, transparent 0 58%, rgba(59,31,92,.18) 59% 63%, transparent 64%);
}
.btn-color[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--bianco), 0 0 0 6px var(--fucsia); }

/* Ritagli di stoffa */
.fabrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.fabric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px 4px 8px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  font-size: 12.5px;
  font-weight: 500;
}
.fabric .cut { width: 56px; height: 56px; clip-path: var(--pinked); }
.fabric .cut svg { width: 100%; height: 100%; display: block; }
.fabric[aria-pressed="true"] { background: #FFE3EF; box-shadow: inset 0 0 0 2.5px var(--fucsia); }

.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.sticker-btn {
  aspect-ratio: 1;
  border: 2px dashed var(--punti);
  border-radius: 16px;
  background: var(--carta);
  padding: 6px;
}
.sticker-btn svg { width: 100%; height: 100%; }
.sticker-btn:active { border-color: var(--fucsia); }

.wide-btn {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--ink);
  border-radius: 24px;
  background: var(--bianco);
  font-size: 15px;
  font-weight: 500;
}
.cta {
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 25px;
  background: var(--fucsia);
  color: var(--bianco);
  font-size: 16px;
  font-weight: 600;
}
.cta:active { transform: translateY(1px); }

.empty { font-size: 15px; line-height: 1.45; color: var(--ink-soft); }

/* Finestre */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(59, 31, 92, .45);
}
.card {
  width: min(520px, 100%);
  padding: 26px;
  background: var(--bianco);
  border: 3px solid var(--ink);
  border-radius: 24px;
}
.card h2 { margin: 0 0 16px; font-size: 22px; font-weight: 600; }
.card input {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  font: 500 18px 'Lexend', system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}
.row { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  background-color: var(--carta);
  background-image: radial-gradient(var(--punti) 1.5px, transparent 1.7px);
  background-size: 22px 22px;
}
.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 24px 16px;
  background: var(--metro);
  border-bottom: 3px solid var(--ink);
}
.overlay-head h2 { margin: 0; font-family: 'Shrikhand', serif; font-weight: 400; font-size: 30px; }
.coll-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  align-content: start;
  gap: 18px;
  padding: 24px;
}
.look {
  display: flex;
  flex-direction: column;
  background: var(--bianco);
  border: 2.5px solid var(--ink);
  border-radius: 20px;
  overflow: hidden;
}
.look .thumb { height: 260px; padding: 10px; background: var(--carta); border-bottom: 2px dashed var(--punti); }
.look .thumb svg { width: 100%; height: 100%; }
.look .meta { padding: 12px 12px 4px; font-weight: 600; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.look .row { justify-content: flex-start; margin: 8px 12px 12px; gap: 8px; }
.look .chip { min-height: 42px; padding: 0 14px; font-size: 14px; }
.look .chip.danger[data-armed="true"] { background: var(--fucsia); border-color: var(--fucsia); color: var(--bianco); }
.coll-grid .empty { grid-column: 1 / -1; max-width: 46ch; }

/* Sfilata */
.runway {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  background: #24123A;
}
.spot {
  position: absolute;
  left: 50%; top: -10%;
  width: 70vh; height: 120vh;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 0%, rgba(255, 236, 170, .35), transparent 65%);
  clip-path: polygon(40% 0, 60% 0, 100% 100%, 0 100%);
  pointer-events: none;
}
.floor {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 62%;
  clip-path: polygon(43% 0, 57% 0, 86% 100%, 14% 100%);
  background:
    linear-gradient(90deg, transparent 49.6%, rgba(255,255,255,.55) 49.6% 50.4%, transparent 50.4%),
    linear-gradient(180deg, #FF8FC1 0%, #FFC7DD 100%);
}
.walker {
  position: absolute;
  left: 50%; bottom: 3vh;
  height: 82vh;
  aspect-ratio: 400 / 760;
  transform-origin: 50% 100%;
  opacity: 0;
}
.bob { width: 100%; height: 100%; }
.bob svg { width: 100%; height: 100%; display: block; }
.bob.walking { animation: bob .55s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0) rotate(-1.4deg); } to { transform: translateY(-1.6%) rotate(1.4deg); } }
.name-card {
  position: absolute;
  left: 4vw; bottom: 10vh;
  max-width: 30vw;
  padding: 16px 20px;
  background: var(--metro);
  border: 3px solid var(--ink);
  border-radius: 18px;
  color: var(--ink);
  transform: translateX(-130%) rotate(-3deg);
  transition: transform .45s cubic-bezier(.2, 1.4, .4, 1);
}
.name-card.show { transform: translateX(0) rotate(-3deg); }
.name-card span { display: block; font-size: 14px; margin-bottom: 4px; }
.name-card strong { display: block; font-family: 'Shrikhand', serif; font-weight: 400; font-size: clamp(22px, 3vw, 34px); line-height: 1.1; overflow-wrap: anywhere; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.runway-close { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 18px; }
.runway-end {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 30px 34px;
  background: var(--bianco);
  border: 3px solid var(--ink);
  border-radius: 26px;
  text-align: center;
}
.end-title { margin: 0; font-family: 'Shrikhand', serif; font-size: 40px; }
.runway-end .row { justify-content: center; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 40;
  padding: 14px 22px;
  border-radius: 26px;
  background: var(--ink);
  color: var(--metro);
  font-weight: 600;
  font-size: 16px;
  transform: translate(-50%, calc(100% + 60px));
  visibility: hidden;
  transition: transform .3s ease, visibility 0s .3s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; transition: transform .3s ease; }

/* iPad in verticale e schermi stretti */
@media (orientation: portrait), (max-width: 760px) {
  .studio { grid-template-columns: 1fr; grid-template-rows: 1fr minmax(0, 46%); }
  .panel { border-left: 0; border-top: 3px solid var(--ink); }
  .hint { max-width: 200px; }
}
@media (max-width: 760px) {
  .tape { flex-wrap: wrap; row-gap: 4px; padding-bottom: 18px; }
  .actions { width: 100%; justify-content: space-between; }
  .act span { display: none; }
  .act { min-width: 44px; min-height: 44px; padding: 6px; }
  .logo { font-size: 22px; }
  .tab { min-width: 0; font-size: 11px; letter-spacing: -.01em; }
  .panel-body { padding: 14px 14px calc(30px + env(safe-area-inset-bottom)); }
  .hint { display: none; }
  .name-card { max-width: 60vw; }
}

@media (prefers-reduced-motion: reduce) {
  .bob.walking, .g-pulse { animation: none; }
  .name-card, .toast { transition: none; }
}

/* Schermata di atterraggio */
.landing {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background-color: var(--carta);
  background-image: radial-gradient(var(--punti) 1.5px, transparent 1.7px);
  background-size: 22px 22px;
  -webkit-user-select: text;
  user-select: text;
}
body.is-landing .app { display: none; }
.landing .tape { justify-content: center; padding-top: calc(14px + env(safe-area-inset-top)); padding-bottom: 26px; }
.landing .logo { font-size: clamp(30px, 5vw, 46px); }
.land-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
  align-items: center;
  gap: clamp(20px, 4vw, 56px);
  width: min(1100px, 100%);
  margin: 0 auto;
  padding: clamp(20px, 4vw, 48px) clamp(16px, 4vw, 48px) calc(32px + env(safe-area-inset-bottom));
}
.land-hero { height: min(66vh, 620px); }
.land-hero svg { width: 100%; height: 100%; display: block; }
.land-title {
  margin: 0 0 14px;
  font-family: 'Shrikhand', 'Lexend', serif;
  font-weight: 400;
  font-size: clamp(30px, 4.2vw, 48px);
  line-height: 1.08;
  max-width: 16ch;
}
.land-lead { margin: 0 0 28px; font-size: clamp(17px, 1.8vw, 20px); line-height: 1.5; max-width: 40ch; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; counter-reset: passo; max-width: 560px; }
.steps li {
  counter-increment: passo;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bianco);
  border: 2.5px solid var(--ink);
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.4;
}
.steps li::before {
  content: counter(passo);
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--metro);
  border: 2.5px solid var(--ink);
  font-family: 'Shrikhand', serif;
  font-size: 20px;
}
.steps li small { display: block; margin-top: 3px; font-size: 14px; color: var(--ink-soft); }
.steps .ico {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--carta);
  color: #0A84FF;
}
.steps .ico svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.steps .ico img { width: 46px; height: 46px; border-radius: 11px; }
.land-note { margin: 18px 0 0; font-size: 15px; line-height: 1.45; color: var(--ink-soft); max-width: 52ch; }
.land-qr { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin-top: 8px; }
.land-qr img { width: 168px; height: 168px; padding: 10px; background: var(--bianco); border: 2.5px solid var(--ink); border-radius: 18px; }
.land-qr p { margin: 0; font-size: 17px; line-height: 1.5; max-width: 30ch; }
.land-qr strong { font-weight: 600; }
.land-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 24px; }
.land-link { color: var(--ink); font-size: 15px; font-weight: 500; text-underline-offset: 3px; }

@media (orientation: portrait), (max-width: 760px) {
  .land-body { grid-template-columns: 1fr; align-items: start; }
  .land-hero { height: 34vh; order: -1; }
  .land-title, .land-lead, .steps, .land-note { max-width: none; }
}
@media (max-width: 520px) {
  .steps li { grid-template-columns: 38px 1fr; font-size: 16px; }
  .steps li::before { width: 38px; height: 38px; font-size: 17px; }
  .steps .ico { display: none; }
}
