/* =============================================
   PIETRO MICILLO v2 — Design Lusso
   Rivista Enigmistica Premium
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400&family=Roboto:wght@300;400;500;700&family=Dancing+Script:wght@600;700&display=swap');

/* ─── CSS VARIABLES ─── */
:root {
  --oro: #FFD700;
  --oro-scuro: #B8860B;
  --oro-chiaro: #FFF3B0;
  --oro-metallico: linear-gradient(135deg, #FFD700 0%, #FFA500 40%, #FFD700 60%, #B8860B 100%);
  --azzurro: #1565C0;
  --azzurro-chiaro: #42A5F5;
  --azzurro-cielo: #E3F2FD;
  --verde: #2E7D32;
  --verde-chiaro: #A5D6A7;
  --rosso: #C62828;
  --crema: #FFFDE7;
  --beige: #FFF8E1;
  --legno-scuro: #2C1A0E;
  --legno-medio: #4A2C0A;
  --grigio-chiaro: #F5F5F5;
  --nero: #1A1A2E;
  --bianco: #FFFFFF;
  --carta: #F5ECD7;
  --ombra: 0 4px 20px rgba(0,0,0,0.15);
  --ombra-oro: 0 4px 20px rgba(255,215,0,0.35);
  --ombra-profonda: 0 8px 40px rgba(0,0,0,0.3);
  --bordo-radius: 12px;
  --transizione: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

/* ─── BODY — SFONDO CARTA INVECCHIATA ─── */
body {
  font-family: 'Roboto', sans-serif;
  min-height: 100vh;
  color: #2C1A0E;
  overflow-x: hidden;
  /* Sfondo carta invecchiata con texture */
  background-color: #E8D5B0;
  background-image:
    /* Macchie d'inchiostro leggere */
    radial-gradient(ellipse at 15% 25%, rgba(139,90,43,0.12) 0%, transparent 40%),
    radial-gradient(ellipse at 85% 70%, rgba(101,67,33,0.10) 0%, transparent 35%),
    radial-gradient(ellipse at 50% 50%, rgba(255,248,220,0.4) 0%, transparent 60%),
    /* Filigrana orizzontale — righe sottili */
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 28px,
      rgba(139,90,43,0.06) 28px,
      rgba(139,90,43,0.06) 29px
    ),
    /* Leggero pattern carta */
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 60px,
      rgba(180,130,60,0.03) 60px,
      rgba(180,130,60,0.03) 61px
    );
  transition: background 0.5s ease;
}

