/* Ottimizzazioni per migliorare l'esperienza utente */

/* Miglioramenti per il caricamento delle pagine */
.preload-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease-out;
}

.preload-animation.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid rgba(52, 152, 219, 0.2);
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Miglioramenti per l'accessibilità */
:focus {
  outline: 3px solid rgba(52, 152, 219, 0.5);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #3498db;
  color: white;
  padding: 8px;
  z-index: 100;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

/* Miglioramenti per la leggibilità */
body {
  line-height: 1.8;
  font-size: 16px;
}

p, li {
  max-width: 70ch; /* Limite ottimale per la leggibilità */
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

/* Miglioramenti per il contrasto */
.btn, .skill-tag {
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

/* Miglioramenti per il feedback utente */
.btn, nav a, .game-card, .gallery-item, .faq-question {
  position: relative;
  overflow: hidden;
}

.btn:after, nav a:after, .game-card:after, .gallery-item:after, .faq-question:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0.2);
  opacity: 0;
  transition: opacity 0.3s;
}

.btn:active:after, nav a:active:after, .game-card:active:after, .gallery-item:active:after, .faq-question:active:after {
  opacity: 1;
  transition: opacity 0s;
}

/* Tooltip migliorati */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]:before, [data-tooltip]:after {
  position: absolute;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
}

[data-tooltip]:before {
  content: attr(data-tooltip);
  padding: 6px 10px;
  background-color: #2c3e50;
  color: white;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 5px;
  font-size: 0.85rem;
  font-weight: normal;
}

[data-tooltip]:after {
  content: '';
  border-top: 5px solid #2c3e50;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
}

[data-tooltip]:hover:before, [data-tooltip]:hover:after {
  visibility: visible;
  opacity: 1;
}

/* Miglioramenti per la navigazione */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.breadcrumb a, .breadcrumb span {
  margin-right: 5px;
}

.breadcrumb a:after {
  content: '›';
  margin-left: 5px;
  color: rgba(255, 255, 255, 0.7);
}

/* Miglioramenti per i form */
input, select, textarea {
  transition: border-color 0.3s, box-shadow 0.3s;
}

input:focus, select:focus, textarea:focus {
  border-color: #3498db;
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.25);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.form-feedback {
  margin-top: 5px;
  font-size: 0.85rem;
}

.form-feedback.error {
  color: #e74c3c;
}

.form-feedback.success {
  color: #2ecc71;
}

/* Miglioramenti per la stampa */
@media print {
  header, footer, .btn, .cta-section, .games-filter, .games-categories {
    display: none !important;
  }
  
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: #fff;
  }
  
  a {
    color: #000;
    text-decoration: underline;
  }
  
  .game-card, .game-info, .game-description {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }
  
  h2, h3 {
    page-break-after: avoid;
  }
  
  img {
    max-width: 100% !important;
  }
  
  p, h2, h3 {
    orphans: 3;
    widows: 3;
  }
}

/* Miglioramenti per il tema scuro */
@media (prefers-color-scheme: dark) {
  body.dark-theme {
    background-color: #1a1a1a;
    color: #f0f0f0;
  }
  
  body.dark-theme .game-card,
  body.dark-theme .game-info,
  body.dark-theme .game-description,
  body.dark-theme .test-section,
  body.dark-theme .feature-card,
  body.dark-theme .skill-card,
  body.dark-theme .age-group-card,
  body.dark-theme .value-card,
  body.dark-theme .team-card {
    background-color: #2d2d2d;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  }
  
  body.dark-theme .game-card h3,
  body.dark-theme h2,
  body.dark-theme h3,
  body.dark-theme h4 {
    color: #f0f0f0;
  }
  
  body.dark-theme .meta-item,
  body.dark-theme p,
  body.dark-theme li {
    color: #d0d0d0;
  }
  
  body.dark-theme .placeholder {
    background: linear-gradient(45deg, #333 25%, #444 25%, #444 50%, #333 50%, #333 75%, #444 75%);
  }
  
  body.dark-theme .placeholder::after {
    color: #888;
  }
  
  body.dark-theme .btn {
    background-color: #3498db;
  }
  
  body.dark-theme .btn:hover {
    background-color: #2980b9;
  }
  
  body.dark-theme input,
  body.dark-theme select,
  body.dark-theme textarea {
    background-color: #333;
    color: #f0f0f0;
    border-color: #555;
  }
  
  body.dark-theme input:focus,
  body.dark-theme select:focus,
  body.dark-theme textarea:focus {
    border-color: #3498db;
  }
}

/* Miglioramenti per le animazioni */
.fade-in {
  animation-duration: 0.5s;
  animation-fill-mode: both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate3d(0, 20px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.fade-in-up {
  animation-name: fadeInUp;
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translate3d(-20px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.fade-in-left {
  animation-name: fadeInLeft;
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translate3d(20px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

.fade-in-right {
  animation-name: fadeInRight;
}

/* Miglioramenti per le prestazioni */
.lazy-load {
  opacity: 0;
  transition: opacity 0.3s;
}

.lazy-load.loaded {
  opacity: 1;
}

/* Miglioramenti per dispositivi touch */
@media (hover: none) {
  .btn:hover, nav a:hover, .game-card:hover {
    transform: none;
    box-shadow: var(--box-shadow);
  }
  
  .game-card-image img:hover {
    transform: none;
  }
  
  [data-tooltip]:hover:before, [data-tooltip]:hover:after {
    visibility: hidden;
    opacity: 0;
  }
  
  [data-tooltip]:active:before, [data-tooltip]:active:after {
    visibility: visible;
    opacity: 1;
  }
}

/* Miglioramenti per la navigazione mobile */
@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: block;
    background: none;
    border: none;
    width: 30px;
    height: 25px;
    position: relative;
    cursor: pointer;
    z-index: 1001;
  }
  
  .mobile-menu-toggle span {
    display: block;
    position: absolute;
    height: 3px;
    width: 100%;
    background: white;
    border-radius: 3px;
    opacity: 1;
    left: 0;
    transform: rotate(0deg);
    transition: .25s ease-in-out;
  }
  
  .mobile-menu-toggle span:nth-child(1) {
    top: 0px;
  }
  
  .mobile-menu-toggle span:nth-child(2) {
    top: 10px;
  }
  
  .mobile-menu-toggle span:nth-child(3) {
    top: 20px;
  }
  
  .mobile-menu-toggle.active span:nth-child(1) {
    top: 10px;
    transform: rotate(135deg);
  }
  
  .mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
    left: -60px;
  }
  
  .mobile-menu-toggle.active span:nth-child(3) {
    top: 10px;
    transform: rotate(-135deg);
  }
  
  nav ul {
    position: fixed;
    top: 0;
    right: -100%;
    width: 80%;
    max-width: 300px;
    height: 100vh;
    background-color: var(--dark-bg);
    flex-direction: column;
    padding: 80px 20px 20px;
    transition: right 0.3s ease;
    z-index: 1000;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
  }
  
  nav ul.show {
    right: 0;
  }
  
  nav li {
    margin: 10px 0;
  }
  
  nav a {
    display: block;
    padding: 10px;
  }
}
