/* ChemLab — core design system
   Dark laboratory shell, glass panels, restrained neon accents. */

:root {
  /* surfaces */
  --bg: #05080f;
  --bg-2: #070c16;
  --panel: rgba(17, 26, 42, 0.62);
  --panel-solid: #0d1524;
  --panel-2: rgba(23, 34, 54, 0.72);
  --line: rgba(126, 168, 214, 0.16);
  --line-strong: rgba(126, 168, 214, 0.32);

  /* ink */
  --ink: #e9f2ff;
  --ink-2: #a9bdd6;
  --ink-3: #6f849e;

  /* accents */
  --cyan: #35e0d8;
  --cyan-dim: #1a9c98;
  --violet: #8b7bff;
  --lime: #9ef01a;
  --amber: #ffb340;
  --rose: #ff5d7a;
  --blue: #4aa8ff;

  --exo: #ff7a45;
  --endo: #4aa8ff;

  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 22px;

  --shadow: 0 18px 48px -18px rgba(0, 0, 0, 0.85);
  --shadow-glow: 0 0 0 1px rgba(53, 224, 216, 0.22), 0 12px 40px -14px rgba(53, 224, 216, 0.35);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --topbar-h: 62px;
  --ease: cubic-bezier(0.22, 0.68, 0.36, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.2; }
p { margin: 0 0 0.7em; }
p:last-child { margin-bottom: 0; }
a { color: var(--cyan); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 6px; }

/* ---------- animated background ---------- */
.lab-grid-bg {
  position: fixed; inset: 0; z-index: -3; pointer-events: none;
  background:
    linear-gradient(180deg, #060a12 0%, #04070d 55%, #070b14 100%),
    repeating-linear-gradient(0deg, rgba(80,140,200,0.055) 0 1px, transparent 1px 44px),
    repeating-linear-gradient(90deg, rgba(80,140,200,0.055) 0 1px, transparent 1px 44px);
  background-blend-mode: normal, screen, screen;
  mask-image: radial-gradient(120% 100% at 50% 0%, #000 30%, rgba(0,0,0,0.35) 100%);
}
.lab-glow {
  position: fixed; z-index: -2; pointer-events: none;
  width: 62vw; height: 62vw; max-width: 900px; max-height: 900px;
  border-radius: 50%; filter: blur(90px); opacity: 0.4;
}
.lab-glow-a { top: -22vw; left: -12vw; background: radial-gradient(circle, rgba(53,224,216,0.30), transparent 65%); }
.lab-glow-b { bottom: -26vw; right: -14vw; background: radial-gradient(circle, rgba(139,123,255,0.28), transparent 65%); }

/* ---------- boot screen ---------- */
.boot {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #0a1220, #04070d 70%);
  transition: opacity 0.45s var(--ease), visibility 0.45s;
}
.boot.done { opacity: 0; visibility: hidden; }
.boot-inner { text-align: center; }
.boot-title {
  font-size: 2rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  background: linear-gradient(100deg, var(--cyan), #b9a6ff 70%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.boot-sub { color: var(--ink-3); font-size: 0.82rem; font-family: var(--mono); margin-top: 4px; }
.boot-bar { width: 190px; height: 3px; margin: 18px auto 0; background: rgba(255,255,255,0.08); border-radius: 99px; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 40%; border-radius: 99px; background: linear-gradient(90deg, var(--cyan), var(--violet)); animation: bootslide 1.1s var(--ease) infinite; }
@keyframes bootslide { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }
.boot-flask {
  width: 58px; height: 70px; margin: 0 auto 14px; position: relative;
  border: 2px solid rgba(53,224,216,0.55); border-radius: 6px 6px 26px 26px;
  overflow: hidden; box-shadow: 0 0 26px rgba(53,224,216,0.25) inset;
}
.boot-flask-liquid {
  position: absolute; inset: auto 0 0 0; height: 45%;
  background: linear-gradient(180deg, rgba(53,224,216,0.85), rgba(53,224,216,0.35));
  animation: bootbubble 1.6s ease-in-out infinite alternate;
}
@keyframes bootbubble { from { height: 38%; } to { height: 58%; } }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 clamp(12px, 2.4vw, 26px);
  background: linear-gradient(180deg, rgba(7,12,22,0.96), rgba(7,12,22,0.78));
  backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px;
  color: #04121a; background: linear-gradient(140deg, var(--cyan), #7ce8c0);
  box-shadow: 0 0 22px rgba(53,224,216,0.4);
}
.brand-text { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.05; display: flex; flex-direction: column; }
.brand-text b { font-weight: 800; color: var(--cyan); }
.brand-text small { font-size: 0.58rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--ink-3); font-weight: 500; }

.nav { display: flex; gap: 3px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 13px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--ink-2); cursor: pointer; white-space: nowrap;
  font-size: 0.87rem; font-weight: 550; transition: all 0.18s var(--ease);
}
.nav button svg { opacity: 0.75; }
.nav button:hover { color: var(--ink); background: rgba(120,170,220,0.08); }
.nav button[aria-current="page"] {
  color: #05121a; background: linear-gradient(140deg, var(--cyan), #6fe3c6);
  box-shadow: 0 6px 18px -8px rgba(53,224,216,0.9);
}
.nav button[aria-current="page"] svg { opacity: 1; }

.hud { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.hud-level { display: flex; align-items: center; gap: 9px; padding: 5px 12px 5px 6px; border: 1px solid var(--line); border-radius: 99px; background: var(--panel); }
.hud-level-badge {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.82rem; font-weight: 800; color: #0a0f1a;
  background: conic-gradient(from 210deg, var(--cyan), var(--violet), var(--cyan));
}
.hud-level-meta { min-width: 104px; }
.hud-level-name { font-size: 0.68rem; font-weight: 650; letter-spacing: 0.04em; color: var(--ink); }
.hud-xp-bar { height: 4px; border-radius: 99px; background: rgba(255,255,255,0.1); overflow: hidden; margin: 3px 0 2px; }
.hud-xp-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--cyan), var(--violet)); transition: width 0.6s var(--ease); }
.hud-xp-text { font-size: 0.6rem; color: var(--ink-3); font-family: var(--mono); }
.hud-stat { text-align: center; padding: 4px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); line-height: 1.1; }
.hud-stat b { display: block; font-size: 0.95rem; font-family: var(--mono); }
.hud-stat span { font-size: 0.56rem; text-transform: uppercase; letter-spacing: 0.11em; color: var(--ink-3); }

