:root {
  --pt-alkali-metal: #eb6834;
  --pt-alkaline-earth-metal: #1baf7a;
  --pt-transition-metal: #2a78d6;
  --pt-post-transition-metal: #e87ba4;
  --pt-metalloid: #008300;
  --pt-nonmetal: #0d7f86;
  --pt-halogen: #4a3aa7;
  --pt-noble-gas: #e34948;
  --pt-lanthanide: #eda100;
  --pt-actinide: #be3a6f;
  --pt-tint: 13%;
  --pt-edge: 42%;
  --pt-heat-0: #cde2fb;
  --pt-heat-1: #3987e5;
  --pt-heat-2: #0d366b;
  --pt-heat-flip: 0.575;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pt-alkali-metal: #d95926;
    --pt-alkaline-earth-metal: #199e70;
    --pt-transition-metal: #3987e5;
    --pt-post-transition-metal: #d55181;
    --pt-metalloid: #1f9a1f;
    --pt-nonmetal: #2aa9b1;
    --pt-halogen: #9085e9;
    --pt-noble-gas: #e66767;
    --pt-lanthanide: #c98500;
    --pt-actinide: #e0709c;
    --pt-tint: 17%;
    --pt-edge: 46%;
    --pt-heat-0: #0d366b;
    --pt-heat-1: #2a78d6;
    --pt-heat-2: #cde2fb;
    --pt-heat-flip: 0.48;
  }
}

:root[data-theme="dark"] {
  --pt-alkali-metal: #d95926;
  --pt-alkaline-earth-metal: #199e70;
  --pt-transition-metal: #3987e5;
  --pt-post-transition-metal: #d55181;
  --pt-metalloid: #1f9a1f;
  --pt-nonmetal: #2aa9b1;
  --pt-halogen: #9085e9;
  --pt-noble-gas: #e66767;
  --pt-lanthanide: #c98500;
  --pt-actinide: #e0709c;
  --pt-tint: 17%;
  --pt-edge: 46%;
  --pt-heat-0: #0d366b;
  --pt-heat-1: #2a78d6;
  --pt-heat-2: #cde2fb;
  --pt-heat-flip: 0.48;
}

[data-category="alkali-metal"] { --cat: var(--pt-alkali-metal); }
[data-category="alkaline-earth-metal"] { --cat: var(--pt-alkaline-earth-metal); }
[data-category="transition-metal"] { --cat: var(--pt-transition-metal); }
[data-category="post-transition-metal"] { --cat: var(--pt-post-transition-metal); }
[data-category="metalloid"] { --cat: var(--pt-metalloid); }
[data-category="nonmetal"] { --cat: var(--pt-nonmetal); }
[data-category="halogen"] { --cat: var(--pt-halogen); }
[data-category="noble-gas"] { --cat: var(--pt-noble-gas); }
[data-category="lanthanide"] { --cat: var(--pt-lanthanide); }
[data-category="actinide"] { --cat: var(--pt-actinide); }

.pt {
  --pt-width: max(100%, min(100vw - 64px, 1392px));
  width: var(--pt-width);
  margin-inline: calc((100% - var(--pt-width)) / 2);
}

.pt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
}

