/* ============================================================
   Periodic table (apps/periodic, js/periodic-table.js)
   Loaded on every page by base.html (Swup needs the same stylesheet
   set everywhere), so every rule is scoped under .page-periodic, the
   class the table and element pages put on #swup.
   The grid itself is always left-to-right (dir="ltr" on .pt-grid);
   everything around it follows the page's direction.
   ============================================================ */

.page-periodic {
  /* Element type colours: a light tint for the tile and an ink for its
     text (contrast ≥ 4.5:1 on the tint). */
  --pt-alkali-bg: #fde2d8;      --pt-alkali-ink: #9a3412;
  --pt-alkaline-bg: #fdf0c4;    --pt-alkaline-ink: #7c4a03;
  --pt-transition-bg: var(--blue-100); --pt-transition-ink: var(--blue-800);
  --pt-post-bg: #e2e8f0;        --pt-post-ink: #334155;
  --pt-lanthanide-bg: #f1e3fb;  --pt-lanthanide-ink: #6b21a8;
  --pt-actinide-bg: #fbe1ee;    --pt-actinide-ink: #9d174d;
  --pt-metalloid-bg: #d5f1ed;   --pt-metalloid-ink: #115e59;
  --pt-nonmetal-bg: var(--green-50); --pt-nonmetal-ink: var(--green-700);
  --pt-halogen-bg: #e6f5d3;     --pt-halogen-ink: #3f6212;
  --pt-noble-bg: #e4e2fb;       --pt-noble-ink: #3730a3;
  --pt-unknown-bg: #eceeed;     --pt-unknown-ink: var(--neutral-700);
  --pt-gap: 4px;
}

.page-periodic .pt-tile--alkali     { --pt-bg: var(--pt-alkali-bg);     --pt-ink: var(--pt-alkali-ink); }
.page-periodic .pt-tile--alkaline   { --pt-bg: var(--pt-alkaline-bg);   --pt-ink: var(--pt-alkaline-ink); }
.page-periodic .pt-tile--transition { --pt-bg: var(--pt-transition-bg); --pt-ink: var(--pt-transition-ink); }
.page-periodic .pt-tile--post       { --pt-bg: var(--pt-post-bg);       --pt-ink: var(--pt-post-ink); }
.page-periodic .pt-tile--lanthanide { --pt-bg: var(--pt-lanthanide-bg); --pt-ink: var(--pt-lanthanide-ink); }
.page-periodic .pt-tile--actinide   { --pt-bg: var(--pt-actinide-bg);   --pt-ink: var(--pt-actinide-ink); }
.page-periodic .pt-tile--metalloid  { --pt-bg: var(--pt-metalloid-bg);  --pt-ink: var(--pt-metalloid-ink); }
.page-periodic .pt-tile--nonmetal   { --pt-bg: var(--pt-nonmetal-bg);   --pt-ink: var(--pt-nonmetal-ink); }
.page-periodic .pt-tile--halogen    { --pt-bg: var(--pt-halogen-bg);    --pt-ink: var(--pt-halogen-ink); }
.page-periodic .pt-tile--noble      { --pt-bg: var(--pt-noble-bg);      --pt-ink: var(--pt-noble-ink); }
.page-periodic .pt-tile--unknown    { --pt-bg: var(--pt-unknown-bg);    --pt-ink: var(--pt-unknown-ink); }

/* ---- hero ---- */
.page-periodic .pt-hero { padding-block-end: 32px; }
.page-periodic .pt-hero .news-hero__text { max-width: 680px; }

/* ---- section ---- */
.page-periodic .pt {
  padding: 32px var(--page-pad) 72px;
}

.page-periodic .pt__inner {
  max-width: 1296px;
  margin-inline: auto;
}

/* ---- filters / legend ---- */
.page-periodic .pt-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-block-end: 20px;
}

.page-periodic .pt-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--slate-200);
  border-radius: 9999px;
  background: #fff;
  color: var(--neutral-700);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.page-periodic .pt-chip:hover { border-color: var(--neutral-500); }

.page-periodic .pt-chip[aria-pressed="true"] {
  border-color: var(--blue-600);
  background: var(--blue-100);
  color: var(--blue-800);
}

.page-periodic .pt-chip--group { font-weight: 700; }
.page-periodic .pt-chip[hidden] { display: none; }

