:root {
  --bg: #0f1117;
  --panel: #171a24;
  --panel-2: #1e2230;
  --text: #eef0f5;
  --muted: #9aa1b2;
  --accent: #63e6be;
  --border: #2a2f3f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.site-header {
  text-align: center;
  padding: 32px 16px 16px;
}
.site-header h1 {
  margin: 0 0 4px;
  font-size: 2.2rem;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #63e6be, #4dabf7, #da77f2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 60px;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 20px 0;
  font-size: 0.75rem;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* Periodic table grid */
.table-wrap {
  overflow-x: auto;
  padding-bottom: 12px;
}
.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(50px, 1fr));
  grid-auto-rows: minmax(50px, 1fr);
  gap: 3px;
  min-width: 980px;
}

.element-tile {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 5px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  border-top: 3px solid var(--tile-color, #888);
  user-select: none;
}
.element-tile:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  z-index: 5;
  background: #262b3d;
}
.element-tile.selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #24352f;
}
.element-tile .num {
  font-size: 0.55rem;
  color: var(--muted);
}
.element-tile .sym {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
}
.element-tile .nm {
  font-size: 0.48rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.placeholder-tile {
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--muted);
}

.footer-gap-row {
  grid-column: 1 / span 3;
}

/* Mixer */
.mixer-section {
  margin-top: 40px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}
.mixer-section h2 {
  margin-top: 0;
}
.mixer-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: -8px;
}

.mix-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 60px;
  padding: 14px;
  background: var(--panel-2);
  border-radius: 10px;
  margin: 16px 0;
}
.empty-tray {
  color: var(--muted);
  margin: 0;
  font-size: 0.9rem;
}

.mix-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #262b3d;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 8px 6px 14px;
}
.mix-chip .chip-symbol {
  font-weight: 700;
}
.mix-chip input[type="number"] {
  width: 48px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 4px;
  text-align: center;
}
.mix-chip button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
}
.mix-chip button:hover { color: #ff6b6b; }

.mixer-actions {
  display: flex;
  gap: 10px;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 0.9rem;
}
.btn:hover { background: #262b3d; }
.btn.primary {
  background: var(--accent);
  color: #0f1117;
  font-weight: 700;
  border: none;
}
.btn.primary:hover { filter: brightness(1.08); }

.result-card {
  margin-top: 20px;
  padding: 20px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.result-card.found { border-left: 4px solid var(--accent); }
.result-card.none { border-left: 4px solid #ff6b6b; }
.result-card h3 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}
.result-formula {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.result-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  padding: 28px;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 4px;
}
.modal-title .big-symbol {
  font-size: 2.2rem;
  font-weight: 700;
}
.modal-category {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: capitalize;
  margin-bottom: 16px;
}

.modal-photo {
  width: 100%;
  border-radius: 10px;
  margin: 12px 0;
  background: var(--panel-2);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.modal-photo img {
  width: 100%;
  display: block;
  object-fit: cover;
  max-height: 260px;
}
.modal-photo .loading, .modal-photo .no-photo {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 30px;
}

.modal-extract {
  font-size: 0.9rem;
  color: var(--text);
  margin: 12px 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  font-size: 0.85rem;
  margin: 16px 0;
}
.stat-grid dt { color: var(--muted); }
.stat-grid dd { margin: 0; font-weight: 600; }

.modal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.modal-links a, .modal-links button {
  font-size: 0.8rem;
  text-decoration: none;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 8px;
}
.modal-links a:hover, .modal-links button:hover { background: #262b3d; }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 20px;
}

@media (max-width: 700px) {
  .stat-grid { grid-template-columns: 1fr; }
}