/* ─── BODY MODALITÀ GIOCO — LEGNO SCURO ─── */
body.mode-game {
  background-color: #1C0F06;
  background-image:
    /* Venatura del legno rovere */
    repeating-linear-gradient(
      87deg,
      transparent 0px, transparent 8px,
      rgba(255,255,255,0.012) 8px, rgba(255,255,255,0.012) 9px,
      transparent 9px, transparent 18px,
      rgba(0,0,0,0.08) 18px, rgba(0,0,0,0.08) 19px
    ),
    repeating-linear-gradient(
      93deg,
      transparent 0px, transparent 15px,
      rgba(255,255,255,0.008) 15px, rgba(255,255,255,0.008) 16px
    ),
    /* Colore base legno con sfumature */
    radial-gradient(ellipse at 20% 30%, rgba(80,40,10,0.8) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(60,25,5,0.6) 0%, transparent 50%),
    linear-gradient(160deg, #2C1810 0%, #1A0E06 40%, #251309 60%, #1C0F06 100%);
}

/* ─── BODY MODALITÀ WORD SEARCH — TOVAGLIA TRATTORIA ─── */
body.mode-word-search {
  background-color: #FAFAFA;
  background-image:
    /* Tovaglia a quadretti rossa e bianca stile trattoria */
    repeating-conic-gradient(
      rgba(200, 30, 30, 0.12) 0% 25%,
      rgba(255,255,255,0) 0% 50%
    ),
    repeating-conic-gradient(
      rgba(200, 30, 30, 0.06) 0% 25%,
      rgba(255,255,255,0) 0% 50%
    );
  background-size: 40px 40px, 20px 20px;
  background-position: 0 0, 10px 10px;
}

/* Bordi ornamentali laterali */
body::before, body::after {
  content: '';
  position: fixed;
  top: 0; bottom: 0;
  width: 6px;
  background: linear-gradient(180deg,
    var(--oro) 0%, var(--oro-scuro) 20%,
    var(--oro) 40%, var(--oro-scuro) 60%,
    var(--oro) 80%, var(--oro-scuro) 100%
  );
  z-index: 1000;
  pointer-events: none;
  box-shadow: 0 0 15px rgba(255,215,0,0.4);
}
body::before { left: 0; }
body::after { right: 0; }

/* ─── HEADER LUSSO — LEGNO INCISO ─── */
#header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: #1A0D05;
  background-image:
    repeating-linear-gradient(
      89deg,
      transparent 0px, transparent 10px,
      rgba(255,255,255,0.015) 10px, rgba(255,255,255,0.015) 11px,
      transparent 11px, transparent 22px,
      rgba(0,0,0,0.1) 22px, rgba(0,0,0,0.1) 23px
    ),
    linear-gradient(180deg, #2C1810 0%, #1A0D05 100%);
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, transparent, var(--oro) 20%, var(--oro-scuro) 50%, var(--oro) 80%, transparent) 1;
  box-shadow: 0 4px 30px rgba(0,0,0,0.6), 0 2px 0 rgba(255,215,0,0.2);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.logo-icon {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, #FFD700, #FFA500, #B8860B);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  box-shadow: 0 4px 15px rgba(255,215,0,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
  border: 1px solid rgba(255,215,0,0.5);
  position: relative;
}

.logo-text h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.55rem;
  font-weight: 900;
  /* Effetto incisione dorata */
  background: linear-gradient(180deg, #FFE566 0%, #FFD700 40%, #B8860B 70%, #FFD700 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  letter-spacing: 1.5px;
  line-height: 1.1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.logo-text p {
  font-size: 0.65rem;
  color: rgba(255,215,0,0.6);
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Chips statistiche */
.header-stats { display: flex; gap: 12px; align-items: center; }

.stat-chip {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  padding: 5px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.8);
  font-size: 0.8rem;
  backdrop-filter: blur(4px);
}
.stat-chip .val { font-weight: 700; color: var(--oro); }

/* Mode Tabs nel header */
.mode-tabs-header {
  display: flex;
  background: rgba(0,0,0,0.3);
  border-radius: 25px;
  padding: 3px;
  border: 1px solid rgba(255,215,0,0.2);
  gap: 2px;
}

.mode-tab-btn {
  padding: 7px 18px;
  border: none;
  border-radius: 22px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255,255,255,0.6);
  background: transparent;
  transition: var(--transizione);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 5px;
}

.mode-tab-btn.attivo {
  background: linear-gradient(135deg, var(--oro), #FFA500);
  color: #1A0D05;
  box-shadow: 0 2px 8px rgba(255,215,0,0.4);
}

.mode-tab-btn:hover:not(.attivo) {
  color: white;
  background: rgba(255,215,0,0.1);
}

.header-controls { display: flex; gap: 8px; align-items: center; }

.btn-header {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  padding: 7px 14px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: var(--transizione);
  display: flex;
  align-items: center;
  gap: 5px;
}
.btn-header:hover { background: rgba(255,215,0,0.15); border-color: var(--oro); color: var(--oro); }

/* ─── BARRA PROGRESSO ─── */
#progress-bar-container {
  background: rgba(0,0,0,0.4);
  height: 5px;
  position: relative;
  overflow: visible;
}

#progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #FFD700, #FFA500, #FF6B35);
  width: 0%;
  transition: width 0.6s ease;
  box-shadow: 0 0 8px rgba(255,165,0,0.6);
  position: relative;
}

#progress-bar::after {
  content: '';
  position: absolute;
  top: -1px; right: 0;
  width: 6px; height: 7px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(255,215,0,0.8);
}

#progress-label {
  position: absolute;
  right: 8px; top: -20px;
  font-size: 0.62rem;
  color: var(--oro);
  font-weight: 700;
}

/* ─── LAYOUT PRINCIPALE ─── */
#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 22px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 900px) {
  #app {
    grid-template-columns: 1fr 340px;
    grid-template-rows: auto 1fr;
    align-items: start;
  }
  #toolbar { grid-column: 1 / -1; }
  #game-area { grid-column: 1; }
  #sidebar { grid-column: 2; grid-row: 2; }
  #schermata-selezione { grid-column: 1 / -1; }
  #ws-section { grid-column: 1 / -1; }
}

