/* =============================== */
/* VARIABLES & COLORS */
/* =============================== */
:root {
  --metal-color: #4a90e2;
  --text-light: #fff;
  --text-dark: #222;
  --bg-light: #f3f4f6;
  --bg-dark: #121212;
  --box-shadow-light: rgba(0,0,0,0.15);
  --box-shadow-dark: rgba(255,255,255,0.1);

  --state-solid: #4CAF50;
  --state-liquid: #2196F3;
  --state-gas: #f44336;

  --alkali-metal: #ff6b6b;
  --alkaline-earth-metal: #ffd28a;
  --transition-metal: #ffb86b;
  --post-transition-metal: #d4af37;
  --metalloid: #a9d86e;
  --nonmetal: #76c893;
  --halogen: #67d7ff;
  --noble-gas: #c7a6f5;
  --lanthanide: #ffb6c1;
  --actinide: #ddb0e6;
  --reactive-nonmetal: #47b8a3;
}

/* =============================== */
/* BASE */
/* =============================== */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-feature-settings: "liga" 0;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 20px;
  font-family: Inter, Arial, sans-serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  transition: background-color 0.35s ease, color 0.35s ease;
  user-select: none;
}

body.dark {
  background-color: var(--bg-dark);
  color: var(--text-light);
}

/* =============================== */
/* HEADER */
/* =============================== */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: inherit;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 8px;
}

.toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 6px 10px;
  border-radius: 8px;
  color: inherit;
  transition: background-color 0.3s ease;
}
.toggle-btn:hover {
  background-color: rgba(0,0,0,0.05);
}
body.dark .toggle-btn:hover {
  background-color: rgba(255,255,255,0.06);
}

/* ====== LEGEND SECTION ====== */
#legend {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 20px;
  margin: 20px auto;
  max-width: 1100px;
  background: rgba(0,0,0,0.04);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

body.dark #legend {
  background: rgba(255,255,255,0.06);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  background-color: rgba(0,0,0,0.05);
  cursor: pointer;
  transition: all 0.25s ease;
  color: var(--text-dark);
}

body.dark .legend-item {
  background-color: rgba(255,255,255,0.08);
  color: var(--text-light);
}

.legend-item:hover {
  transform: translateY(-3px);
  background-color: rgba(0,0,0,0.1);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

body.dark .legend-item:hover {
  background-color: rgba(255,255,255,0.15);
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
}

.legend-item.active {
  background-color: var(--metal-color);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transform: scale(1.05);
}

@media (max-width: 768px) {
  #legend {
    gap: 10px;
    padding: 10px;
  }
  .legend-item {
    font-size: 14px;
    padding: 8px 12px;
  }
  .legend-color {
    width: 16px;
    height: 16px;
  }
}

  
/* ====== Temperature Control ====== */

#temp-control {
  max-width: 750px;
  margin: 20px auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

#temp-control button {
  background-color: #e5e7eb;
  color: #1f2937;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
body.dark #temp-control button {
  background-color: #374151;
  color: #e5e7eb;
}

#temp-control input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 10px;
  border-radius: 10px;
  background: linear-gradient(90deg, #3b82f6, #ef4444);
  outline: none;
  box-shadow: inset 0 0 6px rgba(0,0,0,0.25);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: white;
  border: 4px solid #3b82f6;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.2);
  border-color: #ef4444;
  box-shadow: 0 0 12px rgba(239,68,68,0.6);
}

#temp-control input[type="number"] {
  font-size: 14px;
}


/* =============================== */
/* PERIODIC TABLE WRAPPER */
/* =============================== */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin-top: -8px; /* 👈 moves table up slightly */
}

.table-layout {
  min-width: 1320px; /* prevents shrinking */
  margin: 0 auto;
  padding-bottom: 16px;
}

/* =============================== */
/* PERIODIC TABLE GRID */
/* =============================== */
#periodic-table {
  display: grid;
  grid-template-columns: repeat(18, 72px);
  grid-auto-rows: 72px;
  gap: 4px;
}

/* =============================== */
/* ELEMENT BOXES */
/* =============================== */
.element-box {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  box-shadow: 0 4px 14px var(--box-shadow-light);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  padding: 6px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.25s ease;
  position: relative;
}

