:root {
  --bg: #f5f5f5;
  --text: #222;
  --card-bg: #ffffff;
  --card-hover: #e0e0e0;
  --accent: #007acc;
  /* Add a subtle base tint per category */
  --nonmetal-bg:        #e0f7f3;
  --noble-gas-bg:       #fff9cc;
  --alkali-metal-bg:    #ffe9e2;
  --alkaline-earth-metal-bg:  #eaefff;
  --metalloid-bg:       #fae7f4;
  --halogen-bg:         #f0fbe3;
  --transition-metal-bg:#fff6e7;
  --lanthanide-bg:      #f5f5f5;
  --actinide-bg:        #f5f3fa;
  --post-transition-metal-bg: #fdeafa;
  --unknown-bg:         #f0f0f0;
}

[data-theme="light"] .element-card.nonmetal         { border-color: #5abda0; color: #3a8f7a; }
[data-theme="light"] .element-card.noble-gas        { border-color: #ffe566; color: #c9a800; }
[data-theme="light"] .element-card.alkali-metal     { border-color: #ff9b88; color: #c25443; }
[data-theme="light"] .element-card.alkaline-earth-metal   { border-color: #9ebdff; color: #4a75cc; }
[data-theme="light"] .element-card.metalloid        { border-color: #fface9; color: #c557a6; }
[data-theme="light"] .element-card.halogen          { border-color: #d5f879; color: #8aa634; }
[data-theme="light"] .element-card.transition-metal { border-color: #ffe2a2; color: #c89d3a; }
[data-theme="light"] .element-card.lanthanide       { border-color: #e0e0ff; color: #8080cc; }
[data-theme="light"] .element-card.actinide         { border-color: #efd6ff; color: #9a66c0; }
[data-theme="light"] .element-card.post-transition-metal  { border-color: #ffc3dd; color: #bb5680; }
[data-theme="light"] .element-card.unknown          { border-color: #dddddd; color: #888888; }
[data-theme="light"] .element-card.nonmetal .card-info         { background: #e8f9f4; }
[data-theme="light"] .element-card.noble-gas .card-info        { background: #fffbd9; }
[data-theme="light"] .element-card.alkali-metal .card-info     { background: #ffeae4; }

/* dark theme */
[data-theme="dark"] {
  --bg: #1b1b1b;
  --text: #f5f5f5;
  --card-bg: #2c2c2c;
  --card-hover: #333333;
  --accent: #61dbfb;
}

/* Base Layout */
body {
  font-family: 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
}


html {
  overflow-y: scroll; /* Always reserve scrollbar space */
}




.nuclear-img {
  display: block;
  max-width: 80%;
  margin: 0.4rem auto 0;
  height: auto;
}

















/* header {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#themeToggle {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
} */



/* =========================
   Header Styling
   ========================= */
/* =========================
   Header Styling with Content Alignment
   ========================= */
header {
  background-color: var(--header-bg, #f9f9f9);
  color: var(--header-text, #222);
  border-bottom: 2px solid var(--header-border, #ccc);
  position: sticky;
  top: 0;
  z-index: 1000;
}

/* Inner wrapper to match main content width */
header .header-inner {
  max-width: 1600px; /* same as .table-container */
  margin: 0 auto;
  padding: 0.75rem 1rem; /* same horizontal padding as .table-container */
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Title */
header h1 {
  font-size: 1.6rem;
  font-weight: bold;
  margin: 0;
  line-height: 1;
}

/* Theme Toggle Icon */
#themeToggle {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.6rem;
  cursor: pointer;

  /* Fix size to prevent shift */
  width: 2.4rem;    /* slightly larger than font-size */
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  line-height: 1;   /* no line-height affecting centering */
  padding: 0;
  overflow: hidden;

  /* Force consistent emoji rendering */
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}


/* Light theme variables */
:root {
  --header-bg: #f9f9f9;
  --header-text: #222;
  --header-border: #ccc;
}

/* Dark theme variables */
[data-theme="dark"] {
  --header-bg: #222;
  --header-text: #f9f9f9;
  --header-border: #444;
}





















/* Container & Grid */
.table-container {
  max-width: 1600px;
  margin: 2rem auto;
  padding: 1rem;
  box-sizing: border-box;
}

.periodic-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(45px, 1fr));
  gap: 8px;
  justify-content: center;
  align-content: start;
  box-sizing: border-box;
}

/* Element Card */
.element-card {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.5rem;
  text-align: center;
  position: relative;
  cursor: pointer;
  transition: background 0.3s, transform 0.3s;
  overflow: visible;
  font-size: clamp(0.6rem, 1vw, 0.85rem);
  line-height: 1.1;
}
.element-card.nonmetal         { border-color: #00d3a9; color: #00d3a9; }
.element-card.noble-gas        { border-color: #ffea00; color: #ffea00; }
.element-card.alkali-metal     { border-color: #ff6b6b; color: #ff6b6b; }
.element-card.alkaline-earth-metal   { border-color: #6a9eff; color: #6a9eff; }
.element-card.metalloid        { border-color: #ff8be6; color: #ff8be6; }
.element-card.halogen          { border-color: #b4f000; color: #b4f000; }
.element-card.transition-metal { border-color: #ffc361; color: #ffc361; }
.element-card.lanthanide       { border-color: #aaaaff; color: #aaaaff; }
.element-card.actinide         { border-color: #da77ff; color: #da77ff; }
.element-card.post-transition-metal  { border-color: #ff67b3; color: #ff67b3; }
.element-card.unknown          { border-color: #cccccc; color: #cccccc; }

.element-card:hover,
.element-card:focus-within {
  background: var(--card-hover);
  transform: scale(1.05);
  z-index: 1;
}

.element-card .symbol {
  font-size: 1.4rem;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.element-card .number {
  font-size: 0.8rem;
  opacity: 0.6;
}

.element-card .name {
  font-size: 0.9rem;
  margin-top: 0.3rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-info {
  display: none;
  position: fixed; /* fixed instead of absolute so it stays in viewport centre */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%); /* true centring */
  background: inherit;
  color: inherit;
  padding: 0.6rem 0.8rem;
  border: 2px solid currentColor;
  border-radius: 6px;
  box-shadow: 0 0 8px rgba(0,0,0,0.2);
  white-space: nowrap;
  z-index: 1000; /* above everything else */
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
  pointer-events: none;
  line-height: 1.6;
  font-size: 0.75rem;
}
.card-info img {
  display: block;
  max-width: 200px;
  margin: 0 auto 0.5rem;
}
.element-card:hover .card-info,
.element-card:focus-within .card-info,
.element-card.show-info .card-info {
  display: block;
  opacity: 1;
}



/* f-block Styling */
.element-card.f-block {
  font-size: 0.75rem;
  padding: 0.4rem;
}

.row-lanthanides .element-card,
.row-actinides .element-card {
  background: rgba(255, 255, 0, 0.08);
}

/* Legend */
.legend {
  padding: 1rem;
}

.legend h2 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
}

.legend ul {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.5rem;
}

.legend li {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
}

.color-box {
  width: 16px;
  height: 16px;
  display: inline-block;
  margin-right: 8px;
  border: 2px solid currentColor;
  border-radius: 3px;
}

/* Category Colors */
.nonmetal         { border-color: #66c2a5; }
.noble-gas        { border-color: #ffd92f; }
.alkali-metal     { border-color: #fc8d62; }
.alkaline-earth-metal   { border-color: #8da0cb; }
.metalloid        { border-color: #e78ac3; }
.halogen          { border-color: #a6d854; }
.transition-metal { border-color: #e5c494; }
.lanthanide       { border-color: #b3b3b3; }
.actinide         { border-color: #c2a5cf; }
.post-transition-metal  { border-color: #f781bf; }
.unknown          { border-color: #999999; }

/* Responsive */
@media (max-width: 900px) {
  .periodic-grid {
    grid-template-columns: repeat(9, minmax(45px, 1fr));
    gap: 6px;
  }
}

@media (max-width: 600px) {
  .periodic-grid {
    grid-template-columns: repeat(5, minmax(50px, 1fr));
    gap: 5px;
  }

  .element-card {
    padding: 0.4rem;
    font-size: 0.75rem;
  }
}

/* Floating Legend */
.legend-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1000;
}
.legend-fab > summary {
  list-style: none;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.legend-fab > summary::-webkit-details-marker { display: none; }

.legend-panel {
  margin-top: 0.5rem;
  background: var(--card-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 0.75rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}

.legend-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.5rem;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font: inherit;
}
.legend-chip .color-box { margin: 0; }

.legend-chip.is-active {
  color: var(--text);
}

.element-card.selected {
  transform: scale(1.12);
  outline: 2px solid currentColor;
  box-shadow: 0 12px 30px rgba(0,0,0,0.35);
  z-index: 5;
}
.element-card.selected:hover { transform: scale(1.15); }

.element-card.dim {
  opacity: 0.35;
  filter: grayscale(0.15) saturate(0.6);
}
.element-card.dim:hover { transform: none; }

.element-card:hover:not(.selected) { transform: scale(1.05); }
.color-box.selected { background-color: currentColor; }

/* Legend color mapping */
.color-box.nonmetal         { color: #66c2a5; }
.color-box.noble-gas        { color: #ffd92f; }
.color-box.alkali-metal     { color: #fc8d62; }
.color-box.alkaline-earth-metal   { color: #8da0cb; }
.color-box.metalloid        { color: #e78ac3; }
.color-box.halogen          { color: #a6d854; }
.color-box.transition-metal { color: #e5c494; }
.color-box.lanthanide       { color: #b3b3b3; }
.color-box.actinide         { color: #c2a5cf; }
.color-box.post-transition-metal  { color: #f781bf; }
.color-box.unknown          { color: #999999; }

.color-box { border-color: currentColor; }
.color-box.selected { background-color: currentColor; }
.legend-chip .color-box { transition: background-color 140ms ease; }
#globalInfoCard {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card-bg);
  color: var(--text);
  padding: 0.8rem 1rem;
  border: 2px solid currentColor;
  border-radius: 6px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
  z-index: 9999; /* Above everything */
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  line-height: 1.6;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#globalInfoCard.active {
  display: block;
  opacity: 1;
}
.info-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6); /* dark semi-transparent */
  z-index: 9998; /* just below the info card */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.info-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}
#globalInfoCard {
  pointer-events: none;
}
#globalInfoCard img,
#globalInfoCard button,
#globalInfoCard a {
  pointer-events: auto; /* keep clickable elements usable */
}
.info-backdrop {
  pointer-events: none;
}
.info-backdrop {
  position: absolute;
  top: var(--info-top);
  left: var(--info-left);
  width: var(--info-width);
  height: var(--info-height);
}
/* Info cell inside the table */
#infoCell.in-grid {
  background: var(--card-bg);
  border: 2px solid currentColor;
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.9rem;
  grid-column: span 10;
  align-self: start;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  transition: background 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

#infoCell.in-grid img {
  max-width: 100%;
  display: block;
  margin: 0 auto 0.5rem;
}

#infoCell.in-grid em {
  display: block;
  margin-top: 0.5rem;
  font-style: italic;
}

#infoCell.in-grid strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 1.1rem;
}
/* Two-column layout: periodic grid + info panel */
.table-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px; /* left = grid, right = fixed panel */
  gap: 16px;
  align-items: start;
}

/* Ensure the grid itself sits in column 1 */
.periodic-grid {
  grid-column: 1;
}

/* Right-hand info panel */
#infoCell.info-panel {
  grid-column: 2;
  position: sticky;
  top: 80px; /* keeps it below the header */
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid currentColor;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  max-height: calc(100vh - 120px);
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Images inside the panel */
#infoCell.info-panel img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 0.75rem;
}

/* Empty state text */
#infoCell.info-panel em {
  opacity: 0.85;
}

/* Responsive: stack panel below grid on narrow screens */
@media (max-width: 900px) {
  .table-container {
    grid-template-columns: 1fr;
  }
  #infoCell.info-panel {
    grid-column: 1;
    position: relative;
    top: 0;
    max-height: none;
  }
}
/* Two-column layout: periodic grid + info panel */
.table-container {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px; /* left = grid, right = fixed panel */
  gap: 16px;
  align-items: start;
}

/* Ensure the grid itself sits in column 1 */
.periodic-grid {
  grid-column: 1;
}

/* Right-hand info panel */
#infoCell.info-panel {
  grid-column: 2;
  position: sticky;
  top: 80px; /* keeps it below the header */
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid currentColor;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  max-height: calc(100vh - 120px);
  overflow: auto;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Images inside the panel */
#infoCell.info-panel img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto 0.75rem;
}

/* Empty state text */
#infoCell.info-panel em {
  opacity: 0.85;
}

/* Responsive: stack panel below grid on narrow screens */
@media (max-width: 900px) {
  .table-container {
    grid-template-columns: 1fr;
    overflow-x: auto;
    padding: 0;              /* remove horizontal padding */
    margin: 0;               /* prevent margin cut-off */
  }

  .periodic-grid {
    min-width: 1300px;       /* adjust to exact total table width */
    overflow-x: auto;
    padding: 0;
    margin: 0;
  }

  #infoCell.info-panel {
    grid-column: 1;
    position: relative;
    top: 0;
    max-height: none;
  }
}


/* === FIXED LAYOUT FOR INFO + LEGEND COLUMN === */
.table-container {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  max-width: 1600px;
  margin: 2rem auto;
  padding: 1rem;
  align-items: start;
  box-sizing: border-box;
}

.periodic-grid {
  grid-column: 1;
}

.info-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: stretch;
}

#infoCell.info-panel,
#legend.legend-below {
  width: 100%;
  box-sizing: border-box;
}

#legend.legend-below {
  max-height: none !important;
  overflow: visible !important;
}

@media (max-width: 900px) {
  .table-container {
    grid-template-columns: 1fr;
  }

  .info-column {
    grid-column: 1;
  }
}
.table-container {
  display: grid;
  grid-template-columns: 1fr 360px; /* left = grid, right = info+legend */
  gap: 16px;
  align-items: start;
}

.periodic-grid {
  grid-column: 1;
}

.info-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#infoCell,
#legend {
  width: 100%;
  box-sizing: border-box;
  max-width: 360px;
}

@media (max-width: 900px) {
  .table-container {
    grid-template-columns: 1fr;
  }

  .info-column {
    grid-column: 1;
  }
}

/* === LAYOUT FIX PATCH === */

.table-container {
  display: grid;
  grid-template-columns: 1fr 360px; /* Periodic table on left, info column on right */
  gap: 1.5rem;
  align-items: start;
  max-width: 1600px;
  margin: 2rem auto;
  padding: 1rem;
  box-sizing: border-box;
}

.periodic-grid {
  grid-column: 1;
}

.info-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  align-items: stretch;
}

#infoCell.info-panel,
#legend.legend-below {
  width: 100%;
  box-sizing: border-box;
  max-width: 360px;
  background: var(--card-bg);
  color: var(--text);
  border: 2px solid currentColor;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

#legend.legend-below {
  overflow: visible;
  max-height: none;
}

/* MOBILE STACKING */
@media (max-width: 900px) {
  .table-container {
    grid-template-columns: 1fr;
  }

  .info-column {
    grid-column: 1;
  }
}
/* === Stack each legend chip vertically === */
.legend-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}

.legend-chip {
  width: 100%;
  max-width: 100%;
  justify-content: flex-start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 900px) {
  .table-container {
    display: block;
    padding: 0;
    margin: 0;
  }

  .periodic-grid {
    overflow-x: auto;
    overflow-y: hidden;
    display: inline-grid;
    grid-template-columns: repeat(18, minmax(45px, 1fr)); /* full 18 cols */
    gap: 6px;
    width: max-content;
    padding: 1rem;
    margin: 0 auto;
  }

  .info-column {
    padding: 1rem;
  }

  #infoCell.info-panel {
    position: relative;
    top: 0;
    max-height: none;
  }
}
