:root {
  --bg: #07080b;
  --ink: #e9e2cf;
  --dim: #7d776a;
  --gold: #d9ad5b;
  --red: #c4453a;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* niente zoom col doppio tocco (la pagina resta alla sua scala) */
/* niente menu "salva immagine" né trascinamento tenendo premuto sulle immagini dell'app */
img {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

#screen {
  position: relative;
  /* La grana animata sborda apposta oltre i bordi: qui si taglia, così la pagina non può mai scorrere di lato. */
  overflow: hidden;
  overflow: clip;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--dim);
  text-align: center;
  margin: 0;
}

.glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(217, 173, 91, 0.1) 0%, rgba(7, 8, 11, 0) 50%);
  pointer-events: none;
}

/* grana: poco più grande dello schermo (si sposta di pochi punti), non 4 volte: meno memoria e meno calore */
.grain {
  position: absolute;
  inset: -6%;
  opacity: 0.06;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 0.8s steps(4) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1.5%); }
  50% { transform: translate(1.5%, -2%); }
  75% { transform: translate(-1.5%, -1%); }
  100% { transform: translate(0, 0); }
}

.stage {
  position: relative;
  z-index: 0;
  width: min(78vw, 360px);
  height: min(78vw, 360px);
}

#coin {
  position: fixed;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.dial {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 165%;
  height: 165%;
  transform: translate(-50%, -50%);
  color: var(--gold);
  opacity: 0.09;
  pointer-events: none;
}

.dial-a,
.dial-b {
  transform-origin: 350px 350px;
}

.dial-a {
  animation: spin 240s linear infinite;
}

.dial-b {
  animation: spin 150s linear infinite reverse;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Luce morbida dall'alto, senza contorni: tre bagliori sovrapposti che respirano a ritmi diversi. */
.beam {
  position: absolute;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(70% 60% at 50% -8%, rgba(255, 228, 170, 0.09) 0%, rgba(255, 228, 170, 0.03) 45%, rgba(255, 228, 170, 0) 75%),
    radial-gradient(32% 50% at 50% -4%, rgba(255, 240, 210, 0.07) 0%, rgba(255, 240, 210, 0) 70%);
  animation: breathe 7s ease-in-out infinite;
}

.beam::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(45% 38% at 50% 44%, rgba(217, 173, 91, 0.06) 0%, rgba(217, 173, 91, 0) 70%);
  animation: breathe 11s ease-in-out infinite reverse;
}

@keyframes breathe {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.dust {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.lines {
  position: relative;
  z-index: 2;
  margin-top: 28px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.headline {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.3em;
  color: var(--ink);
  margin: 0;
}

.headline.granted {
  color: var(--gold);
}

.headline.denied {
  color: var(--red);
}

.hint {
  margin-top: 18px;
  color: var(--gold);
  opacity: 0;
}

.hint.visible {
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

.footer {
  position: absolute;
  z-index: 2;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
}

.grain {
  z-index: 3;
}

#screen.leaving .lines,
#screen.leaving .footer,
#screen.leaving .dial {
  transition: opacity 0.5s ease;
  opacity: 0;
}

/* ---------- Dossier di arruolamento ---------- */

.dossier {
  position: absolute;
  z-index: 2;
  top: max(12vh, 64px);
  left: 50%;
  transform: translateX(-50%);
  width: min(100% - 40px, 420px);
}

.form-id {
  text-align: left;
  font-size: 10px;
  margin-bottom: 28px;
}

.field-title {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.25em;
  color: var(--ink);
  margin: 0 0 10px;
  min-height: 26px;
}

.field-help {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--dim);
  margin: 0 0 26px;
}

.field-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(217, 173, 91, 0.35);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 18px;
  letter-spacing: 0.08em;
  padding: 10px 0;
  caret-color: var(--gold);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color 0.2s ease;
}

.field-input:focus {
  border-bottom-color: var(--gold);
}

/* mai sotto i 16 px nei campi: sotto, il telefono ingrandisce da solo la pagina appena li si tocca */
.field-input.address {
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  word-break: break-all;
}

.field-error {
  min-height: 20px;
  margin: 12px 0 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: var(--red);
}

.field-input::placeholder {
  color: rgba(125, 119, 106, 0.55);
  letter-spacing: 0.04em;
}

/* ---------- Review: foglio classificato ---------- */

.sheet {
  position: relative;
  padding: 0 16px 16px;
  border: 1px solid rgba(233, 226, 207, 0.14);
  background:
    repeating-linear-gradient(0deg, rgba(233, 226, 207, 0.025) 0 1px, transparent 1px 26px),
    linear-gradient(180deg, #111216 0%, #0b0c0f 100%);
  overflow: hidden;
  animation: sheet-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(10px); clip-path: inset(0 0 100% 0); }
  to { opacity: 1; transform: none; clip-path: inset(0 0 0 0); }
}

/* Crocini agli angoli, come su un documento da archivio. */
.sheet::before,
.sheet::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 12px;
  height: 12px;
  border: 0 solid var(--gold);
  opacity: 0.6;
}

