/* Molecule Builder UI */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 90% 70% at 50% 38%, #1a1d34 0%, #0c0d1c 55%, #06070f 100%);
  color: #e0e0ee;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 44px 1fr;
  grid-template-areas:
    "top"
    "center";
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
#topbar {
  grid-area: top;
  background: #13131c;
  border-bottom: 1px solid #2a2a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 44px;
  z-index: 50;
  min-width: 0;
  overflow: visible;
}
.topbar-right { flex-shrink: 0; }

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
.app-logo {
  width: 30px;
  height: 30px;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.45));
}
.app-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: #fff;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.hint {
  font-size: 11px;
  color: #777788;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { display: flex; gap: 6px; }

.action-btn {
  background: #1c1c2a;
  color: #e0e0ee;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 200ms, transform 120ms, border-color 200ms;
}

.action-btn:hover {
  background: #2a2a3a;
  border-color: #3a3a4a;
}

.action-btn.danger:hover {
  background: #4a1c20;
  border-color: #aa3a40;
  color: #ffcccc;
}

.action-btn.toggle.on {
  background: #1c2a3a;
  border-color: #44aaff;
  color: #aaddff;
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 2px 0 8px 0;
}

.panel-sub-title {
  font-size: 10px;
  color: #888899;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 10px 0 4px 0;
}

/* ---------- Floating panel (periodic table, library, reactions, info) ---------- */
.floating-panel {
  position: absolute;
  top: 56px;
  left: 16px;
  width: 820px;
  height: 540px;
  min-width: 280px;
  min-height: 200px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  background: rgba(18, 18, 28, 0.86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  z-index: 8;
  display: flex;
  flex-direction: column;
  resize: both;
  overflow: hidden;
  transition: box-shadow 200ms, border-color 200ms;
}
.floating-panel.focused {
  border-color: rgba(68,170,255,0.55);
  box-shadow: 0 16px 50px rgba(0,0,0,0.6), 0 0 0 1px rgba(68,170,255,0.25);
  z-index: 9;
}
.floating-panel::after {
  /* Visible resize affordance — the native resize handle is invisible against dark bg. */
  content: '';
  position: absolute;
  right: 2px; bottom: 2px;
  width: 14px; height: 14px;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.18) 60%, transparent 60%),
    linear-gradient(135deg, transparent 75%, rgba(255,255,255,0.18) 75%, rgba(255,255,255,0.18) 85%, transparent 85%);
  border-bottom-right-radius: 10px;
}

.floating-panel[hidden] { display: none !important; }

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(40, 40, 60, 0.55);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  cursor: move;
  user-select: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: #e6e6f0;
  flex: 0 0 auto;
}

.panel-header-title { text-transform: uppercase; font-size: 11px; }
.panel-header-spacer { flex: 1; }

.panel-header-search {
  background: rgba(10, 10, 20, 0.6);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 5px;
  color: #e0e0ee;
  font-family: inherit;
  font-size: 11px;
  padding: 3px 7px;
  width: 110px;
  outline: none;
  transition: border-color 150ms, width 150ms;
}
.panel-header-search:focus { border-color: rgba(68,170,255,0.55); width: 140px; }
.panel-header-search::-webkit-search-cancel-button { -webkit-appearance: none; }

.panel-header-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: #ccccdd;
  width: 22px;
  height: 22px;
  line-height: 1;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 150ms, border-color 150ms, color 150ms;
}
.panel-header-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.25);
  color: #fff;
}

.panel-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 10px 12px 14px;
}

/* ---------- Periodic table ---------- */
.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  gap: 3px;
}

.periodic-row {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 3px;
}

.periodic-row.indented {
  margin-left: calc((100% / 18) * 2);
  margin-right: calc((100% / 18) * 1);
}

.element-btn {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(0,0,0,0.4);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  overflow: hidden;
  transition: transform 120ms, filter 200ms, box-shadow 200ms, border-color 200ms;
  min-height: 24px;
}

.element-btn:hover {
  filter: brightness(1.15);
  transform: scale(1.08);
  z-index: 2;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  cursor: grab;
}
.element-btn:active { cursor: grabbing; }
.element-btn.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.element-btn .e-num {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 9px;
  line-height: 1;
  opacity: 0.85;
}

