/* ===== Periodic Table – Textbook Style ===== */

/* ---- Category color palette (soft, muted textbook tones) ---- */
:root {
  --cat-alkali:        #e07060;
  --cat-alkaline:      #f0b050;
  --cat-transition:    #e8a080;
  --cat-post-trans:    #80b8c8;
  --cat-metalloid:     #60b080;
  --cat-nonmetal:      #58a058;
  --cat-halogen:       #70a0d0;
  --cat-noble:         #b080c0;
  --cat-lanthanide:    #60a8b8;
  --cat-actinide:      #c08090;
  --cat-unknown:       #a09890;

  --cell-gap: 2px;
  --cell-min: 54px;
  --cell-h: 68px;
  --pt-bg: #ffffff;
  --pt-border: #d8d8d4;
}

/* ---- Header ---- */
.pt-header {
  text-align: center;
  padding: 32px 16px 12px;
}
.pt-header h1 {
  font-size: 2rem;
  margin-bottom: 4px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.pt-search-wrap {
  max-width: 420px;
  margin: 16px auto 0;
}
.pt-search {
  text-align: center;
  font-size: 1rem;
  padding: 10px 16px;
  border-radius: 24px;
  background: #fff;
  border: 1.5px solid #ccc;
  transition: border-color .2s, box-shadow .2s;
}
.pt-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---- Main container ---- */
.pt-main {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ---- Table wrapper (scroll on small screens) ---- */
.pt-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  background: var(--pt-bg);
  border: 1px solid var(--pt-border);
  border-radius: 6px;
  margin-bottom: 16px;
}

/* ---- 18-column grid ---- */
.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(var(--cell-min), 1fr));
  gap: var(--cell-gap);
  min-width: 980px;
}

/* ---- Element cell ---- */
.pt-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--cell-h);
  min-height: 44px;
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  transition: box-shadow .15s, outline .15s;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.25);
  font-weight: 600;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.08);
}
.pt-cell:hover {
  outline: 2px solid rgba(0,0,0,.35);
  outline-offset: -1px;
  box-shadow: inset 0 0 0 999px rgba(255,255,255,.08);
}
.pt-cell:active {
  box-shadow: inset 0 0 0 999px rgba(0,0,0,.06);
}

.pt-cell .num {
  font-size: .58rem;
  line-height: 1;
  opacity: .85;
  margin-bottom: 1px;
  font-weight: 500;
}
.pt-cell .sym {
  font-size: 1.15rem;
  line-height: 1.15;
  font-weight: 700;
}
.pt-cell .mass {
  font-size: .52rem;
  line-height: 1;
  opacity: .78;
  margin-top: 2px;
  font-weight: 400;
}

/* Empty placeholder cell */
.pt-cell--empty {
  background: transparent !important;
  cursor: default;
  pointer-events: none;
  box-shadow: none;
  border-color: transparent;
}
.pt-cell--empty:hover {
  outline: none;
  box-shadow: none;
}

/* Dimmed (filtered out) */
.pt-cell--dimmed {
  opacity: .15;
  pointer-events: none;
}

/* ---- Category backgrounds ---- */
.pt-cat-alkali        { background: var(--cat-alkali); }
.pt-cat-alkaline      { background: var(--cat-alkaline); }
.pt-cat-transition    { background: var(--cat-transition); }
.pt-cat-post-trans    { background: var(--cat-post-trans); }
.pt-cat-metalloid     { background: var(--cat-metalloid); }
.pt-cat-nonmetal      { background: var(--cat-nonmetal); }
.pt-cat-halogen       { background: var(--cat-halogen); }
.pt-cat-noble         { background: var(--cat-noble); }
.pt-cat-lanthanide    { background: var(--cat-lanthanide); }
.pt-cat-actinide      { background: var(--cat-actinide); }
.pt-cat-unknown       { background: var(--cat-unknown); }

/* ---- Series rows ---- */
.pt-series-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 0 8px;
}
.pt-series-label {
  font-size: .78rem;
  font-weight: 700;
  color: var(--soft);
  min-width: 90px;
  text-align: right;
  flex-shrink: 0;
}
.pt-grid--lanthanides,
.pt-grid--actinides {
  grid-template-columns: repeat(15, minmax(var(--cell-min), 1fr));
  min-width: 0;
  flex: 1;
  background: var(--pt-bg);
  border: 1px solid var(--pt-border);
  padding: 6px;
  border-radius: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---- Legend ---- */
.pt-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  margin-top: 20px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pt-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .76rem;
  color: var(--ink);
}
.pt-legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.1);
}

