/* Periodic Speller — reference table experience: the "Table" button,
   modal overlay shell, category legend, and the 18×10 CSS grid that
   lays out the full periodic table with lanthanide/actinide rows. */

/* Table reference button */
#tableBtn {
  flex-shrink: 0;
  background: none;
  border: 2px solid var(--border);
  color: var(--accent);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.75rem;
  border-radius: 12px;
  line-height: 1;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

#tableBtn:hover {
  background: var(--border);
  color: var(--text);
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: color-mix(in srgb, var(--pure-black) 75%, transparent);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease-out;
}

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 95vw;
  max-height: 92vh;
  overflow: auto;
  padding: 1.5rem;
  box-shadow: 0 24px 64px color-mix(in srgb, var(--pure-black) 50%, transparent);
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text);
  background: var(--border);
}

/* Legend */
.modal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  margin-bottom: 1rem;
  font-size: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

/* Periodic table grid: 18 columns x 10 rows (7 main + gap + 2 for lanthanides/actinides) */
.periodic-grid {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  grid-template-rows: repeat(10, auto);
  gap: 2px;
  min-width: 750px;
}

.pgrid-cell {
  aspect-ratio: 1;
  min-width: 38px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  padding: 2px;
}

.pgrid-cell:hover {
  transform: scale(1.25);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--pure-black) 40%, transparent);
  z-index: 2;
}

.pgrid-cell .pgrid-num {
  font-size: 0.5rem;
  font-weight: 600;
  opacity: 0.7;
  line-height: 1;
}

.pgrid-cell .pgrid-sym {
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.15;
  color: var(--pure-white);
}

.pgrid-cell .pgrid-name {
  font-size: 0.38rem;
  opacity: 0.7;
  line-height: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.pgrid-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 38px;
}

@media (max-width: 480px) {
  header {
    padding-top: 4rem;
  }

  header h1 {
    font-size: 1.6rem;
  }

  #wordInput {
    font-size: 1.1rem;
    padding: 0.8rem 2.5rem 0.8rem 1rem;
  }

  .tile,
  .tile-unmatched {
    width: 76px;
    height: 96px;
  }

  .tile-symbol {
    font-size: 2rem;
  }

  .tile-unmatched .tile-symbol {
    font-size: 2rem;
  }

  .tiles {
    gap: 0.4rem;
  }

  .modal-content {
    padding: 1rem;
  }

  .modal-header h2 {
    font-size: 1rem;
  }

  .periodic-grid {
    min-width: 600px;
    gap: 1px;
  }

  .pgrid-cell {
    min-width: 30px;
  }

  .pgrid-cell .pgrid-sym {
    font-size: 0.75rem;
  }

  .pgrid-cell .pgrid-num,
  .pgrid-cell .pgrid-name {
    display: none;
  }
}
