/* ============================================================================
   ATOMIC LAB — PERIODIC TABLE
   The grid is 18 columns x 10 rows (7 periods, a spacer, 2 f-block rows).
   Tiles size themselves from the container, so the table always fits without
   horizontal scroll on desktop and scrolls as one unit on small screens.
   ========================================================================== */

/* Track 1 of each axis is the group/period rail. It is `auto`, so when the
   rail labels are hidden (mini variant) it collapses to zero and the same
   coordinate maths keeps working. Tiles live at (row + 1, col + 1); grid row 9
   is the gap between the main block and the f-block strip. */
.ptable {
  display: grid;
  grid-template-columns: auto repeat(18, minmax(0, 1fr));
  grid-template-rows: auto repeat(7, minmax(0, 1fr)) clamp(0.4rem, 1.1vw, 1rem) repeat(2, minmax(0, 1fr));
  gap: clamp(2px, 0.32vw, 5px);
  width: 100%;
  container-type: inline-size;
}

.ptable__rail {
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: clamp(7px, 0.85cqi, 10px);
  letter-spacing: 0.08em;
  color: var(--ink-3);
  opacity: 0.75;
  user-select: none;
}
.ptable__rail--p { padding-inline-end: 0.35rem; }
.ptable--mini .ptable__rail { display: none; }

/* --- tiles ------------------------------------------------------------- */
.el {
  --c: var(--f-unknown);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 6% 7%;
  aspect-ratio: 1 / 1.06;
  min-width: 0;
  border-radius: clamp(3px, 0.45cqi, 7px);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--c) 30%, transparent), color-mix(in srgb, var(--c) 9%, transparent) 62%),
    rgba(255, 255, 255, 0.022);
  border: 1px solid color-mix(in srgb, var(--c) 34%, transparent);
  color: var(--ink);
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 180ms var(--e-spring),
    box-shadow 180ms var(--e-out),
    border-color 180ms var(--e-out),
    background 320ms var(--e-out),
    opacity 220ms var(--e-out);
}

.el::before {
  content: '';
  position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 62%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity 180ms var(--e-out);
}

.el:hover, .el:focus-visible {
  transform: translateY(-3px) scale(1.06);
  z-index: 20;
  border-color: var(--c);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--c) 60%, transparent),
    0 10px 30px -6px color-mix(in srgb, var(--c) 55%, transparent),
    0 4px 14px rgba(0,0,0,0.6);
}
.el:hover::before, .el:focus-visible::before { opacity: 1; }

.el__z {
  font-family: var(--font-mono);
  font-size: clamp(6px, 1.05cqi, 11px);
  line-height: 1;
  color: color-mix(in srgb, var(--c) 62%, white 38%);
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}
.el__s {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(11px, 2.35cqi, 25px);
  line-height: 1.02;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow: 0 1px 10px color-mix(in srgb, var(--c) 55%, transparent);
}
.el__n {
  font-size: clamp(5px, 0.82cqi, 9.5px);
  line-height: 1.15;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.el__v {
  font-size: clamp(5px, 0.8cqi, 9px);
  line-height: 1.1;
  color: color-mix(in srgb, var(--c) 55%, white 45%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.el.is-nodata { --c: #2a3145; }
.el.is-nodata .el__s { color: var(--ink-3); text-shadow: none; }

/* Filter dimming */
.el.is-off { opacity: 0.14; filter: saturate(0.25); pointer-events: none; }
.ptable.is-filtered .el:not(.is-off) { box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 70%, transparent); }

/* Comparison selection */
.el.is-sel {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff, 0 0 26px -4px var(--c);
  z-index: 15;
}
.el.is-sel::after {
  content: '';
  position: absolute; top: 3px; right: 3px;
  width: 6px; height: 6px; border-radius: 50%; background: #fff;
}

/* State cues in phase mode */
.el.is-gas   { animation: gas-shimmer 3.5s var(--e-inout) infinite; }
.el.is-liquid::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0; height: 34%;
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--c) 55%, transparent));
  pointer-events: none;
}
@keyframes gas-shimmer { 0%,100% { opacity: 0.82; } 50% { opacity: 1; } }

/* f-block strip */
.el--f { opacity: 0.97; }

