/* Layout e tipografia di Retune 432. */

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html {
  background: var(--cobalt);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--cobalt);
  color: var(--text-1);
  font-family: var(--font);
  font-weight: var(--weight);
  font-size: var(--body-size);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-numeric: tabular-nums;
}

a { color: inherit; text-decoration: none; }

/* Le safe area tengono il contenuto lontano da notch, Dynamic Island e barra Home. */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(var(--space-3), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(var(--space-3), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}

/* ---------- Tipografia ---------- */

.label {
  font-size: var(--label-size);
  letter-spacing: var(--label-tracking);
  text-transform: uppercase;
  color: var(--text-3);
  line-height: 1.4;
}

.figure {
  display: flex;
  align-items: baseline;
  gap: .12em;
  font-size: var(--figure-size);
  font-weight: var(--figure-weight);
  letter-spacing: -.035em;
  line-height: .9;
}
.figure .unit {
  font-size: var(--label-size);
  letter-spacing: var(--label-tracking);
  font-weight: var(--weight);
  color: var(--text-3);
  text-transform: uppercase;
}
.figure--md {
  font-size: clamp(56px, 14vw, 88px);
}

.lede,
.sub {
  color: var(--text-2);
  max-width: 46ch;
}
.sub { font-size: var(--small-size); }
.muted { color: var(--text-3); }

/* ---------- Barra superiore e piè di pagina ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: var(--touch);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-height: var(--touch);
}
.brand svg { height: 34px; width: auto; display: block; }   /* il diapason, in verticale */
.topbar nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 4px;
}

.footer {
  margin-top: var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
}

/* ---------- Colonna e sezioni ---------- */

.column {
  flex: 1;
  width: min(var(--column), 100%);
  margin: 0 auto;
  padding-top: var(--space-6);
}

.step + .step {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rule);
}
.step > .label:first-child { margin-bottom: var(--space-3); }

/* Con un file caricato la schermata di benvenuto sparisce: il file sale subito sotto al logo,
   senza il grande spazio iniziale e senza la riga di separazione sopra. */
.column:has(> #step-load[hidden]) { padding-top: var(--space-4); }
#step-load[hidden] + .step { margin-top: 0; padding-top: 0; border-top: 0; }

.reveal { animation: reveal .7s var(--ease) both; }
@keyframes reveal {
  from { opacity: 0; transform: translateY(12px); }
}

/* ---------- 1. Caricamento ---------- */

.hero {
  font-size: clamp(48px, 11vw, 84px);
  font-weight: var(--figure-weight);
  letter-spacing: -.025em;
  line-height: 1;
  margin: var(--space-3) 0;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 200px;
  margin-top: var(--space-5);
  border-radius: 32px;
  text-align: center;
  cursor: pointer;
  /* Superficie grande: vetro più tenue, altrimenti il riflesso diventa una macchia */
  --fill-top: rgba(255, 255, 255, .09);
  --fill-bottom: rgba(255, 255, 255, .03);
  --spec: .12;
}
.drop.glass:active { --fill-top: rgba(255, 255, 255, .14); --fill-bottom: rgba(255, 255, 255, .05); --spec: .2; transform: scale(.985); }
@media (hover: hover) {
  .drop.glass:hover { --spec: .18; }
}
.drop .glass-button { pointer-events: none; }

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.formats { margin-top: var(--space-3); text-align: center; }

/* Mentre trascini un file sopra la finestra */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgb(8 59 191 / .55);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s var(--ease);
}
body.is-dragging .drop-overlay { opacity: 1; }
.drop-overlay .figure--md { font-size: clamp(40px, 8vw, 64px); }

/* ---------- 2. File ---------- */

