/* =============================
   STYLES GLOBALI
   ============================= */
@font-face {
  font-family: 'GillSans';
  src: url('../fonts/Gill Sans.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

:root {
  --bg: #000;
  --fg: #0f0;
  --fg-dim: #0c0;
  --fg-user: #0d0; /* colore username leggermente più scuro */
  --danger: #b00000;
  --warn: #ffcc00;
  --border: 1px solid var(--fg);
  --radius: 8px;
  --max-col: 560px;
  --placeholder: rgba(0, 255, 0, 0.6);
  --btn-bg: #0c0;
}

* { box-sizing: border-box; }

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: 'GillSans', 'Courier New', Courier, monospace;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0;
  margin: 0;
  overflow-x: hidden;
}

/* =============================
   USER BAR
   ============================= */
.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0.8rem 1rem;
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--bg);
  z-index: 1000;
}
.user-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.user-actions .toggle {
  margin-bottom: 0;
  display: inline-flex;
  align-items: center;
  line-height: 1.1;
}
#user-handle {
  font-weight: bold;
  color: var(--fg-user);
  font-size: 1.2rem;
}
/* =============================
   MAIN CONTAINER
   ============================= */
.container {
  width: 100%;
  max-width: 100%;
  padding: 8rem 1rem 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

/* =============================
   TIMER
   ============================= */
.timer {
  font-size: 13rem;
  margin-bottom: 2rem;
  letter-spacing: 4px;
  text-align: center;
  transition: all 0.5s ease;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
}
.timer.waiting { color: var(--warn); text-shadow: none; }
.timer.active {
  color: var(--fg);
  text-shadow: 0 0 5px var(--fg), 0 0 10px var(--fg), 0 0 20px var(--fg), 0 0 40px var(--fg), 0 0 80px var(--fg);
}
.timer.dead { color: var(--danger); text-shadow: none; opacity: 0.85; }

/* =============================
   TOGGLE BUTTONS
   ============================= */
.toggle {
  background: none;
  border: var(--border);
  color: var(--fg);
  padding: 0.5rem 1rem;
  margin-bottom: 1.25rem;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.3;
  transition: box-shadow .25s ease, opacity .25s ease;
  font-weight: normal;
}
.toggle:hover, .toggle.active {
  box-shadow: 0 0 10px var(--fg);
  opacity: 1;
}

/* =============================
   FORM (INTERFACE)
   ============================= */
body.interface .form {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  width: min(92vw, var(--max-col));
  align-items: stretch;
  margin: 0 auto;
}
body.interface .form .input-group {
  display: grid;
  grid-template-columns: 1fr;
  margin-bottom: 0.8rem; /* spaziatura extra tra i campi */
}
body.interface .form input,
body.interface .form select,
body.interface .form textarea {
  display: block !important;
  width: 100% !important;
  min-width: 0;
  padding: .65rem .75rem;
  background: #111;
  border: var(--border);
  color: var(--fg);
  font-size: 1rem;
}
/* evidenzia il campo username destinatario */
body.interface .form input[name="toUser"] {
  background: #0a0a0a;
  border-color: #0ff;
  box-shadow: 0 0 6px rgba(0,255,255,0.5);
}

body.interface .form button[type="submit"] {
  align-self: stretch;
  width: 100%;
  padding: .8rem 1rem;
  font-size: 1.05rem;
  background: var(--fg);
  color: var(--bg);
  border: none;
  font-weight: bold;
  cursor: pointer;
  transition: box-shadow .25s ease, filter .25s ease;
  margin-top: 0.75rem;
  margin-bottom: 1rem;
}
body.interface .form button[type="submit"]:hover {
  box-shadow: 0 0 10px var(--fg);
  filter: brightness(1.05);
}

/* =============================
   LOG AREA
   ============================= */
.log-container {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  width: 100%;
  max-width: var(--max-col);
  align-items: stretch;
  margin-top: 1rem;
}
.log-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: .5rem;
  text-align: left;
}
.log-header label { margin: 0; font-size: 1rem; }
.log-header select {
  background: #000;
  color: var(--fg);
  border: var(--border);
  padding: .35rem .5rem;
  font-size: 1rem;
  height: 2rem;
}
.log {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .25rem;
  text-align: left;
}
.log-entry {
  border-bottom: var(--border);
  padding: .5rem 0;
}

/* =============================
   MESSAGGI STATO
   ============================= */