.sheet::before {
  left: 6px;
  border-width: 0 0 1px 1px;
}

.sheet::after {
  right: 6px;
  border-width: 0 1px 1px 0;
}

.sheet-band {
  display: flex;
  justify-content: space-between;
  margin: 0 -16px;
  padding: 7px 16px;
  background: var(--red);
  color: #0b0c0f;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.34em;
}

.sheet-meta {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 14px;
  margin-bottom: 14px;
  border-bottom: 1px dashed rgba(233, 226, 207, 0.14);
  font-size: 9px;
}

.sheet-rows {
  margin: 0;
}

.sheet-row dt {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.26em;
  color: var(--dim);
}

.sheet-row dd {
  position: relative;
  margin: 5px 0 16px;
  min-height: 22px;
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.sheet-row dd.big {
  min-height: 28px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold);
}

.sheet-row dd.none {
  color: var(--dim);
}

/* Barra di censura che si ritira verso destra e scopre il dato. */
.sheet-row .bar {
  position: absolute;
  left: 0;
  top: 1px;
  bottom: 1px;
  width: 78%;
  background: #000;
  box-shadow: 0 0 0 1px rgba(233, 226, 207, 0.06);
  transform-origin: right center;
  transition: transform 0.32s cubic-bezier(0.7, 0, 0.3, 1);
}

.sheet-row dd.big .bar {
  width: 64%;
}

.sheet-row dd.open .bar {
  transform: scaleX(0);
}

.sheet-foot {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding-top: 12px;
  border-top: 1px dashed rgba(233, 226, 207, 0.14);
}

.barcode {
  width: 132px;
  height: 26px;
  fill: rgba(233, 226, 207, 0.55);
}

.awaiting {
  font-size: 10px;
  color: var(--red);
  animation: pulse 1.6s ease-in-out infinite;
}

/* Linea di scansione che passa lenta sul foglio. */
.scanline {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 60px;
  background: linear-gradient(180deg, rgba(217, 173, 91, 0) 0%, rgba(217, 173, 91, 0.07) 85%, rgba(217, 173, 91, 0.35) 100%);
  pointer-events: none;
  opacity: 0;
  animation: scan 4.5s cubic-bezier(0.45, 0, 0.55, 1) 0.8s infinite;
}

@keyframes scan {
  0% { transform: translateY(-60px); opacity: 0; }
  10% { opacity: 1; }
  60% { transform: translateY(420px); opacity: 1; }
  61%, 100% { transform: translateY(420px); opacity: 0; }
}

/* ---------- Tesserino ---------- */

.card-wrap {
  position: relative;
  z-index: 2;
  width: min(90vw, 390px);
  transition: transform 0.25s ease-out;
  transform-style: preserve-3d;
}

#screen:has(.card-wrap) {
  perspective: 900px;
}

.card {
  --mx: 50%;
  --my: 50%;
  position: relative;
  padding: 18px 18px 16px;
  border: 1px solid rgba(217, 173, 91, 0.45);
  border-radius: 14px;
  background:
    repeating-linear-gradient(115deg, rgba(217, 173, 91, 0.035) 0 1px, transparent 1px 7px),
    radial-gradient(120% 90% at 0% 0%, #1f2026 0%, #121318 55%, #0a0b0e 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 210, 0.12),
    inset 0 0 0 4px rgba(7, 8, 11, 0.6),
    inset 0 0 0 5px rgba(217, 173, 91, 0.14),
    0 30px 80px rgba(0, 0, 0, 0.7);
  overflow: hidden;
  animation: card-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(40px) rotateX(55deg) scale(0.92); }
  to { opacity: 1; transform: none; }
}

.card.shake {
  animation: card-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both, shake 0.22s ease-out;
}

@keyframes shake {
  0% { transform: translate(0, 0) scale(1); }
  30% { transform: translate(0, 3px) scale(0.985); }
  60% { transform: translate(0, -1px) scale(1.003); }
  100% { transform: translate(0, 0) scale(1); }
}

/* Riflesso metallico: una passata all'ingresso, poi segue l'inclinazione. */
.card-sheen {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(60% 50% at var(--mx) var(--my), rgba(255, 236, 196, 0.1) 0%, rgba(255, 236, 196, 0) 70%);
  mix-blend-mode: screen;
  overflow: hidden;
}