.element-btn .e-sym {
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.element-btn .e-name {
  font-size: 7px;
  line-height: 1;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 0 1px;
  opacity: 0.85;
}

.element-cell-empty {
  visibility: hidden;
}

/* When the panel gets small, hide the name to keep symbols readable */
.floating-panel.compact .element-btn .e-name { display: none; }

/* ---------- Molecule library ---------- */
.molecule-library {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mol-item {
  background: #1a1a26;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 200ms, border-color 200ms, transform 120ms;
}

.mol-item:hover {
  background: #22223a;
  border-color: #44aaff;
}

.mol-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
}

.mol-formula {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  color: #44aaff;
  font-weight: 500;
}

.mol-desc {
  font-size: 11px;
  color: #888899;
  margin-top: 3px;
  line-height: 1.3;
}

/* ---------- Canvas area ---------- */
#canvas-area {
  grid-area: center;
  position: relative;
  overflow: hidden;
  background: #05050a;
}

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

/* ---------- Atom hover tooltip ---------- */
.atom-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 15, 25, 0.92);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1.25;
  color: #e8e8f4;
  white-space: nowrap;
  z-index: 9;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  transform: translate(12px, -50%);
}

.atom-tooltip .tt-name {
  font-weight: 600;
  color: #fff;
}

.atom-tooltip .tt-sub {
  font-size: 10px;
  color: #aaaabb;
  margin-top: 1px;
}

/* ---------- Circular atom context menu ---------- */
.atom-menu {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
  z-index: 7;
}

.atom-menu[hidden] { display: none; }

.atom-menu-btn {
  position: absolute;
  pointer-events: auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(20, 22, 32, 0.92);
  color: #e6e6f0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  box-shadow: 0 6px 18px rgba(0,0,0,0.6), 0 0 0 1px rgba(0,0,0,0.4);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 180ms ease-out,
              background-color 160ms,
              border-color 160ms;
  user-select: none;
  padding: 0;
}

.atom-menu.show .atom-menu-btn {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.atom-menu.show .atom-menu-btn:nth-child(1) { transition-delay: 30ms; }
.atom-menu.show .atom-menu-btn:nth-child(2) { transition-delay: 90ms; }
.atom-menu.show .atom-menu-btn:nth-child(3) { transition-delay: 150ms; }
.atom-menu.show .atom-menu-btn:nth-child(4) { transition-delay: 210ms; }

.atom-menu-btn:hover {
  background: rgba(40, 44, 60, 0.97);
  border-color: rgba(255,255,255,0.32);
}

.atom-menu-btn.primary:hover {
  background: rgba(30, 70, 130, 0.97);
  border-color: rgba(100, 180, 255, 0.75);
  color: #cce6ff;
}

.atom-menu-btn.danger:hover {
  background: rgba(120, 30, 40, 0.97);
  border-color: rgba(255, 90, 100, 0.7);
  color: #ffcccc;
}

.atom-menu-btn .amb-icon {
  font-size: 19px;
  line-height: 1;
  margin-bottom: 3px;
  font-weight: 700;
}

.atom-menu-btn .amb-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
  font-weight: 600;
}

.atom-menu.moving .atom-menu-btn {
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
}

/* Move-mode chrome */
#canvas-area.moving { cursor: move; }
#canvas-area.moving #atom-tooltip { display: none !important; }

/* Drag-and-drop: highlight canvas when an element is dragged over it */
#canvas-area.drag-target::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 3px rgba(80, 180, 255, 0.7);
  background: rgba(80, 180, 255, 0.06);
  z-index: 5;
}

.move-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 22, 32, 0.92);
  border: 1px solid rgba(100, 180, 255, 0.4);
  color: #cce6ff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.move-hint[hidden] { display: none; }

.move-hint kbd {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  color: #fff;
}

/* ---------- Stats overlay ---------- */
.stats-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(20, 20, 30, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 10px 14px;
  min-width: 140px;
  color: #e0e0ee;
  font-size: 12px;
  z-index: 5;
  pointer-events: none;
}

.stats-formula {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.stats-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-top: 2px;
  font-size: 11px;
}

.stats-label {
  color: #888899;
  text-transform: uppercase;
  font-size: 9px;
  letter-spacing: 0.08em;
  min-width: 38px;
}

.stats-unit {
  color: #666677;
  font-size: 10px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .hint { display: none; }
  .library-panel { width: 240px; }
}
@media (max-width: 900px) {
  .library-panel { width: 200px; }
  .reactions-panel { right: 232px; }
}

