* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  padding: 16px;
  background: #f4f4f4;
  color: #1a1a1a;
}

.page-header h1 {
  text-align: center;
  font-size: 32px;
  margin: 0 0 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

#search {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #999;
  border-radius: 6px;
  min-width: 220px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-btn {
  padding: 6px 10px;
  font-size: 12px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  background: #ddd;
  color: #111;
}

.filter-btn.active {
  border-color: #111;
  font-weight: bold;
}

#load-error {
  text-align: center;
  color: #b00808;
  font-weight: bold;
}

.periodic-table {
  display: grid;
  grid-template-columns: 56px repeat(3, minmax(48px, 1fr)) 24px repeat(15, minmax(48px, 1fr));
  grid-template-rows: 32px repeat(7, minmax(64px, auto)) 16px repeat(2, minmax(64px, auto));
  gap: 3px;
  max-width: 1400px;
  margin: 0 auto;
}

.group-number, .period-number, .star-marker, .breakout-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 13px;
  color: #b00808;
}

.breakout-label {
  justify-content: flex-start;
  font-size: 14px;
}

.tile {
  border: 1px solid #333;
  border-radius: 4px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  position: relative;
  background: #ccc;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.tile:hover {
  transform: scale(1.05);
  z-index: 2;
}

.tile.dimmed {
  opacity: 0.15;
}

.tile-number { font-size: 10px; align-self: flex-start; }
.tile-symbol { font-size: 20px; font-weight: bold; }
.tile-mass { font-size: 9px; }
.tile-name { font-size: 9px; }

.tile-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 10px;
}

.tile[data-category="Noble-Gases"] { background: orange; }
.tile[data-category="Halogens"] { background: rgb(0, 225, 255); }
.tile[data-category="Non-Metals"] { background: rgb(46, 157, 190); }
.tile[data-category="Metalloids"] { background: pink; }
.tile[data-category="Post-Transition-Metals"] { background: rgb(168, 168, 168); }
.tile[data-category="Transition-Metals"] { background: #BADA55; }
.tile[data-category="Alkalai-Metals"] { background: #ffd332; }
.tile[data-category="Alkaline-Earth-Metals"] { background: #aa9b88; }
.tile[data-category="Lanthanides"] { background: rgb(187, 1, 187); }
.tile[data-category="Actinides"] { background: rgb(233, 50, 50); }
.tile[data-category="Unknown-Properties"] { background: rgb(202, 198, 198); }

#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#modal-overlay[hidden] { display: none; }

#modal {
  background: white;
  border-radius: 8px;
  padding: 24px;
  max-width: 420px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

#modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 24px;
  border: none;
  background: none;
  cursor: pointer;
}

#modal-body h2 { margin-top: 0; }
#modal-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
#modal-body dt { font-weight: bold; }
#modal-body dd { margin: 0; }

@media (max-width: 900px) {
  body {
    padding: 8px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  #search {
    width: 100%;
  }

  .periodic-table {
    grid-template-columns: 48px repeat(3, 60px) 20px repeat(15, 60px);
    grid-template-rows: 28px repeat(7, 56px) 12px repeat(2, 56px);
    overflow-x: auto;
    width: 100%;
  }

  .tile-name {
    display: none;
  }

  #modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
}
