:root {
  --bg: #0a0a0a;
  --bg-soft: #131313;
  --bg-card: #161616;
  --bg-deep: #0d0d0d;
  --line: #232323;
  --line-strong: #333;
  --ink: #f3f3f3;
  --ink-soft: #b5b5b5;
  --ink-mute: #6a6a6a;
  --accent: #a78bfa;
  --accent-warm: #f97316;
  --accent-cool: #6ec6ff;
  --r: 14px;
  --r-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Tajawal', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.lab {
  display: grid;
  grid-template-rows: 56px 1fr 84px;
  height: 100vh;
  width: 100vw;
}

.lab__topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.back {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 18px;
  border: 1px solid var(--line);
  transition: 0.2s;
}
.back:hover { color: var(--ink); border-color: var(--line-strong); }
.title { display: flex; flex-direction: column; line-height: 1.15; }
.title__ar { font-size: 16px; font-weight: 700; }
.title__en {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--ink-mute);
  letter-spacing: 0.1em;
}
.topbar-btn {
  margin-inline-start: auto;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  font-size: 13px; font-weight: 500;
  transition: 0.2s;
  display: flex; align-items: center; gap: 6px;
}
.topbar-btn:hover { color: var(--ink); border-color: var(--accent); }
.topbar-btn + .topbar-btn { margin-inline-start: 0; }
#experimentsBtn { color: var(--accent); border-color: var(--accent); }
#experimentsBtn:hover { background: rgba(167, 139, 250, 0.1); }

.lab__grid {
  display: grid;
  grid-template-columns: 280px 1fr 340px;
  gap: 16px;
  padding: 16px 16px 8px;
  min-height: 0;
}

