:root {
  --bg-0: #05060a;
  --bg-1: #0a0d16;
  --bg-2: #10141f;
  --surface: rgba(20, 26, 40, 0.62);
  --surface-strong: rgba(20, 26, 40, 0.88);
  --border: rgba(148, 176, 220, 0.14);
  --border-strong: rgba(148, 176, 220, 0.28);
  --text: #e8ecf5;
  --text-muted: #8891a8;
  --text-dim: #5a6274;
  --accent: #4af0c0;   /* cool teal — cloud & positive readouts */
  --accent-warm: #ffb347; /* copper-orange accent */
  --danger: #ff5e7a;
  --k-shell: #ffd166;
  --l-shell: #f78c6b;
  --m-shell: #c792ea;
  --n-shell: #82aaff;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --transition: 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 30% 20%, rgba(74, 240, 192, 0.05), transparent 60%),
    radial-gradient(1000px 700px at 80% 90%, rgba(255, 179, 71, 0.04), transparent 60%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }

/* Top brand bar */
.topbar {
  position: absolute; top: 20px; left: 20px; z-index: 10;
  display: flex; align-items: center;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  color: var(--accent-warm);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px 14px; border-radius: 12px;
}
.brand-text { line-height: 1.2; }
.brand-title {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--text);
  letter-spacing: 0.2px;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px; color: var(--text-muted);
  margin-top: 2px;
}

/* Right readout panel — compact */
.readout {
  position: absolute; top: 16px; right: 16px; z-index: 10;
  width: 232px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text);
}
.readout-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.panel-title {
  white-space: nowrap;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted); margin: 0;
}
.readout-grid { display: flex; flex-direction: column; }
.readout-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 3px 0;
}
.k { font-size: 11px; color: var(--text-muted); }
.v { font-family: var(--font-mono); font-size: 12px; color: var(--text); white-space: nowrap; }
.hud-value { font-variant-numeric: tabular-nums lining-nums; font-weight: 500; }
.u { color: var(--text-dim); font-size: 10px; margin-left: 3px; }
.tag {
  padding: 2px 6px; border-radius: 5px; font-size: 10px;
  font-family: var(--font-mono);
  background: rgba(74, 240, 192, 0.1); color: var(--accent);
  border: 1px solid rgba(74, 240, 192, 0.2);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tag.warn { background: rgba(255, 179, 71, 0.12); color: var(--accent-warm); border-color: rgba(255, 179, 71, 0.28); }
.tag.hot  { background: rgba(255, 94, 122, 0.14); color: var(--danger); border-color: rgba(255, 94, 122, 0.3); }

.shells-inline {
  display: flex; justify-content: space-between;
  margin-top: 6px; padding-top: 6px;
  border-top: 1px solid rgba(148, 176, 220, 0.08);
  font-family: var(--font-mono); font-size: 10px; color: var(--text-muted);
}
.shells-inline span { display: inline-flex; align-items: center; gap: 4px; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 6px currentColor; }
.k-dot { background: var(--k-shell); color: var(--k-shell); }
.l-dot { background: var(--l-shell); color: var(--l-shell); }
.m-dot { background: var(--m-shell); color: var(--m-shell); }
.n-dot { background: var(--n-shell); color: var(--n-shell); }

.view-details { margin-top: 6px; border-top: 1px solid rgba(148, 176, 220, 0.08); padding-top: 6px; }
.view-details summary {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); cursor: pointer; list-style: none; font-weight: 600;
}
.view-details summary::-webkit-details-marker { display: none; }
.view-details summary::after { content: " +"; color: var(--text-dim); }
.view-details[open] summary::after { content: " −"; }

