/* Base styles */
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f8f9fa; margin: 0; padding: 0; }

/* Popup */
.eh-popup {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.eh-popup-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white; padding: 2.5em; border-radius: 15px; width: 450px;
  max-width: 90vw; box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
.eh-popup-content h2 { margin-top: 0; text-align: center; }
.eh-popup-content button {
  background: linear-gradient(45deg, #ff6b6b, #ee5a24);
  color: white; border: none; padding: 12px 30px; border-radius: 25px;
  font-size: 1.1em; font-weight: bold; cursor: pointer;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2); transition: transform 0.2s;
}
.eh-popup-content button:hover { transform: translateY(-2px); }

/* Game controls */
#game-controls { background: rgba(255,255,255,0.9); padding: 10px; border-radius: 10px; margin: 10px auto; }
.control-btn {
  margin: 0 5px; padding: 6px 15px; border: none; border-radius: 20px;
  font-size: 0.9rem; cursor: pointer; transition: all 0.3s;
  background: linear-gradient(45deg, #3498db, #2980b9); color: white;
}
.control-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.stop-btn { background: linear-gradient(45deg, #e74c3c, #c0392b); }

/* HUD */
#eh-hud {
  display: flex; justify-content: space-between; padding: 0.8em 1.5em;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white; font-size: 1.1em; border-radius: 10px; margin-bottom: 0.5em;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* Game layout - KEY FIX: Added flex-shrink: 0 to right panel and flex: 1 to table */
.game-container { 
  display: flex; 
  gap: 20px; 
  width: 100%; 
  margin: 0; 
  padding: 10px;
  box-sizing: border-box;
  align-items: flex-start;
}
.left-panel { 
  flex: 1; 
  min-width: 0; /* Important: Allows the table to shrink */
}
.right-panel {
  width: 300px; 
  flex-shrink: 0; /* Prevents the info panel from being squished */
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white; padding: 20px; border-radius: 15px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* Question and clues */
#eh-question {
  font-size: 1.2em; margin-bottom: 0.5em; padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white; border-radius: 12px; font-weight: 600;
}
#eh-clues { margin-bottom: 1em; }
.eh-clue-btn {
  margin: 4px; padding: 8px 14px; font-size: 0.9em; border-radius: 25px;
  border: none; background: linear-gradient(45deg, #ff9a9e, #fecfef);
  color: #333; cursor: pointer; transition: all 0.3s; font-weight: 600;
}
#eh-clue-text {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  padding: 12px; border-radius: 10px; margin-top: 5px; min-height: 40px;
  color: #333; font-weight: 500; font-size: 0.9em;
}

/* Periodic Table Container */
#periodic-table-container {
  background: #ffffff;
  padding: 10px;
  border-radius: 15px; 
  margin: 10px 0;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  border: 2px solid #e9ecef;
  overflow: hidden; /* Keeps the table from spilling out */
}

/* Main Periodic Table - KEY FIX: Changed grid-template-columns */
#eh-periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(20px, 1fr));
  grid-template-rows: repeat(7, auto);
  gap: 2px;
  background: #ffffff;
}

/* Element styling */
.eh-element {
  border-radius: 4px; text-align: center; padding: 4px 1px;
  cursor: pointer; 
  border: 1px solid rgba(0,0,0,0.1);
  font-size: 0.7em; font-weight: bold; color: white;
  transition: all 0.2s ease;
  display: flex; flex-direction: column; justify-content: center;
  aspect-ratio: 1/1.1;
}
.eh-element:hover { transform: scale(1.1); z-index: 10; }

.eh-element.eh-correct { animation: correctPulse 1s; background: linear-gradient(45deg, #00b894, #00cec9) !important; }
.eh-element.eh-wrong { animation: wrongShake 0.5s; background: linear-gradient(45deg, #e74c3c, #fd79a8) !important; }

@keyframes correctPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes wrongShake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Element categories */
.eh-nonmetal { background: linear-gradient(135deg, #ff6b6b, #ee5a24); }
.eh-noble { background: linear-gradient(135deg, #fdcb6e, #e17055); }
.eh-alkali { background: linear-gradient(135deg, #00b894, #00cec9); }
.eh-alkaline { background: linear-gradient(135deg, #55a3ff, #3742fa); }
.eh-metalloid { background: linear-gradient(135deg, #26de81, #20bf6b); }
.eh-metal { background: linear-gradient(135deg, #74b9ff, #0984e3); }
.eh-halogen { background: linear-gradient(135deg, #a29bfe, #6c5ce7); }
.eh-lanthanide { background: linear-gradient(135deg, #fd79a8, #fdcb6e); }
.eh-actinide { background: linear-gradient(135deg, #e84393, #d63031); }
.eh-posttransition { background: linear-gradient(135deg, #00cec9, #55a3ff); }

/* Rare Earth Elements */
#rare-earth-elements {
  margin-top: 15px; 
  background: #f8f9fa;
  padding: 10px; 
  border-radius: 12px;
  border: 1px solid #dee2e6;
}
.series-label { color: #2c3e50; font-weight: bold; margin-bottom: 8px; text-align: center; font-size: 0.9em; }
#lanthanides-row, #actinides-row {
  display: grid; 
  grid-template-columns: repeat(15, minmax(18px, 1fr));
  gap: 2px; justify-content: start; margin-bottom: 10px;
}
#lanthanides-row .eh-element, #actinides-row .eh-element { height: 35px; font-size: 0.65em; }

/* Element details panel */
#eh-element-details h3 { margin-top: 0; text-align: center; font-size: 1.3em; margin-bottom: 15px; }
#element-info { font-size: 0.9rem; line-height: 1.4; }
#element-info p {
  margin: 8px 0; padding: 10px;
  background: rgba(255,255,255,0.25);
  border-radius: 8px; border-left: 4px solid rgba(255,255,255,0.6);
}
.element-name {
  font-size: 1.2em; font-weight: bold; text-align: center;
  padding: 12px; background: rgba(255,255,255,0.35);
  border-radius: 12px; margin-bottom: 15px;
}

/* Tablet/Mobile logic */
@media (max-width: 1024px) {
  .game-container { flex-direction: column; align-items: center; }
  .right-panel { width: 100%; max-width: 600px; order: 2; }
  .left-panel { order: 1; width: 100%; }
}