/* Reset di base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/*******************************************
  FONT E BACKGROUND
********************************************/
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  /* Evita scroll orizzontale imprevisto */
}

body {
  display: flex;
  flex-direction: column;
  font-family: 'Poppins', sans-serif;
  line-height: 1.6;
  /* Original colors: #b1c4ca, #a8bcc2, #9fb4bb */
  background: linear-gradient(135deg, #b1c4ca 0%, #a8bcc2 50%, #8caab5 100%);
  color: #2d2d2d;
  min-height: 100vh;
  position: relative;
}

/* Background Decorativo per Glassmorphism */
.background-decor {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  /* Sfocatura elevata per effetto soft */
  opacity: 0.6;
  animation: float 10s infinite ease-in-out;
}

/* Colori derivati dalla palette originale ma più intensi per fare contrasto */
.blob-1 {
  background: #f18b70;
  /* Peach/Salmon dai bottoni */
  width: 400px;
  height: 400px;
  top: -100px;
  left: -50px;
  animation-delay: 0s;
}

.blob-2 {
  background: #4d7d87;
  /* Teal dai titoli */
  width: 350px;
  height: 350px;
  bottom: -50px;
  right: -50px;
  animation-delay: 2s;
}

.blob-3 {
  background: #fff;
  width: 200px;
  height: 200px;
  top: 40%;
  left: 60%;
  opacity: 0.3;
  animation-delay: 4s;
}

@keyframes float {
  0% {
    transform: translate(0, 0) scale(1);
  }

  33% {
    transform: translate(30px, -50px) scale(1.1);
  }

  66% {
    transform: translate(-20px, 20px) scale(0.9);
  }

  100% {
    transform: translate(0, 0) scale(1);
  }
}

/* Wrapper con larghezza massima e margini */
.wrapper {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
  position: relative;
  z-index: 1;
}

/*******************************************
  TITOLI
********************************************/
h1 {
  text-align: center;
  margin-bottom: 50px;
  color: #2d2d2d;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  font-size: 2.8rem;
}

h2 {
  margin-top: 0;
  color: #4d7d87;
  font-weight: 600;
  padding-bottom: 12px;
  margin-bottom: 25px;
  border-bottom: 2px solid rgba(77, 125, 135, 0.2);
  display: inline-block;
  /* Sottolineatura corta */
  width: 100%;
}

/*******************************************
  LAYOUT PRINCIPALE
********************************************/
.container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 40px;
  align-items: stretch;
  /* Forces equal height */
  margin-bottom: 40px;
}

/*******************************************
  SEZIONI (GLASS CARDS)
********************************************/
section {
  background: rgba(255, 255, 255, 0.65);
  /* Semi-trasparente */
  backdrop-filter: blur(16px) saturate(180%);
  /* Effetto Glass */
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  /* Bordo sottile */
  box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
  /* Ombra morbida */
  padding: 35px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

section:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px 0 rgba(31, 38, 135, 0.2);
}

/*******************************************
  FORMS E CAMPI
********************************************/
.form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
}

.form-row.no-wrap {
  flex-wrap: wrap;
  /* Cambiato a wrap per sicurezza su schermi piccoli, gestito da media query */
}

@media (min-width: 500px) {
  .form-row.no-wrap {
    flex-wrap: nowrap;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  position: relative;
}

.form-group label {
  font-weight: 600;
  color: #4d7d87;
  margin-bottom: 8px;
  font-size: 0.95rem;
  margin-left: 5px;
}

#birthGroup {
  flex: 2;
}

#genderGroup {
  flex: 1;
  min-width: 80px;
}

#placeGroup {
  flex: 3;
}

/* Stile migliorato per input e select */
input[type="text"],
input[type="date"],
select {
  text-transform: uppercase;
  padding: 14px 18px;
  font-size: 15px;
  width: 100%;
  box-sizing: border-box;
  /* Glassy input */
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid transparent;
  border-radius: 12px;
  color: #2d2d2d;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  font-family: 'Poppins', sans-serif;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.03);
}

input[type="text"]:focus,
input[type="date"]:focus,
select:focus {
  outline: none;
  background: rgba(255, 255, 255, 1);
  border-color: #4d7d87;
  box-shadow: 0 4px 12px rgba(77, 125, 135, 0.15);
  transform: translateY(-1px);
}

