:root {
  --blu: #005baa;
  --arancio: #f7941d;
  --verde: #87f773;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: #18344d;
  font-family: Arial, Helvetica, sans-serif;
  background: #eef7ff;
}

#contenitore {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
}

/* Testata: riprende la struttura originale di Gira la Ruota. */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  width: 100%;
  padding-bottom: 10px;
  margin-bottom: 15px;
}

.logo-giocoscuola { flex: 0 0 auto; }

.logo-giocoscuola img {
  display: block;
  width: 300px;
  max-width: 100%;
  height: auto;
  margin-right: 200px;
}

#menuGiocoscuola {
  flex: 1;
  padding-top: 20px;
  margin-right: 20px;
  text-align: right;
  font-family: "Comic Sans MS", "Comic Sans", cursive;
}

#menuGiocoscuola > a,
.menu-dropdown-toggle {
  display: inline-block;
  padding: 8px 12px;
  margin-left: 5px;
  border: 0;
  border-radius: 6px;
  color: var(--blu);
  background: transparent;
  text-decoration: none;
  font: bold 20px "Comic Sans MS", "Comic Sans", cursive;
  line-height: 1.2;
  cursor: pointer;
  transition: .25s;
}

#menuGiocoscuola > a:hover,
.menu-dropdown-toggle:hover,
.menu-dropdown.aperto .menu-dropdown-toggle {
  color: #fff;
  background: var(--blu);
}

.menu-dropdown {
  position: relative;
  display: inline-block;
}

.menu-dropdown-panel {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  right: 0;
  display: none;
  min-width: 220px;
  padding: 6px 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
  text-align: left;
}

.menu-dropdown.aperto .menu-dropdown-panel { display: block; }

.menu-dropdown-panel a {
  display: block;
  padding: 9px 15px;
  color: var(--blu);
  text-decoration: none;
  font: bold 17px "Comic Sans MS", "Comic Sans", cursive;
}

.menu-dropdown-panel a:hover { color: #fff; background: var(--arancio); }

#btnMenu {
  display: none;
  width: 58px;
  height: 48px;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--arancio);
  box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
  cursor: pointer;
}

#btnMenu:hover { background: #e67e00; }

#btnMenu span {
  display: block;
  width: 28px;
  height: 4px;
  margin: 5px auto;
  border-radius: 3px;
  background: #fff;
}

#headerGiocoscuola {
  clear: both;
  width: 100%;
  margin-top: 10px;
}

#headerGiocoscuola img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

/* Grafica del Memory. Queste regole non toccano la testata. */
#contenitoregioco {
  width: min(100%, 1060px);
  margin: 22px auto 35px;
  padding: 28px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(0, 91, 170, .16);
  text-align: center;
}

#contenitoregioco h1 {
  margin: 0;
  color: var(--blu);
  font: 700 clamp(28px, 4vw, 40px) "Comic Sans MS", "Comic Sans", cursive;
}

.istruzioni { margin: 8px 0 20px; font-size: 18px; }


/* =========================================================
   SELEZIONE MATERIA E ARGOMENTO
   ========================================================= */

.selezione-memory {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 18px;
    margin: 12px 0 20px;
    flex-wrap: wrap;
}

.campo-selezione {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.campo-selezione label {
    color: var(--blu);
    font-size: 16px;
    font-weight: bold;
}

.campo-selezione select {
    width: 220px;
    min-width: 220px;
    height: 42px;
    padding: 7px 12px;

    border: 2px solid #c9e3f8;
    border-radius: 9px;

    background: #f7fbff;
    color: #18344d;

    font-size: 16px;
    font-weight: bold;

    cursor: pointer;
    outline: none;
}

.campo-selezione select:focus {
    border-color: var(--blu);
    box-shadow: 0 0 0 3px rgba(0, 91, 170, .12);
}

.campo-selezione select:disabled {
    opacity: .55;
    cursor: not-allowed;
}




.pannello-partita {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 18px;
}

.pannello-partita > div {
  min-width: 105px;
  padding: 8px 13px;
  border: 2px solid #d5e9fb;
  border-radius: 10px;
  background: #f6fbff;
}

.pannello-partita span { display: block; color: var(--blu); font-size: 13px; font-weight: bold; }
.pannello-partita strong { font-size: 22px; }

#restart {
  border: 0;
  border-radius: 9px;
  padding: 13px 17px;
  color: #fff;
  background: var(--arancio);
  font: bold 17px "Comic Sans MS", "Comic Sans", cursive;
  cursor: pointer;
  box-shadow: 0 3px 7px rgba(0, 0, 0, .2);
}

