@import url("https://fonts.googleapis.com/css2?family=Tinos:wght@400;700&display=swap");

:root {
  --page-pad: clamp(8px, 1.35vw, 28px);
  --gap: clamp(3px, 0.32vw, 6px);
  --label-col: clamp(22px, 1.7vw, 34px);
  --tile: min(96px, calc((100vw - (2 * var(--page-pad)) - var(--label-col) - (18 * var(--gap))) / 18));
  --top-row: clamp(24px, 1.9vw, 34px);
  --series-gap: clamp(34px, 3.6vw, 62px);
  --ink: #090909;
  --soft-ink: #3f3f46;
  --blue: #245cff;
  --shadow: 0 18px 70px rgba(24, 36, 54, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Tinos", "Times New Roman", Georgia, serif;
  background:
    linear-gradient(rgba(242, 248, 255, 0.56), rgba(242, 248, 255, 0.56)),
    url("img/background.jpg") center / cover fixed;
}

button,
a {
  font: inherit;
}

.page-shell {
  min-height: 100vh;
  overflow-x: hidden;
  padding: 2px var(--page-pad) 24px;
}

.page-header {
  text-align: center;
}

.page-header h1 {
  margin: 0 0 2px;
  font-size: min(3.2vw, 58px);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.table-stage {
  position: relative;
}

.table-scroll {
  overflow: visible;
  padding-bottom: 0;
}

.periodic-grid {
  display: grid;
  grid-template-columns: var(--label-col) repeat(18, var(--tile));
  grid-template-rows: var(--top-row) repeat(7, var(--tile)) var(--series-gap) var(--tile) var(--tile);
  gap: var(--gap);
  width: calc(var(--label-col) + 18 * var(--tile) + 18 * var(--gap));
  max-width: 100%;
  align-items: stretch;
}

.group-label,
.period-label,
.series-label {
  display: grid;
  place-items: center;
  color: #000;
  font-size: clamp(14px, 1.35vw, 25px);
  line-height: 1;
}

.group-label:not(.group-1):not(.group-18) {
  align-self: end;
  padding-bottom: clamp(3px, 0.55vw, 10px);
}

.period-label {
  justify-content: end;
  padding-right: 6px;
}

.series-label {
  justify-content: end;
  padding-right: clamp(8px, 1.2vw, 22px);
  border: 0;
  background: transparent;
  color: #21142e;
  font-size: clamp(15px, 1.45vw, 28px);
  cursor: pointer;
  transition: transform 160ms ease, text-shadow 160ms ease;
}

.series-label:hover,
.series-label:focus-visible {
  transform: scale(1.08);
  outline: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

.element {
  position: relative;
  display: grid;
  grid-template:
    "number mass" calc(var(--tile) * 0.19)
    "symbol symbol" minmax(0, calc(var(--tile) * 0.53))
    "name name" calc(var(--tile) * 0.28) / 1fr 1fr;
  min-width: 0;
  min-height: 0;
  padding: max(3px, calc(var(--tile) * 0.055)) max(4px, calc(var(--tile) * 0.075)) max(5px, calc(var(--tile) * 0.075));
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  color: #090909;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6), 0 2px 7px rgba(20, 30, 50, 0.12);
  cursor: pointer;
  opacity: 1;
  translate: 0 0;
  scale: 1;
  animation: tileReveal 620ms cubic-bezier(0.18, 0.86, 0.28, 1) backwards;
  animation-delay: var(--reveal-delay, 0ms);
  will-change: scale, translate;
  transition: scale 160ms ease, translate 160ms ease, box-shadow 160ms ease;
}

.element:hover,
.element:focus-visible {
  z-index: 5;
  translate: 0 -2px;
  scale: 1.08;
  outline: none;
  box-shadow: 0 14px 28px rgba(20, 30, 50, 0.24);
}

@keyframes tileReveal {
  0% {
    opacity: 0;
    translate: 0 14px;
    scale: 0.9;
    filter: blur(3px);
  }

  70% {
    opacity: 1;
    translate: 0 -2px;
    scale: 1.02;
    filter: blur(0);
  }

  100% {
    opacity: 1;
    translate: 0 0;
    scale: 1;
    filter: blur(0);
  }
}

.element-number {
  grid-area: number;
  align-self: start;
  justify-self: start;
  color: var(--blue);
  font-size: clamp(10px, calc(var(--tile) * 0.18), 18px);
  line-height: 1;
}

.element-mass {
  grid-area: mass;
  align-self: start;
  justify-self: end;
  font-size: clamp(7px, calc(var(--tile) * 0.12), 12px);
  line-height: 1;
}

.element-symbol {
  grid-area: symbol;
  align-self: center;
  justify-self: center;
  font-size: clamp(24px, calc(var(--tile) * 0.57), 58px);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0;
}

.element-name {
  grid-area: name;
  align-self: end;
  justify-self: center;
  min-width: 0;
  max-width: 100%;
  overflow: visible;
  padding: 0 1px;
  color: var(--soft-ink);
  font-size: clamp(8px, calc(var(--tile) * 0.17), 18px);
  line-height: 1;
  overflow-wrap: normal;
  text-align: center;
  text-overflow: clip;
  white-space: nowrap;
}

.element-name[data-length="medium"] {
  font-size: clamp(8px, calc(var(--tile) * 0.155), 16px);
}

.element-name[data-length="long"] {
  font-size: clamp(7px, calc(var(--tile) * 0.128), 13px);
}

.placeholder {
  grid-template:
    "number mass" calc(var(--tile) * 0.32)
    "symbol symbol" 1fr
    "name name" calc(var(--tile) * 0.1) / 1fr 1fr;
}

.placeholder .element-symbol {
  color: #492057;
  font-size: clamp(11px, calc(var(--tile) * 0.18), 18px);
  line-height: 1.15;
}

.placeholder .element-name {
  display: none;
}

.nonmetal { background: rgba(186, 192, 252, 0.68); border-color: #9ba4ff; }
.alkali { background: rgba(255, 227, 221, 0.76); border-color: #ff9a8f; }
.alkaline { background: rgba(255, 241, 206, 0.78); border-color: #f3c477; }
.transition { background: rgba(238, 240, 242, 0.76); border-color: #c6c9cc; }
.post-transition { background: rgba(185, 255, 200, 0.7); border-color: #77e993; }
.metalloid { background: rgba(198, 248, 255, 0.72); border-color: #65d9ea; }
.halogen { background: rgba(222, 201, 246, 0.78); border-color: #c3a2eb; }
.noble { background: rgba(235, 204, 246, 0.8); border-color: #d9a7ed; }
.lanthanide { background: rgba(255, 220, 240, 0.78); border-color: #ff9bca; }
.actinide { background: rgba(255, 172, 251, 0.72); border-color: #f36bea; }

.radioactive::after {
  content: "☢";
  position: absolute;
  right: max(3px, calc(var(--tile) * 0.04));
  top: calc(var(--tile) * 0.22);
  bottom: auto;
  display: grid;
  place-items: center;
  width: clamp(12px, calc(var(--tile) * 0.19), 18px);
  height: clamp(12px, calc(var(--tile) * 0.19), 18px);
  border-radius: 50%;
  color: #171717;
  background: #ffdc35;
  font-size: clamp(9px, calc(var(--tile) * 0.14), 13px);
  line-height: 1;
}

.topic-link {
  position: absolute;
  z-index: 3;
  border: 0;
  color: #000;
  background: transparent;
  cursor: pointer;
}

.groups-link {
  top: calc(var(--top-row) + var(--tile) * 0.31);
  left: calc(var(--label-col) + var(--tile) * 1.7);
  display: inline-flex;
  align-items: center;
  padding: 6px 8px;
  font-size: clamp(15px, 1.2vw, 22px);
  transition: transform 160ms ease, text-shadow 160ms ease;
}

.groups-link:hover,
.groups-link:focus-visible,
.periods-link:hover,
.periods-link:focus-visible {
  transform: scale(1.12);
  outline: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

.periods-link {
  top: calc(var(--top-row) + (var(--tile) + var(--gap)) * 7 + var(--tile) * 0.08);
  left: calc(var(--label-col) + var(--tile) * 0.02);
  padding: 2px 8px;
  font-size: clamp(15px, 1.25vw, 23px);
  transition: transform 160ms ease, text-shadow 160ms ease;
}

.sample-footer {
  padding-top: clamp(18px, 2vw, 34px);
}

.category-legend {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(8px, 1.6vw, 30px);
  align-items: stretch;
  max-width: 1720px;
  margin: 0 auto clamp(20px, 3.2vw, 54px);
}

.legend-chip {
  display: grid;
  place-items: center;
  min-height: 70px;
  padding: 7px 8px;
  border: 2px solid currentColor;
  border-radius: 8px;
  color: #111;
  background: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  font-size: clamp(13px, 0.94vw, 18px);
  line-height: 1.14;
  text-align: center;
  transition: transform 160ms ease, box-shadow 160ms ease;
  will-change: transform;
}

.legend-chip:hover,
.legend-chip:focus-visible {
  transform: scale(1.08);
  outline: none;
  box-shadow: 0 10px 22px rgba(24, 36, 54, 0.18);
}

.legend-chip.alkali { background: rgba(255, 227, 221, 0.76); border-color: #ff9a8f; }
.legend-chip.alkaline { background: rgba(255, 241, 206, 0.78); border-color: #f3c477; }
.legend-chip.transition { background: rgba(238, 240, 242, 0.76); border-color: #c6c9cc; }
.legend-chip.post-transition { background: rgba(185, 255, 200, 0.7); border-color: #77e993; }
.legend-chip.metalloid { background: rgba(198, 248, 255, 0.72); border-color: #65d9ea; }
.legend-chip.nonmetal { background: rgba(186, 192, 252, 0.68); border-color: #9ba4ff; }
.legend-chip.halogen { background: rgba(222, 201, 246, 0.78); border-color: #c3a2eb; }
.legend-chip.noble { background: rgba(235, 204, 246, 0.8); border-color: #d9a7ed; }
.legend-chip.lanthanide { background: rgba(255, 220, 240, 0.78); border-color: #ff9bca; }
.legend-chip.actinide { background: rgba(255, 172, 251, 0.72); border-color: #f36bea; }

.footer-links {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 56px);
  border-top: 1px solid rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.footer-links button,
.footer-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
  padding: 8px 12px;
  border: 0;
  border-right: 1px solid rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  color: #0000ee;
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  font-size: clamp(16px, 1.05vw, 20px);
  text-decoration: underline;
}

.footer-left-1 { grid-column: 1; grid-row: 1; }
.footer-left-2 { grid-column: 1; grid-row: 2; }
.footer-left-3 { grid-column: 1; grid-row: 3; }
.footer-mid-1 { grid-column: 2; grid-row: 1; }
.footer-mid-2 { grid-column: 2; grid-row: 2; }
.footer-mid-3 { grid-column: 2; grid-row: 3; }
.footer-language { grid-column: 3; grid-row: 1; }
.footer-right-2 { grid-column: 3; grid-row: 2; }
.footer-right-3 { grid-column: 3; grid-row: 3; }

.footer-pair {
  padding: 0;
}

.footer-pair button {
  flex: 1 1 50%;
  height: 100%;
  border: 0;
  border-right: 1px solid rgba(0, 0, 0, 0.18);
  border-bottom: 0;
  background: transparent;
}

.footer-pair button:last-child {
  border-right: 0;
}

.footer-language {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 56px;
  padding: 8px 12px;
  border-right: 1px solid rgba(0, 0, 0, 0.18);
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.16);
}

.footer-links img,
.footer-language img,
.footer-mini img {
  transition: transform 150ms ease, filter 150ms ease;
}

.footer-links button:hover img,
.footer-links button:focus-visible img,
.footer-language a:hover img,
.footer-language a:focus-visible img,
.footer-mini a:hover img,
.footer-mini a:focus-visible img {
  transform: scale(1.15);
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.2));
}

.footer-language img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.footer-links img {
  width: 44px;
  height: 34px;
  object-fit: contain;
}

.footer-mini {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1vw, 18px);
  padding: 18px 0 4px;
}

.footer-mini img {
  display: block;
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.footer-mini span {
  color: #333;
}

.element-dialog {
  width: min(1360px, 96vw);
  max-width: 96vw;
  height: min(900px, 90vh);
  padding: 0;
  border: 0;
  border-radius: 12px;
  color: #121212;
  background: rgba(248, 251, 255, 0.96);
  box-shadow: var(--shadow);
}

.element-dialog::backdrop {
  background: rgba(8, 12, 18, 0.62);
  backdrop-filter: blur(4px);
}

.dialog-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: #16181d;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 30px;
  line-height: 1;
  padding: 0;
}

.dialog-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 70px 18px 26px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.dialog-kicker {
  margin: 0 0 4px;
  color: #3f55d6;
  font: 700 13px/1.2 Arial, sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

.dialog-header h2 {
  margin: 0;
  font-size: clamp(34px, 3vw, 54px);
  font-weight: 400;
  line-height: 0.95;
}

.source-link {
  flex: 0 0 auto;
  color: #163a7a;
  font: 700 14px/1.2 Arial, sans-serif;
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.dialog-content {
  display: block;
  min-height: 0;
  overflow: auto;
}

.video-panel,
.wiki-panel {
  min-width: 0;
  min-height: 0;
}

.video-panel {
  display: grid;
  grid-template-rows: auto auto;
  padding: 0 0 18px;
  background: #090909;
}

.video-panel[hidden] {
  display: none;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 0;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 0;
  background: #111;
}

.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.slider-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-top: 18px;
}

.slider-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 30px;
  line-height: 1;
  padding: 0;
}

.slider-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.slider-dots {
  display: flex;
  gap: 7px;
}

.slider-dot {
  width: 11px;
  height: 11px;
  border: 0;
  border-radius: 50%;
  background: #858585;
  cursor: pointer;
}

.slider-dot.is-active {
  background: #d91818;
  box-shadow: 0 0 0 3px rgba(217, 24, 24, 0.18);
}

.wiki-panel iframe {
  display: block;
  width: 100%;
  min-height: 520px;
  height: 62vh;
  border: 0;
  background: #fff;
}

@media (max-width: 1200px) {
  .category-legend {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (max-width: 900px) {
  :root {
    --tile: auto;
    --gap: 7px;
  }

  .page-shell {
    padding-top: 0;
    padding-inline: 8px;
  }

  .page-header h1 {
    font-size: clamp(18px, 4.2vw, 28px);
    line-height: 1.05;
    margin-bottom: 6px;
    white-space: normal;
  }

  .table-stage {
    margin-top: 0;
  }

  .periodic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    grid-template-rows: none;
    gap: 8px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
  }

  .groups-link,
  .periods-link,
  .group-label,
  .period-label,
  .series-label,
  .placeholder {
    display: none;
  }

  .element {
    grid-column: auto !important;
    grid-row: auto !important;
    aspect-ratio: 1;
    min-height: 84px;
    padding: 6px 7px;
  }

  .element-number {
    font-size: 13px;
  }

  .element-mass {
    font-size: 9px;
  }

  .element-symbol {
    font-size: clamp(34px, 11vw, 54px);
  }

  .element-name,
  .element-name[data-length="medium"],
  .element-name[data-length="long"] {
    font-size: clamp(11px, 3.2vw, 16px);
  }

  .radioactive::after {
    top: 24%;
    bottom: auto;
  }

  .element-dialog {
    height: 94vh;
  }

  .dialog-header {
    display: block;
    padding: 18px 62px 14px 18px;
  }

  .source-link {
    display: inline-block;
    margin-top: 8px;
  }

  .category-legend {
    grid-template-columns: repeat(2, 1fr);
  }

  .footer-links {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .footer-cell,
  .footer-language {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .element {
    opacity: 1;
    translate: 0 0;
    scale: 1;
    animation: none;
  }
}