body.dark .element-box {
  box-shadow: 0 4px 14px var(--box-shadow-dark);
}

.element-box:hover {
  transform: translateY(-3px);
  z-index: 20;
}
.element-box.dimmed {
  opacity: 0.25;
  pointer-events: none;
}

.atomic-number {
  position: absolute;
  top: 2px;
  left: 8px;
  font-size: 10px;
  font-weight: 700;
}

.symbol {
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.name {
  font-size: 10px;
  line-height: 1;
  white-space: normal;
  word-break: break-word;
  overflow: visible;
}

.weight {
  font-size: 9px;
  opacity: 0.8;
}

/* =============================== */
/* CATEGORY COLORS */
/* =============================== */
.alkali-metal { background: var(--alkali-metal); }
.alkaline-earth-metal { background: var(--alkaline-earth-metal); color:#222; }
.transition-metal { background: var(--transition-metal); color:#111; }
.post-transition-metal { background: var(--post-transition-metal); color:#111; }
.metalloid { background: var(--metalloid); color:#111; }
.nonmetal { background: var(--nonmetal); }
.halogen { background: var(--halogen); color:#042a2b; }
.noble-gas { background: var(--noble-gas); color:#111; }
.lanthanide { background: var(--lanthanide); color:#111; }
.actinide { background: var(--actinide); color:#111; }
.reactive-nonmetal { background: var(--reactive-nonmetal); }

/* =============================== */
/* STATE COLORS */
/* =============================== */
body.state-active .state-solid { background: var(--state-solid) !important; }
body.state-active .state-liquid { background: var(--state-liquid) !important; }
body.state-active .state-gas { background: var(--state-gas) !important; }

/* =============================== */
/* HOVER PANEL (RESTORED COLORS) */
/* =============================== */
#hover-panel {
  position: fixed;
  top: 80px;
  right: 16px;
  width: 360px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  background: rgba(255,255,255,0.96);
  color: var(--text-dark);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(2,6,23,0.18);
  z-index: 1200;
}

body.dark #hover-panel {
  background: rgba(18,18,18,0.95);
  color: var(--text-light);
  border: 1px solid rgba(255,255,255,0.04);
  box-shadow: 0 18px 40px rgba(255,255,255,0.03);
}

#hover-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#hover-panel .meta {
  color: #475569;
}
body.dark #hover-panel .meta {
  color: #94a3b8;
}

#hover-panel table td:first-child {
  color: var(--metal-color);
}
body.dark #hover-panel table td:first-child {
  color: #7fb3ff;
}


/* =============================== */
/* MOBILE PANEL BEHAVIOR */
/* =============================== */
@media (max-width: 768px) {
  #hover-panel {
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 16px;
    border-radius: 14px;
  }
}

#temp-control input[type="range"] {
  flex: 1;
  height: 16px;              /* thicker */
  border-radius: 16px;
  background: linear-gradient(90deg, #3b82f6, #ef4444);
  box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
}

/* Larger thumb */
input[type="range"]::-webkit-slider-thumb {
  width: 32px;
  height: 32px;
  border: 5px solid #3b82f6;
}

input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.25);
}

#temp-control {
  max-width: 750px; /* was 600px */
}

/* =============================== */
/* ELEMENT HOVER WHITE GLOW */
/* =============================== */

.element-box {
  position: relative;
  transition:
    transform 0.15s ease,
    box-shadow 0.25s ease;
}

/* Light mode */
.element-box:hover,
.element-box:focus-visible {
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.95),   /* crisp white border */
    0 0 18px rgba(255,255,255,0.75),    /* soft glow */
    0 6px 20px rgba(0,0,0,0.25);        /* depth */
}

/* Dark mode – slightly stronger */
body.dark .element-box:hover,
body.dark .element-box:focus-visible {
  box-shadow:
    0 0 0 2px rgba(255,255,255,1),
    0 0 26px rgba(255,255,255,0.85),
    0 6px 24px rgba(0,0,0,0.6);
}

/* Optional lift */
.element-box:hover {
  transform: translateY(-3px) scale(1.03);
}


