/* Add viewport-specific base styles */
html, body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  font-family: Verdana, Geneva, Tahoma, sans-serif;
}

/* Container for all content */
.main-container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 10px;
  box-sizing: border-box;
}

.button-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

#help-button {
   
    color: #00b4d8;
    border: 4px solid #00b4d8;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 50px;
    height: 50px;
    text-align: center;
    line-height: 34px;
}

#help-button:hover {
    background-color: #none;
}

/* Consistent container styling for all major sections */
#keyboard-cont, 
.guess-input, 
#clues {
  width: 95%;
  max-width: 600px;
  margin: 10px auto;
  border: 8px solid #00b4d8;
  border-radius: 50px;
  padding: 0.5rem;
  box-sizing: border-box;
}


/* Title container styling */
.title-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  /*margin: 20px auto;
  text-align: center;*/
  width: 100%;
  margin: 10px 0;
  padding: 0 10px;
  box-sizing: border-box;
}

.guess-input {
  width: 95%;
  max-width: 600px;
  margin: 10px auto;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  border: 8px solid #00b4d8;
  border-radius: 50px;
  padding: 12px; /* Increased padding to accommodate inner border */
  box-sizing: border-box;
  position: relative; /* For pseudo-element positioning */
}



#guess-input {
  text-transform: uppercase;
  width: 90%;
  border: 3px solid #00b4d8;
  justify-content: center;
  border-radius: 25px;
  margin: auto;
  padding: 1rem;
  flex-wrap: wrap;
  display: flex;
  font-size: 16px;
  text-align: center;
  position: relative;
  z-index: 2; /* Place above the inner border */
  cursor: default;
}

/* Result text positioning */
#result {
  position: relative;
  z-index: 2; /* Place above the inner border */
}

#swipe-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.swipe-line {
  position: absolute;
  height: 3px; /* Made slightly thicker for emphasis */
  background-color: #ffb703;
  transform-origin: left center;
  pointer-events: none;
}

.swipe-line.animated {
  background-color: #00ff00; /* Different color for completion */
  box-shadow: 0 0 5px #00ff00; /* Add glow effect */
}

window.addEventListener('load', function() {
  const styleElement = document.createElement('style');
  styleElement.textContent = `
    #swipe-container {
      position: fixed;
      z-index: 100;
      pointer-events: none;
    }
    
    /* Make sure the keyboard has a position context */
    #keyboard-cont {
      position: relative;
    }
    
    /* Add this class to the keyboard to keep it fixed in position */
    .keyboard-fixed {
      position: relative;
    }
    
    /* Style for the swipe lines */
    .swipe-line {
      position: absolute;
      height: 4px;
      background-color: #ffb703;
      border-radius: 2px;
      transform-origin: left center;
      box-shadow: 0 0 5px rgba(255, 183, 3, 0.7);
    }
  `;
  document.head.appendChild(styleElement);
  
  // Initial draw
  if (mysteryWord) {
    drawSwipe(mysteryWord);
  }
});

 #keyboard-cont {
  justify-content: center;
  gap: 0.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
    

 #keyboard-cont div {
   display: flex;
   justify-content: center;
 }

 
 /* Make rows take full width */
.row {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 2px 0;
  gap: 2px;
  box-sizing: border-box;
}

 .key {
  height: 50px;
  width: 40px;
  font-size: 1.6rem;
  font-weight: 700;
  margin: 2px;
  cursor: pointer;
  text-transform: uppercase;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-grow: 0;
  flex-shrink: 0;
  padding: 0;
 
  box-sizing: border-box;
  border-radius: 6px;
  background-color: #f0f0f0;
  border: 1px solid #ccc;
  transition: all 0.2s ease;
 }
  
.key:hover {
  background-color: #e0e0e0;
}

 .second-row {
  margin: 0.5rem 0;
  justify-content: center;
  width: 100%;
}

.third-row {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: calc(7 * (40px + 4px)); /* 7 keys × (width + total margin) */
  margin: 2px auto;
}

 .fourth-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: calc(7 * (40px + 4px)); /* Match the third row width exactly */
  margin: 5px auto;
  box-sizing: border-box;
}

.fourth-row .key.special {
  flex-grow: 1;
  width: auto;
  margin: 2px 4px;
  padding: 0 8px;
  font-size: 1.1rem;
  background-color: #e0e0e0;
}

.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

 /*Clues*/
 #clues {
  text-align: center;
}

