:root {
  --bg: #E4E9ED;
  --surface: #F7F9FA;
  --ink: #17222B;
  --muted: #56636E;
  --line: #C3CCD3;
  --signal: #F2B705;
  --signal-ink: #1A1400;
  --ok: #2E8B57;
  --ok-ink: #FFFFFF;
  --err: #B3261E;
  --err-ink: #FFFFFF;
  --display: Bahnschrift, "DIN Alternate", "DIN Next", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11171C;
    --surface: #1A232A;
    --ink: #E3E9ED;
    --muted: #93A1AC;
    --line: #2C3943;
    --ok: #3FB37A;
    --ok-ink: #06140C;
    --err: #F2766B;
    --err-ink: #1E0705;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  line-height: 1.45;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
           env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.bar, main, .foot {
  width: 100%;
  max-width: 34rem;
  margin: 0 auto;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.bar { padding-top: 1.5rem; padding-bottom: 1rem; }

.bar h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--muted);
}

main { flex: 1; }

/* ---------- Form ---------- */

.stack { display: flex; flex-direction: column; gap: 0.5rem; }

.lead { margin: 0 0 1rem; font-size: 1.1rem; }

label { font-weight: 600; font-size: 0.95rem; margin-top: 0.5rem; }

input {
  font: inherit;
  font-size: 1.1rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

#otp { font-family: var(--display); font-size: 1.6rem; letter-spacing: 0.3em; }

button { font: inherit; cursor: pointer; }

.primary {
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 600;
  font-size: 1.05rem;
}

.primary:disabled { opacity: 0.6; cursor: progress; }

.link {
  background: none;
  border: 0;
  padding: 0.5rem 0;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  align-self: flex-start;
}

:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 2px;
}

.msg { min-height: 1.5em; margin: 0.75rem 0 0; color: var(--muted); }
.msg.is-error { color: var(--err); font-weight: 600; }

.loading { color: var(--muted); }

/* ---------- Cancelli ---------- */

.gates { display: flex; flex-direction: column; gap: 0.9rem; }

.gate {
  --p: 0;
  position: relative;
  display: block;
  width: 100%;
  min-height: 7.5rem;
  padding: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.face {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 7.5rem;
  padding: 1.25rem;
}

/* Strato giallo che "scorre" come un cancello mentre tieni premuto */
.face.fill {
  position: absolute;
  inset: 0;
  background: var(--signal);
  color: var(--signal-ink);
  clip-path: inset(0 calc(100% - var(--p) * 100%) 0 0);
}

.name {
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(1.6rem, 7vw, 2.2rem);
  line-height: 1.1;
}

.hint { margin-top: 0.4rem; font-size: 0.95rem; color: var(--muted); }
.fill .hint { color: inherit; opacity: 0.8; }

.gate[data-state="busy"] .fill { clip-path: none; }
.gate[data-state="busy"] { cursor: progress; }

.gate[data-state="done"] .fill {
  clip-path: none;
  background: var(--ok);
  color: var(--ok-ink);
}

.gate[data-state="error"] .fill {
  clip-path: none;
  background: var(--err);
  color: var(--err-ink);
}

.empty { color: var(--muted); }

/* ---------- Video ---------- */

.gate-card { display: flex; flex-direction: column; }

.video {
  position: relative;
  margin: 0;
  aspect-ratio: 4 / 3;
  max-height: 42vh;
  background: #000;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}

.video img { display: block; width: 100%; height: 100%; object-fit: contain; }

.video-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.6);
}

.gate-card.has-video .video:not([hidden]) + .gate { border-radius: 0 0 6px 6px; }

/* ---------- Piè di pagina ---------- */

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding-top: 1.5rem;
  padding-bottom: 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.foot strong { color: var(--ink); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
