/**
 * Impariamo l'Italiano! - Main Stylesheet - Version 3
 * ========================================
 * Common styles for all pages
 * Using CSS Custom Properties for theming and consistency
 *
 * VERSION 3 CHANGES:
 * - Enhanced mobile responsiveness with proper touch targets
 * - Fixed font-size scaling to prevent iOS auto-zoom
 * - Improved navigation dropdown behavior on mobile
 * - Better z-index management for game elements
 */

/* ===========================
   CSS Custom Properties - ASR Design System
   =========================== */
:root {
  /* ASR Color Palette */
  --color-primary: #003DA5;
  --color-primary-dark: #002D72;
  --color-secondary: #0891B2;
  --color-white: #FFFFFF;

  /* Italian flag colors - for legacy compatibility */
  --color-italian-green: #008C45;
  --color-italian-red: #CE2B37;
  --color-italian-white: #FFFFFF;

  /* Game-specific color variations */
  --color-green-light: #6AAA64;
  --color-green-dark: #538d4e;
  --color-red-dark: #b71c1c;
  --color-orange: #FF8C00;

  /* ASR Extended Palette */
  --primary-blue: #003DA5;
  --secondary-blue: #002D72;
  --dark-navy: #001F4C;
  --accent-red: #DC143C;
  --light-gray: #F8F9FA;
  --medium-gray: #E9ECEF;
  --border-gray: #DEE2E6;
  --text-dark: #212529;
  --text-muted: #6C757D;
  --text-light: #495057;

  /* Legacy color names for compatibility */
  --color-gray-100: #F8F9FA;
  --color-gray-200: #E9ECEF;
  --color-gray-300: #DEE2E6;
  --color-gray-400: #999999;
  --color-gray-500: #787c7e;
  --color-gray-600: #666666;
  --color-gray-700: #212529;
  --color-black: #000000;

  /* Typography - ASR System Fonts */
  --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-base: 16px;
  --font-size-small: 14px;
  --font-size-large: 18px;
  --font-size-xlarge: 24px;
  --font-size-xxlarge: 32px;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-bold: 700;

  /* Spacing */
  --spacing-xs: 5px;
  --spacing-sm: 10px;
  --spacing-md: 15px;
  --spacing-lg: 20px;
  --spacing-xl: 30px;
  --spacing-xxl: 40px;

  /* Layout */
  --container-max-width: 980px;
  --border-radius-small: 6px;
  --border-radius-medium: 8px;
  --border-radius-large: 12px;
  --border-radius-round: 50%;

  /* ASR Shadows */
  --shadow-small: 0 2px 4px rgba(0,0,0,0.08);
  --shadow-medium: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-large: 0 8px 24px rgba(0,0,0,0.15);
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.15);

  /* Transitions */
  --transition-fast: 0.2s ease;
  --transition-medium: 0.3s ease;
  --transition-slow: 0.5s ease;

  /* Z-index layers - Updated for proper stacking */
  --z-base: 1;
  --z-dropdown: 100;
  --z-mobile-menu: 150;
  --z-modal: 200;
  --z-notification: 300;
}

/* ===========================
   Reset & Base Styles
   =========================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-primary);
  background: linear-gradient(180deg, var(--light-gray) 0%, var(--color-white) 100%);
  color: var(--text-dark);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  margin: 0;
}

/* ===========================
   Typography
   =========================== */
h1, h2, h3, h4, h5, h6 {
  margin-bottom: var(--spacing-md);
  line-height: 1.2;
  font-weight: var(--font-weight-bold);
}

h1 {
  font-size: 2.2rem;
  color: var(--primary-blue);
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0 0 10px 0;
}

h2 {
  font-size: var(--font-size-xlarge);
  color: var(--text-dark);
  margin-top: var(--spacing-lg);
}

h3 {
  font-size: var(--font-size-large);
  color: var(--primary-blue);
  margin-bottom: var(--spacing-xs);
}

p {
  margin-bottom: var(--spacing-md);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-dark);
  text-decoration: underline;
}

/* ===========================
   Header - ASR Style with Centered Logo
   =========================== */
header {
  background: var(--color-white);
  border-bottom: 3px solid var(--primary-blue);
  box-shadow: var(--shadow-sm);
  padding: 20px 0;
  width: 100%;
}

.header-content {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

header h1 {
  color: var(--primary-blue);
  text-align: center;
  margin: 0;
}

header img {
  max-width: 400px;
  height: auto;
  display: block;
}

/* ===========================
   Navigation
   =========================== */
nav {
  background: linear-gradient(135deg, #0891B2 0%, #0E7490 100%);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) 0;
  position: relative;
  box-shadow: var(--shadow-small);
  z-index: var(--z-mobile-menu);
}

nav .hamburger {
  display: none;
  position: absolute;
  right: var(--spacing-lg);
  font-size: var(--font-size-xlarge);
  color: var(--color-white);
  cursor: pointer;
  transition: transform var(--transition-fast);
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}

nav .hamburger:hover {
  transform: scale(1.1);
}

nav .menu-items {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

nav a,
nav .dropdown {
  color: var(--color-white);
  text-decoration: none;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius-small);
  transition: all var(--transition-medium);
  position: relative;
  font-weight: var(--font-weight-medium);
}

/* Underline effect for all nav links - both regular and dropdown triggers */
nav a::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--color-white);
  transform: translateX(-50%);
  transition: width var(--transition-medium);
}

