/* ============================================================================
   ATOMIC LAB — ATOM BUILDER PAGE
   ========================================================================== */

.pg-lab { --sect-y: clamp(3rem, 5vw, 5rem); }

/* Particle key colours, shared by the legend, counters and cards */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot--p { background: radial-gradient(circle at 32% 30%, #ffb0a2, #d93b26); box-shadow: 0 0 8px rgba(217,59,38,0.7); }
.dot--n { background: radial-gradient(circle at 32% 30%, #c3d4ea, #46608a); box-shadow: 0 0 8px rgba(120,160,210,0.55); }
.dot--e { background: radial-gradient(circle at 32% 30%, #eafdff, #59e6ff); box-shadow: 0 0 8px rgba(89,230,255,0.8); }

/* --- Header ------------------------------------------------------------- */
.lab-head { padding-top: calc(var(--nav-h) + clamp(1.25rem, 3vw, 2.25rem)); padding-bottom: clamp(1rem, 2vw, 1.5rem); }
.lab-head__row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-5); flex-wrap: wrap; }
.lab-head__row .lede { margin-top: 0.7rem; max-width: 60ch; }
.lab-head__row .eyebrow { margin-bottom: 0.6rem; }
.lab-head__keys { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: var(--t-3xs); color: var(--ink-3); letter-spacing: 0.06em; padding-bottom: 0.4rem; }
.lab-head__keys span { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }

/* --- Bench layout ------------------------------------------------------- */
.lab {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: clamp(0.85rem, 1.6vw, 1.25rem);
  align-items: stretch;
}

.lab__stage {
  position: relative;
  min-height: clamp(420px, 58vh, 640px);
  border: 1px solid var(--edge);
  border-radius: var(--r-4);
  background:
    radial-gradient(circle at 50% 48%, rgba(89,230,255,0.07), transparent 62%),
    radial-gradient(circle at 50% 48%, rgba(217,59,38,0.06), transparent 34%),
    rgba(5, 8, 14, 0.55);
  overflow: hidden;
}
.lab__stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

.lab__legend {
  position: absolute; top: 1rem; left: 1rem;
  display: flex; flex-direction: column; gap: 0.4rem;
  font-family: var(--font-mono); font-size: var(--t-3xs);
  letter-spacing: 0.1em; color: var(--ink-2);
  pointer-events: none;
}
.lab__legend span { display: inline-flex; align-items: center; gap: 0.45rem; }

.lab__reset { position: absolute; top: 1rem; right: 1rem; }
.lab__hint {
  position: absolute; bottom: 1rem; right: 1rem;
  font-size: var(--t-3xs); letter-spacing: 0.1em; color: var(--ink-3);
  opacity: 0.7; pointer-events: none;
}

.lab__iso {
  position: absolute; bottom: 1rem; left: 1rem;
  display: flex; flex-direction: column; gap: 0.15rem;
  pointer-events: none;
}
.lab__isolabel { font-size: var(--t-3xs); letter-spacing: 0.18em; color: var(--ink-3); }
.lab__isoval {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(1.75rem, 3.6vw, 2.75rem); line-height: 1;
  letter-spacing: -0.03em; color: #fff;
  text-shadow: 0 0 30px rgba(89,230,255,0.45);
}
.lab__isoval sup { font-size: 0.5em; color: var(--beam); vertical-align: super; }

/* --- Side rail ---------------------------------------------------------- */
.lab__side { display: flex; flex-direction: column; gap: 0.7rem; min-width: 0; }
.lab__card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--edge);
  border-radius: var(--r-3);
  background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.008));
}
.lab__k { font-size: var(--t-3xs); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }

.lab__id { display: flex; align-items: center; gap: 0.9rem; }
.lab__sym {
  --fam: var(--f-nonmetal);
  width: 60px; height: 60px; flex: none;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.6rem;
  letter-spacing: -0.03em; color: #fff;
  border-radius: var(--r-3);
  background: color-mix(in srgb, var(--fam) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--fam) 45%, transparent);
  transition: background var(--d-3) var(--e-out), border-color var(--d-3) var(--e-out);
}
.lab__id > div { display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-start; min-width: 0; }
.lab__name { font-family: var(--font-display); font-weight: 600; font-size: var(--t-md); }
.lab__massno { margin-left: auto; text-align: right; }
.lab__massno .mono { display: block; font-size: var(--t-3xs); letter-spacing: 0.12em; }
.lab__massno strong { font-size: 1.5rem; font-weight: 500; letter-spacing: -0.02em; }

