: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: #ff4422;
  --accent-warm: #ffb84d;
  --accent-cool: #6ec6ff;
  --effusive: #ff7a3d;
  --explosive: #ef4444;
  --mixed: #ffb84d;
  --supereruptive: #b91c5c;
  --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 88px 90px;
  height: 100vh;
  width: 100vw;
}

/* topbar */
.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;
  background: transparent;
  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; }
.topbar-btn__icon { font-size: 14px; }
#experimentsBtn { color: var(--accent); border-color: var(--accent); }
#experimentsBtn:hover { background: rgba(255, 68, 34, 0.1); }

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

/* meters */
.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));
  border-radius: 3px;
  transition: width 0.6s ease, background 0.6s ease;
}
.meter[data-meter="vei"] .meter__fill {
  background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444, #b91c5c);
}
.meter[data-meter="temp"] .meter__fill {
  background: linear-gradient(90deg, #6ec6ff, #ffb84d, #ff4422);
}
.meter[data-meter="viscosity"] .meter__fill {
  background: linear-gradient(90deg, #6ec6ff, #ffb84d, #ef4444);
}
.meter[data-meter="silica"] .meter__fill {
  background: linear-gradient(90deg, #5d7c4a, #c5a572, #e8e8e8);
}
.meter[data-meter="gas"] .meter__fill {
  background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444);
}
.meter[data-meter="height"] .meter__fill {
  background: linear-gradient(90deg, #2c2c2c, #6a6a6a, #c5a572);
}
.meter__value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px; color: var(--ink-soft);
  align-self: end;
}

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

/* stage */
.stage {
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at center, #181014 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; }

#profileCanvas, #tectonicCanvas {
  max-width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 12px 32px rgba(0, 0, 0, 0.6));
}

/* map */
.map-wrap {
  position: relative;
  width: 100%; height: 100%;
  display: grid;
  place-items: center;
}
#mapSvg { width: 100%; height: 100%; }
.map-site { cursor: pointer; transition: 0.2s; }
.map-site .map-site__halo {
  opacity: 0.5;
  transition: 0.2s;
}
.map-site:hover .map-site__halo { opacity: 1; }
.map-site.is-current .map-site__halo { opacity: 1; animation: pulse 2s ease infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.6); opacity: 0.3; }
}
.map-site__dot { transition: 0.2s; }
.map-site.is-current .map-site__dot { fill: var(--accent); r: 5; }
.map-site__label {
  fill: var(--ink);
  font-size: 6px;
  font-family: 'Tajawal', sans-serif;
  font-weight: 600;
  pointer-events: none;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.85);
  stroke-width: 1.4px;
  stroke-linejoin: round;
}
.map-site.is-current .map-site__label { fill: #ffd9a0; font-weight: 800; font-size: 7px; }
.map-tooltip {
  position: absolute;
  padding: 10px 14px;
  background: rgba(20, 20, 20, 0.97);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  font-size: 12px;
  pointer-events: none;
  max-width: 260px;
  line-height: 1.5;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.map-tooltip[hidden] { display: none; }
.map-tooltip h4 { font-size: 13px; margin-bottom: 4px; color: var(--accent); }
.map-tooltip .type {
  margin-top: 6px;
  font-size: 10px; color: var(--ink-mute);
  text-transform: uppercase; letter-spacing: 0.05em;
}

/* microscope */
.micro-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%; height: 100%;
  padding: 8px;
}
#microCanvas {
  max-width: 100%;
  max-height: calc(100% - 40px);
  border-radius: 50%;
  background: #000;
  box-shadow: 0 0 0 4px #1a1a1a, 0 0 0 6px var(--line-strong), 0 12px 40px rgba(0,0,0,0.7);
}
.micro-caption {
  font-size: 12px; color: var(--ink-mute);
  text-align: center; max-width: 480px;
}

/* experiment menu */
.experiment-menu {
  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] { display: none; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.experiment-menu__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 0;
}
.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: #1d1614;
}
.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 */
.experiment-overlay {
  position: absolute;
  inset: 60px 24px 24px 24px;
  padding: 16px;
  background: rgba(8, 8, 8, 0.98);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  backdrop-filter: blur(14px);
  z-index: 7;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.3s ease;
}
.experiment-overlay[hidden] { display: none; }
.experiment-overlay__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.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;
}
#experimentCanvas {
  max-width: 100%;
  max-height: 100%;
}
.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 */
.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: #1d1d1d;
  color: var(--ink-soft);
  font-weight: 500;
}
.card__family[data-family="effusive"] { background: rgba(255, 122, 61, 0.15); color: var(--effusive); }
.card__family[data-family="explosive"] { background: rgba(239, 68, 68, 0.18); color: var(--explosive); }
.card__family[data-family="mixed"] { background: rgba(255, 184, 77, 0.18); color: var(--mixed); }
.card__family[data-family="supereruptive"] { background: rgba(185, 28, 92, 0.2); color: var(--supereruptive); }
.card__origin { font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
.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__where { font-size: 12px; color: var(--ink-mute); margin-top: 2px; }
.card__where em { font-style: normal; color: var(--ink-soft); }
.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 (volcano types) */
.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: 110px;
  flex-shrink: 0;
  transition: 0.3s;
}
.selector-card:hover { border-color: var(--accent); }
.selector-card.is-active {
  border-color: var(--accent);
  background: #1c1410;
  box-shadow: 0 0 24px rgba(255, 68, 34, 0.25);
}
.selector-card__icon { font-size: 18px; line-height: 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-warm); }

/* timeline */
.timeline {
  background: var(--bg-deep);
  border-top: 1px solid var(--line);
  padding: 8px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#timelineSvg {
  width: 100%;
  height: 56px;
  display: block;
}
.timeline__hint {
  font-size: 11px;
  color: var(--ink-mute);
  font-family: 'JetBrains Mono', monospace;
  text-align: center;
  letter-spacing: 0.03em;
}
.timeline__hint b { color: var(--accent); }
.tl-eon { transition: opacity 0.3s; }
.tl-eon-label { fill: var(--ink); font-size: 10px; font-family: 'Tajawal', sans-serif; pointer-events: none; }
.tl-event-line { stroke: rgba(255,255,255,0.25); stroke-dasharray: 2 3; }
.tl-event-tick { fill: var(--ink-soft); }
.tl-event-label { fill: var(--ink-mute); font-size: 9px; font-family: 'Tajawal', sans-serif; }
.tl-rock-window {
  fill: rgba(255, 68, 34, 0.2);
  stroke: var(--accent);
  stroke-width: 1.5;
  filter: drop-shadow(0 0 6px rgba(255, 68, 34, 0.5));
}

/* responsive */
@media (max-width: 1200px) {
  .lab__grid { grid-template-columns: 230px 1fr 300px; }
}
@media (max-width: 1000px) {
  .lab { grid-template-rows: 56px 1fr auto auto 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; }
  .composition { flex-basis: 100%; border-top: 1px solid var(--line); }
}