nav a:hover,
nav .dropdown:hover {
  background: #0E7490;
  transform: translateY(-2px);
  /* Explicitly override default anchor hover styles */
  color: var(--color-white);
  text-decoration: none;
}

/* Underline animation on hover */
nav a:hover::before {
  width: 80%;
}

nav a.active,
nav .dropdown.active {
  background: #0E7490;
  font-weight: var(--font-weight-bold);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Dropdown Styles */
nav .dropdown {
  cursor: pointer;
  position: relative;
}

/* Dropdown arrow */
nav .dropdown > a::after {
  content: '\25BC';
  font-size: 8px;
  font-weight: 400;
  margin-left: 6px;
  display: inline-block;
  transition: transform 0.2s ease;
}

nav .dropdown:hover > a::after {
  transform: rotate(180deg);
}

/* Create invisible bridge to prevent gap between trigger and dropdown */
nav .dropdown::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 10px;  /* Bridge the gap */
  background: transparent;
  z-index: var(--z-dropdown);
}

nav .dropdown-content {
  display: none;
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  background: #0891B2;
  min-width: 160px;
  box-shadow: var(--shadow-large);
  border-radius: var(--border-radius-small);
  z-index: calc(var(--z-mobile-menu) + 1);
  opacity: 0;
  transform: translateY(-10px);
  animation: dropdownFadeIn 0.3s ease forwards;
}

/* Keep dropdown visible when hovering parent OR dropdown content */
nav .dropdown:hover .dropdown-content,
nav .dropdown-content:hover {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

nav .dropdown-content a {
  color: var(--color-white);
  padding: var(--spacing-sm) var(--spacing-md);
  text-decoration: none;
  display: block;
  transition: background var(--transition-fast);
}

nav .dropdown-content a:hover {
  background: #0E7490;
  /* Ensure no blue color or underline on dropdown links */
  color: var(--color-white);
  text-decoration: none;
}

/* ===========================
   Main Container
   =========================== */
.container {
  width: 90%;
  max-width: var(--container-max-width);
  margin: var(--spacing-xl) auto;
  padding: var(--spacing-lg);
  background: var(--color-white);
  box-shadow: var(--shadow-medium);
  border-radius: var(--border-radius-medium);
  flex-grow: 1;
  animation: fadeIn 0.5s ease;
}

/* ===========================
   Footer - ASR Style
   =========================== */
footer {
  margin-top: 60px;
  padding: 40px 20px;
  background: var(--light-gray);
  border-top: 1px solid var(--border-gray);
  text-align: center;
  width: 100%;
}

.footer-text {
  max-width: 800px;
  margin: 0 auto;
  color: var(--text-light);
  font-size: 0.95rem;
  line-height: 1.6;
}

footer a {
  color: var(--primary-blue);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-fast);
}

footer a:hover {
  color: var(--secondary-blue);
  text-decoration: underline;
}

footer img {
  height: 22px;
  margin-left: 3px;
  vertical-align: text-bottom;
}

/* ===========================
   Form Elements
   =========================== */
button {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border: none;
  color: var(--color-white);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  border-radius: var(--border-radius-small);
  cursor: pointer;
  transition: all var(--transition-medium);
  margin: var(--spacing-xs);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
  /* Ensure adequate touch target */
  min-height: 44px;
  min-width: 44px;
}

button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:hover::before {
  width: 300px;
  height: 300px;
}

button:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

button:disabled {
  background: var(--color-gray-300);
  color: var(--color-gray-500);
  cursor: not-allowed;
  transform: none;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  padding: var(--spacing-sm);
  font-size: var(--font-size-base);
  font-family: var(--font-primary);
  border-radius: var(--border-radius-small);
  border: 1px solid var(--color-gray-300);
  margin: var(--spacing-xs);
  transition: all var(--transition-fast);
  background: var(--color-white);
  /* Ensure adequate touch target */
  min-height: 44px;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
select:focus,
textarea:focus {
  outline: 3px solid transparent;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 140, 69, 0.1);
}

select {
  cursor: pointer;
  /* Remove default browser arrow */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  /* Add custom arrow via SVG background */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

/* ===========================
   Utility Classes
   =========================== */
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--spacing-xs); }
.mt-2 { margin-top: var(--spacing-sm); }
.mt-3 { margin-top: var(--spacing-md); }
.mt-4 { margin-top: var(--spacing-lg); }
.mt-5 { margin-top: var(--spacing-xl); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--spacing-xs); }
.mb-2 { margin-bottom: var(--spacing-sm); }
.mb-3 { margin-bottom: var(--spacing-md); }
.mb-4 { margin-bottom: var(--spacing-lg); }
.mb-5 { margin-bottom: var(--spacing-xl); }