.file {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: var(--space-2);
}
.file__name {
  font-size: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 3. Stima ---------- */

.estimate .figure { margin: var(--space-1) 0 var(--space-3); }

.meter {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.meter__track {
  height: 2px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.meter__track span {
  display: block;
  height: 100%;
  width: calc(var(--level, 0) * 100%);
  background: var(--white);
  transition: width .8s var(--ease);
}
.meter__value { color: var(--text-2); font-size: var(--small-size); }

.notice {
  margin-top: var(--space-3);
  padding: var(--space-2) 0 0;
  border-top: 1px solid var(--rule);
  color: var(--text-2);
  font-size: var(--small-size);
}

.adjust { margin-top: var(--space-4); }
.adjust__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.adjust__scale {
  display: flex;
  justify-content: space-between;
  padding: 0 60px;
}
.adjust__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-3);
}

/* Barra di avanzamento sottile */
.progress { margin-top: var(--space-3); }
.progress__track {
  height: 2px;
  background: var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.progress__track span {
  display: block;
  height: 100%;
  width: calc(var(--progress, 0) * 100%);
  background: var(--white);
  transition: width .2s linear;
}
.progress .label { margin-top: var(--space-1); }

/* ---------- 4. Reintonazione ---------- */

.shift {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  margin: var(--space-1) 0 var(--space-4);
}

/* ---------- 5. Ascolto ---------- */

.waveform {
  display: block;
  width: 100%;
  height: 132px;
  cursor: pointer;
  touch-action: pan-y;
}
.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.time {
  display: flex;
  margin-top: var(--space-1);
  justify-content: space-between;
  color: var(--text-3);
  font-size: var(--small-size);
}

.keys-hint { margin-top: var(--space-3); text-align: center; max-width: none; }
@media (hover: none) {
  .keys-hint,
  .drop-hint { display: none; }
}

/* ---------- 6. Esportazione ---------- */

.fields {
  display: grid;
  gap: var(--space-3);
}
.field {
  display: grid;
  gap: var(--space-1);
  justify-items: start;
}
.export-info { margin: var(--space-3) 0 var(--space-4); white-space: pre-line; }

/* ---------- Avvisi temporanei ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(var(--space-3), env(safe-area-inset-bottom)) + 8px);
  z-index: 30;
  transform: translate(-50%, 0);
  max-width: calc(100% - 2 * var(--gutter));
  padding: 14px 22px;
  border-radius: 999px;
  font-size: var(--small-size);
  text-align: center;
  animation: reveal .5s var(--spring) both;
}

/* ---------- Barra di anteprima degli stati (solo con ?dev nell'indirizzo, fase 3) ---------- */

.devbar {
  position: fixed;
  left: 50%;
  top: max(10px, env(safe-area-inset-top));
  z-index: 40;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  max-width: calc(100% - 20px);
  overflow-x: auto;
}
.devbar button {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.devbar button:hover { background: rgba(255, 255, 255, .12); }

/* ---------- Desktop ---------- */

@media (min-width: 768px) {
  .column { padding-top: 14vh; }
  .waveform { height: 168px; }
  .fields { grid-template-columns: auto auto; justify-content: start; gap: var(--space-4); }
}

/* iPhone in verticale: controlli a tutta larghezza dove serve */
@media (max-width: 480px) {
  .adjust__scale { padding: 0 56px; }
  .export .glass-button--prominent,
  .retune .glass-button--prominent { width: 100%; }
  .file { grid-template-columns: 1fr; }
  .file .glass-button { justify-self: start; }
}

.notice-inline { margin-top: var(--space-1); color: var(--text-2); }

/* ---------- Installazione e aggiornamenti (PWA) ---------- */

.topnav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 4px;
  border: 0;
  background: none;
  font-family: inherit;
  cursor: pointer;
}
.nav-link:hover { color: var(--text-1); }

.sheet {
  border: 0;
  padding: 0;
  margin: auto;
  width: min(440px, calc(100% - 2 * var(--gutter)));
  background: transparent;
  color: var(--white);
  overflow: visible;
}
.sheet::backdrop {
  background: rgb(3 22 84 / .45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.sheet__panel {
  padding: var(--space-4) var(--space-3) var(--space-3);
  border-radius: 28px;
  --fill-top: rgba(255, 255, 255, .22);
  --fill-bottom: rgba(255, 255, 255, .10);
  --spec: .2;
}
.sheet__text {
  margin: var(--space-2) 0 var(--space-4);
  color: var(--text-2);
  font-size: var(--body-size);
}
.sheet__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.update {
  position: fixed;
  left: 50%;
  top: max(var(--space-2), env(safe-area-inset-top));
  z-index: 35;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 6px 6px 6px 22px;
  border-radius: 999px;
  font-size: var(--small-size);
  white-space: nowrap;
  animation: reveal .5s var(--spring) both;
}

.footer-link { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 4px; }
.footer-link:hover { color: var(--text-1); }

/* ---------- Accordatore (tuner/) ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.nav-link[aria-current="page"] { color: var(--text-1); }

.tuner { padding-top: var(--space-4); }

/* Nota grande con l'ottava in piccolo, poi la frequenza */
.tuner-note {
  margin: var(--space-1) 0 var(--space-2);
  min-height: .9em;
}
.tuner-octave {
  font-size: .32em;
  letter-spacing: 0;
  color: var(--text-2);
}
.tuner-freq {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
}

/* Scala da −50 a +50 cent, una tacca ogni 10 */
.tuner-meter {
  position: relative;
  height: 64px;
  margin-top: var(--space-4);
  --cents: 0;
}
.tuner-meter__scale {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--rule);
}
.tuner-meter__scale span {
  width: 1px;
  height: 14px;
  align-self: flex-end;
  background: var(--rule-strong);
}
.tuner-meter__scale .is-center {
  height: 100%;
  background: var(--white);
}
.tuner-meter__needle {
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: calc(50% + var(--cents) * 1%);
  width: 6px;
  margin-left: -3px;
  border-radius: 3px;
  background: var(--white);
  box-shadow: 0 0 0 1px rgb(3 22 84 / .25);
  transition: left .12s linear, width .3s var(--spring), margin-left .3s var(--spring), opacity .3s var(--ease);
}
.tuner-meter__labels {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-1);
}

.tuner-cents {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  margin-top: var(--space-3);
  font-size: 20px;
}

/* Intonato (entro ±2 cent): l'ago si allarga in una barra piena */
.tuner-reading.is-in-tune .tuner-meter__needle {
  width: 28px;
  margin-left: -14px;
  box-shadow: 0 0 24px rgba(255, 255, 255, .55);
}
.tuner-reading.is-in-tune .tuner-cents #cents-value::after { content: " · in tune"; color: var(--text-2); }

/* Suono finito: l'ultima lettura resta un attimo, attenuata; a riposo tutto è spento */
.tuner-reading.is-held :is(.tuner-note, .tuner-freq, .tuner-meter__needle, .tuner-cents) { opacity: .45; }
.tuner-reading.is-idle .tuner-meter__needle { opacity: .25; }
.tuner-reading.is-idle :is(.tuner-note, .tuner-freq) { color: var(--text-3); }
.tuner-reading :is(.tuner-note, .tuner-freq, .tuner-cents) { transition: opacity .3s var(--ease); }

.tuner-drift__head {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.tuner-trace {
  display: block;
  width: 100%;
  height: 120px;
}
.tuner-drift .sub { margin-top: var(--space-2); }

.tuner-controls > .glass-button--lg { width: 100%; }
.tuner-status { margin-top: var(--space-2); max-width: none; }

.tuner-ref { grid-template-columns: auto 1fr auto; }
.tuner-ref__value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: var(--space-1);
}
.segmented.is-none .segmented__thumb { opacity: 0; }

@media (min-width: 768px) {
  .tuner { padding-top: 8vh; }
  .tuner-controls > .glass-button--lg { width: auto; min-width: 260px; }
  .tuner-trace { height: 150px; }
}

@media (prefers-reduced-motion: reduce) {
  .tuner-meter__needle { transition: none; }
}