.pt-search {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.pt-search-field {
  position: relative;
  display: flex;
  align-items: center;
  width: 260px;
}

.pt-search-field .icon {
  position: absolute;
  left: 10px;
  color: var(--text-subtle);
  pointer-events: none;
}

.pt-search-field .input {
  padding-left: 32px;
}

.pt-count {
  color: var(--text-subtle);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pt-modes {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}

.pt-modes-label {
  color: var(--text-subtle);
  font-size: 12.5px;
  white-space: nowrap;
}

.pt-modes .chip {
  height: 26px;
  font-size: 12.5px;
}

.pt-legend {
  display: flex;
  align-items: center;
  min-height: 34px;
  margin: var(--space-3) 0 var(--space-2);
}

.pt-legend-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 2px var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pt-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: nowrap;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.pt-legend-item:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.pt-legend-item[aria-pressed="true"] {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.pt-swatch {
  display: inline-block;
  flex: none;
  width: 11px;
  height: 11px;
  border: 1px solid color-mix(in oklab, var(--cat, var(--border-strong)) 70%, var(--surface));
  border-radius: 3px;
  background: color-mix(in oklab, var(--cat, var(--surface-raised)) 45%, var(--surface));
}

.pt-swatch-missing {
  border-color: var(--border-strong);
  background: var(--surface-raised);
}

.pt-scale {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-5);
  font-size: 12.5px;
}

.pt-scale-title {
  color: var(--text);
  font-weight: 500;
}

.pt-scale-unit {
  color: var(--text-muted);
  font-weight: 400;
}

.pt-scale-range {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.pt-scale-bar {
  width: 180px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(in oklab 90deg, var(--pt-heat-0), var(--pt-heat-1), var(--pt-heat-2));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 8%, transparent);
}

.pt-scale-missing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.pt-scroll {
  overflow-x: auto;
  padding-bottom: 2px;
}

.pt-frame {
  container: pt / inline-size;
  display: grid;
  min-width: 720px;
}

.pt-table,
.pt-overlay {
  --gap: 3px;
  --label: 20px;
  --cell: calc((100cqi - var(--label) - 18 * var(--gap)) / 18);
  --row: calc(var(--cell) * 1.04);
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: var(--label) repeat(18, minmax(0, 1fr));
  grid-template-rows: 22px repeat(7, var(--row)) max(8px, calc(var(--cell) * 0.28)) repeat(2, var(--row));
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pt-overlay {
  pointer-events: none;
}

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

.pt-element {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  justify-items: center;
  align-items: center;
  width: 100%;
  min-width: 0;
  padding: 4px 2px 5px;
  border: 1px solid color-mix(in oklab, var(--cat, var(--border-strong)) var(--pt-edge), var(--surface));
  border-radius: 7px;
  background: color-mix(in oklab, var(--cat, var(--surface-raised)) var(--pt-tint), var(--surface));
  color: var(--text);
  font-size: 10px;
  line-height: 1.12;
  text-align: center;
  transition: transform 120ms var(--ease-out), box-shadow 120ms ease, opacity 150ms ease;
}

.pt-element:hover {
  z-index: 2;
  border-color: color-mix(in oklab, var(--cat, var(--border-strong)) 80%, var(--surface));
  box-shadow: var(--shadow-medium);
  transform: translateY(-1px);
}

.pt-element:focus-visible {
  z-index: 3;
  outline-offset: 1px;
}

.pt-element[aria-current="true"] {
  z-index: 1;
  box-shadow: inset 0 0 0 2px var(--text);
}

.pt-number {
  justify-self: start;
  padding-left: 2px;
  color: var(--text-muted);
  font-size: 1.05em;
  font-variant-numeric: tabular-nums;
}

.pt-symbol {
  font-size: 2.4em;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1;
}

.pt-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.95em;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.pt-value {
  margin-top: 1px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pt[data-mode="electronegativity"] .pt-cell { --t: var(--t-electronegativity); }
.pt[data-mode="radius"] .pt-cell { --t: var(--t-radius); }
.pt[data-mode="ionization"] .pt-cell { --t: var(--t-ionization); }
.pt[data-mode="affinity"] .pt-cell { --t: var(--t-affinity); }
.pt[data-mode="melting"] .pt-cell { --t: var(--t-melting); }
.pt[data-mode="boiling"] .pt-cell { --t: var(--t-boiling); }
.pt[data-mode="density"] .pt-cell { --t: var(--t-density); }
.pt[data-mode="discovered"] .pt-cell { --t: var(--t-discovered); }

.pt:not([data-mode="category"]) :is(.pt-element, .pt-inset-tile) {
  --heat: color-mix(in oklab, var(--pt-heat-2) calc(clamp(0, var(--t) * 2 - 1, 1) * 100%), color-mix(in oklab, var(--pt-heat-1) calc(clamp(0, var(--t) * 2, 1) * 100%), var(--pt-heat-0)));
  --ink: color-mix(in srgb, var(--primary-contrast) calc(clamp(0, (var(--t) - var(--pt-heat-flip)) * 1000, 1) * 100%), var(--text));
  border-color: var(--heat, var(--border));
  background: var(--heat, var(--surface-raised));
  color: var(--ink, var(--text-subtle));
}

.pt:not([data-mode="category"]) :is(.pt-number, .pt-name, .pt-value, .pt-inset-number, .pt-inset-weight) {
  color: inherit;
  opacity: 0.82;
}

.pt:not([data-mode="category"]) .pt-value {
  opacity: 1;
  font-weight: 550;
}

.pt:not([data-mode="category"]) .pt-element[aria-current="true"] {
  box-shadow: inset 0 0 0 2px var(--ink, var(--text)), 0 0 0 1px var(--text);
}

.pt[data-filtering] .pt-cell:not([data-match]) .pt-element,
.pt[data-highlight] .pt-cell:not([data-lit]) .pt-element {
  opacity: 0.2;
}

.pt[data-filtering] .pt-cell[data-match] .pt-element {
  box-shadow: 0 0 0 2px var(--accent);
}

.pt[data-filtering] .pt-cell[data-match] .pt-element[aria-current="true"] {
  box-shadow: inset 0 0 0 2px var(--text), 0 0 0 2px var(--accent);
}

.pt-group,
.pt-period {
  color: var(--text-subtle);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pt-group {
  align-self: end;
  justify-self: center;
  padding-bottom: 5px;
}

.pt-period {
  align-self: center;
  justify-self: start;
}

.pt-placeholder {
  display: grid;
  place-items: center;
  border: 1px dashed color-mix(in oklab, var(--cat) var(--pt-edge), var(--surface));
  border-radius: clamp(4px, calc(var(--cell) * 0.09), 7px);
  background: color-mix(in oklab, var(--cat) calc(var(--pt-tint) * 0.6), var(--surface));
  color: var(--text-muted);
  font-size: clamp(7px, calc(var(--cell) * 0.13), 10.5px);
  font-variant-numeric: tabular-nums;
}

.pt:not([data-mode="category"]) .pt-placeholder {
  border-color: var(--border);
  background: none;
}

.pt-inset {
  grid-area: 2 / 4 / 5 / 14;
  display: flex;
  align-items: stretch;
  min-width: 0;
  padding: calc(var(--row) * 0.12) calc(var(--cell) * 0.35) calc(var(--row) * 0.2);
}

.pt-inset-card {
  display: flex;
  align-items: center;
  gap: calc(var(--cell) * 0.32);
  width: 100%;
  min-width: 0;
}

.pt-inset-tile {
  display: grid;
  grid-template-rows: auto 1fr auto;
  flex: none;
  height: 100%;
  aspect-ratio: 1;
  padding: calc(var(--cell) * 0.14);
  border: 1px solid color-mix(in oklab, var(--cat) var(--pt-edge), var(--surface));
  border-radius: 12px;
  background: color-mix(in oklab, var(--cat) calc(var(--pt-tint) + 4%), var(--surface));
  box-shadow: var(--shadow-small);
}

.pt-inset-number {
  color: var(--text-muted);
  font-size: clamp(11px, calc(var(--cell) * 0.2), 15px);
  font-variant-numeric: tabular-nums;
}

.pt-inset-symbol {
  align-self: center;
  justify-self: center;
  font-size: calc(var(--row) * 0.95);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1;
}

.pt-inset-weight {
  justify-self: center;
  color: var(--text-muted);
  font-size: clamp(11px, calc(var(--cell) * 0.19), 14px);
  font-variant-numeric: tabular-nums;
}

.pt-inset-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.pt-inset-name {
  font-size: clamp(16px, calc(var(--cell) * 0.34), 24px);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.pt-inset-meta {
  color: var(--text-muted);
  font-size: 12.5px;
}

.pt-inset-configuration {
  font-size: 13.5px;
}

.pt-configuration sup {
  font-size: 0.72em;
  line-height: 0;
}

.pt-configuration small {
  color: var(--text-subtle);
  font-size: 0.85em;
}

.pt-inset-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, max-content));
  gap: 4px var(--space-6);
  margin: calc(var(--row) * 0.08) 0 0;
  font-size: 12.5px;
}

.pt-inset-facts div {
  display: grid;
  gap: 0;
  min-width: 0;
}

.pt-inset-facts dt {
  color: var(--text-subtle);
  font-size: 11.5px;
}

.pt-inset-facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pt-inset-facts .current dd {
  font-weight: 600;
}

.pt-inset-hint {
  display: grid;
  align-content: center;
  gap: var(--space-2);
  max-width: 460px;
  color: var(--text-subtle);
  font-size: 13px;
  line-height: 1.55;
}

.pt-details {
  margin-top: var(--space-6);
}

.pt-details-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-5);
  color: var(--text-subtle);
  font-size: 14px;
  text-align: center;
}

.pt-details .panel-header h2 {
  gap: var(--space-3);
  font-size: 16px;
}

.pt-details .panel-header h2:focus-visible {
  outline-offset: 4px;
}

.pt-details .panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.pt-details-mark {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid color-mix(in oklab, var(--cat) var(--pt-edge), var(--surface));
  border-radius: var(--radius);
  background: color-mix(in oklab, var(--cat) calc(var(--pt-tint) + 4%), var(--surface));
  font-size: 15px;
  font-weight: 650;
}

.pt-details-body > * + * {
  margin-top: var(--space-6);
}

.pt-details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-5) var(--space-10);
  align-items: start;
}

