/***********************
 * DESKTOP-GATE.CSS
 * Schermata di soglia per terminali desktop.
 *
 * Due stati:
 *   .is-paired    -> URL con ?id=xxxxxxxx  (esiste una lettura personale)
 *   .is-unpaired  -> URL senza id          (nessuna lettura personale)
 *
 * Più la modalità "frame": html.zhd-frame vincola l'app alla larghezza
 * per cui è stata disegnata, invece di stirarla sul desktop.
 *
 * RICHIEDE: variables.css (token colore/bordo)
 ***********************/

:root {
  --gate-bg: var(--primary-color);
  --gate-ink: var(--secondary-color);
  --gate-hair: var(--secondary-color-opacity);
  --gate-frame-w: 430px;
}

/* =====================
   OVERLAY
   ===================== */
#desktop-gate {
  position: fixed;
  inset: 0;
  z-index: 2147483000; /* sopra loader (600), lock (10000), tooltip (9999) */

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 40px;
  box-sizing: border-box;

  background: var(--gate-bg);
  color: var(--gate-ink);

  opacity: 0;
  transition: opacity 500ms ease;
}

#desktop-gate.is-visible {
  opacity: 1;
}

/* quando il gate è attivo il documento sotto non deve scrollare */
html.zhd-gated,
html.zhd-gated body {
  overflow: hidden !important;
}

/* =====================
   DOCUMENTO
   ===================== */
.gate-doc {
  position: relative;
  width: 100%;
  max-width: 900px;
  border: var(--border);
  background: var(--gate-bg);
}

/* segni di registro agli angoli: linguaggio "documento tecnico" */
.gate-doc::before,
.gate-doc::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border: var(--border);
  background: var(--gate-bg);
}
.gate-doc::before {
  top: -5px;
  left: -5px;
}
.gate-doc::after {
  bottom: -5px;
  right: -5px;
}

/* --- intestazione: eco dell'header dell'app --- */
.gate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;

  padding: 14px 20px;
  border-bottom: var(--border);

  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.gate-head .gate-program {
  font-weight: 500;
}

.gate-head .gate-status {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.55;
}

.gate-head .gate-dot {
  width: 7px;
  height: 7px;
  border: var(--border);
  border-radius: 50%;
  border-color: var(--gate-ink);
  animation: gate-pulse 2.4s ease-in-out infinite;
}

@keyframes gate-pulse {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

/* --- corpo: testo a sinistra, QR a destra --- */
.gate-body {
  display: grid;
  grid-template-columns: 1fr auto;
}

.gate-copy {
  padding: 34px 34px 30px;
  border-right: var(--border);
}

.gate-kicker {
  margin: 0 0 18px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.5;
}

.gate-title {
  margin: 0 0 18px;
  font-size: 1.9rem;
  font-weight: 500;
  line-height: 1.1;
  max-width: 20ch;
}

.gate-text {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 300;
  line-height: 1.35;
  max-width: 46ch;
}

.gate-text + .gate-text {
  margin-top: 0.9rem;
}

/* --- colonna QR --- */
.gate-scan {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;

  padding: 34px;
  min-width: 240px;
}

.gate-qr {
  width: 172px;
  height: 172px;
  padding: 10px;
  box-sizing: content-box;
  border: var(--border);
  background: var(--gate-bg);
}

.gate-qr svg {
  display: block;
  width: 100%;
  height: 100%;
  shape-rendering: crispEdges;
}

.gate-qr svg path {
  fill: var(--gate-ink);
}

.gate-scan-label {
  margin: 0;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.5;
}

.gate-scan-label .gate-id {
  display: block;
  margin-top: 4px;
  opacity: 0.5;
  letter-spacing: 0.12em;
}

/* --- piede: la scelta dichiarata --- */
.gate-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 30px;

  padding: 20px 34px;
  border-top: var(--border);
}

.gate-note {
  margin: 0;
  max-width: 62ch;
  font-size: 0.82rem;
  font-weight: 300;
  line-height: 1.35;
  opacity: 0.72;
}

.gate-note strong {
  font-weight: 500;
  opacity: 1;
}

.gate-bypass {
  flex: none;
  align-self: center;

  padding: 10px 16px;
  border: var(--border);
  background: transparent;
  color: var(--gate-ink);
  cursor: pointer;

  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;

  transition:
    background-color 200ms ease,
    color 200ms ease;
}

.gate-bypass:hover,
.gate-bypass:focus-visible {
  background: var(--gate-ink);
  color: var(--gate-bg);
  outline: none;
}

/* =====================
   RESPONSIVE DEL GATE
   (finestra desktop stretta / alta)
   ===================== */
@media (max-width: 860px), (max-height: 620px) {
  #desktop-gate {
    padding: 24px;
    overflow-y: auto;
    align-items: flex-start;
  }

  .gate-body {
    grid-template-columns: 1fr;
  }

  .gate-copy {
    border-right: none;
    border-bottom: var(--border);
    padding: 26px;
  }

  .gate-title {
    font-size: 1.5rem;
  }

  .gate-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    padding: 20px 26px;
  }

  .gate-bypass {
    align-self: flex-start;
  }
}

/* =====================
   MODALITÀ FRAME
   L'app in "public mode" su desktop non viene stirata:
   viene mostrata alla larghezza per cui è stata disegnata.
   ===================== */
html.zhd-frame {
  background: #e6e6e6;
}

html.zhd-frame body {
  width: var(--gate-frame-w);
  margin: 0 auto;
  background: transparent;
}

/* fondale del frame: un elemento fisso, non i bordi del body
   (il body è alto quanto il contenuto in flusso, cioè quasi nulla) */
html.zhd-frame body::before {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  left: calc(50% - (var(--gate-frame-w) / 2));
  width: var(--gate-frame-w);
  box-sizing: border-box;

  background: var(--primary-color);
  border-left: var(--border);
  border-right: var(--border);

  z-index: 0;
  pointer-events: none;
}

/* Tutti gli elementi in position: fixed vanno riportati dentro il frame.
   NB: si usa left/calc e non translateX(-50%), perché header e viste
   ricevono transform inline dalle sequenze di reveal. */
html.zhd-frame header,
html.zhd-frame main,
html.zhd-frame main .view,
html.zhd-frame #load-page {
  width: var(--gate-frame-w) !important;
  left: calc(50% - (var(--gate-frame-w) / 2)) !important;
  right: auto !important;
}

/* Dentro il frame, "100vw" non è più la larghezza dell'app.
   Le regole che ci fanno affidamento vanno riportate al contenitore:
   - la mappa dei fusi (world-rank.css / world-rank-end.css)
   - la track del marquee "winning nation" (world-rank-end.css)
   marquee.js misura con getBoundingClientRect, quindi si adegua da solo. */
html.zhd-frame .content .visual-map-content span svg,
html.zhd-frame .track {
  width: 100% !important;
}

/* etichetta che dichiara la scelta invece di nasconderla */
.frame-caption {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2147482000;

  display: flex;
  align-items: center;
  gap: 10px;

  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary-color);
  opacity: 0.45;
  pointer-events: none;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .frame-caption {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #desktop-gate,
  .gate-head .gate-dot {
    transition: none;
    animation: none;
  }
}
