/* Atom Explorer — styles */
:root {
  --bg: #05070f;
  --panel: rgba(10, 14, 28, 0.78);
  --panel-border: rgba(140, 170, 255, 0.16);
  --text: #e6eefc;
  --muted: #93a4c7;
  --accent: #3ee6ff;
  --accent-2: #a78bfa;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, select, input { font: inherit; color: inherit; }

#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; cursor: grab; }
#viewport canvas:active { cursor: grabbing; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl {
  color: #d6e4ff; font-size: 12px; letter-spacing: .02em; white-space: nowrap; pointer-events: none;
  background: rgba(5, 8, 20, .55); border: 1px solid rgba(255, 255, 255, .08);
  padding: 2px 7px; border-radius: 999px; backdrop-filter: blur(4px);
  transform: translateY(-120%);
}
.hoverTip { position: absolute; z-index: 5; transform: translate(-50%, -100%); pointer-events: none; white-space: nowrap; padding: 4px 10px; border-radius: 999px; background: rgba(5, 8, 20, .92); border: 1px solid rgba(62, 230, 255, .6); color: #fff; font-size: 13px; }
.hoverTip[hidden] { display: none; }
.lbl-sub { pointer-events: auto; cursor: pointer; font-weight: 600; }
.lbl-sub:hover { border-color: rgba(62, 230, 255, .7); color: #fff; }
.lbl-nucleus { color: #ffb199; border-color: rgba(255, 138, 101, .35); }
.lbl-shell { color: #cfc2ff; }
.lbl-quark { font-weight: 700; font-size: 11px; padding: 1px 6px; color: #fff; background: rgba(0,0,0,.6); }

/* ---------- panels ---------- */
.glass {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow);
}

#hud { position: fixed; top: 14px; left: 14px; width: 330px; max-height: calc(100vh - 28px); overflow: auto; padding: 14px 16px; z-index: 5; }
#hud .brand { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
#hud .logo { font-size: 30px; line-height: 1; filter: drop-shadow(0 0 10px var(--accent)); animation: spin 14s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#hud h1 { font-size: 18px; margin: 0; letter-spacing: .01em; }
#hud p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.row > label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
select {
  background: rgba(255,255,255,.06); border: 1px solid var(--panel-border); border-radius: 8px; padding: 6px 10px; outline: none;
}
select option { background: #0c1224; }
.seg { display: inline-flex; border: 1px solid var(--panel-border); border-radius: 999px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 7px 12px; font-size: 12px; cursor: pointer; color: var(--muted); }
.seg button.active { background: linear-gradient(90deg, rgba(62,230,255,.25), rgba(167,139,250,.25)); color: #fff; }
.tg { font-size: 12px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; user-select: none; }
.tg input { accent-color: var(--accent); }
input[type=range] { width: 130px; accent-color: var(--accent); }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btn {
  background: rgba(255,255,255,.06); border: 1px solid var(--panel-border); border-radius: 10px; padding: 7px 11px; font-size: 12px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover { background: rgba(255,255,255,.12); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: linear-gradient(90deg, #ffcf4a, #ff8a65); color: #1a1200; border: 0; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.hint { font-size: 11px; color: var(--muted); margin-top: 6px; }
kbd { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; font-size: 11px; }

/* ---------- details pane ---------- */
#details {
  position: fixed; top: 14px; right: 14px; bottom: 14px; width: 380px; z-index: 5; display: flex; flex-direction: column; overflow: hidden;
}
.dHead { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--panel-border); font-size: 12px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.dHead button { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; }
#detailsBody { padding: 14px 16px 20px; overflow: auto; flex: 1; }
.crumbs { font-size: 11px; color: var(--muted); margin-bottom: 8px; display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.title { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 22px; }
.dot { width: 16px; height: 16px; border-radius: 50%; box-shadow: 0 0 14px currentColor; flex: none; }
.sym { font-weight: 400; color: var(--muted); font-size: 16px; }
.badge { display: inline-block; font-size: 11px; color: #0b1020; background: var(--accent-2); border-radius: 999px; padding: 2px 9px; margin-bottom: 10px; font-weight: 600; }
.lede { font-size: 14px; line-height: 1.55; margin: 8px 0 12px; }
.ctx { font-size: 13px; line-height: 1.5; color: #cfe0ff; background: rgba(62,230,255,.08); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 6px; margin: 10px 0; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.stats div { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); border-radius: 10px; padding: 8px 10px; }
.stats b { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.stats span { font-size: 13px; line-height: 1.35; }
.stats .wide { grid-column: 1 / -1; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 16px 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px solid var(--panel-border); cursor: pointer; transition: background .15s;
}
.chip:hover { background: rgba(255,255,255,.13); }
.chip .dot { width: 9px; height: 9px; box-shadow: 0 0 8px currentColor; }
.chip small { color: var(--muted); }
.fact { font-size: 13px; line-height: 1.5; background: linear-gradient(135deg, rgba(167,139,250,.14), rgba(62,230,255,.08)); border-radius: 10px; padding: 10px 12px; }
.fact::before { content: "💡 "; }
.small { font-size: 12px; color: var(--muted); line-height: 1.5; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.motion { font-size: 13px; line-height: 1.5; }
.motion::before { content: "🌀 "; }

#openDetails { display: none; position: fixed; right: 14px; bottom: 14px; z-index: 6; }

/* ---------- legend ---------- */
#legend { position: fixed; left: 14px; bottom: 14px; z-index: 5; padding: 8px 10px; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100vw - 440px); }
#legend .chip { font-size: 11px; padding: 4px 9px; }
#legend .chip.on { background: rgba(255,255,255,.16); }

/* ---------- toast / help / loading ---------- */
#toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -20px); z-index: 8; padding: 10px 16px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal { position: fixed; inset: 0; z-index: 20; background: rgba(2,4,10,.6); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal.hidden { display: none; }
.modal .card { width: min(560px, 100%); max-height: 90vh; overflow: auto; padding: 22px 24px; }
.modal h2 { margin: 0 0 6px; }
.modal ul { padding-left: 18px; line-height: 1.7; font-size: 14px; }
.modal .close { float: right; }
#loading { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; background: var(--bg); color: var(--muted); font-size: 14px; }
#loading .logo { font-size: 48px; animation: spin 3s linear infinite; filter: drop-shadow(0 0 16px var(--accent)); }
#loading.error { color: #ffb4b4; text-align: center; padding: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  #hud { width: calc(100vw - 28px); max-height: 46vh; }
  #details { top: auto; left: 14px; right: 14px; bottom: 14px; width: auto; height: 50vh; transform: translateY(calc(100% + 20px)); transition: transform .3s; }
  #details.open { transform: none; }
  #openDetails { display: block; }
  #legend { display: none; }
}

/* ---------- v2: element button, demos, overlays ---------- */
.elementBtn { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; padding: 8px 12px; background: rgba(255,255,255,.08); }
.elementBtn .dot { width: 12px; height: 12px; }
.elementBtn small { color: var(--muted); }
.elementBtn .caret { color: var(--muted); margin-left: 2px; }
.demos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0 8px; padding: 8px; border: 1px dashed var(--panel-border); border-radius: 12px; }
.demosLabel { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-right: 2px; }
.btn.weak { background: linear-gradient(90deg, #c084fc, #a78bfa); color: #1a1030; border: 0; font-weight: 600; }
.btn.strong { background: linear-gradient(90deg, #7dffb3, #3ee6ff); color: #04221a; border: 0; font-weight: 600; }
.btn.weak:hover, .btn.strong:hover { filter: brightness(1.08); }
.badge.warn { background: #fbbf24; }
.badge.dim { background: rgba(255,255,255,.12); color: var(--muted); }
.energy { font-size: 13px; line-height: 1.5; }
.energy::before { content: "⚡ "; }
.lbl-energy { color: #ffe08a; border-color: rgba(255,207,74,.5); font-weight: 600; transform: translateY(-160%); }

.modalHead { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.modalHead h2 { margin: 0 0 4px; }
.modalHead p { margin: 0; }
.modalTools { display: flex; gap: 12px; align-items: center; flex: none; }
.modal .card.wide { width: min(1400px, 100%); }
.modal.hidden { display: none; }
#ptable, #sm { background: rgba(5, 7, 15, 0.82); }

/* periodic table */
.ptGrid {
  display: grid; grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr)) 10px repeat(2, minmax(0, 1fr));
  gap: 4px; min-width: 760px;
}
.tile {
  --c: #888; position: relative; aspect-ratio: 1 / 1; border-radius: 8px; border: 1px solid color-mix(in srgb, var(--c) 55%, transparent);
  background: color-mix(in srgb, var(--c) 22%, rgba(10,14,28,.6)); color: var(--text); cursor: pointer; padding: 3px 4px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; line-height: 1.05; overflow: hidden;
  transition: transform .12s, background .15s, box-shadow .15s; font: inherit;
}
.tile:hover { transform: scale(1.12); z-index: 2; background: color-mix(in srgb, var(--c) 55%, rgba(10,14,28,.4)); box-shadow: 0 6px 24px color-mix(in srgb, var(--c) 50%, transparent); }
.tile.current { outline: 2px solid #fff; outline-offset: 1px; background: color-mix(in srgb, var(--c) 60%, rgba(10,14,28,.3)); }
.tile .z { position: absolute; top: 3px; left: 5px; font-size: 9px; color: var(--muted); }
.tile .sy { font-size: clamp(13px, 1.5vw, 22px); font-weight: 700; color: var(--c); filter: brightness(1.25); }
.tile .nm { font-size: clamp(7px, .62vw, 10px); color: #dbe4ff; margin-top: 2px; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tile .ms { font-size: clamp(6px, .55vw, 9px); color: var(--muted); margin-top: 1px; }
.tile.rich::after { content: "★"; position: absolute; top: 2px; right: 4px; font-size: 9px; color: #ffd166; }
.tile.ph { background: rgba(255,255,255,.04); border-style: dashed; cursor: default; font-size: 10px; color: var(--muted); }
.ptLegend { margin-top: 14px; }

/* Standard Model */
.smGrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.smHead { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: center; padding-bottom: 4px; line-height: 1.3; }
.smHead small { text-transform: none; letter-spacing: 0; font-size: 11px; }
.smCard {
  --c: #888; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--c) 55%, transparent); color: var(--text); cursor: pointer; font: inherit;
  background: color-mix(in srgb, var(--c) 18%, rgba(10,14,28,.6)); padding: 12px 12px 10px; text-align: left; display: flex; flex-direction: column; gap: 4px;
  transition: transform .12s, background .15s, box-shadow .15s; min-height: 118px;
}
.smCard:hover { transform: translateY(-3px); background: color-mix(in srgb, var(--c) 40%, rgba(10,14,28,.5)); box-shadow: 0 8px 28px color-mix(in srgb, var(--c) 45%, transparent); }
.smCard .sy { font-size: 30px; font-weight: 700; color: var(--c); filter: brightness(1.25); line-height: 1; }
.smCard .nm { font-size: 14px; font-weight: 600; }
.smCard .row { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; color: var(--muted); }
.smCard.quark { --c: #ff8fa3; }
.smCard.lepton { --c: #7dd3fc; }
.smCard.gauge { --c: #fcd34d; }
.smCard.scalar { --c: #e879f9; }

@media (max-width: 980px) {
  .modal .card.wide { padding: 14px; }
  .ptGrid { overflow-x: auto; }
  .smGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .smHead { display: none; }
  .smCard { grid-column: auto !important; grid-row: auto !important; }
}

/* ---------- Simorium hub integration ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 5px; margin: -2px 0 10px; padding: 3px 10px;
  font-size: 11px; letter-spacing: .02em; color: var(--muted); text-decoration: none;
  background: rgba(255,255,255,.04); border: 1px solid var(--panel-border); border-radius: 999px;
  transition: color .15s, border-color .15s, background .15s;
}
.back-link:hover, .back-link:focus-visible { color: var(--accent); border-color: var(--accent); background: rgba(62,230,255,.08); }
.back-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