/* ─── TOOLBAR ─── */
#toolbar {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-radius: var(--bordo-radius);
  padding: 14px 20px;
  box-shadow: var(--ombra), 0 1px 0 rgba(255,215,0,0.3);
  border: 1px solid rgba(255,215,0,0.3);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ─── PULSANTI 3D REALI ─── */
.btn {
  padding: 10px 22px;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  position: relative;
  white-space: nowrap;
  /* Effetto 3D */
  transform-style: preserve-3d;
  user-select: none;
}

.btn:active { transform: translateY(2px) !important; }

.btn-verde {
  background: linear-gradient(180deg, #56C963 0%, #3DA44D 50%, #2E7D32 100%);
  color: white;
  box-shadow:
    0 6px 0 #1B5E20,
    0 8px 15px rgba(46,125,50,0.4);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.3);
}
.btn-verde:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #1B5E20, 0 12px 20px rgba(46,125,50,0.5); }
.btn-verde:active { box-shadow: 0 2px 0 #1B5E20, 0 4px 10px rgba(46,125,50,0.4); }

.btn-blu {
  background: linear-gradient(180deg, #2196F3 0%, #1976D2 50%, #0D47A1 100%);
  color: white;
  box-shadow:
    0 6px 0 #0A3270,
    0 8px 15px rgba(21,101,192,0.4);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.3);
}
.btn-blu:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #0A3270, 0 12px 20px rgba(21,101,192,0.5); }
.btn-blu:active { box-shadow: 0 2px 0 #0A3270, 0 4px 10px rgba(21,101,192,0.4); }

.btn-oro {
  background: linear-gradient(180deg, #FFE566 0%, #FFD700 40%, #FFA500 100%);
  color: #2C1A0E;
  box-shadow:
    0 6px 0 #B8860B,
    0 8px 15px rgba(255,165,0,0.4);
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
  border-top: 1px solid rgba(255,255,255,0.5);
}
.btn-oro:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #B8860B, 0 12px 20px rgba(255,165,0,0.5); }
.btn-oro:active { box-shadow: 0 2px 0 #B8860B, 0 4px 10px rgba(255,165,0,0.4); }

.btn-rosso {
  background: linear-gradient(180deg, #EF5350 0%, #D32F2F 50%, #B71C1C 100%);
  color: white;
  box-shadow:
    0 6px 0 #7F0000,
    0 8px 15px rgba(183,28,28,0.4);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.3);
}
.btn-rosso:hover { transform: translateY(-2px); }
.btn-rosso:active { box-shadow: 0 2px 0 #7F0000, 0 4px 10px rgba(183,28,28,0.4); }

.btn-grigio {
  background: linear-gradient(180deg, #90A4AE 0%, #78909C 50%, #546E7A 100%);
  color: white;
  box-shadow: 0 6px 0 #37474F, 0 8px 15px rgba(84,110,122,0.4);
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  border-top: 1px solid rgba(255,255,255,0.3);
}
.btn-grigio:hover { transform: translateY(-2px); }
.btn-grigio:active { box-shadow: 0 2px 0 #37474F; }

/* ─── PANNELLI PRINCIPALI — Carta crema vellutata ─── */
#game-area, #pannello-indizi, #pannello-info, #schermata-selezione {
  background-color: #FAF0DC;
  background-image:
    /* Texture carta vellutata — leggere imperfezioni */
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.5) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(200,160,100,0.15) 0%, transparent 40%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  border-radius: var(--bordo-radius);
  box-shadow:
    var(--ombra-profonda),
    inset 0 1px 0 rgba(255,255,255,0.7),
    inset 0 -1px 0 rgba(139,90,43,0.1);
  border: 1px solid rgba(184,134,11,0.3);
  overflow: hidden;
}

/* ─── HEADER GIOCO ─── */
.game-header {
  background: linear-gradient(135deg,
    rgba(255,248,220,0.95),
    rgba(255,240,180,0.95)
  );
  padding: 16px 22px;
  border-bottom: 2px solid rgba(184,134,11,0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
}

.game-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,215,0,0.5), transparent);
}

.game-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--legno-medio);
}

.badge {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-facile { background: #E8F5E9; color: #2E7D32; border: 1px solid #A5D6A7; }
.badge-medio { background: #FFF8E1; color: #F57F17; border: 1px solid #FFE082; }
.badge-difficile { background: #FFEBEE; color: #C62828; border: 1px solid #EF9A9A; }

/* ─── GRIGLIA CRUCIVERBA ─── */
#griglia-container {
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
  background: rgba(0,0,0,0.02);
}

#griglia {
  display: inline-grid;
  gap: 2px;
  background: #3D2B1A;
  border: 4px solid #3D2B1A;
  border-radius: 8px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.1);
  padding: 3px;
  user-select: none;
}

/* ─── CELLE CRUCIVERBA — Carta crema con imperfezioni ─── */
.cella {
  width: 42px; height: 42px;
  position: relative;
  background-color: #FFFEF2;
  background-image:
    radial-gradient(ellipse at 30% 30%, rgba(255,255,255,0.8) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(210,180,140,0.1) 0%, transparent 50%);
  border: 1px solid #B8A080;
  transition: var(--transizione);
  cursor: text;
  border-radius: 2px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.cella.nera {
  background: linear-gradient(135deg, #2C1810, #1A0D05);
  cursor: default;
  border-color: #2C1810;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.cella.attiva-principale {
  background: linear-gradient(135deg, #1565C0, #1976D2) !important;
  border-color: var(--azzurro) !important;
  box-shadow: 0 0 0 2px rgba(66,165,245,0.5), 0 4px 12px rgba(21,101,192,0.3) !important;
}
.cella.attiva-principale .cella-input { color: white !important; }

.cella.in-parola-attiva {
  background-color: #EDF4FF;
  background-image: radial-gradient(ellipse at 50% 50%, rgba(255,255,255,0.9) 0%, transparent 70%);
  border-color: #90CAF9;
  box-shadow: 0 0 0 1px rgba(66,165,245,0.3);
}

.cella.corretta {
  background: linear-gradient(135deg, #E8F5E9, #C8E6C9) !important;
  border-color: var(--verde) !important;
  animation: pop-correct 0.4s ease;
}

.cella.errata {
  background: linear-gradient(135deg, #FFEBEE, #FFCDD2) !important;
  border-color: var(--rosso) !important;
  animation: shake 0.4s ease;
}

.cella.rivelata {
  background: linear-gradient(135deg, #FFFDE7, #FFF9C4) !important;
  border-color: var(--oro-scuro) !important;
}

@keyframes pop-correct {
  0% { transform: scale(1); }
  50% { transform: scale(1.15) rotate(3deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(5px) rotate(2deg); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* Input cella — effetto scrittura stilografica */
.cella-input {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  /* Font manoscritto elegante */
  font-family: 'Dancing Script', 'Playfair Display', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: #1A0A00;
  cursor: text;
  outline: none;
  caret-color: transparent;
  padding-top: 6px;
  text-transform: uppercase;
  z-index: 1;
  letter-spacing: -0.5px;
}

.cella-numero {
  position: absolute;
  top: 2px; left: 2px;
  font-size: 0.48rem;
  font-weight: 700;
  color: #C62828;
  line-height: 1;
  z-index: 2;
  pointer-events: none;
  font-family: 'Roboto', sans-serif;
}

@keyframes pen-write {
  0% { opacity: 0; transform: scale(0.2) rotate(-15deg); }
  60% { transform: scale(1.15) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
.lettera-scritta { animation: pen-write 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

/* ─── INDIZIO CORRENTE ─── */
#indizio-corrente {
  background: linear-gradient(135deg, #1565C0 0%, #0D47A1 100%);
  color: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  border-top: 2px solid rgba(255,215,0,0.3);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
.indizio-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--oro); font-weight: 700; white-space: nowrap; }
.indizio-testo-corrente { font-size: 0.88rem; color: white; line-height: 1.4; flex: 1; font-style: italic; }
.indizio-dir { background: var(--oro); color: #1A0D05; font-size: 0.65rem; font-weight: 700; padding: 3px 10px; border-radius: 10px; }

/* ─── SIDEBAR ─── */
#sidebar { display: flex; flex-direction: column; gap: 16px; }

#pannello-info {
  padding: 16px;
}

.pannello-header {
  background: linear-gradient(135deg, rgba(255,248,220,0.95), rgba(255,240,180,0.9));
  padding: 12px 16px;
  border-bottom: 1px solid rgba(184,134,11,0.3);
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 700;
  color: #4A2C0A;
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }

.info-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.8), rgba(255,248,220,0.6));
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  border: 1px solid rgba(184,134,11,0.2);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.7);
  transition: var(--transizione);
}
.info-card:hover { border-color: rgba(184,134,11,0.4); transform: translateY(-1px); }
.info-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 1.2px; color: #8D6E63; margin-bottom: 4px; }
.info-val { font-size: 1.3rem; font-weight: 700; color: var(--azzurro); font-family: 'Playfair Display', serif; }
.info-val.timer { color: var(--rosso); }
.info-val.punti { color: var(--verde); }

/* Pannello indizi */
#pannello-indizi { overflow: hidden; }

.indizi-tabs { display: flex; background: rgba(0,0,0,0.05); border-bottom: 1px solid rgba(184,134,11,0.2); }

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  color: #8D6E63;
  transition: var(--transizione);
  border-bottom: 3px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tab-btn.attivo { color: var(--azzurro); border-bottom-color: var(--azzurro); background: rgba(255,255,255,0.6); }
.tab-btn:hover:not(.attivo) { background: rgba(66,165,245,0.08); color: var(--azzurro); }

.indizi-lista { max-height: 380px; overflow-y: auto; padding: 6px; }

.indizio-item {
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 3px;
  cursor: pointer;
  transition: var(--transizione);
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid transparent;
}
.indizio-item:hover { background: rgba(66,165,245,0.08); border-color: rgba(66,165,245,0.2); }
.indizio-item.attivo {
  background: linear-gradient(135deg, rgba(21,101,192,0.08), rgba(66,165,245,0.12));
  border-color: rgba(66,165,245,0.3);
}

.indizio-num {
  min-width: 26px; height: 26px;
  background: var(--azzurro);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(21,101,192,0.3);
}
.indizio-item.attivo .indizio-num { background: var(--oro-scuro); }
.indizio-testo { font-size: 0.8rem; line-height: 1.4; color: #4A2C0A; padding-top: 3px; font-style: italic; }
.indizio-risolto .indizio-num { background: var(--verde); }
.indizio-risolto .indizio-testo { text-decoration: line-through; color: #999; }

/* ─── SELEZIONE PUZZLE ─── */
#schermata-selezione { padding: 28px; }

.selezione-titolo {
  font-family: 'Playfair Display', serif;
  font-size: 1.9rem;
  font-weight: 900;
  color: #4A2C0A;
  text-align: center;
  margin-bottom: 6px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.selezione-sottotitolo { text-align: center; color: #8D6E63; font-size: 0.88rem; margin-bottom: 24px; font-style: italic; }

.filtri-difficolta { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }

.filtro-btn {
  padding: 8px 20px;
  border-radius: 20px;
  border: 2px solid;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  transition: var(--transizione);
  background: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.filtro-btn[data-diff="tutti"] { border-color: var(--azzurro); color: var(--azzurro); }
.filtro-btn[data-diff="facile"] { border-color: var(--verde); color: var(--verde); }
.filtro-btn[data-diff="medio"] { border-color: #F57F17; color: #F57F17; }
.filtro-btn[data-diff="difficile"] { border-color: var(--rosso); color: var(--rosso); }
.filtro-btn.attivo, .filtro-btn:hover { color: white; transform: translateY(-1px); }
.filtro-btn[data-diff="tutti"].attivo,.filtro-btn[data-diff="tutti"]:hover { background: var(--azzurro); }
.filtro-btn[data-diff="facile"].attivo,.filtro-btn[data-diff="facile"]:hover { background: var(--verde); }
.filtro-btn[data-diff="medio"].attivo,.filtro-btn[data-diff="medio"]:hover { background: #F57F17; }
.filtro-btn[data-diff="difficile"].attivo,.filtro-btn[data-diff="difficile"]:hover { background: var(--rosso); }

.puzzle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }

.puzzle-card {
  background:
    radial-gradient(ellipse at 20% 20%, rgba(255,255,255,0.5) 0%, transparent 50%),
    linear-gradient(135deg, #FFFBF0, #F5E6C8);
  border: 1px solid rgba(184,134,11,0.25);
  border-radius: var(--bordo-radius);
  padding: 18px;
  cursor: pointer;
  transition: var(--transizione);
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.8);
}

.puzzle-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 5px; height: 100%;
  background: var(--azzurro);
  border-radius: var(--bordo-radius) 0 0 var(--bordo-radius);
}
.puzzle-card[data-diff="facile"]::before { background: linear-gradient(180deg, #4CAF50, #2E7D32); }
.puzzle-card[data-diff="medio"]::before { background: linear-gradient(180deg, #FF9800, #F57F17); }
.puzzle-card[data-diff="difficile"]::before { background: linear-gradient(180deg, #F44336, #C62828); }

.puzzle-card:hover {
  transform: translateY(-5px) rotate(0.5deg);
  box-shadow: 0 16px 40px rgba(0,0,0,0.15), 0 2px 0 rgba(255,215,0,0.4);
  border-color: var(--oro-scuro);
}

.puzzle-card.completato {
  background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
  border-color: var(--verde);
}

.puzzle-card .p-nome { font-family: 'Playfair Display', serif; font-size: 1rem; font-weight: 700; color: #4A2C0A; margin-bottom: 6px; }
.puzzle-card .p-tema { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px; color: #8D6E63; margin-bottom: 8px; }
.puzzle-card .p-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.star-rating { color: var(--oro); font-size: 0.9rem; text-shadow: 0 1px 2px rgba(0,0,0,0.1); }
.completato-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--verde); color: white;
  border-radius: 50%; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; box-shadow: 0 2px 6px rgba(46,125,50,0.4);
}

/* ─── WORD SEARCH SECTION ─── */
#ws-section {
  display: none;
  grid-column: 1 / -1;
}

#ws-schermata-selezione { padding: 28px; }

#ws-game-area {
  display: none;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  grid-column: 1 / -1;
  align-items: start;
}

@media (max-width: 900px) {
  #ws-game-area { grid-template-columns: 1fr; }
}

.ws-game-panel {
  background-color: #FAF0DC;
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.5) 0%, transparent 50%);
  border-radius: var(--bordo-radius);
  box-shadow: var(--ombra-profonda);
  border: 1px solid rgba(184,134,11,0.3);
  overflow: hidden;
}

/* Griglia word search */
#ws-griglia-wrap {
  padding: 16px;
  overflow: auto;
  cursor: crosshair;
  /* Effetto luce soffusa da lampada */
  background: radial-gradient(ellipse at 50% 0%, rgba(255,240,180,0.3) 0%, transparent 60%);
}

#ws-griglia {
  display: inline-grid;
  gap: 1px;
  background: rgba(139,90,43,0.3);
  border: 3px solid rgba(139,90,43,0.5);
  border-radius: 6px;
  padding: 2px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  user-select: none;
  -webkit-user-select: none;
}

/* Celle word search — carta crema */
.ws-cell {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Dancing Script', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #2C1A0E;
  background-color: #FFFEF5;
  background-image: radial-gradient(ellipse at 50% 30%, rgba(255,255,255,0.8) 0%, transparent 70%);
  border: 1px solid rgba(184,134,11,0.15);
  border-radius: 2px;
  cursor: crosshair;
  transition: background 0.15s ease, transform 0.1s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.ws-cell.selecting {
  background: linear-gradient(135deg, #BBDEFB, #90CAF9) !important;
  color: #0D47A1 !important;
  transform: scale(1.05);
  z-index: 2;
  border-color: #42A5F5;
  box-shadow: 0 2px 8px rgba(66,165,245,0.4);
}

.ws-cell.ws-found {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  border-radius: 4px;
  font-weight: 700;
  transition: all 0.3s ease;
  animation: found-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes found-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1.02); }
}

.ws-cell.ws-error {
  background: #FFEBEE !important;
  color: #C62828 !important;
  animation: shake 0.4s ease;
}

/* ─── LISTA PAROLE WORD SEARCH ─── */
.ws-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ws-stats-panel {
  background-color: #FAF0DC;
  background-image: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.5) 0%, transparent 50%);
  border-radius: var(--bordo-radius);
  box-shadow: var(--ombra);
  border: 1px solid rgba(184,134,11,0.3);
  padding: 14px;
}

.ws-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ws-stat { background: rgba(255,255,255,0.6); border-radius: 8px; padding: 10px; text-align: center; border: 1px solid rgba(184,134,11,0.2); }
.ws-stat-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 1px; color: #8D6E63; margin-bottom: 3px; }
.ws-stat-val { font-size: 1.2rem; font-weight: 700; color: var(--azzurro); font-family: 'Playfair Display', serif; }

/* Progress WS */
.ws-progress-wrap { margin-top: 10px; }
.ws-progress-label { font-size: 0.68rem; color: #8D6E63; margin-bottom: 4px; display: flex; justify-content: space-between; }
.ws-progress-bar-bg { background: rgba(0,0,0,0.1); border-radius: 10px; height: 8px; overflow: hidden; }
#ws-progress-bar { height: 100%; background: linear-gradient(90deg, #FFD700, #4CAF50); border-radius: 10px; width: 0%; transition: width 0.5s ease; }

/* Lista parole */
.ws-parole-panel {
  background-color: #FAF0DC;
  border-radius: var(--bordo-radius);
  box-shadow: var(--ombra);
  border: 1px solid rgba(184,134,11,0.3);
  overflow: hidden;
  max-height: 500px;
}

.ws-parole-header { padding: 12px 16px; background: linear-gradient(135deg, rgba(255,248,220,0.95), rgba(255,240,180,0.9)); border-bottom: 1px solid rgba(184,134,11,0.3); font-family: 'Playfair Display', serif; font-size: 0.95rem; font-weight: 700; color: #4A2C0A; }

#ws-parole-lista { padding: 8px; overflow-y: auto; max-height: 380px; }

.ws-parola-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  margin-bottom: 3px;
  border: 1px solid rgba(184,134,11,0.15);
  background: rgba(255,255,255,0.5);
  transition: var(--transizione);
  font-family: 'Dancing Script', serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #2C1A0E;
  letter-spacing: 0.5px;
}

.ws-parola-item.ws-parola-trovata {
  text-decoration: line-through;
  color: #777;
  border-width: 2px;
  animation: found-pop 0.4s ease;
}

.ws-check { font-size: 0.9rem; flex-shrink: 0; }
.ws-check.hidden { visibility: hidden; }
.ws-parola-testo { flex: 1; }

/* ─── MODALI ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.3s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: linear-gradient(135deg, #FFFEF5, #FAF0DC);
  border-radius: 20px;
  padding: 36px;
  max-width: 500px;
  width: 100%;
  box-shadow:
    0 25px 60px rgba(0,0,0,0.4),
    0 0 0 3px rgba(255,215,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.8);
  animation: slide-up 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  text-align: center;
  border: 1px solid rgba(184,134,11,0.4);
}

/* Banner tricolore sul modale vittoria */
.modal-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: linear-gradient(90deg, #009246 33.3%, white 33.3% 66.6%, #CE2B37 66.6%);
  border-radius: 20px 20px 0 0;
}

@keyframes slide-up {
  from { transform: translateY(50px) scale(0.85); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-emoji { font-size: 4rem; margin-bottom: 12px; display: block; }
.modal-titolo { font-family: 'Playfair Display', serif; font-size: 2.2rem; font-weight: 900; color: #4A2C0A; margin-bottom: 8px; letter-spacing: 1px; }
.modal-testo { color: #6D4C41; font-size: 0.95rem; margin-bottom: 20px; line-height: 1.7; font-style: italic; }
.modal-stat { font-size: 1.5rem; font-weight: 700; color: var(--verde); margin: 6px 0; font-family: 'Playfair Display', serif; }
.modal-btn-group { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Canvas coriandoli */
#confetti-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 999; }

/* ─── TOAST ─── */
#toast-container { position: fixed; bottom: 24px; right: 28px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

.toast {
  background: linear-gradient(135deg, #2C1810, #1A0D05);
  color: white;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.85rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4), 0 1px 0 rgba(255,215,0,0.2);
  animation: toast-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 300px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,215,0,0.2);
}
.toast.successo { background: linear-gradient(135deg, #2E7D32, #1B5E20); }
.toast.errore { background: linear-gradient(135deg, #C62828, #7F0000); }
.toast.info { background: linear-gradient(135deg, #1565C0, #0A3270); }
.toast.avviso { background: linear-gradient(135deg, #E65100, #BF360C); }

@keyframes toast-in {
  from { transform: translateX(120px) scale(0.8); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

/* ─── TOGGLE MUSICA ─── */
.music-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  padding: 6px 12px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transizione);
  display: flex;
  align-items: center;
  gap: 5px;
}
.music-toggle.on { background: rgba(255,215,0,0.15); border-color: var(--oro); color: var(--oro); }
.music-toggle:hover { border-color: var(--oro); color: var(--oro); }

/* ─── LOADING ─── */
#loading {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1A0D05, #2C1810, #1A0D05);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: white;
  transition: opacity 0.6s ease;
}

.loading-logo {
  font-family: 'Playfair Display', serif;
  font-size: 2.8rem;
  font-weight: 900;
  background: linear-gradient(180deg, #FFE566, #FFD700, #B8860B, #FFD700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin-bottom: 6px;
  animation: pulse-glow 2s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(255,215,0,0.3));
}

.loading-sub { font-size: 0.82rem; color: rgba(255,215,0,0.6); letter-spacing: 5px; text-transform: uppercase; margin-bottom: 44px; }

.loading-spinner {
  width: 56px; height: 56px;
  border: 3px solid rgba(255,215,0,0.1);
  border-top-color: var(--oro);
  border-right-color: rgba(255,165,0,0.5);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 10px rgba(255,215,0,0.3)); }
  50% { filter: drop-shadow(0 0 30px rgba(255,215,0,0.6)); }
}

/* ─── SELECT ─── */
select {
  appearance: none; -webkit-appearance: none;
  background: rgba(255,255,255,0.8) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%234A2C0A' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 2px solid rgba(184,134,11,0.3);
  border-radius: 8px;
  padding: 8px 32px 8px 12px;
  font-size: 0.85rem;
  color: #4A2C0A;
  cursor: pointer;
  transition: var(--transizione);
  min-width: 140px;
  font-family: 'Roboto', sans-serif;
}
select:focus { outline: none; border-color: var(--oro-scuro); box-shadow: 0 0 0 3px rgba(184,134,11,0.15); }

/* ─── TASTIERA MOBILE ─── */
#tastiera-virtuale {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(180deg, #1C0F06, #0D0702);
  padding: 10px 8px 16px;
  z-index: 500;
  border-top: 2px solid rgba(255,215,0,0.3);
  box-shadow: 0 -6px 30px rgba(0,0,0,0.5);
}

@media (max-width: 768px) and (pointer: coarse) {
  #tastiera-virtuale { display: block; }
  body { padding-bottom: 185px; }
}

.tastiera-riga { display: flex; justify-content: center; gap: 4px; margin-bottom: 6px; }

.tasto {
  width: 30px; height: 40px;
  background: linear-gradient(180deg, #F5E6C8, #D4B896);
  border: none;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s ease;
  box-shadow: 0 3px 0 #8B6914, 0 4px 8px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #2C1A0E;
  font-family: 'Dancing Script', serif;
}
.tasto:active { transform: translateY(3px); box-shadow: 0 0 0 #8B6914; }
.tasto.speciale { width: 50px; background: linear-gradient(180deg, #546E7A, #37474F); color: white; font-family: 'Roboto', sans-serif; font-size: 0.68rem; box-shadow: 0 3px 0 #263238; }
.tasto.invio { width: 62px; background: linear-gradient(180deg, #56C963, #2E7D32); color: white; box-shadow: 0 3px 0 #1B5E20; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); }
::-webkit-scrollbar-thumb { background: rgba(184,134,11,0.3); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(184,134,11,0.5); }

/* ─── RESPONSIVE ─── */
@media (max-width: 600px) {
  body::before, body::after { width: 3px; }
  #app { padding: 10px 10px; }
  .header-inner { padding: 8px 14px; }
  .logo-text h1 { font-size: 1.15rem; }
  .logo-text p, .header-stats { display: none; }
  .mode-tabs-header { order: 3; width: 100%; }
  .cella { width: 30px; height: 30px; }
  .cella-input { font-size: 1.1rem; padding-top: 4px; }
  .cella-numero { font-size: 0.4rem; }
  .ws-cell { width: 24px; height: 24px; font-size: 0.8rem; }
  .puzzle-grid { grid-template-columns: 1fr 1fr; }
  .modal-box { padding: 22px 16px; }
  .modal-titolo { font-size: 1.6rem; }
}

@media (max-width: 380px) {
  .cella { width: 24px; height: 24px; }
  .cella-input { font-size: 0.9rem; }
  .ws-cell { width: 20px; height: 20px; font-size: 0.68rem; }
}

/* ─── EFFETTO LUCE LAMPADA (overlay animato) ─── */
.lamp-overlay {
  position: fixed;
  top: -200px; left: 50%;
  transform: translateX(-50%);
  width: 600px; height: 600px;
  background: radial-gradient(ellipse at 50% 0%, rgba(255,240,180,0.08) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: lamp-sway 8s ease-in-out infinite;
}

@keyframes lamp-sway {
  0%, 100% { left: 50%; }
  33% { left: 55%; }
  66% { left: 45%; }
}