.card-sheen::after {
  content: "";
  position: absolute;
  top: -50%;
  bottom: -50%;
  width: 40%;
  background: linear-gradient(100deg, rgba(255, 236, 196, 0) 0%, rgba(255, 236, 196, 0.16) 50%, rgba(255, 236, 196, 0) 100%);
  transform: translateX(-120%) rotate(8deg);
  animation: sweep 1.4s cubic-bezier(0.4, 0, 0.2, 1) 0.5s both;
}

@keyframes sweep {
  to { transform: translateX(360%) rotate(8deg); }
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(217, 173, 91, 0.22);
}

.card-org {
  margin: 0;
  font-family: "Times New Roman", Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.42em;
  color: var(--gold);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.8), 0 -1px 0 rgba(255, 236, 196, 0.15);
}

.card-sub {
  margin-top: 4px;
  text-align: left;
  font-size: 8px;
  letter-spacing: 0.3em;
}

.card-no {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.card-no .mono {
  font-size: 8px;
}

.card-no strong {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.card-body {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  align-items: start;
}

.card-photo {
  position: relative;
  width: 92px;
  height: 92px;
  margin-top: 4px;
}

.card-seal {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(217, 173, 91, 0.5), 0 6px 18px rgba(0, 0, 0, 0.6);
}

.card-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 1px dashed rgba(217, 173, 91, 0.45);
  animation: spin 40s linear infinite;
}

.card-fields {
  margin: 0;
  min-width: 0;
}

.card-fields dt {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--dim);
}

.card-fields dd {
  margin: 3px 0 11px;
  min-height: 17px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.card-fields dd.card-codename {
  min-height: 28px;
  font-size: 23px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.1em;
}

.card-fields dd.card-specialty {
  font-style: italic;
  letter-spacing: 0.02em;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  letter-spacing: 0.2em;
}

.badge.unverified {
  border: 1px solid rgba(233, 226, 207, 0.22);
  color: var(--dim);
}

.badge.verified {
  border: 1px solid var(--gold);
  color: var(--gold);
}

/* Zona leggibile a macchina, come sui passaporti. */
.card-mrz {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid rgba(233, 226, 207, 0.08);
}

.card-mrz p {
  margin: 0;
  min-height: 16px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: rgba(233, 226, 207, 0.42);
  white-space: nowrap;
  overflow: hidden;
}

.stamp {
  position: absolute;
  z-index: 4;
  right: 16px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 12px 4px;
  border: 4px double var(--red);
  border-radius: 6px;
  color: var(--red);
  font-family: var(--mono);
  opacity: 0;
  transform: rotate(-11deg) scale(2.8);
  pointer-events: none;
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='60'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -3 2.4'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='60'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -3 2.4'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  transition: transform 0.33s cubic-bezier(0.55, 0, 1, 0.45), opacity 0.12s linear;
}

.stamp b {
  font-size: 24px;
  letter-spacing: 0.16em;
}

.stamp small {
  font-size: 9px;
  letter-spacing: 0.3em;
}

.stamp.down {
  opacity: 0.92;
  transform: rotate(-11deg) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .grain,
  .dial-a,
  .dial-b,
  .beam,
  .scanline,
  .card-ring,
  .awaiting {
    animation: none;
  }

  .card-sheen::after {
    display: none;
  }
}

/* Mini app ridotta a icona in Telegram: animazioni CSS ferme finché non si riapre (vedi main.js). */
html.asleep *,
html.asleep *::before,
html.asleep *::after {
  animation-play-state: paused !important;
}

/* nuova versione sul server: barra in alto, un tocco ricarica (main.js, watchForUpdates) */
.upd-bar {
  position: fixed;
  z-index: 9999;
  left: 12px;
  right: 12px;
  top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  font-family: var(--mono, monospace);
  text-align: left;
  color: #fff0cf;
  border: 1px solid rgba(255, 214, 140, 0.55);
  background:
    repeating-linear-gradient(115deg, rgba(255, 214, 140, 0.04) 0 1px, transparent 1px 7px),
    linear-gradient(90deg, rgba(255, 200, 110, 0.2), rgba(255, 200, 110, 0.06) 70%),
    #0b0a08;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  transform: translateY(calc(-100% - 30px));
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.upd-bar::before, .upd-bar::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1.5px solid #ffe2a8;
}
.upd-bar::before { left: -2px; top: -2px; border-right: 0; border-bottom: 0; }
.upd-bar::after { right: -2px; bottom: -2px; border-left: 0; border-top: 0; }
.upd-bar.in {
  transform: none;
}
.upd-bar b {
  font-size: 10.5px;
  letter-spacing: 0.16em;
}
.upd-bar span {
  flex: none;
  padding: 6px 10px;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: #2a1a06;
  background: linear-gradient(180deg, #e9c47a, #b8893f);
}
.upd-bar.go {
  opacity: 0.6;
}