.meters {
  display: flex; flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow-y: auto;
  max-height: 100%;
}
.meter { display: flex; flex-direction: column; gap: 5px; }
.meter__label {
  font-size: 11px; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.meter__bar { height: 5px; background: #1d1d1d; border-radius: 3px; overflow: hidden; }
.meter__fill {
  height: 100%; width: 5%;
  background: linear-gradient(90deg, var(--accent-cool), var(--accent), var(--accent-warm));
  border-radius: 3px;
  transition: width 0.6s ease;
}
.meter[data-meter="age"] .meter__fill { background: linear-gradient(90deg, #c5a572, #a85630, #8b3838, #5d2820); }
.meter[data-meter="o2"] .meter__fill { background: linear-gradient(90deg, #5d2820, #fbbf24, #34d399); }
.meter[data-meter="co2"] .meter__fill { background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444); }
.meter[data-meter="temp"] .meter__fill { background: linear-gradient(90deg, #6ec6ff, #fbbf24, #ef4444, #b91c5c); }
.meter__value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--ink-soft);
  align-self: end;
}

.atmosphere {
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.atmosphere__label {
  font-size: 11px; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.atmosphere__bar {
  height: 12px; display: flex;
  border-radius: 3px; overflow: hidden;
  background: #1d1d1d;
}
.atmosphere__bar-segment { height: 100%; transition: width 0.6s ease; }
.atmosphere__legend { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.atmosphere__legend li {
  font-size: 11px; display: flex; align-items: center; gap: 6px;
  color: var(--ink-soft);
}
.atmosphere__legend .swatch {
  width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0;
}
.atmosphere__legend .pct {
  margin-inline-start: auto;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink-mute);
}

.isotopes {
  margin-top: 6px;
  display: flex; flex-direction: column; gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.isotopes__label {
  font-size: 11px; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.isotopes__list {
  display: flex; flex-direction: column; gap: 4px;
}
.isotope-row {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.isotope-row.is-relevant {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.08);
}
.isotope-row__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
}
.isotope-row__name { color: var(--ink); flex: 1; font-weight: 500; }
.isotope-row__half {
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink-mute);
  font-size: 9px;
}

.stage {
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at center, #14111c 0%, #0a0a0a 70%);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 20px 16px;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.view-tabs {
  display: flex; gap: 4px;
  padding: 4px;
  background: var(--bg-deep);
  border-radius: var(--r-sm);
  margin-bottom: 12px;
  align-self: center;
}
.view-tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border-radius: var(--r-sm);
  color: var(--ink-mute);
  font-size: 13px; font-weight: 500;
  transition: 0.2s;
}
.view-tab:hover { color: var(--ink-soft); }
.view-tab.is-active {
  background: var(--bg-card);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.view-tab__icon { font-size: 14px; color: var(--accent); }

.view-stack {
  flex: 1; position: relative;
  display: grid; place-items: center;
  width: 100%; min-height: 0;
}
.view {
  display: grid; place-items: center;
  width: 100%; height: 100%; min-height: 0;
}
.view[hidden] { display: none; }
canvas { max-width: 100%; max-height: 100%; }

.experiment-menu, .experiment-overlay {
  position: absolute;
  inset: 60px 24px 24px 24px;
  padding: 18px;
  background: rgba(13, 13, 13, 0.98);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  backdrop-filter: blur(12px);
  z-index: 6;
  display: flex; flex-direction: column;
  gap: 12px;
  animation: modalIn 0.25s ease;
}
.experiment-menu[hidden], .experiment-overlay[hidden] { display: none; }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.experiment-menu__head, .experiment-overlay__head {
  display: flex; align-items: center; justify-content: space-between;
}
.experiment-menu__head em { color: var(--accent); font-style: normal; font-weight: 700; }
.experiment-menu__close, .experiment-overlay__close {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #1d1d1d;
  color: var(--ink-mute);
  font-size: 16px; line-height: 1;
}
.experiment-menu__close:hover, .experiment-overlay__close:hover { color: var(--ink); }
.experiment-menu__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  overflow-y: auto;
}
.experiment-card {
  display: flex; flex-direction: column; gap: 6px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  text-align: start;
  transition: 0.2s;
}
.experiment-card:hover { border-color: var(--accent); background: #1c1820; }
.experiment-card:disabled { opacity: 0.35; cursor: not-allowed; }
.experiment-card__head { display: flex; align-items: center; gap: 8px; }
.experiment-card__icon { font-size: 22px; }
.experiment-card__title { font-size: 14px; font-weight: 700; color: var(--ink); }
.experiment-card__desc { font-size: 12px; color: var(--ink-soft); line-height: 1.5; }
.experiment-card__avail { font-size: 10px; color: var(--ink-mute); margin-top: auto; font-family: 'JetBrains Mono', monospace; }
.experiment-overlay__title { font-size: 15px; font-weight: 700; color: var(--accent); }
.experiment-overlay__stage { flex: 1; display: grid; place-items: center; min-height: 0; }
.experiment-overlay__caption {
  font-size: 13px; color: var(--ink-soft);
  text-align: center;
  padding: 12px 0 0;
  line-height: 1.6;
  min-height: 50px;
  border-top: 1px solid var(--line);
  margin-top: 10px;
}

.info {
  display: flex; flex-direction: column;
  gap: 12px; min-height: 0; overflow: hidden;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
.card__head { display: flex; align-items: center; justify-content: space-between; }
.card__label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px; color: var(--ink-mute);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.card__name { font-size: 24px; font-weight: 900; letter-spacing: -0.01em; }
.card__family {
  display: inline-block; width: max-content;
  font-size: 11px; padding: 3px 8px;
  border-radius: 3px;
  background: rgba(167, 139, 250, 0.15); color: var(--accent);
  font-weight: 500;
}
.card__origin { font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.card__subhead {
  font-size: 12px;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}
.card__signs {
  list-style: none;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--ink-soft);
}
.card__signs li { padding-inline-start: 14px; position: relative; }
.card__signs li::before {
  content: "·"; position: absolute;
  inset-inline-start: 4px;
  color: var(--accent); font-weight: 700;
}
.card__when {
  display: flex; flex-direction: column; gap: 5px;
  margin-top: 4px; padding: 10px;
  background: var(--bg-deep);
  border-radius: var(--r-sm);
  border-inline-start: 2px solid var(--accent-warm);
}
.card__when-row {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 11px; align-items: baseline;
}
.card__when-label { color: var(--ink-mute); white-space: nowrap; flex-shrink: 0; }
.card__when-val { color: var(--ink); text-align: end; font-size: 12px; line-height: 1.4; }
.card__fact {
  font-size: 12px; color: var(--ink-soft); font-style: italic;
  border-inline-start: 2px solid var(--accent);
  padding-inline-start: 10px; margin-top: 4px;
}

.selector {
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  display: grid; place-items: center;
  overflow: hidden;
}
.selector__inner {
  display: flex; gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
  max-width: 100%;
}
.selector-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 4px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg-card);
  min-width: 130px; flex-shrink: 0;
  transition: 0.3s;
}
.selector-card:hover { border-color: var(--accent); }
.selector-card.is-active {
  border-color: var(--accent);
  background: #1a1620;
  box-shadow: 0 0 24px rgba(167, 139, 250, 0.25);
}
.selector-card__bar {
  width: 100%; height: 4px; border-radius: 2px;
  background: var(--card-color);
  transition: 0.3s;
  opacity: 0.6;
}
.selector-card.is-active .selector-card__bar { opacity: 1; }
.selector-card__name { font-size: 12px; font-weight: 700; }
.selector-card__sub { font-size: 10px; color: var(--ink-mute); }
.selector-card.is-active .selector-card__sub { color: var(--accent); }

@media (max-width: 1200px) {
  .lab__grid { grid-template-columns: 230px 1fr 300px; }
}
@media (max-width: 1000px) {
  .lab { grid-template-rows: 56px 1fr auto; }
  .lab__grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .meters { flex-direction: row; flex-wrap: wrap; max-height: none; }
  .meter { flex: 1 1 130px; }
  .atmosphere { flex-basis: 100%; border-top: 1px solid var(--line); }
  .isotopes { flex-basis: 100%; }
}
