/* ═══════════════════════════════════════════════════════════════
   controls.css  —  EduNudge SciLab | Structure of the Atom
   Element selector grid — periodic table style tiles
═══════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────
   1.  ELEMENT GRID CONTAINER
─────────────────────────────────────────────────────────────── */
.element-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: var(--space-xs);
  width: 100%;
}




/* ───────────────────────────────────────────────────────────────
   2.  ELEMENT BUTTON TILE
   Mimics periodic table cell layout:
   ┌─────────┐
   │ 1       │  ← atomic number
   │    H    │  ← symbol (large)
   │Hydrogen │  ← name (small)
   └─────────┘
─────────────────────────────────────────────────────────────── */
.element-btn {
  --el-color: #4fc3f7;
  /* overridden per element by controls.js */

  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5px 3px 4px;
  background: var(--bg-panel-section);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 48px;
  width: 100%;

  /* Smooth transitions on all visual properties */
  transition: background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);

  /* Prevent text selection on rapid clicks */
  user-select: none;
}

/* ── Hover state ── */
.element-btn:hover {
  background: var(--bg-panel-hover);
  border-color: var(--el-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3),
    0 0 8px color-mix(in srgb, var(--el-color) 30%, transparent);
  z-index: 2;
}

/* ── Active / selected state ── */
.element-btn.active {
  border-color: var(--el-color);
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px var(--el-color),
    0 0 14px color-mix(in srgb, var(--el-color) 35%, transparent),
    0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 3;
}

/* ── Pressed / click feedback ── */
.element-btn:active {
  transform: translateY(0px) scale(0.97);
  box-shadow: none;
}

/* ───────────────────────────────────────────────────────────────
   3.  TILE CONTENT — Atomic Number
─────────────────────────────────────────────────────────────── */
.btn-atomic-no {
  position: absolute;
  top: 3px;
  left: 4px;
  font-size: 7px;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-mono);
  line-height: 1;
  transition: color var(--transition-fast);
}

.element-btn:hover .btn-atomic-no,
.element-btn.active .btn-atomic-no {
  color: var(--el-color);
}

/* ───────────────────────────────────────────────────────────────
   4.  TILE CONTENT — Element Symbol
─────────────────────────────────────────────────────────────── */
.btn-symbol {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-top: 10px;
  letter-spacing: -0.02em;
  transition: color var(--transition-fast),
    text-shadow var(--transition-fast);
}

.element-btn:hover .btn-symbol,
.element-btn.active .btn-symbol {
  color: var(--el-color);
  text-shadow: 0 0 12px color-mix(in srgb, var(--el-color) 70%, transparent);
}

/* ───────────────────────────────────────────────────────────────
   5.  TILE CONTENT — Element Name
─────────────────────────────────────────────────────────────── */
.btn-name {
  font-size: 6.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding: 0 2px;
  transition: color var(--transition-fast);
}

.element-btn:hover .btn-name,
.element-btn.active .btn-name {
  color: var(--text-secondary);
}

/* ───────────────────────────────────────────────────────────────
   6.  TILE BOTTOM COLOUR BAR
   A thin coloured line at the bottom of each tile
   using the element's own colour — like period table colour coding
─────────────────────────────────────────────────────────────── */
.element-btn::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--el-color);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  opacity: 0.35;
  transition: opacity var(--transition-fast),
    height var(--transition-fast);
}

.element-btn:hover::after,
.element-btn.active::after {
  opacity: 0.9;
  height: 3px;
}

/* ───────────────────────────────────────────────────────────────
   7.  NOBLE GAS HIGHLIGHT
   Elements with valency 0 (He, Ne, Ar) get a subtle
   purple tint to distinguish them visually
─────────────────────────────────────────────────────────────── */
.element-btn[data-index="1"],
/* He */
.element-btn[data-index="9"],
/* Ne */
.element-btn[data-index="17"] {
  /* Ar */
  background: rgba(162, 155, 254, 0.06);
}

/* ───────────────────────────────────────────────────────────────
   8.  GRID ROW SEPARATORS
   Visual period separators — after H, after Ne, after Ar
   Mimics the period breaks in a real periodic table
─────────────────────────────────────────────────────────────── */

/* After Period 1 (H, He) */
.element-btn[data-index="1"] {
  grid-column: span 1;
}

/* Subtle gap after each period using margin on period-starters */
.element-btn[data-index="2"],
/* Li — start of period 2 */
.element-btn[data-index="10"],
/* Na — start of period 3 */
.element-btn[data-index="18"] {
  /* K  — start of period 4  */
  margin-top: 4px;
}

/* ───────────────────────────────────────────────────────────────
   9.  GRID SCROLL  (if panel is too short)
─────────────────────────────────────────────────────────────── */
.panel-section:has(.element-grid) {
  overflow-y: auto;
  flex: 1;
  /* take remaining space in left panel */
  min-height: 0;
  /* allow shrinking */
}

/* ───────────────────────────────────────────────────────────────
   10. FOCUS STYLES  (keyboard accessibility)
─────────────────────────────────────────────────────────────── */
.element-btn:focus-visible {
  outline: 2px solid var(--brand-glow);
  outline-offset: 2px;
}

.element-btn:focus:not(:focus-visible) {
  outline: none;
}

/* ───────────────────────────────────────────────────────────────
   11. RESPONSIVE
─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .element-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .element-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
  }

  .element-btn {
    min-height: 40px;
    padding: 4px 2px 3px;
  }

  .btn-symbol {
    font-size: 12px;
  }

  .btn-name {
    display: none;
  }
}

@media (max-width: 480px) {
  .element-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .element-btn {
    min-height: 36px;
  }

  .btn-atomic-no {
    font-size: 7px;
  }
}