*,*::before,*::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Helvetica Neue", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Arial, sans-serif;
  background: #f7f6f2;
  color: #1f1f1d;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 24px 16px 60px;
}
.container { max-width: 1320px; margin: 0 auto; }

header { margin-bottom: 18px; }
h1 {
  font-size: clamp(22px, 3vw, 30px);
  margin: 0 0 6px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #1f1f1d;
}
.subtitle {
  color: #5f5e5a;
  font-size: 14px;
  margin: 0;
  max-width: 720px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 14px;
  align-items: center;
}
.search-box {
  flex: 0 1 220px;
  min-width: 160px;
  padding: 8px 12px;
  border: 1px solid #d3d1c7;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  color: #1f1f1d;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box:focus {
  outline: none;
  border-color: #185fa5;
  box-shadow: 0 0 0 3px rgba(24, 95, 165, 0.12);
}
.filter {
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid #d3d1c7;
  background: #fff;
  color: #444441;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  white-space: nowrap;
}
.filter:hover { border-color: #888780; }
.filter.active {
  background: #1f1f1d;
  color: #fff;
  border-color: #1f1f1d;
}
.view-toggle {
  margin-left: auto;
  display: flex;
  gap: 4px;
  background: #ebe9e1;
  padding: 3px;
  border-radius: 7px;
}
.view-btn {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: #444441;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.view-btn.active {
  background: #fff;
  color: #1f1f1d;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.group-labels {
  display: grid;
  grid-template-columns: 28px repeat(18, minmax(48px, 1fr));
  gap: 3px;
  margin-bottom: 4px;
  min-width: 920px;
  font-size: 11px;
  color: #5f5e5a;
  text-align: center;
  font-weight: 500;
}
.group-labels > div { line-height: 1.1; padding: 2px 0; }
.group-labels .roman { font-size: 9px; opacity: 0.7; display: block; }

.period-label {
  font-size: 12px;
  color: #5f5e5a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
}

.pt-wrapper {
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.pt-grid {
  display: grid;
  grid-template-columns: 28px repeat(18, minmax(48px, 1fr));
  gap: 3px;
  min-width: 920px;
}

.cell {
  aspect-ratio: 0.95;
  border-radius: 4px;
  padding: 3px 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid rgba(0,0,0,0.06);
  transition: transform 0.12s ease, opacity 0.2s, box-shadow 0.12s;
  position: relative;
  user-select: none;
  overflow: hidden;
}
.cell:hover {
  transform: scale(1.15);
  z-index: 5;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  border-color: #1f1f1d;
}
.cell.dim { opacity: 0.18; }
.cell.selected {
  border-color: #1f1f1d;
  border-width: 2px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
}
.cell .num { font-size: 9px; line-height: 1; opacity: 0.78; font-weight: 500; padding-left: 1px; }
.cell .sym {
  font-size: clamp(13px, 2.4vw, 17px);
  font-weight: 600;
  line-height: 1;
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cell .mass { font-size: 8px; line-height: 1; opacity: 0.72; text-align: center; font-weight: 400; }
.cell .name-da { font-size: 7.5px; line-height: 1; text-align: center; opacity: 0.68; font-weight: 400; padding: 0 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row-marker {
  font-size: 10px;
  color: #888780;
  background: #ebe9e1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.cat-alkali { background: #f9d8e3; color: #4b1528; }
.cat-alkaline { background: #fbe1b3; color: #412402; }
.cat-transition { background: #cee1f5; color: #042c53; }
.cat-posttrans { background: #e1ddc9; color: #2c2c2a; }
.cat-metalloid { background: #d8e8b8; color: #173404; }
.cat-nonmetal { background: #b9e6d3; color: #04342c; }
.cat-halogen { background: #f3c7b5; color: #4a1b0c; }
.cat-noble { background: #d6d3f5; color: #26215c; }
.cat-lanthanide { background: #f5c0c0; color: #501313; }
.cat-actinide { background: #ecbfd1; color: #4b1528; }
.cat-unknown { background: #d6d4cb; color: #444441; }

body.view-state .cell.state-solid { background: #ffffff; color: #1f1f1d; }
body.view-state .cell.state-liquid { background: #d8d3e8; color: #2c1f4a; }
body.view-state .cell.state-gas { background: #f3c7b5; color: #4a1b0c; }
body.view-state .cell.state-synthetic { background: #b8d4d0; color: #04342c; }

.sw-solid { background: #fff; }
.sw-liquid { background: #d8d3e8; }
.sw-gas { background: #f3c7b5; }
.sw-synthetic { background: #b8d4d0; }

.detail {
  margin-top: 22px;
  padding: 22px 24px;
  background: #fff;
  border-radius: 10px;
  border: 1px solid #e5e3da;
  display: none;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.detail.show { display: block; }
.detail-head {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.detail-sym {
  width: 84px;
  height: 84px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 6px;
  border: 1px solid rgba(0,0,0,0.08);
}
.detail-sym .ds-num { font-size: 11px; opacity: 0.75; align-self: flex-start; line-height: 1; }
.detail-sym .ds-sym { font-size: 30px; font-weight: 600; line-height: 1; margin: 4px 0; }
.detail-sym .ds-mass { font-size: 9px; opacity: 0.7; line-height: 1; }
.detail-title { flex: 1; min-width: 200px; }
.detail-name {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
  color: #1f1f1d;
  letter-spacing: -0.01em;
}
.detail-name .latin {
  color: #888780;
  font-weight: 400;
  font-size: 16px;
  font-style: italic;
}
.detail-cat {
  font-size: 14px;
  color: #5f5e5a;
  margin: 4px 0 0;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: #f7f6f2;
  border-radius: 6px;
  padding: 10px 12px;
}
.stat-label {
  font-size: 10.5px;
  color: #5f5e5a;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.stat-val {
  font-size: 14px;
  font-weight: 500;
  color: #1f1f1d;
  word-wrap: break-word;
}
.stat-val.small { font-size: 12px; }

.description {
  background: #f7f6f2;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13.5px;
  color: #2c2c2a;
  line-height: 1.6;
  margin-bottom: 12px;
}
.description strong { color: #1f1f1d; font-weight: 600; }

.lab-tip {
  background: #f0f6fa;
  border-left: 3px solid #185fa5;
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 13px;
  color: #042c53;
  line-height: 1.55;
}
.lab-tip strong { font-weight: 600; }

.legends {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 16px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid #e5e3da;
  border-radius: 8px;
}
@media (min-width: 720px) {
  .legends { grid-template-columns: 1fr 1fr; }
}
.legend-block h3 {
  font-size: 12px;
  margin: 0 0 8px;
  color: #1f1f1d;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: #444441;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}

.info-banner {
  background: #fff;
  border: 1px solid #e5e3da;
  border-left: 3px solid #185fa5;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: #444441;
}
.info-banner strong { color: #1f1f1d; font-weight: 600; }

footer {
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid #e5e3da;
  font-size: 12.5px;
  color: #5f5e5a;
  line-height: 1.6;
}
footer a { color: #185fa5; text-decoration: none; }
footer a:hover { text-decoration: underline; }
footer .brand { font-weight: 600; color: #1f1f1d; }

@media print {
  body { background: #fff; padding: 12px; }
  .controls, .view-toggle, footer .interactive-only { display: none; }
  .cell:hover { transform: none; box-shadow: none; }
  .pt-wrapper { overflow: visible; }
  .pt-grid { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .cell, .detail, .filter, .view-btn, .search-box { transition: none; animation: none; }
  .cell:hover { transform: none; }
}
