/* style.css - Completo con repisa EXTREMADAMENTE ALTA */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  background: radial-gradient(circle at center, #2e3f4e 0%, #1e2a3a 50%, #0f1722 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Segoe UI', 'Palatino', system-ui, sans-serif;
  margin: 0;
  padding: 5px;
  overflow: hidden;
}

#fullscreen-btn, #sound-toggle-btn {
  position: fixed;
  top: 10px;
  z-index: 2000;
  background: rgba(237, 219, 192, 0.9);
  border: 2px solid #b8a17e;
  color: #1f2a36;
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}
#fullscreen-btn { right: 10px; }
#sound-toggle-btn { right: 55px; }

#fullscreen-btn:hover, #sound-toggle-btn:hover { background: #eddbc0; transform: scale(1.1); }

/* Pantalla de inicio */
#start-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15, 23, 34, 0.96);
  display: flex; justify-content: center; align-items: center;
  z-index: 9999; backdrop-filter: blur(6px);
  padding: 10px;
}
#start-screen.hidden { display: none; }

.start-content {
  text-align: center; color: #ffebd6; border: 3px solid #b8a17e;
  padding: 18px 15px; background: #1e2a3a; border-radius: 20px;
  box-shadow: 0 0 45px rgba(184, 161, 126, 0.3);
  max-width: 580px; width: 95%;
}
.start-content h1 { font-size: 1.6rem; margin-bottom: 8px; color: #eddbc0; }
.start-content p { font-size: 0.95rem; color: #c8bdab; margin-bottom: 12px; }

#table-selector-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.table-choice-btn {
  background: linear-gradient(to bottom, #d4955b, #995c28);
  border: 2px solid #ffd0a6; padding: 10px 4px; font-size: 1rem;
  color: white; text-shadow: 1px 1px 3px black; cursor: pointer;
  border-radius: 10px; font-weight: bold; transition: all 0.2s ease;
  touch-action: manipulation;
}

#game-container {
  position: relative;
  background: transparent;
  max-width: 1000px;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px 10px;
}

#diamonds-counter {
  position: absolute;
  top: 5px;
  right: 110px;
  background: rgba(30, 42, 58, 0.9);
  border: 2px solid #b8a17e;
  padding: 4px 12px;
  border-radius: 25px;
  color: #ffebd6;
  font-size: 1rem;
  font-weight: bold;
  box-shadow: 0 4px 10px rgba(0,0,0,0.5);
  z-index: 100;
}
#diamonds-count { color: #7ef9ff; text-shadow: 0 0 5px rgba(126, 249, 255, 0.6); }

#cauldron-area {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex: 1;
  justify-content: flex-start;
}

#question-box {
  background: #eddbc0;
  padding: 0.3rem 1.2rem;
  border-radius: 40px;
  box-shadow: inset 0 -3px 0 #7a6a52, 0 4px 12px rgba(0,0,0,0.6);
  margin-bottom: 2px;
  z-index: 5;
  border: 2px solid #b8a17e;
}

#question-text {
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  font-weight: bold;
  color: #1f2a36;
  letter-spacing: 1px;
}

#alchemist-and-cauldron {
  position: relative;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex: 1;
  max-height: 52vh;
}

#alchemist-lives-container {
  position: absolute;
  left: 5px;
  bottom: 0;
  height: 100%;
  width: 180px;
  z-index: 2;
  pointer-events: none;
}

#alchemist-img {
  position: absolute;
  left: -10px;
  bottom: -20px;
  height: clamp(180px, 42vh, 320px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 15px rgba(0,0,0,0.7));
  z-index: 3;
}

#witch-img {
  position: absolute;
  right: -20px;
  top: 0;
  height: clamp(160px, 38vh, 260px);
  width: auto;
  object-fit: contain;
  z-index: 10;
  filter: drop-shadow(0 8px 15px rgba(0,0,0,0.8));
  transition: transform 3.5s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.4s ease;
  transform-origin: center;
}

#witch-img.witch-hidden {
  transform: translateX(0px) translateY(0px) scale(0) scaleX(-1);
  opacity: 0;
  pointer-events: none;
}

#witch-img.witch-attacking {
  transform: translateX(-35vw) translateY(20px) scale(1) scaleX(-1);
  opacity: 1;
}

#witch-img.witch-disappear-early {
  opacity: 0 !important;
  transform: translateX(-35vw) translateY(20px) scale(0.3) scaleX(-1) rotate(-20deg) !important;
  filter: blur(8px) !important;
  transition: opacity 0.4s ease, transform 0.4s ease, filter 0.4s ease !important;
}

