/* ============================================================
   Base & Reset
   ============================================================ */

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

:root {
  --bg-primary: #0f1119;
  --bg-secondary: #161822;
  --bg-tertiary: #1c1f2e;
  --bg-surface: #212439;
  --border: #2a2d42;
  --text-primary: #e8eaf0;
  --text-secondary: #9a9db5;
  --text-muted: #6b6e85;
  --accent: #5b8def;
  --accent-dim: #3b5fc0;
  --danger: #e0556a;
  --success: #4caf90;
  --warning: #e5b848;
  --purple: #9b7aef;
  --radius: 8px;
  --radius-sm: 5px;
  --transition: 150ms ease;
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Layout
   ============================================================ */

#app {
  display: grid;
  grid-template-columns: 300px 1fr 360px;
  grid-template-rows: 1fr;
  width: 100vw;
  height: 100vh;
}

/* ============================================================
   Sidebar
   ============================================================ */

#sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.sidebar-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.sidebar-group {
  margin-bottom: 2px;
}

.sidebar-group-header {
  padding: 8px 20px 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-molecule-list {
  display: flex;
  flex-direction: column;
}

.sidebar-molecule-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  cursor: pointer;
  transition: background var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-molecule-item:hover {
  background: var(--bg-tertiary);
}

.sidebar-molecule-item.active {
  background: var(--bg-surface);
  border-left-color: var(--accent);
}

.mol-item-formula {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 40px;
}

.mol-item-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Viewer
   ============================================================ */

#viewer {
  position: relative;
  background: radial-gradient(ellipse at center, #1a1d2e 0%, #0f1119 100%);
  cursor: grab;
}

#viewer:active {
  cursor: grabbing;
}

#viewer canvas {
  display: block;
}

/* Toolbar overlay on viewer */
#toolbar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px;
  z-index: 5;
  backdrop-filter: blur(10px);
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.toolbar-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.toolbar-btn.active {
  background: var(--accent-dim);
  color: #fff;
}

.toolbar-btn .key-hint {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 2px;
  padding: 1px 4px;
  background: var(--bg-primary);
  border-radius: 3px;
}

.toolbar-btn.active .key-hint {
  color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.2);
}

/* Legend hint */
#legend {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
  font-size: 10px;
  color: var(--text-muted);
  z-index: 5;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.lp {
  background: #cc88ff;
  opacity: 0.7;
}

.legend-dot.geo {
  background: transparent;
  border: 1.5px solid #4466aa;
  opacity: 0.6;
}

/* ============================================================
   Info Panel
   ============================================================ */

#info-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 10;
}

.info-section {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 16px;
}

.info-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Molecule identity */
#mol-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

#mol-formula {
  font-size: 28px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
}

#mol-charge {
  font-size: 16px;
  color: var(--text-secondary);
  margin-left: 4px;
}

.mol-identity-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

/* VSEPR info */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.info-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
}

.info-value.highlight {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 14px;
}

.info-value.geometry {
  color: var(--purple);
}

/* Hybridization badge */
.hyb-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--purple));
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 260px 1fr 300px;
  }
}

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  #sidebar {
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #info-panel {
    max-height: 200px;
    border-left: none;
    border-top: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px;
  }
  .info-section {
    flex: 1;
    min-width: 140px;
    padding: 10px;
  }
}

/* ============================================================
   Loading states & transitions
   ============================================================ */

.sidebar-molecule-item {
  transition: all 120ms ease;
}

.toolbar-btn {
  transition: all 120ms ease;
}

/* Pulse animation for geometry wireframe */
@keyframes geo-pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.55; }
}

#viewer canvas + canvas {
  /* CSS2DRenderer canvas */
}