.pt-isotopes-section h3 {
  margin-bottom: var(--space-3);
  font-size: 14px;
  font-weight: 600;
}

.pt-isotopes-section > p {
  margin-bottom: var(--space-3);
  font-size: 13.5px;
}

.pt-isotopes :is(th, td) {
  vertical-align: baseline;
}

.pt-isotopes .numeric {
  text-align: right;
}

.pt-isotopes td.numeric {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.pt-isotopes th[scope="row"] {
  padding-block: 9px;
  background: none;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
}

.pt-isotopes sup,
.pt-details sup {
  line-height: 0;
}

.pt-isotopes tbody tr:last-child > * {
  border-bottom: 0;
}

.pt-more {
  border-top: 1px solid var(--border);
}

.pt-more summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) 0 0;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
}

.pt-more summary::-webkit-details-marker {
  display: none;
}

.pt-more summary::after {
  content: "+";
  color: var(--text-subtle);
  font-size: 17px;
  font-weight: 400;
}

.pt-more[open] summary::after {
  content: "\2212";
}

.pt-more[open] .facts {
  margin-top: var(--space-4);
}

.pt-cpk {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.pt-cpk-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
}

.pt-sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: none;
  max-height: 88dvh;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-bottom: 0;
  border-radius: var(--radius-extra-large) var(--radius-extra-large) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-large);
  animation: pt-sheet-in 240ms var(--ease-out);
}