/*******************************************
  PULSANTI
********************************************/
button {
  background: linear-gradient(135deg, #f18b70 0%, #f39f8a 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  font-weight: 600;
  border-radius: 12px;
  padding: 16px 32px;
  transition: all 0.3s ease;
  font-family: 'Poppins', sans-serif;
  font-size: 15px;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 15px rgba(241, 139, 112, 0.4);
  width: 100%;
  /* Bottoni full width su mobile/card */
  display: block;
}

button:hover {
  background: linear-gradient(135deg, #ff9b80 0%, #ffaf9a 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(241, 139, 112, 0.5);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(241, 139, 112, 0.4);
}

/* Stile migliorato per il bottone "Copia" dentro il risultato */
.copy-button {
  width: auto;
  /* Sovrascrive width: 100% */
  background: #4d7d87;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  margin-left: 10px;
  box-shadow: 0 2px 8px rgba(77, 125, 135, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.copy-button:hover {
  background: #5a8a94;
  box-shadow: 0 4px 12px rgba(77, 125, 135, 0.4);
  transform: translateY(-2px);
}

/*******************************************
  OUTPUT BOX
********************************************/
.output-box {
  margin-top: 30px;
  background: rgba(255, 255, 255, 0.7);
  padding: 20px 25px;
  border-radius: 12px;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.1rem;
  color: #2d2d2d;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

#cfResultText {
  font-weight: 600;
  letter-spacing: 1px;
  overflow-wrap: break-word;
  /* Evita sforamenti su mobile */
}

/*******************************************
  DECODIFICA FORM
********************************************/
#decodeForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#decodeForm label {
  font-weight: 600;
  color: #4d7d87;
  font-size: 0.95rem;
  margin-left: 5px;
}

.input-group {
  display: flex;
  gap: 15px;
  width: 100%;
}

#decodeForm input[type="text"] {
  flex: 1;
  /* Prende tutto lo spazio disponibile */
  margin-top: 0;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid transparent;
}

#decodeBtn {
  width: auto;
  flex: 0 0 auto;
  /* Non si espande */
  margin-bottom: 0;
}

@media (max-width: 500px) {
  .input-group {
    flex-direction: column;
    gap: 10px;
  }

  #decodeBtn {
    width: 100%;
  }
}

/*******************************************
  SEZIONE FOOTER
********************************************/
footer {
  text-align: center;
  padding: 30px;
  /* Glass footer scuro */
  background: rgba(45, 45, 45, 0.85);
  backdrop-filter: blur(10px);
  color: rgba(255, 255, 255, 0.7);
  margin-top: auto;
  width: 100%;
  font-size: 0.9rem;
  z-index: 1;
}

footer a {
  color: #f18b70;
  text-decoration: none;
  font-weight: 600;
  transition: all 0.3s ease;
}

footer a:hover {
  color: #fff;
  text-shadow: 0 0 10px rgba(241, 139, 112, 0.6);
}

/*******************************************
  RESPONSIVE
********************************************/
@media (max-width: 965px) {
  h1 {
    font-size: 2.2rem;
  }
}

@media (max-width: 768px) {
  .form-row {
    flex-wrap: wrap;
  }

  #birthGroup,
  #genderGroup,
  #placeGroup {
    flex: 1 0 45%;
    /* Due per riga circa */
  }

  #placeGroup {
    flex: 1 0 100%;
    /* Comune su riga intera */
  }
}

@media (max-width: 480px) {
  .wrapper {
    padding: 20px 15px;
  }

  section {
    padding: 25px 20px;
  }

  h1 {
    font-size: 1.8rem;
    margin-bottom: 30px;
  }

  .output-box {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  .copy-button {
    width: 100%;
    margin-left: 0;
  }
}

/*******************************************
  DECODE RESULT STYLES
********************************************/
.decode-grid {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 30px;
}

.decode-item {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 140px;
  align-items: center;
  /* Crucial for centering */
  justify-content: center;
  text-align: center;
  padding: 0 15px;
  border-right: 1px solid rgba(77, 125, 135, 0.2);
}

.decode-item:last-child {
  border-right: none;
}

.decode-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #4d7d87;
  font-weight: 600;
  margin-bottom: 4px;
}

.decode-value {
  font-size: 1.1rem;
  font-weight: 500;
  color: #2d2d2d;
}

@media (max-width: 600px) {
  .decode-grid {
    flex-direction: column;
    gap: 15px;
  }

  .decode-item {
    border-right: none;
    border-bottom: 1px solid rgba(77, 125, 135, 0.1);
    padding-bottom: 10px;
  }

  .decode-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }
}

/*******************************************
  TOAST NOTIFICATIONS
********************************************/
#toast-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  /* Allow clicks through container */
}

.toast {
  background: rgba(45, 45, 45, 0.9);
  backdrop-filter: blur(10px);
  color: #fff;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 12px;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  min-width: 250px;
  border-left: 5px solid;
  pointer-events: auto;
  /* Re-enable pointer events for toasts */
}

.toast.show {
  transform: translateX(0);
}

.toast.success {
  border-left-color: #2ecc71;
}

.toast.error {
  border-left-color: #e74c3c;
}

.toast.info {
  border-left-color: #3498db;
}

@media (max-width: 480px) {
  #toast-container {
    left: 20px;
    right: 20px;
    bottom: 20px;
  }

  .toast {
    width: 100%;
    min-width: auto;
  }
}