.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  cursor: pointer; color: var(--ink-2); transition: all 0.15s var(--ease);
}
.icon-btn:hover { color: var(--ink); border-color: var(--line-strong); background: rgba(120,170,220,0.14); }

/* ---------- generic panels & typography ---------- */
.view { padding: clamp(14px, 2.2vw, 26px); max-width: 1560px; margin: 0 auto; }
.view:focus { outline: none; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.panel-pad { padding: clamp(13px, 1.6vw, 20px); }

.page-head { margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; }
.page-head h1 { font-size: clamp(1.35rem, 2.4vw, 1.85rem); }
.page-head .sub { color: var(--ink-2); font-size: 0.9rem; max-width: 70ch; margin-top: 4px; }

.eyebrow {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.17em;
  color: var(--cyan); font-weight: 700;
}

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 99px; font-size: 0.68rem; font-weight: 650;
  letter-spacing: 0.03em; border: 1px solid var(--line-strong); background: rgba(120,170,220,0.09);
  color: var(--ink-2); white-space: nowrap;
}
.chip-cyan { color: var(--cyan); border-color: rgba(53,224,216,0.4); background: rgba(53,224,216,0.12); }
.chip-violet { color: #b9a6ff; border-color: rgba(139,123,255,0.4); background: rgba(139,123,255,0.13); }
.chip-amber { color: var(--amber); border-color: rgba(255,179,64,0.4); background: rgba(255,179,64,0.12); }
.chip-rose { color: var(--rose); border-color: rgba(255,93,122,0.4); background: rgba(255,93,122,0.12); }
.chip-lime { color: var(--lime); border-color: rgba(158,240,26,0.35); background: rgba(158,240,26,0.1); }
.chip-blue { color: var(--blue); border-color: rgba(74,168,255,0.4); background: rgba(74,168,255,0.12); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: rgba(120,170,220,0.08); color: var(--ink); cursor: pointer;
  font-size: 0.87rem; font-weight: 600; transition: all 0.16s var(--ease);
}
.btn:hover:not(:disabled) { background: rgba(120,170,220,0.16); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(140deg, var(--cyan), #5fdcb8); color: #04121a;
  border-color: transparent; box-shadow: 0 10px 26px -12px rgba(53,224,216,0.95);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(140deg, #4ef0e8, #6feec8); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { color: var(--rose); border-color: rgba(255,93,122,0.35); background: rgba(255,93,122,0.08); }
.btn-sm { padding: 6px 11px; font-size: 0.79rem; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 0.96rem; }

.field {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: rgba(6,11,20,0.72);
  color: var(--ink); font: inherit; font-size: 0.88rem;
}
.field::placeholder { color: var(--ink-3); }
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-wrap .field { padding-left: 34px; }

.formula { font-family: var(--mono); letter-spacing: 0.01em; }
.formula sub { font-size: 0.72em; }
.formula sup { font-size: 0.7em; }

.eq {
  font-family: var(--mono); font-size: 0.95rem; line-height: 1.9;
  padding: 11px 14px; border-radius: var(--radius-sm);
  background: rgba(4,8,15,0.66); border: 1px solid var(--line);
  overflow-x: auto; white-space: nowrap;
}
.eq .arrow { color: var(--cyan); margin: 0 8px; }
.eq .state { color: var(--ink-3); font-size: 0.82em; }

.divider { height: 1px; background: var(--line); margin: 14px 0; border: 0; }

.empty {
  display: grid; place-items: center; gap: 10px; text-align: center;
  padding: clamp(28px, 6vw, 60px) 20px; color: var(--ink-3);
}
.empty .empty-icon { font-size: 2.4rem; opacity: 0.6; filter: grayscale(0.2); }
.empty h3 { color: var(--ink-2); font-size: 1rem; }
.empty p { max-width: 44ch; font-size: 0.87rem; }

.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.muted { color: var(--ink-3); }
.small { font-size: 0.8rem; }
.tabular { font-family: var(--mono); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(126,168,214,0.3) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: rgba(126,168,214,0.26); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(126,168,214,0.45); background-clip: content-box; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; z-index: 120; right: 16px; bottom: 16px;
  display: grid; gap: 9px; width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; gap: 11px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: linear-gradient(140deg, rgba(20,32,52,0.97), rgba(13,21,36,0.97));
  border: 1px solid var(--line-strong); box-shadow: var(--shadow);
  animation: toastIn 0.4s var(--ease);
}
.toast.out { animation: toastOut 0.3s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(28px); } }
.toast-icon { font-size: 1.25rem; line-height: 1.2; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 0.87rem; font-weight: 700; }
.toast-msg { font-size: 0.79rem; color: var(--ink-2); }
.toast.xp { border-color: rgba(158,240,26,0.4); }
.toast.badge { border-color: rgba(255,179,64,0.45); }
.toast.discovery { border-color: rgba(53,224,216,0.45); box-shadow: var(--shadow-glow); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150; display: grid; place-items: center;
  padding: 18px; background: rgba(3,6,12,0.74); backdrop-filter: blur(6px);
  animation: fade 0.22s var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(720px, 100%); max-height: min(86vh, 900px); overflow: auto;
  background: linear-gradient(150deg, rgba(19,29,48,0.98), rgba(11,18,31,0.99));
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  box-shadow: 0 40px 90px -30px #000; animation: modalIn 0.3s var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(18px) scale(0.98); } }
.modal-head {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  padding: 17px 20px 13px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(19,29,48,0.99), rgba(17,26,43,0.95));
  backdrop-filter: blur(8px);
}
.modal-head h2 { font-size: 1.1rem; }
.modal-body { padding: 18px 20px 22px; }
.modal-close {
  flex-shrink: 0; width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 9px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--ink-2);
}
.modal-close:hover { color: var(--ink); background: rgba(255,255,255,0.07); }

/* ---------- safety strip ---------- */
.safety-strip {
  display: flex; gap: 9px; align-items: center; justify-content: center;
  padding: 9px 16px; margin: 8px auto 20px; max-width: 1560px;
  border-top: 1px solid var(--line); color: var(--ink-3); font-size: 0.74rem;
}
.safety-strip p { margin: 0; }
.safety-strip b { color: var(--amber); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .hud-level-meta { min-width: 78px; }
  .hud-stat { padding: 4px 8px; }
}
@media (max-width: 980px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 9px clamp(10px, 3vw, 18px); gap: 10px; }
  .nav { order: 3; width: 100%; flex: 1 0 100%; padding-bottom: 2px; }
  .hud { margin-left: auto; }
  .brand-text small { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .hud-level-meta, .hud-stat span { display: none; }
  .hud-level { padding: 4px; border: 0; background: transparent; }
  .hud-stat { border-radius: 8px; }
  .nav button { padding: 7px 10px; font-size: 0.8rem; }
  .nav button span { display: none; }
  .nav button svg { opacity: 1; }
  .nav button[aria-current="page"] span { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