#restart:hover { background: #e67e00; }

#message { min-height: 25px; margin: 0 0 12px; color: #137333; font-weight: bold; }






/* =========================================================
   TABELLONE MEMORY 4 x 4
   ========================================================= */

#game-board {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}


/* =========================================================
   CARTA
   ========================================================= */

.memory-card {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    min-width: 0;
    cursor: pointer;
    perspective: 900px;
}


/* =========================================================
   RETRO DELLA CARTA
   ========================================================= */

.memory-card-back {
    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    border: 4px solid #2c81c8;
    border-radius: 12px;

    background: linear-gradient(
        135deg,
        #5bb9ed,
        var(--blu)
    );

    color: #fff;

    font: bold 56px "Comic Sans MS",
        "Comic Sans",
        cursive;

    box-shadow:
        0 2px 5px rgba(0, 0, 0, .18);

    backface-visibility: hidden;

    transition:
        transform .45s ease;
}


/* =========================================================
   FRONTE DELLA CARTA
   ========================================================= */

.memory-card-front {
    position: absolute;
    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;

    padding: 10px;

    border: 4px solid #91cffa;
    border-radius: 12px;

    background: #fff;

    backface-visibility: hidden;

    transform:
        rotateY(180deg);

    transition:
        transform .45s ease;

    box-sizing: border-box;
}


/* =========================================================
   CARTA SCOPERTA
   ========================================================= */

.memory-card.flipped
.memory-card-back,
.memory-card.matched
.memory-card-back {

    transform:
        rotateY(180deg);

}


.memory-card.flipped
.memory-card-front,
.memory-card.matched
.memory-card-front {

    transform:
        rotateY(0deg);

}


/* =========================================================
   IMMAGINI
   ========================================================= */

.memory-card-front img {

    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;

}


/* =========================================================
   DEFINIZIONI
   ========================================================= */

.memory-definition {

    width: 100%;

    padding: 8px;

    color: #134c79;

    font:
        bold clamp(
            14px,
            1.5vw,
            20px
        )
        "Comic Sans MS",
        "Comic Sans",
        cursive;

    line-height: 1.2;

    text-align: center;

    overflow-wrap: break-word;

}


/* =========================================================
   COPPIA TROVATA
   ========================================================= */

.memory-card.matched
.memory-card-front {

    border-color: #51ac47;

    background: #effde9;

}


/* =========================================================
   ERRORE IMMAGINE
   ========================================================= */

.memory-image-error {

    color: #b00020;

    font-weight: bold;

    text-align: center;

}












#footer {
  padding: 12px 18px;
  color: #173b1b;
  background: var(--verde);
  text-align: center;
  font-size: 14px;
}

@media (max-width: 768px) {
  #contenitore { width: min(100%, calc(100% - 20px)); }
  .header { flex-direction: column; align-items: center; }
  .logo-giocoscuola img { margin-right: 0; }

  #btnMenu {
    display: block;
    width: 65px;
    height: 55px;
    margin: -60px 15px 15px auto;
  }

  #menuGiocoscuola {
    display: none;
    width: 100%;
    margin: 0;
    padding: 0;
    text-align: center;
    animation: menuApertura .3s ease;
  }

  #menuGiocoscuola.aperto { display: block; }

  #menuGiocoscuola > a,
  .menu-dropdown,
  .menu-dropdown-toggle {
    display: block;
    width: 100%;
    margin: 0;
  }

  #menuGiocoscuola > a,
  .menu-dropdown-toggle {
    padding: 16px;
    border-bottom: 1px solid #ddd;
    border-radius: 0;
    background: #fff;
    text-align: center;
    font-size: 22px;
  }

  #menuGiocoscuola > a:hover,
  .menu-dropdown-toggle:hover,
  .menu-dropdown.aperto .menu-dropdown-toggle { background: var(--arancio); color: #fff; }

  .menu-dropdown-panel {
    position: static;
    min-width: 0;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    background: #eef7ff;
  }

  .menu-dropdown-panel a { padding: 13px; border-bottom: 1px solid #cfe5f8; text-align: center; font-size: 19px; }
  #contenitoregioco { padding: 20px 12px; }
  .pannello-partita { flex-wrap: wrap; }
  #game-board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}

@keyframes menuApertura {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
  
      .selezione-memory {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .campo-selezione {
        align-items: stretch;
    }

    .campo-selezione select {
        width: 100%;
        min-width: 0;
    }
}