:root {
  --bg-color: #f8fafb;
  --card-bg: #fff;
  --accent-noble: #6a5acd;
  --accent-alkali: #ff7f50;
  --accent-alkaline: #ffd700;
  --accent-metal: #4169e1;
  --accent-nonmetal: #32cd32;
  --accent-metalloid: #20b2aa;
  --accent-halogen: #ff4500;
  --accent-lanthanoid: #da70d6;
  --accent-actinoid: #ba55d3;
  --text-main: #2d3436;
  --text-dim: #636e72;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-color);
  margin: 0;
  padding: 20px;
  color: var(--text-main);
  min-height: 100vh;
}

#table-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-weight: 800;
  letter-spacing: 4px;
  font-size: 1.5rem;
}

nav a {
  text-decoration: none;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.9rem;
}

/* The Grid */
#periodic-grid {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 6px;
  background: white;
  padding: 20px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.element-tile {
  background: #fdfdfd;
  border: 1px solid #eee;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 65px;
  min-height: 80px;
  position: relative;
}

.element-tile:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 10px 20px rgba(0,0,0,0.1);
  z-index: 10;
}

.tile-number {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
}

.tile-symbol {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
}

.tile-name {
  font-size: 9px;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-mass {
  font-size: 8px;
  text-align: center;
  color: var(--text-dim);
}

/* Category Colors */
.diatomic-nonmetal { border-left: 4px solid #32cd32; }
.noble-gas { border-left: 4px solid var(--accent-noble); }
.alkali-metal { border-left: 4px solid var(--accent-alkali); }
.alkaline-earth-metal { border-left: 4px solid var(--accent-alkaline); }
.metalloid { border-left: 4px solid var(--accent-metalloid); }
.polyatomic-nonmetal { border-left: 4px solid #32cd32; }
.post-transition-metal { border-left: 4px solid #4682b4; }
.transition-metal { border-left: 4px solid var(--accent-metal); }
.lanthanide { border-left: 4px solid var(--accent-lanthanoid); }
.actinide { border-left: 4px solid var(--accent-actinoid); }

/* Detail Overlay */
#element-detail {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

#element-detail.hidden {
  display: none;
  opacity: 0;
}

.card {
  background: white;
  width: 90%;
  max-width: 500px;
  padding: 40px;
  border-radius: 30px;
  position: relative;
  box-shadow: 0 30px 60px rgba(0,0,0,0.2);
}

#close-detail {
  position: absolute;
  top: 20px;
  right: 20px;
  background: #eee;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  font-weight: 800;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 25px;
  margin-bottom: 30px;
}

#detail-symbol {
  font-family: 'Playfair Display', serif;
  font-size: 5rem;
  font-weight: 800;
  line-height: 1;
}

#detail-name {
  font-size: 2rem;
  margin: 0;
}

#detail-category {
  text-transform: uppercase;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 30px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-item strong {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.detail-item span {
  font-size: 1.1rem;
  font-weight: 600;
}

.detail-item.full {
  grid-column: span 2;
}

.summary {
  font-size: 0.95rem;
  line-height: 1.6;
  color: #444;
  margin-bottom: 25px;
}

#detail-wiki {
  display: inline-block;
  color: var(--accent-metal);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
}
