/* =====================================================================
   SORTI Scanner - stile
   Palette in cima: cambia --brand e cambi tutta l'app.
   ===================================================================== */
:root {
  --brand:        #89BE58;
  --brand-deep:   #5C9433;
  --brand-glow:   rgba(137, 190, 88, .32);

  --bg:           #070C0A;
  --bg-2:         #0D1512;
  --surface:      rgba(255, 255, 255, .055);
  --surface-2:    rgba(255, 255, 255, .085);
  --line:         rgba(255, 255, 255, .11);
  --text:         #F2F6F4;
  --text-dim:     #9BAAA3;
  --text-faint:   #6B7A73;

  --carta:            #3B87E0;
  --plastica:         #F5B70A;
  --metallo:          #A7B4C2;
  --vetro:            #23A76A;
  --organico:         #A2703F;
  --indifferenziato:  #7A8791;

  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------------- struttura viste ---------------- */
#app { position: absolute; inset: 0; }

.view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transform: translateY(14px) scale(.99);
  transition: opacity .28s ease, transform .28s cubic-bezier(.2,.8,.3,1);
}
.view.active { opacity: 1; pointer-events: auto; transform: none; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------------- sfondo animato ---------------- */
.aurora {
  position: absolute; inset: -30%;
  background:
    radial-gradient(38% 30% at 22% 18%, rgba(137,190,88,.22), transparent 65%),
    radial-gradient(34% 28% at 82% 12%, rgba(58,140,224,.16), transparent 65%),
    radial-gradient(46% 36% at 60% 96%, rgba(92,148,51,.20), transparent 68%);
  filter: blur(12px);
  animation: drift 22s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(3%, 2%, 0) scale(1.08); }
}
@media (prefers-reduced-motion: reduce) { .aurora { animation: none; } }

/* ---------------- HOME ---------------- */
#view-home .scroll { padding: calc(28px + var(--safe-t)) 22px calc(26px + var(--safe-b)); }

/* logo SORTI: lettering vettoriale + pastiglia con il nome della demo */
.brand { display: flex; align-items: center; gap: 13px; }
.logo-word {
  height: 29px; aspect-ratio: 917 / 340; width: auto;
  color: var(--brand); flex: none; display: block;
}
.logo-word.big { height: 38px; }
.brand-tag {
  font-size: 11px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-dim);
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px;
  background: var(--surface); white-space: nowrap;
}
.brand.about { flex-direction: column; align-items: flex-start; gap: 9px; }
.brand-claim { font-size: 13.5px; color: var(--text-dim); }

/* il rombo del logo che pulsa mentre la rete lavora */
.mark-spin {
  width: 19px; aspect-ratio: 96.18 / 100; color: var(--brand);
  margin-right: 9px; vertical-align: -3px; display: inline-block;
  animation: markpulse 1.15s ease-in-out infinite;
}
@keyframes markpulse {
  0%, 100% { opacity: .35; transform: scale(.86) rotate(0deg); }
  50%      { opacity: 1;   transform: scale(1) rotate(90deg); }
}
@media (prefers-reduced-motion: reduce) { .mark-spin { animation: none; opacity: 1; } }

.hero { margin: 26px 0 22px; }
.hero h1 {
  margin: 0; font-size: clamp(27px, 7.8vw, 38px); line-height: 1.1;
  font-weight: 800; letter-spacing: -.025em;
}
.hero h1 em {
  font-style: normal;
  background: linear-gradient(100deg, #A9D877, var(--brand) 55%, #4FB98A);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { margin: 14px 0 0; color: var(--text-dim); font-size: 15.5px; max-width: 30ch; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}

/* contatore */
.counter-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.counter-head h2 { margin: 0; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-dim); font-weight: 700; }
.counter-live { font-size: 11px; color: var(--brand); display: flex; align-items: center; gap: 6px; }
.dot-live { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); animation: pulse 1.9s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .35; transform: scale(.8);} }

.counter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface-2); border-radius: 15px; padding: 13px 14px; }
.stat .n { font-size: 27px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }
.stat.co2 .n { color: var(--brand); }