/* Counters */
.counter { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.5rem 0; }
.counter + .counter { border-top: 1px solid var(--edge-soft); }
.counter__k { display: inline-flex; align-items: center; gap: 0.55rem; font-size: var(--t-sm); color: var(--ink-2); }
.counter__ctl { display: inline-flex; align-items: center; gap: 0.35rem; }
.counter__btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--edge); border-radius: var(--r-2);
  color: var(--ink-2); font-size: 1rem; line-height: 1;
  transition: all var(--d-1) var(--e-out);
  user-select: none;
}
.counter__btn:hover { border-color: var(--edge-strong); background: rgba(255,255,255,0.07); color: #fff; transform: translateY(-1px); }
.counter__btn:active { transform: scale(0.92); }
.counter__v {
  min-width: 3ch; text-align: center;
  font-size: var(--t-md); font-weight: 500; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.counter--p .counter__btn:hover { border-color: rgba(217,59,38,0.6); background: rgba(217,59,38,0.14); }
.counter--n .counter__btn:hover { border-color: rgba(120,160,210,0.6); background: rgba(120,160,210,0.14); }
.counter--e .counter__btn:hover { border-color: rgba(89,230,255,0.6); background: rgba(89,230,255,0.14); }

/* Stability */
.stab__row { display: flex; align-items: center; gap: 0.6rem; margin: 0.6rem 0 0.5rem; }
.stab__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--ink-3); }
.stab__dot.is-stable      { background: var(--ok);     box-shadow: 0 0 12px var(--ok); }
.stab__dot.is-radioactive { background: var(--warn);   box-shadow: 0 0 12px var(--warn); animation: pip-breathe 1.6s infinite; }
.stab__dot.is-beta-minus,
.stab__dot.is-beta-plus   { background: var(--hot);    box-shadow: 0 0 12px var(--hot); animation: pip-breathe 1.6s infinite; }
.stab__dot.is-unbound,
.stab__dot.is-beyond      { background: var(--danger); box-shadow: 0 0 12px var(--danger); }
.stab__dot.is-empty       { background: var(--ink-3); }
.stab__label { font-family: var(--font-display); font-weight: 600; font-size: var(--t-md); }
.stab__detail { font-size: var(--t-2xs); line-height: 1.62; color: var(--ink-2); }
.stab__valley { font-size: var(--t-3xs); color: var(--ink-3); margin-top: 0.6rem; letter-spacing: 0.04em; }
.stab__valley b { color: var(--beam); }

.lab__cfg {
  font-size: var(--t-sm); color: var(--beam);
  margin: 0.55rem 0 0.9rem;
  overflow-wrap: anywhere; line-height: 1.5;
}

/* Shell list (shared with the element page) */
.shells { display: flex; flex-direction: column; gap: 0.4rem; }
.shell { display: grid; grid-template-columns: 2.6rem 1fr auto; align-items: center; gap: 0.5rem; }
.shell__n { font-size: var(--t-3xs); color: var(--ink-3); }
.shell__dots { display: flex; flex-wrap: wrap; gap: 2px; }
.shell__dots i {
  width: 5px; height: 5px; border-radius: 50%; display: block;
  background: var(--fam, var(--beam));
  box-shadow: 0 0 5px var(--fam, var(--beam));
}
.pg-lab .shell__dots i { background: #59e6ff; box-shadow: 0 0 5px rgba(89,230,255,0.8); }
.shell__c { font-size: var(--t-3xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }

@media (max-width: 940px) {
  .lab { grid-template-columns: 1fr; }
  .lab__stage { min-height: 360px; }
}

/* --- Lower row ---------------------------------------------------------- */
.lab-lower {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 0.7rem;
  margin-top: 0.7rem;
}
.presets__row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }
.preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--edge); border-radius: var(--r-2);
  transition: all var(--d-2) var(--e-out);
  min-width: 84px;
}
.preset b { font-family: var(--font-display); font-size: var(--t-sm); font-weight: 700; color: var(--ink); }
.preset span { font-size: var(--t-3xs); color: var(--ink-3); }
.preset:hover {
  border-color: rgba(89,230,255,0.5);
  background: rgba(89,230,255,0.08);
  transform: translateY(-2px);
}

/* Game card */
.game { position: relative; overflow: hidden; transition: border-color var(--d-3) var(--e-out); }
.game.is-on { border-color: rgba(89,230,255,0.35); }
.game.is-solved { border-color: rgba(79,224,138,0.55); background: linear-gradient(180deg, rgba(79,224,138,0.09), rgba(255,255,255,0.008)); }
.game__head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.game__scores { display: flex; gap: 1rem; font-size: var(--t-3xs); letter-spacing: 0.12em; color: var(--ink-3); }
.game__scores b { color: var(--beam); font-size: var(--t-sm); font-weight: 500; margin-left: 0.3rem; }
.game__text { font-family: var(--font-display); font-size: var(--t-md); font-weight: 500; margin: 0.85rem 0 0.5rem; line-height: 1.45; }
.game__hint { font-size: var(--t-2xs); color: var(--ink-3); line-height: 1.55; }
.game__status { font-family: var(--font-mono); font-size: var(--t-2xs); color: var(--ok); margin-top: 0.6rem; min-height: 1.2em; letter-spacing: 0.06em; }
.game__ctl { display: flex; gap: 0.5rem; margin-top: 0.85rem; }

@media (max-width: 820px) { .lab-lower { grid-template-columns: 1fr; } }

/* --- Valley chart ------------------------------------------------------- */
.valley { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(1.5rem, 4vw, 3rem); align-items: center; }
.valley__chart canvas { width: 100%; aspect-ratio: 4 / 3; display: block; }
@media (max-width: 860px) { .valley { grid-template-columns: 1fr; } }
