/* -------------------------
   Importa il font Hey Comic
------------------------- */
@font-face {
  font-family: 'Hey Comic';
  src: url('../../font/HeyComic.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

/* -------------------------
   Variabili CSS
------------------------- */
:root {
  --face-width: 80vmin;
  --face-height: 45vmin;
  --face-radius: 40% 40% 50% 50% / 40% 40% 60% 60%;
  --primary-blue: #58cfff;
  --dark-blue: #0c2a50;
  --darker-blue: #001a33;
  --gray: #efefef;
  --pastel-bg: #f9f9f9;
  /* Occhi */
  --eye-width: 15%;
  --eye-height: 40%;
  --eye-margin: 0 2%;
  --eye-shift: 0;
  /* Blink */
  --blink-duration: 0.2s;
  --blink-steps: 5;
  --blink-delay-min: 10000;
  --blink-delay-max: 15000;
  /* Movimento occhi */
  --shift-delay-min: 60000;
  --shift-delay-max: 120000;
  --shift-min: -5;
  --shift-max: 5;
}

/* -------------------------
   Reset Base
------------------------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
html, body {
  width: 100%;
  height: 100%;
  background: var(--gray);
  overflow: hidden;
  font-family: 'Hey Comic', sans-serif;
  touch-action: manipulation; /* Permette il tocco normale ma disabilita zoom e pinch */
}

/* -------------------------
   Container Principale
------------------------- */
.container {
  width: 100vw;
  height: 100vh;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* -------------------------
   Volto di Tommy
------------------------- */
.face {
  position: relative;
  width: var(--face-width);
  height: var(--face-height);
  border-radius: var(--face-radius);
  background: radial-gradient(circle at 50% 50%, var(--dark-blue) 50%, var(--darker-blue) 100%);
  box-shadow: 0 0 30px rgba(0,0,0,0.5);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}
.face::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 5px solid var(--primary-blue);
  border-radius: inherit;
  opacity: 0.2;
  animation: spin 10s linear infinite;
  pointer-events: none;
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* -------------------------
   Occhi
------------------------- */
.eye {
  position: relative;
  width: var(--eye-width);
  height: var(--eye-height);
  margin: var(--eye-margin);
  transform: translateX(var(--eye-shift));
  transition: transform 2s ease;
}
.eye-inner {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 50%, var(--primary-blue) 40%, #3aabdb 100%);
  border-radius: 50%;
  box-shadow: inset 0 0 10px rgba(255,255,255,0.4);
  transform-origin: bottom center;
}
@keyframes blinkAnim {
  0% { transform: scaleY(1); }
  50% { transform: scaleY(0.1); }
  100% { transform: scaleY(1); }
}
.eye-inner.blinking {
  animation: blinkAnim var(--blink-duration) steps(var(--blink-steps)) forwards;
}

/* -------------------------
   Nuvoletta Parlante
------------------------- */
.speech-bubble {
  position: absolute;
  bottom: 10%;
  right: 10%;
  max-width: 320px;
  padding: 1.5em 1.2em;
  background: var(--dark-blue);
  border: 2px solid var(--primary-blue);
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.3);
  z-index: 10;
  cursor: pointer;
  opacity: 0;
  transform: scale(0);
  animation: bubblePop 0.8s ease-out forwards 1s;
  text-align: center;
}
.speech-bubble::after {
  content: "";
  position: absolute;
  top: 75%;
  left: -10px;
  transform: translateY(-50%);
  border-width: 5px 12px 10px 0;
  border-style: solid;
  border-color: transparent var(--dark-blue) transparent transparent;
}
@keyframes bubblePop {
  0% { opacity: 0; transform: scale(0); }
  80% { opacity: 1; transform: scale(1.1); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes bubbleHide {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0); }
}
@keyframes bubbleShow {
  0% { opacity: 0; transform: scale(0); }
  100% { opacity: 1; transform: scale(1); }
}

/* -------------------------
   Testo Fade
------------------------- */
.fade-text {
  font-size: 1.2em;
  color: var(--primary-blue);
  opacity: 0;
  transition: opacity 0.8s ease-in-out;
  white-space: normal;
  word-break: break-word;
}
.fade-text.visible {
  opacity: 1;
}

/* -------------------------
   Pannello Docente
------------------------- */
.teacher-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 400px;
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid var(--primary-blue);
  border-radius: 24px;
  padding: 25px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: center;
  z-index: 100;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.teacher-panel.active {
  opacity: 1;
  transform: translateY(0);
}

.teacher-panel h3 {
  margin-bottom: 10px;
  font-size: 2em;
  color: var(--primary-blue);
}

.teacher-panel p {
  margin-bottom: 20px;
  font-size: 1.8em;
  font-weight: bold;
  color: var(--dark-blue);
}

.logout-timer {
  font-size: 1.2em;
  margin: 15px 0;
  color: var(--primary-blue);
  font-weight: 500;
}

/* -------------------------
   Icon Container & Icon Button
------------------------- */
.icon-container {
  margin-top: 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.icon-box {
  width: 100%;
  display: flex;
  justify-content: center;
}

.icon-button {
  background: none;
  border: 2px solid var(--primary-blue);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 15px;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-button:hover {
  background: rgba(88, 207, 255, 0.1);
  transform: scale(1.05);
}

.icon-button:active {
  transform: scale(0.95);
}

.icon-button img {
  width: 60px;
  height: 60px;
  filter: invert(67%) sepia(72%) saturate(5495%) hue-rotate(173deg) brightness(101%) contrast(97%);
}

/* -------------------------
   Extra Box (Audio Visualizer)
------------------------- */
.extra-box {
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid var(--primary-blue);
  border-radius: 20px;
  width: 100%;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2em;
  color: var(--primary-blue);
  overflow: hidden;
  position: relative;
  transition: opacity 0.3s ease;
}

.extra-box.active {
  display: flex;
  opacity: 1;
}

.extra-box .upload-status {
  text-align: center;
  padding: 10px;
  font-size: 1.2em;
  font-weight: bold;
  width: 100%;
}

.extra-box .upload-status.progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.extra-box .progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.extra-box .progress-bar-fill {
  height: 100%;
  background: var(--primary-blue);
  width: 0%;
  transition: width 0.3s ease;
}

.extra-box .upload-status.success {
  color: #4CAF50;
  font-weight: bold;
  font-size: 1.4em;
  padding: 15px;
  background: rgba(76, 175, 80, 0.2);
  border-radius: 10px;
  display: block;
  text-align: center;
  animation: fadeIn 0.3s ease-in-out;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
  border: 2px solid #4CAF50;
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.extra-box .upload-status.error {
  color: #f44336;
}

/* Stile per il canvas dell'audio visualizer */
#spectrumCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Responsive Design */
@media (max-width: 768px) {
  .teacher-panel {
    width: 90%;
    max-width: 400px;
  }

  .icon-button {
    width: 100px;
    height: 100px;
  }

  .icon-button img {
    width: 50px;
    height: 50px;
  }
}

/* -------------------------
   PIN Screen Styles
------------------------- */
.pin-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(12, 42, 80, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: none; /* Nascosto di default */
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.pin-screen.visible {
  display: flex;
  opacity: 1;
}

.pin-container {
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 30px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.pin-screen.visible .pin-container {
  transform: translateY(0);
  opacity: 1;
}

.pin-header {
  text-align: center;
  margin-bottom: 30px;
}

.pin-title {
  color: #fff;
  font-size: 20px;
  font-weight: 500;
  margin: 0;
  letter-spacing: 1px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.pin-display {
  display: flex;
  justify-content: center;
  gap: 25px;
  margin: 25px 0 40px;
}

.pin-dot {
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.pin-dot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(88, 207, 255, 0.2);
  opacity: 0;
  transition: all 0.3s ease;
}

.pin-dot.filled {
  background: var(--primary-blue);
  border-color: var(--primary-blue);
  transform: scale(1.1);
  box-shadow: 
      0 0 0 2px rgba(88, 207, 255, 0.1),
      0 0 10px rgba(88, 207, 255, 0.5),
      inset 0 0 8px rgba(255, 255, 255, 0.4);
}

.pin-dot.filled::after {
  opacity: 1;
  animation: pulsePin 2s infinite;
}

@keyframes pulsePin {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.5;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.5);
    opacity: 0;
  }
  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.5;
  }
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  padding: 10px;
}

.pin-key {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.pin-key:hover {
  background: rgba(255, 255, 255, 0.15);
}

.pin-key:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

.digit {
  color: #fff;
  font-size: 32px;
  font-weight: 300;
  position: relative;
  z-index: 2;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Stili speciali per i tasti funzione */
#pinCancel .digit {
  font-size: 16px;
  color: var(--primary-blue);
}

#pinDelete {
  position: relative;
}

#pinDelete .digit {
  display: none;
}

#pinDelete::before {
  content: '⌫';
  color: var(--primary-blue);
  font-size: 28px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.pin-error {
  color: #ff3b30; /* Colore errore iOS */
  text-align: center;
  margin: 10px 0;
  min-height: 20px;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Animazione di pressione */
.pin-key:active::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(88, 207, 255, 0.2) 0%, transparent 60%);
  transform: translate(-50%, -50%) scale(2);
  opacity: 0;
  animation: ripple 0.6s ease-out;
}

@keyframes ripple {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2);
  }
}

/* Responsive adjustments */
@media (max-width: 380px) {
  .pin-container {
    padding: 20px;
  }
  
  .pin-keypad {
    gap: 12px;
  }
  
  .digit {
    font-size: 28px;
  }
}

/* Rimuovo la vecchia barra di progresso fissa */
.upload-progress {
  display: none;
}

@keyframes blink {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}