/* Toggles */
.toggles { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text); cursor: pointer; }
.toggle input {
  appearance: none; width: 26px; height: 14px;
  background: rgba(148, 176, 220, 0.15); border-radius: 999px;
  position: relative; transition: background var(--transition); cursor: pointer; outline: none; margin: 0;
}
.toggle input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 10px; height: 10px;
  background: var(--text); border-radius: 50%; transition: transform var(--transition);
}
.toggle input:checked { background: rgba(74, 240, 192, 0.35); }
.toggle input:checked::after { transform: translateX(12px); background: var(--accent); }
.toggle input:focus-visible { box-shadow: 0 0 0 2px var(--accent); }

/* Scene legend (nucleus vs cloud center) */
.center-legend {
  position: absolute; bottom: 250px; left: 20px; z-index: 9;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 8px 10px; border-radius: 10px;
}
.center-legend span { display: inline-flex; align-items: center; gap: 6px; }
.center-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.cl-nuc { background: #ff8a3a; }
.cl-cloud { border: 1.5px solid #82aaff; }
.cl-bond { background: #c9f2ff; }
.cl-dip { width: 14px !important; height: 2px !important; border-radius: 1px !important; background: #ffffff; }

/* Bottom controls */
.controls {
  position: absolute; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(900px, calc(100% - 40px));
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 18px 22px 14px;
  border-radius: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.slider-head {
  display: flex; justify-content: space-between; align-items: baseline;
}
.slider-head label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600;
}
.slider-value {
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 500;
  color: var(--accent-warm);
  font-variant-numeric: tabular-nums lining-nums;
}
.slider-value .u { font-size: 12px; color: var(--text-muted); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%; height: 8px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--fill, 0%), rgba(148, 176, 220, 0.14) var(--fill, 0%), rgba(148, 176, 220, 0.14) 100%);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  background: var(--accent-warm);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 179, 71, 0.18), 0 2px 10px rgba(255, 179, 71, 0.4);
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: grab;
}
input[type="range"]::-webkit-slider-thumb:active { transform: scale(1.15); cursor: grabbing; }
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px;
  background: var(--accent-warm);
  border: none;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 179, 71, 0.18), 0 2px 10px rgba(255, 179, 71, 0.4);
  cursor: grab;
}
.slider-ticks {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px; color: var(--text-dim);
  margin-top: 2px;
}
.preset-block { display: flex; gap: 8px; flex-wrap: wrap; }
.preset {
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(148, 176, 220, 0.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.preset:hover { color: var(--text); border-color: var(--border-strong); }
.preset.active {
  color: var(--accent-warm);
  background: rgba(255, 179, 71, 0.1);
  border-color: rgba(255, 179, 71, 0.35);
}

/* Field indicator */
.field-indicator {
  position: absolute; bottom: 170px; left: 24px; z-index: 8;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 11px;
  min-width: 180px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}
.field-indicator.visible { opacity: 1; transform: translateY(0); }
.fi-arrow { color: var(--accent-warm); display: block; line-height: 0; margin-bottom: 4px; }
.fi-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-warm);
  font-weight: 500;
}
.fi-note { color: var(--text-muted); font-size: 10px; margin-top: 2px; }

/* Regime footnote */
.regime-note {
  position: absolute;
  left: 50%; bottom: 168px;
  transform: translateX(-50%);
  z-index: 8;
  font-size: 12px; color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: 480px; text-align: center;
  transition: color var(--transition);
}

@media (max-width: 780px) {
  .readout { width: 200px; top: 12px; right: 12px; }
  .center-legend { display: none; }
  .topbar { top: 16px; left: 16px; }
  .controls { width: calc(100% - 24px); padding: 14px 16px 10px; }
  .field-indicator { display: none; }
  .regime-note { display: none; }
}