.pt-sheet::backdrop {
  background: var(--overlay);
}

.pt-sheet .panel-header {
  position: sticky;
  top: 0;
  z-index: 1;
  flex-wrap: wrap;
  row-gap: var(--space-2);
  border-radius: inherit;
  background: var(--surface);
}

.pt-sheet .panel-actions {
  order: 3;
  width: 100%;
  gap: var(--space-2);
}

.pt-sheet .panel-header h2 {
  gap: var(--space-3);
  font-size: 16px;
}

@keyframes pt-sheet-in {
  from {
    opacity: 0;
    transform: translateY(32px);
  }
}

@container pt (width < 1300px) {
  .pt-element {
    font-size: 9px;
  }
}

@container pt (width < 1180px) {
  .pt-name {
    display: none;
  }

  .pt-element {
    font-size: 8.5px;
  }
}

@container pt (width < 1000px) {
  .pt-element {
    padding: 3px 1px 4px;
    border-radius: 5px;
    font-size: 8px;
  }

  .pt-symbol {
    font-size: 2.2em;
  }
}

@container pt (width < 900px) {
  .pt-inset {
    display: none;
  }
}

@container pt (width < 820px) {
  .pt-value {
    display: none;
  }

  .pt-element {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .pt-symbol {
    padding-bottom: 2px;
    font-size: 2em;
  }
}

@media (max-width: 920px) {
  .pt-details-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 719px) {
  .pt-toolbar {
    align-items: stretch;
    flex-direction: column;
    flex-wrap: nowrap;
  }

  .pt-search-field {
    flex: 1;
    width: auto;
  }

  .pt-modes {
    margin-inline: calc(var(--space-4) * -1);
    padding-inline: var(--space-4);
    overflow-x: auto;
  }

  .pt-modes .chips {
    flex-wrap: nowrap;
  }

  .pt-scroll {
    margin-inline: calc(var(--space-4) * -1);
    padding-inline: var(--space-4);
  }

  .pt {
    display: flex;
    flex-direction: column;
  }

  .pt-legend {
    order: 1;
    margin-top: var(--space-2);
  }

  .pt-details {
    order: 2;
  }

  .pt-details .stat-value {
    font-size: 19px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pt-sheet {
    animation: none;
  }

  .pt-element:hover {
    transform: none;
  }
}