.mat-bars { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.mat-row { display: grid; grid-template-columns: 74px 1fr 34px; align-items: center; gap: 10px; font-size: 12.5px; }
.mat-row .nm { color: var(--text-dim); text-transform: capitalize; }
.mat-row .track { height: 7px; border-radius: 5px; background: rgba(255,255,255,.07); overflow: hidden; }
.mat-row .fill { display: block; height: 100%; border-radius: 5px; width: 0; transition: width .7s cubic-bezier(.2,.8,.3,1); }
.mat-row .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-faint); }

/* pulsante principale */
.cta {
  margin-top: 20px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 11px;
  padding: 18px; border-radius: 19px;
  background: linear-gradient(150deg, var(--brand), var(--brand-deep));
  color: #0A1508; font-weight: 800; font-size: 17px; letter-spacing: .01em;
  box-shadow: 0 10px 30px var(--brand-glow);
  transition: transform .14s ease, box-shadow .2s ease, opacity .2s;
}
.cta:active { transform: scale(.975); }
.cta[disabled] { opacity: .55; box-shadow: none; }
.cta svg { width: 21px; height: 21px; }

.ghost {
  width: 100%; margin-top: 10px; padding: 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; font-size: 14.5px; color: var(--text-dim);
}
.ghost:active { background: var(--surface-2); }

/* barra di caricamento modello */
.loader { margin-top: 16px; }
.loader-bar { height: 5px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; }
.loader-bar i { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--brand-deep), var(--brand)); transition: width .3s ease; }
.loader-txt { margin-top: 8px; font-size: 12px; color: var(--text-faint); display: flex; justify-content: space-between; }

.footer-links { margin-top: 22px; display: flex; gap: 9px; }
.chip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 8px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  text-decoration: none;
}
.chip:active { background: var(--surface-2); }
.chip svg { width: 16px; height: 16px; flex: none; }
.legal { margin-top: 16px; font-size: 11px; color: var(--text-faint); text-align: center; line-height: 1.6; }

/* ---------------- FOTOCAMERA ---------------- */
#view-camera { background: #000; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.cam-overlay { position: absolute; inset: 0; pointer-events: none; }
.guide {
  position: absolute; border-radius: 28px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.5);
  transition: box-shadow .3s ease;
}
.guide::before, .guide::after,
.guide i::before, .guide i::after {
  content: ''; position: absolute; width: 30px; height: 30px;
  border: 3px solid var(--brand); border-radius: 12px;
}
.guide::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; }
.guide::after  { top: -2px; right: -2px; border-left: 0; border-bottom: 0; }
.guide i::before { bottom: -2px; left: -2px; border-right: 0; border-top: 0; }
.guide i::after  { bottom: -2px; right: -2px; border-left: 0; border-top: 0; }