#wand-lives {
  position: absolute;
  top: 5px;
  left: 10px;
  display: flex;
  gap: 4px;
  z-index: 20;
  flex-wrap: wrap;
  max-width: 250px;
  min-height: 30px;
}

.wand-life-img {
  width: clamp(24px, 4vw, 32px);
  height: clamp(24px, 4vw, 32px);
  min-width: 22px;
  min-height: 22px;
  object-fit: contain;
  filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.8));
  transition: transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 1.2s ease;
  display: inline-block;
}

.wand-thrown {
  position: fixed !important;
  z-index: 999 !important;
  transform: translate(calc(100vw - 200px), 60px) rotate(720deg) scale(0.3) !important;
  opacity: 0 !important;
}

#cauldron {
  position: relative;
  width: clamp(220px, 35vw, 330px);
  height: clamp(180px, 38vh, 280px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  margin-left: 40px;
}

#cauldron-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.8));
  pointer-events: none;
}

#cauldron-liquid {
  position: absolute;
  bottom: 18%; left: 15%; right: 15%; height: 28%;
  background: radial-gradient(circle at 30% 30%, #38b26a, #1b6b3a);
  border-radius: 50%; opacity: 0.6; pointer-events: none;
  box-shadow: 0 0 12px #38b26a;
}

#bubbles-container {
  position: absolute;
  top: 0%; 
  left: 15%; 
  right: 15%; 
  height: 40%;
  pointer-events: none; 
  z-index: 12;
  overflow: visible;
}

.css-bubble {
  position: absolute;
  bottom: 0; 
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.98), rgba(56, 178, 106, 0.75));
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(126, 249, 255, 0.95);
  animation: bubble-rise 1.3s ease-out forwards;
}

@keyframes bubble-rise {
  0% { 
    transform: translateY(0px) scale(0.5); 
    opacity: 0; 
  }
  20% { 
    opacity: 1; 
  }
  100% { 
    transform: translateY(-80px) scale(1.4); 
    opacity: 0; 
  }
}

#feedback {
  margin-top: 2px;
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  font-weight: bold;
  padding: 4px 14px;
  border-radius: 40px;
  background: #1e2a2f; color: #efebe0;
  border: 2px solid #8f9b8a;
  transition: opacity 0.5s ease;
  z-index: 10;
}
#feedback.hidden { display: none; opacity: 0; }
#feedback.fade-out { opacity: 0; }
#feedback.success { background: #1f4f2b; border-color: #b1d8a0; color: #e7fad6; }
#feedback.error { background: #5f2c2c; border-color: #d99b8a; color: #ffe1d6; }

/* ================================================================ */
/* REPISA EXTREMADAMENTE ALTA - SUBIDA AL MÁXIMO */
/* ================================================================ */
#shelf-container {
  display: block;
  position: relative;
  width: 100%;
  max-width: 480px;
  margin-top: -80px; /* Subida EXTREMA 80px */
  padding-bottom: 8px;
  z-index: 10;
}
/* ================================================================ */

#flasks-container {
  display: flex; justify-content: space-around; align-items: flex-end;
  gap: 0.5rem; padding: 0 10px; position: relative; z-index: 2;
}

.flask {
  position: relative;
  width: clamp(70px, 15vw, 95px);
  height: clamp(90px, 20vh, 125px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}

.bottle-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
  position: relative;
  z-index: 1;
}