/* Ghost markers that point at the f-block */
.el--ghost {
  background: repeating-linear-gradient(135deg, rgba(255,255,255,0.035) 0 5px, transparent 5px 10px);
  border: 1px dashed var(--edge);
  pointer-events: none;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.el__s--ghost { font-size: clamp(6px, 1.05cqi, 11px); color: var(--ink-3); text-shadow: none; letter-spacing: 0; }

/* --- mini variant (homepage deck) -------------------------------------- */
.ptable--mini { gap: clamp(2px, 0.3vw, 4px); }
.ptable--mini .el { padding: 4% 5%; gap: 0; aspect-ratio: 1 / 1; justify-content: center; align-items: center; }
.ptable--mini .el__z { display: none; }
.ptable--mini .el__s { font-size: clamp(8px, 2.1cqi, 17px); }

@container (max-width: 640px) {
  .ptable--mini .el__s { font-size: clamp(7px, 2.4cqi, 12px); }
}

/* --- HUD internals ------------------------------------------------------ */
.hud__head { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.65rem; }
.hud__sym {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  color: #fff;
  background: color-mix(in srgb, var(--fam, var(--beam)) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--fam, var(--beam)) 45%, transparent);
  border-radius: var(--r-2);
}
.hud__head strong { font-size: var(--t-sm); font-weight: 600; }
.hud__head .mono { font-size: var(--t-3xs); letter-spacing: 0.06em; }
.hud__rows { display: flex; flex-direction: column; gap: 0.3rem; }
.hud__rows > div { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; font-size: var(--t-2xs); }
.hud__rows dt { color: var(--ink-3); white-space: nowrap; }
.hud__rows dd { color: var(--ink); text-align: right; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud__sig {
  margin-top: 0.7rem; padding-top: 0.65rem;
  border-top: 1px solid var(--edge-soft);
  font-size: var(--t-3xs); line-height: 1.55; color: var(--ink-2);
  max-width: 30ch;
  white-space: normal;
}

/* --- Legend ------------------------------------------------------------- */
.lg { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.lg__title { font-size: var(--t-3xs); letter-spacing: 0.15em; text-transform: uppercase; color: var(--ink-3); }
.lg__keys { display: flex; flex-wrap: wrap; gap: 0.35rem 0.85rem; }
.lg__key { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--t-3xs); color: var(--ink-2); font-family: var(--font-mono); letter-spacing: 0.03em; }
.lg__key i, .lg__scale i { display: block; width: 9px; height: 9px; border-radius: 2px; flex: none; }
.lg__scale { display: flex; height: 7px; border-radius: 4px; overflow: hidden; max-width: 320px; }
.lg__scale i { width: auto; flex: 1; height: 100%; border-radius: 0; }
.lg__ends { display: flex; justify-content: space-between; max-width: 320px; font-size: var(--t-3xs); color: var(--ink-3); }

/* --- Small screens: the table scrolls as one unit ----------------------- */
@media (max-width: 860px) {
  .ptable-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: var(--gutter);
    scrollbar-width: thin;
  }
  .ptable-scroll .ptable { min-width: 720px; }
  .ptable-scroll::after {
    content: 'swipe →';
    display: block; text-align: right;
    font-family: var(--font-mono); font-size: var(--t-3xs);
    letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3);
    padding-top: 0.5rem;
  }
}

/* ---------------------------------------------------------------------------
   CROSSHAIR — hovering a tile lights its period and its group
   ------------------------------------------------------------------------- */
.ptable.is-cross .el:not(.is-axis) { opacity: 0.42; }
.ptable.is-cross .el.is-axis {
  opacity: 1;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 45%, transparent);
}
.ptable.is-cross .ptable__rail { opacity: 0.35; }
.ptable .el { transition: transform 180ms var(--e-spring), box-shadow 180ms var(--e-out), border-color 180ms var(--e-out), background 320ms var(--e-out), opacity 160ms var(--e-out); }

/* ---------------------------------------------------------------------------
   TRENDS OVERLAY — rails outside the grid, textbook convention
   ------------------------------------------------------------------------- */
.tbl-stage { position: relative; }
.tbl-stage.has-trends .ptable-scroll {
  padding-top: 2.6rem;
  padding-left: 2.6rem;
  transition: padding var(--d-3) var(--e-out);
}
.ptable-scroll { transition: padding var(--d-3) var(--e-out); }

.trendlay {
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--d-3) var(--e-out);
  z-index: 30;
}
.trendlay.is-on { opacity: 1; }

.trail { position: absolute; display: flex; align-items: center; }
.trail__line {
  background: linear-gradient(90deg, transparent, var(--beam) 12%, var(--pulse));
  border-radius: 2px;
}
.trail__head {
  width: 0; height: 0;
  border-style: solid;
  filter: drop-shadow(0 0 6px var(--pulse));
}
.trail__lbl {
  position: absolute;
  font-family: var(--font-mono);
  font-size: var(--t-3xs);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: #cdf6ff;
  white-space: nowrap;
  padding: 0.3rem 0.7rem;
  background: rgba(4, 7, 12, 0.9);
  border: 1px solid rgba(89,230,255,0.3);
  border-radius: var(--r-pill);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

/* horizontal rail across the top */
.trail--top { top: 0.5rem; left: 3.2rem; right: 0.6rem; height: 1.5rem; }
.trail--top .trail__line { flex: 1; height: 2px; }
.trail--top .trail__head {
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent var(--pulse);
}
.trail--top .trail__lbl { left: 50%; transform: translateX(-50%); }

/* vertical rail down the left */
.trail--left { top: 3.2rem; bottom: 0.6rem; left: 0.5rem; width: 1.5rem; flex-direction: column; }
.trail--left .trail__line { flex: 1; width: 2px; background: linear-gradient(180deg, transparent, var(--beam) 12%, var(--pulse)); }
.trail--left .trail__head {
  border-width: 10px 6px 0 6px;
  border-color: var(--pulse) transparent transparent transparent;
}
.trail--left .trail__lbl {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center;
}

@media (max-width: 900px) {
  .tbl-stage.has-trends .ptable-scroll { padding-left: 0; padding-top: 4.5rem; }
  .trail--left { display: none; }
  .trail--top { left: 0.6rem; }
  .trail--top .trail__lbl { white-space: normal; max-width: 90vw; text-align: center; line-height: 1.4; }
}