/* ===== Topbar additions ===== */
.topbar-sep {
  width: 1px;
  background: #2a2a3a;
  margin: 0 4px;
  align-self: stretch;
}
.action-btn.primary {
  background: #44aaff;
  color: #06121e;
  border-color: #44aaff;
}
.action-btn.primary:hover { background: #5cb8ff; border-color: #5cb8ff; }
.action-btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Label layer (atom labels, charge badges, bond captions) ===== */
.label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  overflow: hidden;
}
.atom-label {
  position: absolute;
  transform: translate(-50%, -120%);
  background: rgba(20, 20, 30, 0.78);
  color: #ffffff;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.10);
  white-space: nowrap;
  pointer-events: none;
}
.atom-label.skeletal { display: none; }
.charge-badge {
  position: absolute;
  transform: translate(50%, -120%);
  background: #44aaff;
  color: #06121e;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  line-height: 16px;
  text-align: center;
  border-radius: 50%;
  border: 1px solid #06121e;
}
.charge-badge.positive { background: #5cb8ff; color: #06121e; }
.charge-badge.negative { background: #ff7d6e; color: #1a0606; }
.charge-badge.neutral  {
  background: rgba(28, 28, 40, 0.85);
  color: #99aabb;
  border-color: rgba(255,255,255,0.18);
  font-weight: 500;
}
.bond-caption {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 30, 0.78);
  color: #cce6ff;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.06);
  white-space: nowrap;
}

/* ===== Hybridisation legend ===== */
.hybrid-legend {
  position: absolute;
  bottom: 56px;
  left: 12px;
  background: rgba(20,20,30,0.78);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  color: #cccce0;
  z-index: 7;
  pointer-events: none;
}
.legend-title {
  font-size: 10px;
  color: #888899;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 16px;
}
.legend-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
}