.page-periodic .pt-chip:focus-visible,
.page-periodic .pt-tile:focus-visible,
.page-periodic .pt-drawer__close:focus-visible {
  outline: 2px solid var(--blue-500);
  outline-offset: 2px;
}

.page-periodic .pt-chip__swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--pt-bg);
  box-shadow: inset 0 0 0 1px var(--pt-ink);
}

.page-periodic .pt-hint {
  display: none;
  margin: 0 0 8px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--neutral-500);
}

/* ---- grid ---- */
.page-periodic .pt-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-block: 4px 12px;
  -webkit-overflow-scrolling: touch;
}

.page-periodic .pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(56px, 1fr));
  grid-template-rows: repeat(7, auto) 14px repeat(2, auto);
  gap: var(--pt-gap);
  min-width: calc(18 * 56px + 17 * var(--pt-gap));
  margin: 0;
  padding: 2px;
  list-style: none;
}

.page-periodic .pt-cell { display: flex; min-width: 0; }

.page-periodic .pt-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1.08;
  padding: 4px 3px;
  border: 1px solid color-mix(in srgb, var(--pt-ink) 22%, transparent);
  border-radius: 6px;
  background: var(--pt-bg);
  color: var(--pt-ink);
  font-family: var(--font-sans);
  text-align: center;
  text-decoration: none;
  transition: box-shadow .15s ease, transform .15s ease;
}

.page-periodic a.pt-tile:hover {
  z-index: 1;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow-ink-10);
}

.page-periodic .pt-tile.is-active {
  box-shadow: 0 0 0 2px var(--pt-ink);
}

.page-periodic .pt-tile__number {
  align-self: flex-start;
  font-size: 10px;
  font-weight: 600;
  line-height: 12px;
}

.page-periodic .pt-tile__symbol {
  font-family: var(--font-display-ds);
  font-size: 20px;
  font-weight: 800;
  line-height: 24px;
}

/* One or two CJK characters are legible only a little larger than Latin names. */
.page-periodic .pt-tile__name:lang(zh-hans) { font-size: 12px; }

.page-periodic .pt-tile__name {
  max-width: 100%;
  overflow: hidden;
  font-size: 9.5px;
  font-weight: 500;
  line-height: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.page-periodic .pt-tile__weight {
  font-size: 9px;
  line-height: 11px;
  opacity: .85;
}

.page-periodic .pt-tile--marker {
  font-size: 11px;
  font-weight: 700;
  border-style: dashed;
}

.page-periodic .pt-note {
  margin: 20px 0 0;
  max-width: 780px;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 18px;
  color: var(--neutral-500);
}

@media (max-width: 1200px) {
  .page-periodic .pt-hint { display: block; }
}

@media (max-width: 768px) {
  .page-periodic .pt { padding-block-start: 24px; }
  .page-periodic .pt-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-inline: calc(-1 * var(--page-pad));
    padding-inline: var(--page-pad);
    padding-block-end: 4px;
  }
  .page-periodic .pt-chip { flex: none; }
}

/* ---- element details (side panel and element page) ---- */
.page-periodic .pt-details { font-family: var(--font-sans); color: var(--neutral-black); }

.page-periodic .pt-details__head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-block-end: 20px;
}

.page-periodic .pt-details__tile {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 96px;
  padding: 6px;
  border: 1px solid color-mix(in srgb, var(--pt-ink) 22%, transparent);
  border-radius: 10px;
  background: var(--pt-bg);
  color: var(--pt-ink);
}

.page-periodic .pt-details__tile .pt-tile__number { font-size: 12px; line-height: 14px; }
.page-periodic .pt-details__tile .pt-tile__weight { font-size: 11px; line-height: 14px; }

.page-periodic .pt-details__symbol {
  font-family: var(--font-display-ds);
  font-size: 36px;
  font-weight: 800;
  line-height: 42px;
}

.page-periodic .pt-details__name {
  margin: 0 0 8px;
  font-family: var(--font-display-ds);
  font-size: 30px;
  font-weight: 800;
  line-height: 36px;
  color: var(--neutral-black);
}

.page-periodic .pt-details__type {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--pt-bg);
  color: var(--pt-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
}

.page-periodic .pt-props {
  display: grid;
  margin: 0;
  border-block-start: 1px solid var(--neutral-100);
}