.message {
  margin-top: .5rem;
  margin-bottom: 0.75rem;
  font-size: 1rem;
  font-weight: bold;
  min-height: 1.4rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
}
.message.error {
  background-color: rgba(255, 0, 0, 0.15);
  color: #ff4d4d;
  border: 1px solid #ff4d4d;
}
.message.success {
  background-color: rgba(0, 255, 0, 0.15);
  color: #80ff80;
  border: 1px solid #80ff80;
}
button[disabled] { opacity: .6; cursor: not-allowed; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* =============================
   LAYOUT AUTH
   ============================= */
body.auth {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
  background-color: var(--bg);
}
body.auth .form {
  display: flex;
  flex-direction: column;
  background-color: rgba(0,0,0,0.9);
  padding: 2rem;
  border: var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 0 15px var(--fg);
  gap: 1rem;
}
body.auth input[type="text"],
body.auth input[type="password"] {
  padding: 0.6rem;
  border: var(--border);
  background-color: #111;
  color: var(--fg);
  font-size: 1rem;
  width: 100%;
}
body.auth button[type="submit"] {
  padding: 0.75rem;
  font-size: 1rem;
  background-color: var(--fg);
  color: var(--bg);
  font-weight: bold;
  border: none;
  cursor: pointer;
  transition: 0.25s ease;
}
body.auth button[type="submit"]:hover {
  background-color: #1f1;
  box-shadow: 0 0 5px var(--fg), 0 0 10px var(--fg);
}
.show-password-link {
  font-size: 0.85rem;
  text-decoration: underline;
  color: var(--fg);
  opacity: .8;
  margin-top: -4px;
  margin-bottom: 8px;
}
.show-password-link:hover { opacity: 1; }

/* =============================
   RESPONSIVE
   ============================= */
body.desktop .timer { font-size: 13rem; }
@media (max-width: 480px) {
  body.mobile .timer { flex-direction: column; justify-content: center; align-items: center; font-size: 6rem; }
}
@media (max-width: 768px) and (orientation: landscape) {
  body.mobile .timer { flex-direction: row; justify-content: center; }
}
/* Modal scura stile app (nero/verde) */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: center; justify-content: center; z-index: 2000; padding: 16px; }
.modal .modal-content {
  background: #000;
  color: var(--fg);
  padding: 24px 20px; /* più respiro ai bordi */
  border-radius: 8px;
  width: min(520px, calc(100vw - 56px));
  box-shadow: 0 0 0 1px rgba(0,255,0,.15) inset, 0 0 18px rgba(0,255,0,.25), 0 0 48px rgba(0,255,0,.08);
  border: 1px solid rgba(0,255,0,0.5);
  box-sizing: border-box;
  overflow: hidden; /* evita che i campi escano dai bordi */
}
.modal h3 { margin-top: 0; }
.modal .modal-content .form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100% !important;
  margin: 0 !important;
  /* Evita doppio riquadro: sovrascrive stile dei form globali in modale */
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
}
.modal .form input {
  margin-bottom: 2px;
  background: #111;
  border: var(--border);
  color: var(--fg);
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0; /* evita overflow in flex container */
  box-sizing: border-box;
  padding: 0.75rem 0.9rem; /* rientro visivo degli input */
  border-radius: 6px;
  display: block;
  font-size: 1rem;
}
.modal .form input::placeholder { color: var(--placeholder); opacity: 1; }
.modal .form input:focus { outline: none; border-color: #0d0; box-shadow: 0 0 0 2px rgba(0,255,0,0.2); }
.modal .form button { width: 100% !important; max-width: 100% !important; background: var(--btn-bg); color: var(--bg); border: 1px solid rgba(0,255,0,0.5); padding: .8rem; font-weight: bold; border-radius: 6px; display: block; min-width: 0; font-size: 1rem; line-height: 1.2; cursor: pointer; box-sizing: border-box; transition: background-color .2s ease, box-shadow .2s ease, filter .2s ease, border-color .2s ease; margin: 0; appearance: none; -webkit-appearance: none; }
.modal .form button[type="submit"] { border: 1px solid rgba(0,255,0,0.5); }
.modal .form button:hover { filter: brightness(1.05); box-shadow: 0 0 10px rgba(0,255,0,0.25); }
.modal .form .btn-outline { background: transparent; color: var(--fg); border: 1px solid rgba(0,255,0,0.5); cursor: pointer; transform: translateY(-2px); }
.modal .form .btn-outline:hover { background: #3d3d3d; color: var(--fg); border-color: rgba(255,255,255,0.8); box-shadow: 0 0 12px rgba(255,255,255,0.25); }
.modal .form .actions { display: flex; gap: 10px; width: 100% !important; align-items: center; }
.modal .form .actions button { flex: 1 1 0; min-width: 0; height: 44px; padding: 0 16px; display: flex; align-items: center; justify-content: center; text-align: center; box-sizing: border-box; line-height: normal; margin: 0; }
/* Assicura allineamento perfetto tra Annulla (outline) e Conferma */

.modal h3 { font-size: 1.25rem; margin: 0 0 10px 0; padding-bottom: 6px; border-bottom: 1px solid rgba(0,255,0,.2); }
.modal .message { margin-top: 8px; overflow-wrap: anywhere; }
.modal .message.info { color: rgba(255,255,255,0.7); }

/* Uniforma placeholder e focus anche nei form di login/interfaccia */
body.auth .form input::placeholder,
body.interface .form input::placeholder { color: var(--placeholder); opacity: 1; }
body.auth .form input:focus,
body.interface .form input:focus { outline: none; border-color: #0d0; box-shadow: 0 0 0 2px rgba(0,255,0,0.2); }
.modal .message { margin-top: .5rem; }
/* Modal in modalità "blocco" (sfondo opaco e nasconde UI sottostante) */
.modal.solid { background: #000; }
.modal.no-box .modal-content {
  /* Variante "flat": niente riquadro, come la richiesta PIN su invio tempo */
  background: transparent;
  box-shadow: none;
  border: 0;
  padding: 0;
  width: min(520px, calc(100vw - 56px));
}
.modal.no-box h3 { border-bottom: 0; margin-bottom: 12px; }
.modal.no-box .form { gap: 10px; }
.modal.no-box .form input { background: #111; border-color: rgba(0,255,0,0.5); }
.modal.no-box .form button { margin-top: 4px; }
.pin-solid .timer,
.pin-solid #toggleForm,
.pin-solid #toggleLog,
.pin-solid #log-container,
.pin-solid #form,
.pin-solid .user-bar { visibility: hidden !important; }

/* Centra elementi solo nella modal PIN del login (primo accesso) */
body.auth #pin-modal .modal-content .form {
  align-items: center; /* centra gli elementi orizzontalmente */
  max-width: none !important; /* annulla il max-width:420px dei form login */
  width: 100% !important;     /* occupa tutta la larghezza della modal */
  align-self: stretch !important; /* forza allungamento dentro modal-content */
}
body.auth #pin-modal .modal-content .form input,
body.auth #pin-modal .modal-content .form button {
  max-width: 320px !important; /* accorcia e consente centratura visiva */
  width: 100% !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* =============================
   BUY PAGE
   ============================= */
body.buy .container {
  padding-top: 6.5rem;
}
body.buy h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}
body.buy .intro {
  max-width: 720px;
  text-align: center;
  opacity: 0.85;
  margin-bottom: 1.5rem;
}
.package-list {
  width: min(92vw, var(--max-col));
  display: grid;
  gap: 1rem;
}
.package-card {
  border: var(--border);
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  background: #050505;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.package-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.package-name {
  font-size: 1.2rem;
  font-weight: bold;
}
.package-price {
  color: var(--fg);
  opacity: 0.9;
}
.package-btn {
  background: var(--fg);
  color: var(--bg);
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: box-shadow .25s ease, filter .25s ease;
}
.package-btn:hover {
  box-shadow: 0 0 10px var(--fg);
  filter: brightness(1.05);
}
.package-btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}
.buy-back {
  text-decoration: none;
  color: var(--fg);
  border: var(--border);
  padding: 0.4rem 0.8rem;
}
.buy-back:hover {
  box-shadow: 0 0 10px var(--fg);
}
.redeem {
  width: min(92vw, var(--max-col));
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(0, 255, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.redeem h2 {
  margin: 0;
  font-size: 1.4rem;
}
.redeem-controls {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.qr-frame {
  border: var(--border);
  border-radius: var(--radius);
  background: #020202;
  padding: 0.5rem;
}
#qr-reader {
  width: 100%;
  border-radius: 6px;
  display: block;
  aspect-ratio: 4 / 3;
  background: #000;
  overflow: hidden;
}
#qr-reader video,
#qr-reader canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
.redeem-inputs {
  display: grid;
  gap: 0.75rem;
}