/* ---- Modal overlay ---- */
.pt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  isolation: isolate;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s, visibility .2s;
}
.pt-overlay--open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.pt-modal {
  position: relative;
  max-width: 480px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 24px 24px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0,0,0,.25);
}

.pt-modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  z-index: 10;
  background: transparent;
  color: #888;
  font-size: 1.6rem;
  line-height: 1;
  padding: 4px 10px;
  border: none;
  cursor: pointer;
  border-radius: 8px;
  transition: color .15s, background .15s;
  pointer-events: none;
  visibility: hidden;
}
.pt-overlay--open .pt-modal-close {
  pointer-events: auto;
  visibility: visible;
}
.pt-modal-close:hover {
  color: #222;
  background: #f0f0f0;
}

/* ---- Modal content ---- */
.pt-modal-symbol {
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 2px;
}
.pt-modal-name {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 2px;
}
.pt-modal-cat {
  display: inline-block;
  font-size: .78rem;
  padding: 3px 10px;
  border-radius: 20px;
  color: #fff;
  margin-bottom: 16px;
}
.pt-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: .88rem;
}
.pt-modal-grid dt {
  color: var(--soft);
  font-weight: 500;
}
.pt-modal-grid dd {
  margin: 0;
  font-weight: 600;
}
.pt-modal-desc {
  margin-top: 14px;
  font-size: .9rem;
  color: var(--soft);
  line-height: 1.55;
}

/* ---- Responsive ---- */
@media (max-width: 700px) {
  .pt-header { padding: 18px 10px 4px; }
  .pt-header h1 { font-size: 1.4rem; }
  .pt-search-wrap { margin-top: 10px; }
  .pt-search { font-size: .9rem; padding: 10px 14px; }
  .pt-main { padding: 0 8px 32px; }
  .pt-cell { height: 54px; }
  .pt-cell .sym { font-size: .9rem; }
  .pt-cell .num { font-size: .5rem; }
  .pt-cell .mass { font-size: .46rem; }
  .pt-table-wrap { padding: 4px; margin-bottom: 12px; }
  .pt-series-wrap { gap: 6px; padding: 0 4px; margin-bottom: 8px; }
  .pt-series-label { min-width: 52px; font-size: .68rem; }
  .pt-grid--lanthanides,
  .pt-grid--actinides { padding: 4px; }
  .pt-modal { padding: 22px 16px 18px; }
  .pt-modal-symbol { font-size: 2.6rem; }
  .pt-modal-name { font-size: 1.15rem; }
  .pt-modal-close { top: 6px; right: 8px; font-size: 1.4rem; padding: 2px 8px; }
  .pt-modal-grid { grid-template-columns: 1fr; gap: 4px 0; }
  .pt-modal-grid dt,
  .pt-modal-grid dd { font-size: .82rem; }
  .pt-modal-desc { font-size: .84rem; margin-top: 10px; }
  .pt-legend { gap: 6px 10px; padding: 12px; }
  .pt-legend-item { font-size: .7rem; }
}

@media (max-width: 400px) {
  .pt-header h1 { font-size: 1.2rem; }
  .pt-header p { font-size: .8rem; }
  .pt-cell { height: 46px; }
  .pt-cell .sym { font-size: .78rem; }
  .pt-cell .num { font-size: .46rem; }
  .pt-cell .mass { font-size: .42rem; }
  .pt-grid { --cell-min: 38px; --cell-gap: 1px; }
  .pt-grid--lanthanides,
  .pt-grid--actinides { --cell-min: 38px; --cell-gap: 1px; }
  .pt-table-wrap { padding: 2px; }
  .pt-series-wrap { gap: 4px; padding: 0 2px; }
  .pt-series-label { min-width: 44px; font-size: .62rem; }
  .pt-modal { padding: 18px 12px 16px; }
  .pt-modal-symbol { font-size: 2.2rem; }
}