/* ===== Formula bar (bottom of canvas) ===== */
.formula-bar {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 20, 30, 0.85);
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  padding: 6px 8px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 7;
}
.formula-bar input {
  background: #0a0a14;
  color: #fff;
  border: 1px solid #2a2a3a;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  width: 360px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.formula-bar input:focus { outline: none; border-color: #44aaff; }
.formula-bar.error input { border-color: #ee5566; }

/* ===== Resonance bar ===== */
.resonance-bar {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20,20,30,0.85);
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  padding: 4px 10px;
  z-index: 8;
  font-size: 12px;
  color: #cccce0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.resonance-bar button {
  background: #1c1c2a;
  color: #e0e0ee;
  border: 1px solid #2a2a3a;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}
.resonance-bar button:hover { background: #2a2a3a; }
.rb-title { color: #888899; text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; }

/* ===== Compare canvas ===== */
.compare-canvas {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 360px;
  height: 280px;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  background: #06060c;
  z-index: 6;
}
.compare-label {
  position: absolute;
  top: 296px;
  left: 12px;
  width: 360px;
  text-align: center;
  font-size: 11px;
  color: #888899;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  z-index: 6;
  pointer-events: none;
}

/* ===== Library panel =====
   Default position sits below the stats overlay (which lives at top:12px /
   right:12px, ~100px tall) so the molecule formula/MW/atoms/bonds box stays
   visible. Height is auto so the panel hugs its content; the max-height cap
   keeps it inside the viewport, and the .library-body scrolls when categories
   expand past that. The user can still drag-resize via the corner handle.
   Subtract 44px (topbar) + 130px (top offset within main) + 16px (bottom gutter) */
.library-panel {
  width: 280px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 240px; min-height: 240px;
  top: 130px; left: auto; right: 16px;
}
.library-body { padding: 8px 10px 14px; }
.library-panel .molecule-library { gap: 5px; }
.library-panel .mol-item { padding: 7px 9px; }
.library-panel .mol-name { font-size: 12.5px; }
.library-panel .mol-formula { font-size: 10.5px; }
.library-panel .mol-desc { font-size: 10.5px; margin-top: 2px; }
.mol-item.hidden { display: none !important; }

/* ---------- Accordion (Library + Reactions) ---------- */
.lib-cat-section,
.rxn-cat-section {
  display: flex; flex-direction: column;
  border: 1px solid #23233a;
  border-radius: 6px;
  background: #15151f;
  overflow: hidden;
}
.lib-cat-head,
.rxn-cat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  background: #1a1a26;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  color: #cfd0e0;
  transition: background 150ms;
}
.lib-cat-head:hover,
.rxn-cat-head:hover { background: #22223a; }
.lib-cat-caret,
.rxn-cat-caret {
  display: inline-block;
  width: 10px;
  font-size: 10px;
  color: #8888aa;
  transform: rotate(0deg);
  transition: transform 150ms;
}
.lib-cat-section.open .lib-cat-caret,
.rxn-cat-section.open .rxn-cat-caret { transform: rotate(90deg); }
.lib-cat-name,
.rxn-cat-name {
  flex: 1 1 auto;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.lib-cat-count,
.rxn-cat-count {
  font-size: 10.5px;
  color: #888899;
  font-variant-numeric: tabular-nums;
}
.lib-cat-body,
.rxn-cat-body {
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 6px 7px 8px;
  background: #131320;
}
.lib-cat-section.open .lib-cat-body,
.rxn-cat-section.open .rxn-cat-body { display: flex; }
.lib-cat-section.empty,
.rxn-cat-section.empty { display: none; }

/* ===== Reactions panel ===== */
.reactions-panel {
  width: 360px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 300px; min-height: 240px;
  top: 130px; left: auto; right: 312px;
}
.reactions-panel .panel-body {
  overflow-x: hidden;       /* never horizontal — equations wrap */
  overflow-y: auto;         /* scroll the list vertically */
}
.rxn-list {
  display: flex; flex-direction: column; gap: 5px;
  min-width: 0;
}
.rxn-item {
  background: #1a1a26; border: 1px solid #2a2a3a; border-radius: 6px;
  padding: 8px 10px; cursor: pointer;
  transition: background 200ms, border-color 200ms;
  min-width: 0;
}
.rxn-item:hover { background: #22223a; border-color: #44aaff; }
.rxn-name {
  font-size: 13px; font-weight: 600; color: #fff;
  overflow-wrap: anywhere;
}
.rxn-eq {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px; color: #44aaff; margin-top: 3px;
  overflow-wrap: anywhere; word-break: break-word;
}
.rxn-viewer {
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
}
.rxn-back {
  background: transparent; border: none; color: #888899;
  padding: 0; font-size: 11px; cursor: pointer; text-align: left;
  align-self: flex-start;
}
.rxn-back:hover { color: #44aaff; }
.rxn-viewer-title {
  font-size: 14px; font-weight: 700; color: #fff;
  overflow-wrap: anywhere;
}
.rxn-viewer-eq {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; color: #44aaff;
  overflow-wrap: anywhere; word-break: break-word;
}
.rxn-energy {
  background: rgba(10, 10, 20, 0.6);
  border: 1px solid #2a2a3a; border-radius: 6px;
  height: 90px; padding: 0;
}
.rxn-controls {
  display: flex; gap: 6px; align-items: center;
  flex-wrap: wrap;
}
.rxn-ctl {
  background: #1c1c2a; color: #e0e0ee;
  border: 1px solid #2a2a3a; border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 500; cursor: pointer;
  transition: background 200ms, border-color 200ms;
  white-space: nowrap;
}
.rxn-ctl:hover { background: #2a2a3a; border-color: #3a3a4a; }
.rxn-ctl-icon {
  padding: 5px 8px; font-size: 14px; line-height: 1;
}
.rxn-ctl-primary {
  background: #1c2a3a; border-color: #44aaff; color: #aaddff;
}
.rxn-ctl-primary:hover { background: #244466; }
.rxn-scrubber {
  flex: 1 1 100%;
  -webkit-appearance: none; appearance: none;
  height: 4px; background: #2a2a3a; border-radius: 2px; outline: none;
  margin-top: 2px;
}
.rxn-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: #44aaff; border: 2px solid #0a0a14; cursor: pointer;
}
.rxn-scrubber::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #44aaff; border: 2px solid #0a0a14; cursor: pointer;
}
.rxn-step {
  background: rgba(10, 10, 20, 0.6);
  border-left: 2px solid #44aaff; border-radius: 4px;
  padding: 8px 10px; font-size: 12px; color: #cce6ff;
  line-height: 1.4; min-height: 36px;
  overflow-wrap: anywhere;
}
.rxn-info-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid rgba(68,170,255,0.4);
  color: #aaddff;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 11px;
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}
.rxn-info-btn:hover { background: rgba(68,170,255,0.10); border-color: #44aaff; }

/* ===== Reaction playback (floating) ===== */
.reaction-playback-panel {
  width: 340px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 280px;
  top: auto; left: calc(50% - 170px); right: auto; bottom: 16px;
}
.rxn-playback-body {
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
  overflow-y: auto;
}

/* ===== Topbar dropdown menus ===== */
.menu { position: relative; display: inline-flex; }
.menu-toggle { display: inline-flex; align-items: center; gap: 6px; }
.menu-caret { font-size: 10px; opacity: 0.75; transition: transform 150ms; }
.menu.open .menu-toggle { background: #1c2a3a; border-color: #44aaff; color: #aaddff; }
.menu.open .menu-caret { transform: rotate(180deg); }

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 230px;
  background: rgba(20, 20, 30, 0.97);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  padding: 8px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.menu-panel[hidden] { display: none; }

.menu-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #7d7d96;
  padding: 6px 8px 4px;
}
.menu-divider {
  height: 1px;
  background: #2a2a3a;
  margin: 6px 0;
}

.menu-check,
.menu-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 12.5px;
  color: #d0d0e0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 150ms;
}
.menu-check:hover,
.menu-radio:hover { background: #1c1c2a; color: #fff; }
.menu-check input,
.menu-radio input {
  accent-color: #44aaff;
  margin: 0;
  flex-shrink: 0;
}

.menu-item {
  text-align: left;
  background: transparent;
  border: none;
  color: #d0d0e0;
  padding: 7px 10px;
  font: inherit;
  font-size: 12.5px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.menu-item:hover { background: #1c2a3a; color: #aaddff; }
.menu-item.danger:hover { background: #4a1c20; color: #ffcccc; }
.menu-item-toggle[aria-pressed="true"] {
  background: #1c2a3a;
  color: #aaddff;
  box-shadow: inset 2px 0 0 #44aaff;
}

/* ===== Molecule info panel (textbook card) ===== */
.info-panel {
  width: 420px;
  height: auto;
  max-height: calc(100vh - 190px);
  min-width: 320px; min-height: 240px;
  top: 130px; left: 16px;
}
.mi-panel-body {
  overflow-x: hidden;
  overflow-y: auto;
}
.mi-head { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #232333; }
.mi-name {
  font-size: 20px; font-weight: 700; color: #fff;
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.mi-formula {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px; color: #44aaff; font-weight: 600;
}
.mi-iupac {
  font-size: 12px; color: #aaccff; margin-top: 4px;
  text-transform: none;
}
.mi-aliases {
  font-size: 11px; color: #99aabb; margin-top: 2px;
}
.mi-summary {
  margin: 0 0 12px 0;
  font-size: 13px; line-height: 1.5; color: #d6d6e6;
  font-style: italic;
}
.mi-section { margin-top: 14px; }
.mi-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: #88aaff; margin-bottom: 6px; font-weight: 600;
}
.mi-body {
  margin: 0 0 8px 0;
  font-size: 13px; line-height: 1.55; color: #d6d6e6;
  overflow-wrap: anywhere;
}
.mi-quick {
  display: grid;
  grid-template-columns: minmax(120px, max-content) 1fr;
  gap: 4px 14px;
  background: rgba(10,10,20,0.45);
  border: 1px solid #232333;
  border-radius: 6px;
  padding: 8px 10px;
}
.mi-quick-row { display: contents; }
.mi-quick-k {
  font-size: 11px; color: #8d9ab5;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding-top: 2px;
}
.mi-quick-v {
  font-size: 12.5px; color: #e6e6f0;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}
.mi-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mi-chip {
  display: inline-block;
  background: #1c2a3a; border: 1px solid #2a4a6a;
  color: #aaddff; font-size: 11px;
  padding: 2px 8px; border-radius: 999px;
}
.mi-chip-warn {
  background: #3a2a1a; border-color: #6a4a2a; color: #ffcc88;
}
.mi-list {
  margin: 4px 0 0 0; padding-left: 20px;
  color: #d6d6e6; font-size: 12.5px; line-height: 1.55;
}
.mi-list li { margin-bottom: 3px; }
.mi-refs {
  margin: 4px 0 0 0; padding-left: 18px;
  color: #d6d6e6; font-size: 12px; line-height: 1.6;
}
.mi-refs a { color: #44aaff; text-decoration: none; }
.mi-refs a:hover { color: #5cb8ff; text-decoration: underline; }
.mi-empty { text-align: center; padding: 36px 12px; color: #8d9ab5; }
.mi-empty-title {
  font-size: 13px; color: #d6d6e6; font-weight: 600;
  margin-bottom: 6px;
}
.mi-empty p { font-size: 12px; line-height: 1.5; }
.mi-empty a { color: #44aaff; text-decoration: none; }
.mi-empty a:hover { text-decoration: underline; }

.mi-thumb {
  float: right;
  margin: 0 0 8px 12px;
  max-width: 160px;
  max-height: 160px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid rgba(255,255,255,0.18);
  padding: 8px;
  box-sizing: border-box;
  object-fit: contain;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.mi-category {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #88aaff;
  background: rgba(68,170,255,0.08);
  border: 1px solid rgba(68,170,255,0.28);
  border-radius: 999px;
  padding: 2px 9px;
  margin-bottom: 8px;
}
.mi-source {
  font-size: 10.5px; color: #6a7585; margin-top: 14px; text-align: right;
  font-style: italic;
}