.clue-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem auto;
}

.clue-item {
  position: relative;
  display: inline-block;
  margin: 8px;
  transition: transform 0.2s;
}

.clueButton {
  width: 35px;
  height: 35px;
  background-color: #00b4d8;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 4px 4px 6px rgba(0, 0, 1, 0.5);
  transition: background-color 0.3s, transform 0.2s;
  text-transform: uppercase;
}

.clueButton:hover {
  background-color: #0077b6;
  transform: scale(1.1);
}

button.clueButton {
  /* --- Core Width & Sizing --- */
  width: auto; /* Allow width to expand based on content */
  min-width: 35px; /* Set a minimum width (adjust to match image size approx) */
  height: 35px; /* Keep height consistent (adjust to match image size) */
  padding-left: 8px; /* Add some space between text and border (left) */
  padding-right: 8px; /* Add some space between text and border (right) */
  box-sizing: border-box; /* Include padding and border in the element's total width and height */

  /* --- Text Styling & Alignment --- */
  text-align: center; /* Center the text horizontally */
  vertical-align: middle; /* Align text vertically (useful with fixed height) */
  line-height: 1; /* Adjust if vertical alignment is off */
  font-size: 0.9em; /* Adjust font size as needed */
  font-weight: bold; /* Make the clue stand out */

  /* --- Appearance (match your design) --- */
  border: 1px solid #ccc; /* Example border */
  background-color: #f0f0f0; /* Example background */
  color: #333; /* Example text color */
  border-radius: 4px; /* Example rounded corners */
  cursor: default; /* Indicate it's not clickable anymore */

  /* --- Prevent weird shrinking --- */
  flex-shrink: 0; /* Add this if buttons are inside a flex container and shrinking */
}

.clue-tooltip {
  visibility: hidden;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px;
  background-color: #333;
  color: white;
  border-radius: 6px;
 
  font-size: 14px;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s, visibility 0.3s;
  margin-bottom: 8px;
  width: max-content;
  max-width: 200px;
}

/* Add arrow to tooltip */

.clue-item:hover .clue-tooltip {
  visibility: visible;
  opacity: 1;
}

/* Keep the clue text visible hovering a clue */
.clue-item:hover .clue-tooltip {
  visibility: visible;
  opacity: 1;
}
 
styleSheet.textContent += `
    .swipe-line.generating {
        background-color: #ffb703; /* Fuse color */
        box-shadow: 0 0 15px #ffb703; /* Optional glow for the fuse */
        position: absolute; /* Ensure absolute positioning */
    }

    @keyframes growLine {
        from {
            width: 0;
        }
        to {
            width: 100%;
        }
    }

    .correct-letter-glow {
        animation: letterGlow 4s ease-in-out infinite alternate;
    }

    @keyframes letterGlow {
        from {
            box-shadow: 0 0 40px rgba(255, 255, 0, 0.8); /* Yellow glow */
        }
        to {
            box-shadow: 0 0 40px rgba(255, 255, 0, 0.5);
        }
    }
`;

#toast {
  visibility: hidden;
  min-width: 200px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 8px;
  padding: 12px;
  position: fixed;
  z-index: 1000;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.5s, bottom 0.5s;
}

#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 60px;
}


.word-display {
  margin: 10px 0;
  text-align: center;
  font-size: 18px;
  padding: 10px;
    display: flex;
  align-items: center;
  justify-content: center;
    position: relative;
}


/* Help Button */
#help-button {
  position: relative; /* Or absolute, depending on your layout */
  /*top: 20px; /* Adjust as needed */
  /*right: 20px; /* Adjust as needed */
  cursor: pointer;
  z-index: 1000; /* Ensure it's on top of other elements */
  display: flex;
  align-items: center;
  justify-content: center;
}

#help-button img {
  width: 100px; /* Adjust size as needed */
  height: 40px; /* Adjust size as needed */
}

#help-modal {
  display: none; /* Hidden by default */
  position: fixed; /* Or absolute */
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5); /* Example semi-transparent background */
  justify-content: center; /* To center content horizontally */
  align-items: center; /* To center content vertically */
  z-index: 1000; /* Ensure it's on top */
}