.cam-hint {
  position: absolute; left: 0; right: 0; text-align: center;
  font-size: 14.5px; font-weight: 600;
  text-shadow: 0 2px 12px rgba(0,0,0,.8);
}
.cam-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 20px 22px calc(26px + var(--safe-b));
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
}
.shutter {
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff; border: 5px solid rgba(255,255,255,.35);
  background-clip: padding-box;
  transition: transform .12s ease;
  box-shadow: 0 6px 26px rgba(0,0,0,.5);
}
.shutter:active { transform: scale(.9); }
.shutter[disabled] { opacity: .4; }
.cam-side {
  width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255,255,255,.14); display: grid; place-items: center;
  backdrop-filter: blur(8px);
}
.cam-side svg { width: 22px; height: 22px; }
.cam-side.on { background: var(--brand); color: #0A1508; }
.cam-top {
  position: absolute; top: calc(14px + var(--safe-t)); left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center;
}

/* ---------------- ANALISI ---------------- */
#view-loading { background: var(--bg); align-items: center; justify-content: center; gap: 26px; }
#freeze { max-width: 74vw; max-height: 44vh; border-radius: 20px; border: 1px solid var(--line); filter: saturate(.7) brightness(.72); }
.scanline {
  position: absolute; height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  box-shadow: 0 0 22px 4px var(--brand-glow);
  animation: scan 1.15s ease-in-out infinite alternate;
}
@keyframes scan { from { transform: translateY(0); } to { transform: translateY(var(--scan-h, 200px)); } }
.analyzing { font-size: 18px; font-weight: 700; letter-spacing: .01em; }
.analyzing span { color: var(--brand); }

/* ---------------- RISULTATO ---------------- */
#view-result .scroll { padding: calc(18px + var(--safe-t)) 20px calc(20px + var(--safe-b)); }
.res-wash {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(58% 42% at 50% 0%, var(--mat, var(--brand)), transparent 72%);
  opacity: .30;
}
.res-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.res-back { font-size: 14px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }

.res-icon {
  width: 118px; height: 118px; margin: 6px auto 16px; border-radius: 34px;
  display: grid; place-items: center;
  background: var(--mat-soft, rgba(255,255,255,.08));
  border: 2px solid var(--mat-line, rgba(255,255,255,.25));
  box-shadow: 0 12px 44px var(--mat-glow, transparent);
  animation: pop .42s cubic-bezier(.2,1.3,.4,1);
}
.res-icon svg { width: 62px; height: 62px; color: var(--mat); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

.res-label {
  text-align: center; font-size: clamp(31px, 9vw, 40px); font-weight: 800;
  text-transform: uppercase; letter-spacing: .01em; color: var(--mat); margin: 0;
}
.res-sub { text-align: center; color: var(--text-dim); font-size: 14px; margin: 7px 0 0; }

.res-co2 {
  margin: 20px auto 0; display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 15px 22px; border-radius: 19px;
  background: var(--surface); border: 1.5px solid rgba(137,190,88,.45);
}
.res-co2 .big { font-size: 27px; font-weight: 800; color: var(--brand); font-variant-numeric: tabular-nums; }
.res-co2 .lbl { font-size: 13px; color: var(--text-dim); line-height: 1.25; }

.res-conf { margin-top: 18px; }
.res-conf .head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 7px; }
.probs { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.prob { display: grid; grid-template-columns: 78px 1fr 46px; align-items: center; gap: 10px; font-size: 12.5px; }
.prob .nm { text-transform: capitalize; color: var(--text-dim); }
.prob .track { height: 8px; border-radius: 5px; background: rgba(255,255,255,.07); overflow: hidden; }
.prob .fill { display: block; height: 100%; border-radius: 5px; width: 0; transition: width .6s cubic-bezier(.2,.8,.3,1); }
.prob .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-faint); }

.res-meta { margin-top: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.meta { background: var(--surface); border: 1px solid var(--line); border-radius: 15px; padding: 12px 14px; }
.meta .k { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--text-faint); }
.meta .v { font-size: 14.5px; font-weight: 700; margin-top: 3px; }

.crop-row { margin-top: 16px; display: flex; align-items: center; gap: 14px; }
.crop-row canvas { width: 84px; height: 84px; border-radius: 15px; border: 1px solid var(--line); flex: none; background: #111; }
.crop-row .t { font-size: 12.5px; color: var(--text-dim); }

.res-actions { margin-top: 22px; }

/* ---------------- messaggi / errori ---------------- */
.notice {
  margin-top: 16px; padding: 14px 16px; border-radius: 16px; font-size: 13.5px;
  background: rgba(245,183,10,.10); border: 1px solid rgba(245,183,10,.32); color: #F7D372;
}
.notice.err { background: rgba(255,90,90,.10); border-color: rgba(255,90,90,.34); color: #FF9C9C; }
.notice b { color: inherit; }

/* ---------------- INFO ---------------- */
#view-about .scroll { padding: calc(24px + var(--safe-t)) 22px calc(26px + var(--safe-b)); }
#view-about h2 { font-size: 22px; margin: 22px 0 8px; letter-spacing: -.02em; }
#view-about p { color: var(--text-dim); font-size: 14.5px; margin: 0 0 12px; }
.spec { display: flex; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.spec b { min-width: 116px; color: var(--text-faint); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; padding-top: 2px; }

@media (min-height: 780px) { .hero { margin: 46px 0 30px; } }
@media (min-width: 620px) {
  .scroll > .inner { max-width: 560px; margin: 0 auto; }
}

/* carica una foto invece di scattare (utile per provare il modello) */
.upload-link {
  display: block; width: 100%; margin-top: 12px; text-align: center;
  font-size: 13.5px; color: var(--text-faint); text-decoration: underline;
  text-underline-offset: 3px;
}
.upload-link:active { color: var(--text-dim); }