/* Bead color-mode chips */
.color-modes { display: flex; gap: 4px; margin-top: 6px; }
.cm {
  flex: 1; font: 500 10px var(--font-mono); letter-spacing: 0.4px;
  padding: 4px 0; border-radius: 6px; cursor: pointer;
  background: rgba(148, 176, 220, 0.06); color: var(--text-muted);
  border: 1px solid rgba(148, 176, 220, 0.12);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.cm:hover { color: var(--text); }
.cm.active { background: rgba(74, 240, 192, 0.12); color: var(--accent); border-color: rgba(74, 240, 192, 0.3); }

/* Studio background (like the minutephysics renders) */
body.studio {
  background: radial-gradient(1400px 900px at 50% 40%, #f4f5f7 0%, #dfe2e7 70%, #cfd3da 100%);
}

body.studio .readout, body.studio .brand, body.studio .controls, body.studio .center-legend,
body.studio .field-indicator, body.studio .regime-note {
  background: rgba(16, 19, 27, 0.9);
}

/* Return link when opened full screen from blixt Lab */
.back-link {
  position: fixed; left: 20px; top: 92px; z-index: 30;
  font: 500 11px/1 "JetBrains Mono", monospace; letter-spacing: 0.14em; text-transform: uppercase;
  color: rgba(232, 238, 248, 0.72); text-decoration: none;
  padding: 8px 12px; border: 1px solid rgba(255,255,255,0.14); border-radius: 8px;
  background: rgba(12, 15, 22, 0.6); backdrop-filter: blur(10px);
}
.back-link:hover { color: #fff; border-color: rgba(255,255,255,0.35); }
.back-link[hidden] { display: none; }

/* Inside the Blixt Research page: clear the site's fixed nav bar */
.embedded .readout { top: 84px; }

.color-modes[hidden] { display: none; }

/* ---------- Stack element slots & periodic-table picker ---------- */
.stack-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.stack-slots[hidden] { display: none; }
.slot {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 4px 5px; border-radius: 8px; cursor: pointer;
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border-strong);
  color: var(--text); font-family: var(--font-mono); transition: border-color var(--transition), background var(--transition);
}
.slot b { font-size: 16px; font-weight: 600; line-height: 1.1; }
.slot span { font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.slot.is-m b { color: #ffb070; }
.slot.is-d b { color: #9fe8ff; }
.slot:hover { background: rgba(74, 240, 192, 0.08); border-color: rgba(74, 240, 192, 0.45); }

.ptable {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(3, 5, 10, 0.62); backdrop-filter: blur(6px); padding: 16px;
}
.ptable[hidden] { display: none; }
.pt-card {
  width: min(760px, 100%); max-height: 100%; overflow: auto;
  background: var(--surface-strong); border: 1px solid var(--border-strong); border-radius: 14px; padding: 14px 16px 12px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.pt-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pt-title { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.pt-close { background: none; border: 0; color: var(--text-muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.pt-close:hover { color: var(--text); }
.pt-grid { display: grid; grid-template-columns: repeat(18, 1fr); grid-template-rows: repeat(7, auto) 8px repeat(2, auto); gap: 3px; }
.pt-el {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 0; border-radius: 5px; cursor: pointer;
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; transition: transform 120ms, border-color 120ms;
}
.pt-el i { position: absolute; top: 2px; left: 3px; font-style: normal; font-size: 7px; font-weight: 400; color: var(--text-muted); }
.pt-el.m { background: rgba(255, 150, 80, 0.16); }
.pt-el.d { background: rgba(120, 220, 255, 0.16); }
.pt-el.na { background: rgba(255, 255, 255, 0.03); color: var(--text-dim); cursor: not-allowed; }
.pt-el:not(.na):hover, .pt-el:not(.na):focus-visible { border-color: var(--accent); transform: scale(1.12); z-index: 1; outline: none; }
.pt-el.cur { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pt-gap { display: flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-size: 7px; color: var(--text-dim); }
.pt-foot { display: flex; align-items: center; gap: 14px; margin-top: 10px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); flex-wrap: wrap; }
.pt-key { display: inline-flex; align-items: center; gap: 5px; }
.pt-key i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.pt-key i.m { background: rgba(255, 150, 80, 0.55); }
.pt-key i.d { background: rgba(120, 220, 255, 0.55); }
.pt-info { color: var(--text); margin-left: auto; }
@media (max-width: 560px) { .pt-el { font-size: 9px; } .pt-el i { display: none; } }
.readout-row[hidden] { display: none; }

.shells-inline[hidden] { display: none; }
.stack-slots.single { grid-template-columns: 1fr; }
.slot.wide { flex-direction: row; justify-content: flex-start; gap: 10px; padding: 7px 12px; }
.slot.wide span { font-size: 10px; }
.slot.is-na b { color: #c9ced9; }
.ptable.atom .pt-el:not(.cur) { filter: saturate(0.3); }
.pt-key[hidden] { display: none; }
.slot.wide span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot.wide::after { content: "Change ▸"; margin-left: auto; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }

/* Forces panel (stack mode) */
.forces {
  position: absolute; left: 20px; top: 92px; z-index: 11; width: 290px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-family: var(--font-mono); font-size: 10.5px; color: var(--text);
  padding: 4px 12px 8px;
}
.forces[hidden] { display: none; }
body:has(#back-link:not([hidden])) .forces { top: 136px; }
.fc-head {
  all: unset; box-sizing: border-box; width: 100%; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; padding: 7px 0 5px;
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted);
}
.fc-head:hover { color: var(--text); }
.fc-unit { letter-spacing: 0.04em; text-transform: none; color: var(--text-dim); }
.fc-sec { border-top: 1px solid var(--border); padding: 5px 0 4px; }
.fc-lab { display: flex; justify-content: space-between; font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 3px; }
.fc-ends { letter-spacing: 0.02em; }
.fc-ar { display: grid; grid-template-columns: 70px 1fr 90px; align-items: center; gap: 8px; height: 18px; }
.fc-ar span { color: var(--text-muted); }
.fc-ar em, .fc-row em, .fc-if em { font-style: normal; text-align: right; font-variant-numeric: tabular-nums; }
.fc-bar { height: 5px; border-radius: 3px; background: rgba(255,255,255,0.06); overflow: hidden; }
.fc-bar i { display: block; height: 100%; border-radius: 3px; transition: width 120ms linear; }
.fc-bar.att i { background: linear-gradient(90deg, #2bb3a0, var(--accent)); box-shadow: 0 0 8px rgba(74,240,192,0.6); }
.fc-bar.rep i { background: linear-gradient(90deg, #d9485f, var(--danger)); box-shadow: 0 0 8px rgba(255,94,122,0.6); }
.fc-row { display: grid; grid-template-columns: 24px 1fr 90px 38px; align-items: center; gap: 6px; height: 18px; }
.fc-row b { font-weight: 600; font-size: 12px; }
.fc-row b.m { color: #ffb070; } .fc-row b.d { color: #9fe8ff; }
.fc-row small, .fc-if small, .fc-total small { color: var(--text-dim); font-size: 9px; }
.fc-div { position: relative; height: 8px; border-radius: 4px; background: rgba(255,255,255,0.05); }
.fc-div::before { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--border-strong); }
.fc-div i { position: absolute; top: 1px; bottom: 1px; border-radius: 3px; background: linear-gradient(90deg, #ffd166, #ffb347); box-shadow: 0 0 8px rgba(255,209,102,0.55); transition: width 120ms linear, left 120ms linear; }
.fc-if { display: grid; grid-template-columns: 1fr 90px 78px; gap: 6px; height: 17px; align-items: center; }
.fc-if span { color: var(--text-muted); }
.fc-if small { text-align: right; }
.fc-total .fc-ar { grid-template-columns: 1fr auto auto; }
.fc-total strong { font-size: 14px; color: var(--accent); font-weight: 600; }
.fc-total p { margin: 3px 0 0; font-family: var(--font-body); font-size: 10px; line-height: 1.35; color: var(--text-dim); }
@media (max-width: 760px) { .forces { width: 230px; font-size: 9.5px; } .fc-total p { display: none; } }
body.forces-open .center-legend { display: none; }
.fc-delta { border-top: 1px dashed var(--border); margin-top: 2px; padding-top: 2px; }
.fc-delta em { color: var(--accent); }