.modal {
  display: none; /* Hidden by default */
  position: fixed;
  z-index: 1000;
  top: 0 !important; /* Fix the negative top value */
  left: 0;
  width: 100% !important;
  height: 100% !important;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5); /* Add background overlay */
  
  /* Center the modal content */
  display: flex;
  justify-content: center;
  align-items: center;
  
  /* Prevent scrolling issues on iOS */
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background-color: #fefefe;
  margin: 20px; /* Simplified margin */
  padding: 20px;
  border: 1px solid #888;
  width: 90%; /* More responsive width */
  max-width: 500px; /* Reduced max-width for mobile */
  max-height: 80vh; /* Limit height to viewport */
  position: relative;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  
  /* Remove the problematic top positioning */
  top: auto !important;
  
  /* Make it scrollable if content is too long */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


.close-button {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 24px;
  font-weight: bold;
  color: #000;
  cursor: pointer;
  z-index: 1001;
  
  /* Make it more touchable on mobile */
  min-width: 30px;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}



/* iPhone Safari specific fixes */
@media screen and (max-width: 768px) {
  .modal {
    /* Fix for Safari's address bar height changes */
    height: 100vh !important;
    height: 100dvh !important; /* Dynamic viewport height for newer browsers */
    
    /* Prevent bounce scrolling */
    overscroll-behavior: contain;
    
    /* Ensure it's properly positioned */
    top: 0 !important;
    left: 0 !important;
  }
  
  .modal-content {
    margin: 10px;
    width: calc(100% - 20px);
    max-width: none;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px);
    
    /* Account for iPhone safe areas */
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
  }
  
  .close-button {
    top: max(15px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    font-size: 28px;
    min-width: 40px;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  }
}
  
/* Media queries for responsive design */
@media screen and (max-width: 600px) {
  #keyboard-cont, 
  .guess-input, 
  #clues {
    width: 98%;
    border-width: 6px;
    padding: 0.4rem;
  }
  
  .guess-input {
    border-width: 6px;
    padding: 10px;
  }

  .key {
    height: 45px;
    width: 35px;
    font-size: 1.4rem;
    margin: 1px;
  }
  
  .third-row {
    max-width: calc(7 * (35px + 2px));
  }
   
  .fourth-row {
    max-width: calc(7 * (35px + 2px));
  }
  
  .fourth-row .key.special {
    font-size: 0.9rem;
  }
}

/* Extra small devices */
@media screen and (max-width: 380px) {
  .key {
    height: 36px;
    width: 28px;
    font-size: 1rem;
    margin: 1px;
  }
  
  #keyboard-cont, 
  .guess-input, 
  #clues {
    border-width: 4px;
    padding: 0.3rem;
  }

  .guess-input {
    border-width: 4px;
    padding: 7px;
  }
  
  .third-row {
    max-width: calc(7 * (28px + 2px));
  }
  
  .fourth-row {
    max-width: calc(7 * (28px + 2px));
  }
  
  .fourth-row .key.special {
    font-size: 0.7rem;
  }
}

@media screen and (max-width: 480px) {
  #keyboard-cont, 
  .guess-input, 
  #clues {
    border-width: 5px;
    padding: 0.4rem;
  }
  
  .guess-input {
    border-width: 5px;
    padding: 8px;
  }
  
  #keyboard-cont {
    padding: 0.5rem;
  }
  
  .clueButton {
    width: 30px;
    height: 30px;
    font-size: 16px;
  }
   
  h2 {
    font-size: 1.5rem;
  }

  .key {
    height: 40px;
    width: 30px;
    font-size: 1.2rem;
    margin: 1px;
  }
  
  .third-row {
    max-width: calc(7 * (30px + 2px));
  }
  
  .fourth-row {
    max-width: calc(7 * (30px + 2px));
  }
  
  .fourth-row .key.special {
    font-size: 0.8rem;
  }

  .modal-content {
    margin: 5px;
    width: calc(100% - 10px);
    padding: 15px;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
  }
  
  .modal-content h3 {
    font-size: 1.2rem;
    margin-top: 30px; /* Account for close button */
  }
  
  .modal-content p {
    font-size: 0.9rem;
    line-height: 1.4;
  }
  
  .modal-content dd {
    font-size: 0.8rem;
    margin-bottom: 8px;
  }

  .close-button {
    font-size: 26px;
    top: 8px;
    right: 12px;
  }
}


/* Fix for swipe line positioning on mobile */
@media screen and (max-width: 768px) {
  .swipe-line {
    height: 2px; /* Thinner lines for mobile */
  }
}

/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
  input[type="text"],
  select:focus {
    font-size: 16px !important;
  }
}
/* Prevent body scrolling when modal is open */
body.modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}