.flask-value {
  position: absolute;
  top: 52%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 
    0 2px 10px rgba(0,0,0,0.9),
    0 0 20px rgba(0,0,0,0.6),
    0 0 40px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 10;
  width: 100%;
  text-align: center;
  line-height: 1;
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Estilo cuando la imagen no carga */
.flask.no-image .bottle-img {
  display: none;
}

.flask.no-image {
  background: radial-gradient(ellipse at 40% 30%, 
    rgba(100, 180, 230, 0.3) 0%,
    rgba(60, 140, 200, 0.2) 60%,
    rgba(40, 100, 160, 0.4) 100%
  );
  border-radius: 40% 40% 25% 25% / 50% 50% 20% 20%;
  border: 2px solid rgba(200, 230, 255, 0.3);
  box-shadow: 
    inset -8px -5px 15px rgba(0, 50, 100, 0.2),
    inset 8px 5px 15px rgba(255, 255, 255, 0.15),
    0 8px 0 rgba(30, 60, 80, 0.3),
    0 10px 20px rgba(0,0,0,0.3);
}

.flask.no-image .flask-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 
    0 2px 10px rgba(0,0,0,0.9),
    0 0 20px rgba(0, 150, 255, 0.3),
    0 0 40px rgba(0, 100, 255, 0.1);
  z-index: 10;
  pointer-events: none;
  width: 100%;
  text-align: center;
  line-height: 1;
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Estado deshabilitado para las pocimas */
.flask.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.wooden-shelf {
  position: absolute; bottom: 0; left: 0; right: 0; height: 10px;
  background: linear-gradient(to bottom, #8a5a36, #5c3a21); border-radius: 4px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.7); border-bottom: 2px solid #3d2413;
}

#game-over-screen, #victory-screen {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10, 15, 25, 0.95);
  display: flex; justify-content: center; align-items: center;
  z-index: 9999; backdrop-filter: blur(5px); padding: 10px;
}
#game-over-screen.hidden, #victory-screen.hidden { display: none; }

.game-over-content, .victory-content {
  text-align: center; color: #ffebd6; border: 3px solid #8b3a3a;
  padding: 20px 15px; background: #2a1515; border-radius: 18px;
  box-shadow: 0 0 35px rgba(255, 50, 50, 0.4);
  max-width: 440px; width: 90%;
}
.victory-content { border-color: #3aa85b; background: #152a1a; box-shadow: 0 0 35px rgba(50, 255, 100, 0.4); }

.game-over-content h1, .victory-content h1 { font-size: clamp(1.8rem, 5vw, 2.3rem); margin-bottom: 8px; }
.game-over-content h1 { color: #ff6b6b; }
.victory-content h1 { color: #6bff8a; }

.game-over-content p, .victory-content p { font-size: 1rem; margin-bottom: 10px; }
.score-text-end { font-size: 1.1rem !important; font-weight: bold; color: #7ef9ff; margin-bottom: 15px !important; }

.game-over-content button, .victory-content button {
  background: linear-gradient(to bottom, #d4955b, #995c28);
  border: 2px solid #ffd0a6; padding: 10px 24px; font-size: 1.1rem;
  color: white; text-shadow: 1px 1px 3px black; cursor: pointer;
  border-radius: 40px; font-weight: bold; transition: all 0.2s ease;
  box-shadow: 0 4px 0 #5c3a16, 0 8px 15px rgba(0,0,0,0.6);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-over-content button:active, .victory-content button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #5c3a16;
}

/* Corrección para dispositivos táctiles */
.flask {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: grab;
}

/* Mejora del feedback táctil */
#cauldron.drag-over {
  transform: scale(1.02);
  filter: drop-shadow(0 0 20px rgba(247, 212, 74, 0.8));
  transition: all 0.2s ease;
}

#cauldron {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* ================================================================ */
/* AJUSTES PARA MÓVILES - REPISA EXTREMADAMENTE ALTA */
/* ================================================================ */
@media screen and (max-width: 600px) and (orientation: portrait) {
  #game-container {
    padding: 10px 5px;
    justify-content: space-evenly;
  }

  #alchemist-img {
    height: clamp(140px, 32vh, 220px);
    left: -15px;
  }

  #witch-img {
    height: clamp(130px, 28vh, 190px);
  }

  #cauldron {
    width: clamp(170px, 45vw, 240px);
    height: clamp(140px, 28vh, 200px);
    margin-left: 20px;
  }

  .flask {
    width: clamp(65px, 22vw, 85px);
    height: clamp(80px, 15vh, 105px);
    min-width: 55px;
    min-height: 65px;
  }
  
  .flask-value {
    font-size: clamp(1rem, 2.5vw, 1.3rem);
  }

  /* Repisa EXTREMADAMENTE ALTA en móviles verticales */
  #shelf-container {
    margin-top: -70px;
  }
}

@media screen and (max-width: 768px) and (orientation: landscape) {
  .flask {
    width: clamp(65px, 14vw, 85px);
    height: clamp(80px, 18vh, 105px);
    min-width: 55px;
    min-height: 70px;
  }
  
  .flask-value {
    font-size: clamp(1.2rem, 3vw, 1.6rem);
  }
  
  #cauldron {
    width: clamp(180px, 35vw, 260px);
    height: clamp(150px, 30vh, 220px);
  }
  
  #alchemist-img {
    height: clamp(150px, 35vh, 250px);
  }
  
  #witch-img {
    height: clamp(130px, 30vh, 200px);
  }

  /* Repisa EXTREMADAMENTE ALTA en móviles horizontales */
  #shelf-container {
    margin-top: -60px;
  }
}