.p-0 { padding: 0; }
.p-1 { padding: var(--spacing-xs); }
.p-2 { padding: var(--spacing-sm); }
.p-3 { padding: var(--spacing-md); }
.p-4 { padding: var(--spacing-lg); }
.p-5 { padding: var(--spacing-xl); }

.hidden {
  display: none !important;
}

.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;
}

/* Skip navigation link - visible on focus */
.skip-link:focus {
  position: fixed;
  top: 0;
  left: 0;
  width: auto;
  height: auto;
  padding: var(--spacing-sm) var(--spacing-lg);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--color-primary);
  color: var(--color-white);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  z-index: calc(var(--z-notification) + 1);
  text-decoration: none;
}

/* ===========================
   Z-Index Rules for Game Elements
   =========================== */
/* Ensure canvas and game elements stay below navigation */
canvas,
#wheelCanvas {
  position: relative;
  z-index: var(--z-base);
}

.memory-board,
.game-section canvas,
.game-board,
.wordle-grid,
.crossword-grid {
  position: relative;
  z-index: var(--z-base);
}

/* ===========================
   Animations
   =========================== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dropdownFadeIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

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

/* ===========================
   Responsive Design - Tablet
   =========================== */
@media (max-width: 768px) {
  /* DO NOT reduce base font size - keep at 16px to prevent iOS zoom */

  .container {
    width: 95%;
    padding: var(--spacing-md);
    margin: var(--spacing-lg) auto;
  }

  h1 {
    font-size: 1.8rem;
  }

  h2 {
    font-size: 1.5rem;
  }
}

/* ===========================
   Responsive Design - Mobile
   =========================== */
@media (max-width: 600px) {
  /* Mobile Navigation */
  nav {
    padding: var(--spacing-xl) 0; /* 30px top/bottom for visual balance with header and content */
  }

  nav .hamburger {
    display: block;
    /* Ensure minimum touch target size of 44px */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  nav .menu-items {
    display: none;
    position: absolute;
    flex-direction: column;
    width: 100%;
    background: #0891B2;
    top: 100%;
    left: 0;
    box-shadow: var(--shadow-medium);
    gap: 0;
    /* Critical: Set high z-index to appear above all page content including buttons */
    z-index: var(--z-mobile-menu);
  }

  nav .menu-items.show-menu {
    display: flex;
    animation: fadeInDown 0.3s ease;
  }

  nav a,
  nav .dropdown {
    width: 100%;
    text-align: left;
    border-radius: 0;
    /* Increased padding for better touch targets - minimum 44px height */
    padding: var(--spacing-md) var(--spacing-lg);
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Hide underline effect on mobile */
  nav a::before {
    display: none;
  }

  /* Mobile dropdown - no hover, click to expand */
  nav .dropdown > a::after {
    margin-left: auto;
    transform: rotate(-90deg);
  }

  nav .dropdown.active > a::after {
    transform: rotate(0deg);
  }

  nav .dropdown-content {
    position: static;
    box-shadow: none;
    background: #0E7490;
    animation: none;
    opacity: 1;
    transform: none;
    border-radius: 0;
    margin-left: var(--spacing-lg);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  nav .dropdown.active .dropdown-content {
    max-height: 500px;
  }

  nav .dropdown-content a {
    /* Ensure adequate touch targets for dropdown items */
    padding: var(--spacing-md) var(--spacing-lg);
    min-height: 44px;
  }

  /* Mobile spacing adjustments */
  header {
    padding: var(--spacing-md);
  }

  header h1 {
    font-size: 1.5rem;
  }

  header img {
    max-width: 280px;
  }

  .container {
    border-radius: 0;
    margin: var(--spacing-md) auto;
  }

  button {
    width: 100%;
    margin: var(--spacing-xs) 0;
    /* Ensure adequate touch target size on mobile */
    min-height: 48px;
    padding: var(--spacing-md) var(--spacing-lg);
  }

  input[type="text"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    width: 100%;
    margin: var(--spacing-xs) 0;
    /* Ensure adequate touch target size on mobile */
    min-height: 48px;
    padding: var(--spacing-md);
    /* CRITICAL: 16px font size to prevent iOS zoom on focus */
    font-size: 16px !important;
  }
}

/* ===========================
   Accessibility
   =========================== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  body {
    background: var(--color-white);
  }

  button {
    border: 2px solid currentColor;
  }
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
  :focus-visible {
    outline: 3px solid ButtonText;
  }

  input:focus,
  select:focus,
  textarea:focus {
    outline: 3px solid Highlight;
  }
}

/* Print styles */
@media print {
  header,
  nav,
  footer {
    display: none;
  }

  .container {
    box-shadow: none;
    margin: 0;
    padding: 0;
    width: 100%;
  }
}
