/* Interactive Periodic Table - self-contained styles */

:root {
  --bg: #0f1720;
  --panel: #182430;
  --text: #e8edf2;
  --text-dim: #9fb0c0;
  --border: rgba(255, 255, 255, 0.08);

  /* Category colors */
  --c-alkali-metal: #ff6b6b;
  --c-alkaline-earth-metal: #ffa94d;
  --c-transition-metal: #ffd43b;
  --c-post-transition-metal: #a9e34b;
  --c-metalloid: #38d9a9;
  --c-nonmetal: #4dabf7;
  --c-halogen: #74c0fc;
  --c-noble-gas: #b197fc;
  --c-lanthanide: #f783ac;
  --c-actinide: #e599f7;
  --c-unknown: #adb5bd;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1.25rem;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* White full-width top bar for the site logo */
.pt-topbar { background: #fff; margin: -1.25rem -1.25rem 1.25rem; padding: 0.55rem 1.25rem; }
.pt-logo { display: inline-flex; line-height: 0; }
.pt-logo img { height: 38px; width: auto; display: block; }

.pt-header { text-align: center; margin-bottom: 1rem; }
.pt-header h1 { margin: 0 0 0.25rem; font-size: 1.8rem; }
.pt-subtitle { margin: 0; color: var(--text-dim); font-size: 0.95rem; }

.pt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  max-width: 1200px;
  margin: 0 auto 1.25rem;
}
.pt-search {
  flex: 1 1 260px;
  min-width: 200px;
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
.pt-search:focus { outline: 2px solid var(--c-nonmetal); outline-offset: 1px; }
.pt-clear {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.pt-clear:hover { background: #223141; }
.pt-count { color: var(--text-dim); font-size: 0.9rem; }

.pt-layout {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  max-width: 1200px;
  margin: 0 auto;
}

/* The table scrolls horizontally on small screens */
.pt-table-wrap {
  flex: 1 1 auto;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  position: relative;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* Fading edge hint that more columns are scrollable off to the right (touch devices) */
.pt-table-wrap::after {
  content: "";
  position: sticky;
  top: 0;
  right: 0;
  float: right;
  width: 22px;
  height: 100%;
  margin-right: -22px;
  pointer-events: none;
  background: linear-gradient(to right, transparent, var(--bg));
  opacity: 0;
}
@media (hover: none) and (pointer: coarse) {
  .pt-table-wrap::after { opacity: 1; }
}

.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(44px, 1fr));
  grid-auto-rows: 1fr;
  gap: 3px;
  min-width: 820px;
}

/* An element tile keeps a square-ish shape */
.element {
  grid-column: var(--x);
  grid-row: var(--y);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  aspect-ratio: 1 / 1;
  padding: 3px 4px;
  border: none;
  border-radius: 4px;
  color: #10202a;
  background: var(--c-unknown);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.08s ease, box-shadow 0.08s ease, opacity 0.15s ease;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
}
.element:hover { transform: scale(1.08); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); z-index: 5; }
.element.selected { outline: 3px solid #fff; outline-offset: -1px; z-index: 4; }
.element.dimmed { opacity: 0.18; }

.el-number { font-size: 0.6rem; font-weight: 600; line-height: 1; }
.el-symbol { font-size: 1.1rem; font-weight: 700; line-height: 1.1; }
.el-name { font-size: 0.42rem; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.el-mass { font-size: 0.42rem; line-height: 1; opacity: 0.85; }

.series-marker {
  cursor: default;
  justify-content: center;
  align-items: center;
  opacity: 0.85;
}
.series-marker .el-symbol { font-size: 0.7rem; }

/* Category background colors */
.cat-alkali-metal { background: var(--c-alkali-metal); }
.cat-alkaline-earth-metal { background: var(--c-alkaline-earth-metal); }
.cat-transition-metal { background: var(--c-transition-metal); }
.cat-post-transition-metal { background: var(--c-post-transition-metal); }
.cat-metalloid { background: var(--c-metalloid); }
.cat-nonmetal { background: var(--c-nonmetal); }
.cat-halogen { background: var(--c-halogen); }
.cat-noble-gas { background: var(--c-noble-gas); }
.cat-lanthanide { background: var(--c-lanthanide); }
.cat-actinide { background: var(--c-actinide); }
.cat-unknown { background: var(--c-unknown); }

/* Sidebar: detail + legend */
.pt-sidebar { flex: 0 0 240px; display: flex; flex-direction: column; gap: 1rem; }

.pt-detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  min-height: 180px;
  position: relative;
  border-top: 5px solid var(--c-unknown);
}
.pt-detail.cat-alkali-metal { border-top-color: var(--c-alkali-metal); }
.pt-detail.cat-alkaline-earth-metal { border-top-color: var(--c-alkaline-earth-metal); }
.pt-detail.cat-transition-metal { border-top-color: var(--c-transition-metal); }
.pt-detail.cat-post-transition-metal { border-top-color: var(--c-post-transition-metal); }
.pt-detail.cat-metalloid { border-top-color: var(--c-metalloid); }
.pt-detail.cat-nonmetal { border-top-color: var(--c-nonmetal); }
.pt-detail.cat-halogen { border-top-color: var(--c-halogen); }
.pt-detail.cat-noble-gas { border-top-color: var(--c-noble-gas); }
.pt-detail.cat-lanthanide { border-top-color: var(--c-lanthanide); }
.pt-detail.cat-actinide { border-top-color: var(--c-actinide); }

.detail-hint { color: var(--text-dim); margin: 0; font-size: 0.9rem; }
.detail-symbol { font-size: 2.6rem; font-weight: 700; line-height: 1; }
.detail-number { position: absolute; top: 1.25rem; right: 1.25rem; color: var(--text-dim); font-size: 1.1rem; font-weight: 600; }
.detail-name { margin: 0.35rem 0 0.75rem; font-size: 1.25rem; }
.detail-props { margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.detail-props div { display: flex; justify-content: space-between; gap: 1rem; border-top: 1px solid var(--border); padding-top: 0.5rem; }
.detail-props dt { color: var(--text-dim); font-size: 0.85rem; margin: 0; }
.detail-props dd { margin: 0; font-size: 0.9rem; font-weight: 500; text-align: right; }
.detail-link {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  background: var(--c-nonmetal);
  color: #10202a;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}
.detail-link:hover { filter: brightness(1.08); }

.pt-legend { display: flex; flex-direction: column; gap: 0.25rem; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
}
.legend-item:hover { background: var(--panel); }
.legend-item.active { border-color: var(--border); background: var(--panel); font-weight: 600; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; background: var(--c-unknown); }
.legend-item.cat-alkali-metal .legend-swatch { background: var(--c-alkali-metal); }
.legend-item.cat-alkaline-earth-metal .legend-swatch { background: var(--c-alkaline-earth-metal); }
.legend-item.cat-transition-metal .legend-swatch { background: var(--c-transition-metal); }
.legend-item.cat-post-transition-metal .legend-swatch { background: var(--c-post-transition-metal); }
.legend-item.cat-metalloid .legend-swatch { background: var(--c-metalloid); }
.legend-item.cat-nonmetal .legend-swatch { background: var(--c-nonmetal); }
.legend-item.cat-halogen .legend-swatch { background: var(--c-halogen); }
.legend-item.cat-noble-gas .legend-swatch { background: var(--c-noble-gas); }
.legend-item.cat-lanthanide .legend-swatch { background: var(--c-lanthanide); }
.legend-item.cat-actinide .legend-swatch { background: var(--c-actinide); }

/* Stack sidebar under the table on narrow screens */
@media (max-width: 860px) {
  .pt-layout { flex-direction: column; }
  .pt-sidebar { flex-basis: auto; width: 100%; }
  .pt-legend { flex-direction: row; flex-wrap: wrap; }
  .legend-item { flex: 0 0 auto; }
}

/* Phones: the table is TRANSPOSED so it fits the screen width with no
   horizontal scrolling. Periods (1-7) run left to right as columns and the
   18 groups run top to bottom as rows; the lanthanide/actinide series sit in
   two extra columns on the right, next to the transition metals. */
@media (max-width: 600px) {
  body { padding: 0.6rem; }

  .pt-topbar { margin: -0.6rem -0.6rem 0.85rem; padding: 0.45rem 0.75rem; }
  .pt-logo img { height: 30px; }

  .pt-header h1 { font-size: 1.35rem; }
  .pt-subtitle { font-size: 0.85rem; }

  .pt-toolbar { gap: 0.5rem; margin-bottom: 0.85rem; }
  .pt-search { flex: 1 1 100%; }
  .pt-clear { flex: 0 0 auto; }
  .pt-count { flex: 1 1 auto; text-align: right; }

  .pt-layout { gap: 1rem; }

  /* No more sideways scrolling: everything fits the viewport */
  .pt-table-wrap { overflow-x: visible; padding-bottom: 0; }
  .pt-table-wrap::after { display: none; }

  .pt-grid {
    /* 7 period columns, a slim spacer, then the 2 f-block series columns */
    grid-template-columns: repeat(7, minmax(0, 1fr)) 6px repeat(2, minmax(0, 1fr));
    grid-auto-rows: auto;
    gap: 2px;
    min-width: 0;
  }

  /* Swap the axes: the original column becomes the row and vice versa */
  .element {
    grid-column: var(--y);
    grid-row: var(--x);
    aspect-ratio: 1 / 1.18;
    padding: 2px 3px;
    border-radius: 3px;
  }
  .element:hover { transform: none; box-shadow: none; }

  .el-number { font-size: 0.55rem; }
  .el-symbol { font-size: 0.95rem; }
  .el-name { display: none; }
  .el-mass { font-size: 0.42rem; }
  .series-marker .el-symbol { font-size: 0.55rem; line-height: 1.1; text-align: center; }

  /* On a phone, tapping a tile opens its page, so the hover-preview panel is
     not useful; show the (filterable) legend above the table instead. */
  .pt-sidebar { order: -1; }
  .pt-detail { display: none; }
  .legend-item { padding: 0.35rem 0.55rem; font-size: 0.75rem; }
}