.page-periodic .pt-props__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 12px;
  padding-block: 9px;
  border-block-end: 1px solid var(--neutral-100);
  font-size: 14px;
  line-height: 20px;
}

.page-periodic .pt-props dt { color: var(--neutral-600); }
.page-periodic .pt-props dd { margin: 0; font-weight: 600; }
.page-periodic .pt-props sup { font-size: .7em; line-height: 0; }
.page-periodic .pt-props__note { font-weight: 400; font-size: 12px; color: var(--neutral-500); }

.page-periodic .pt-products { margin-block-start: 24px; }

.page-periodic .pt-products__title {
  margin: 0 0 12px;
  font-family: var(--font-display-ds);
  font-size: 18px;
  font-weight: 700;
  line-height: 24px;
}

.page-periodic .pt-products__list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-periodic .pt-product {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 12px;
  padding: 12px 14px;
  border: 1px solid var(--neutral-100);
  border-radius: 10px;
  background: #fff;
}

.page-periodic .pt-product__name {
  font-weight: 700;
  font-size: 14px;
  line-height: 20px;
  color: var(--neutral-black);
  text-decoration: none;
}

.page-periodic .pt-product__name:hover { color: var(--blue-600); }

.page-periodic .pt-product__meta {
  grid-column: 1;
  margin: 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--neutral-500);
}

.page-periodic .pt-product__quote {
  grid-column: 2;
  grid-row: 1 / span 2;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue-600);
  text-decoration: none;
  white-space: nowrap;
}

.page-periodic .pt-product__quote:hover { text-decoration: underline; }

.page-periodic .pt-products__empty {
  margin: 0 0 14px;
  font-size: 14px;
  line-height: 21px;
  color: var(--neutral-600);
}

.page-periodic .pt-products__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- side panel ---- */
.page-periodic .pt-drawer {
  position: fixed;
  inset: var(--header-h) 0 0;
  z-index: 50;
}

.page-periodic .pt-drawer[hidden] { display: none; }

.page-periodic .pt-drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 15, .32);
}

.page-periodic .pt-drawer__panel {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  display: flex;
  flex-direction: column;
  width: min(480px, 100%);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 28px 40px;
  background: var(--neutral-white);
  box-shadow: 0 0 40px var(--shadow-ink-25);
  outline: none;
}

.page-periodic .pt-drawer__close {
  position: sticky;
  inset-block-start: 0;
  align-self: flex-end;  /* the panel's inline end, whatever the direction */
  flex: none;
  margin-block-end: 4px;
  z-index: 1;
  box-shadow: 0 1px 4px var(--shadow-ink-10);
}


.page-periodic .pt-drawer__body.is-loading { opacity: .5; }

@media (max-width: 768px) {
  .page-periodic .pt-drawer__panel { width: 100%; padding: 20px 20px 32px; }
  .page-periodic .pt-details__name { font-size: 24px; line-height: 30px; }
}

/* ---- element page ---- */
.page-periodic .pt-page { padding: 40px var(--page-pad) 72px; }

.page-periodic .pt-page__inner { max-width: 760px; margin-inline: auto; }

.page-periodic .pt-page__crumbs { margin-block-end: 20px; }

.page-periodic .pt-page__card {
  padding: 32px;
  border: 1px solid var(--neutral-100);
  border-radius: 16px;
  background: #fff;
}

.page-periodic .pt-page__nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  margin-block-start: 24px;
  font-family: var(--font-sans);
  font-size: 14px;
}

.page-periodic .pt-page__step,
.page-periodic .pt-page__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--blue-600);
  font-weight: 600;
  text-decoration: none;
}

.page-periodic .pt-page__step--next { justify-self: end; }
.page-periodic .pt-page__step:hover,
.page-periodic .pt-page__back:hover { text-decoration: underline; }

/* The back arrow is the forward arrow turned round; .icon-dir mirrors both
   in RTL, so there the back one is drawn as is. */
.page-periodic .pt-page__arrow--back { transform: scaleX(-1); }
.page-periodic .pt-page__arrow--back:dir(rtl) { transform: none; }

@media (max-width: 768px) {
  .page-periodic .pt-page { padding-block-start: 24px; }
  .page-periodic .pt-page__card { padding: 20px; }
  .page-periodic .pt-page__nav { grid-template-columns: 1fr 1fr; }
  .page-periodic .pt-page__back { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}
