:root {
  --grid-size: 60px;
  
  /* Light mode colors */
  --bg-primary: #f0f0f0;
  --bg-secondary: #fff;
  --text-primary: #000;
  --text-secondary: #333;
  --border-color: #ccc;
  --shadow-color: rgba(0,0,0,0.1);
  --hover-bg: #e0e0ff;
  --active-bg: #4CAF50;
  --active-text: white;
}

/* Dark mode colors */
body.dark-mode {
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --border-color: #444;
  --shadow-color: rgba(255,255,255,0.1);
  --hover-bg: #2a2a4a;
  --active-bg: #45a049;
  --active-text: #f0f0f0;
}

body {
  margin: 0;
  padding: 20px;
  font-family: Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s, color 0.3s;
}

#game-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}

#periodic-table {
  display: grid;
  grid-template-columns: repeat(18, var(--grid-size));
  grid-template-rows: repeat(9, var(--grid-size));
  gap: 2px;
  background: var(--bg-secondary);
  padding: 10px;
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-color);
}

.element {
  width: var(--grid-size);
  height: var(--grid-size);
  border: 2px solid var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--bg-secondary);
  transition: all 0.2s;
  font-size: 0.8rem;
  position: relative;
}

.element .symbol {
  font-weight: bold;
  font-size: 1.2em;
}

.element .number {
  position: absolute;
  top: 2px;
  left: 2px;
  font-size: 0.7em;
}

.element .tooltip {
  visibility: hidden;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.8);
  color: white;
  width: max-content;
  max-width: 200px;
  text-align: center;
  line-height: 1.4;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  transition: visibility 0s, opacity 0.2s;
  opacity: 0;
}

.element .tooltip .edibility {
  font-style: italic;
  color: #666;
  font-size: 0.7em;
  margin-top: 5px;
  display: block;
}

.element:hover {
  transform: scale(1.1);
  z-index: 1;
  background: var(--hover-bg);
}

.element:hover .tooltip {
  visibility: visible;
  opacity: 1;
}

.element .tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 5px;
  border-style: solid;
  border-color: rgba(0, 0, 0, 0.8) transparent transparent transparent;
}

.element.selected {
  background: var(--hover-bg);
  border-color: var(--active-bg);
}

.element.discovered {
  border-color: #ff0000;
  border-width: 3px;
}

#workspace {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

#mode-selector {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 15px;
}

.mode-btn {
  padding: 10px 20px;
  font-size: 1rem;
  border: 2px solid var(--border-color);
  background: var(--bg-primary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--active-bg);
  color: var(--active-text);
  border-color: #45a049;
}

#pot {
  width: 200px;
  height: 200px;
  position: relative;
  cursor: pointer;
}

#pot svg {
  width: 100%;
  height: 100%;
}

#pot-contents {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  max-width: 80%;
}

.pot-element {
  padding: 5px;
  background: var(--bg-secondary);
  border: 1px solid var(--text-secondary);
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.pot-element:hover {
  background: #ffeeee;
  transform: scale(1.1);
}

#mix-button {
  margin: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  background: var(--active-bg);
  color: var(--active-text);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

#mix-button:hover {
  opacity: 0.9;
}

#element-info {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 20px var(--shadow-color);
  max-width: 400px;
  width: 90%;
}

#element-info.hidden {
  display: none;
}

#close-info {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
}

#search-container {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: 0 2px 10px var(--shadow-color);
}

#search-input {
  flex-grow: 1;
  padding: 8px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

#search-category {
  padding: 8px;
  font-size: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
}

.context-menu {
  position: fixed;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  box-shadow: 2px 2px 5px var(--shadow-color);
  z-index: 1000;
  padding: 5px 0;
}

.context-menu.hidden {
  display: none;
}

.context-menu-item {
  padding: 8px 15px;
  cursor: pointer;
  transition: background 0.2s;
}

.context-menu-item:not(:last-child) {
  border-bottom: 1px solid var(--border-color);
}

.context-menu-item:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.4);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-secondary);
  padding: 20px;
  border-radius: 8px;
  width: 80%;
  max-width: 600px;
  max-height: 70%;
  overflow-y: auto;
  position: relative;
}

.close-modal {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close-modal:hover {
  color: black;
}

#explosives-catalog-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

.explosive-catalog-item {
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 4px;
  text-align: center;
  background: var(--bg-secondary);
}

#explosive-catalog-btn {
  margin: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  background: #ff6b6b;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

#explosive-catalog-btn:hover {
  background: #ff4757;
}

#gas-catalog-btn {
  margin: 10px;
  padding: 10px 20px;
  font-size: 1rem;
  background: #4287f5;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

#gas-catalog-btn:hover {
  background: #3a7bd5;
}

.gas-catalog-item {
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 4px;
  text-align: center;
  background: var(--bg-secondary);
}

#dark-mode-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s;
}

#dark-mode-toggle:hover {
  transform: scale(1.1);
}

#how-to-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  z-index: 100;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#how-to-modal .modal-content {
  max-width: 800px;
}

#how-to-modal .section {
  margin-bottom: 20px;
}

#how-to-modal h3 {
  color: var(--text-primary);
  margin-top: 0;
}

#how-to-modal p {
  color: var(--text-secondary);
  line-height: 1.6;
}

@media (max-width: 768px) {
  :root {
    --grid-size: 40px;  
  }

  #periodic-table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; 
    padding: 5px;
  }

  #game-container {
    padding: 10px;
  }

  #mode-selector {
    flex-wrap: wrap;
  }

  .mode-btn {
    font-size: 0.9rem;
    padding: 8px 15px;
    margin: 2px;
  }

  #search-container {
    flex-direction: column;
    gap: 5px;
  }

  #search-input,
  #search-category {
    width: 100%;
    box-sizing: border-box;
  }

  .modal-content {
    width: 95%;
    max-height: 80vh;
  }

  .element .tooltip {
    width: 150px;
    font-size: 0.7rem;
    white-space: normal;
  }
}

@media (max-width: 768px) {
  #how-to-btn {
    top: 10px;
    right: 10px;
  }

  #dark-mode-toggle {
    bottom: 10px;
    right: 10px;
  }
}