:root {
  --bg: #05060d;
  --bg-panel: rgba(10, 12, 25, 0.85);
  --bg-panel-solid: #0a0c19;
  --fg: #e8ecff;
  --fg-dim: #8a90b8;
  --accent: #66c8ff;
  --accent-warm: #ffb766;
  --accent-violet: #b566ff;
  --border: rgba(180, 200, 255, 0.12);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  --bubble-bg: linear-gradient(135deg, #1a2150, #2a1860);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 56px 1fr 110px;
  grid-template-areas:
    "topbar topbar"
    "sidebar stage"
    "controls controls";
  height: 100vh;
  background:
    radial-gradient(ellipse at 30% 20%, #161e44 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, #2a1248 0%, transparent 55%),
    var(--bg);
}

#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
#topbar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 0;
}
#topbar-controls { display: flex; gap: 8px; }
.topbtn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 16px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.topbtn:hover { background: rgba(255,255,255,0.06); border-color: var(--accent); }
.topbtn.off { opacity: 0.45; text-decoration: line-through; }

#sidebar {
  grid-area: sidebar;
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}
#sim-nav { display: flex; flex-direction: column; gap: 6px; }
.sim-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--fg);
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  transition: all 0.2s ease;
}
.sim-tab:hover { background: rgba(255,255,255,0.04); }
.sim-tab.active {
  background: linear-gradient(120deg, rgba(102, 200, 255, 0.18), rgba(181, 102, 255, 0.18));
  border-color: var(--accent);
  box-shadow: 0 0 24px rgba(102, 200, 255, 0.18);
}
.sim-icon { font-size: 22px; }

#sim-blurb {
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid var(--border);
}
#sim-blurb h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--accent);
}
#sim-blurb p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-dim);
}

#stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#bubble-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.bubble {
  position: absolute;
  background: var(--bubble-bg);
  border: 1px solid rgba(180, 200, 255, 0.25);
  color: var(--fg);
  padding: 12px 16px;
  border-radius: 18px;
  max-width: 280px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: var(--shadow), 0 0 32px rgba(102, 200, 255, 0.25);
  pointer-events: auto;
  animation: bubblePop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom left;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -10px;
  left: 20px;
  width: 20px;
  height: 20px;
  background: inherit;
  border-right: 1px solid rgba(180,200,255,0.25);
  border-bottom: 1px solid rgba(180,200,255,0.25);
  transform: rotate(45deg);
}
.bubble.fade-out { animation: bubbleFade 0.4s ease forwards; }
@keyframes bubblePop {
  0% { transform: scale(0.3) translateY(20px); opacity: 0; }
  60% { transform: scale(1.05) translateY(-4px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes bubbleFade {
  to { transform: scale(0.7) translateY(-12px); opacity: 0; }
}

#controls {
  grid-area: controls;
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Allow scrolling when many buttons (sim3 has 15+ controls). */
  overflow-y: auto;
}
#sim-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  min-height: 36px;
}
#sim-controls label { font-size: 13px; color: var(--fg-dim); display: flex; align-items: center; gap: 8px; }
#sim-controls input[type="range"] { accent-color: var(--accent); width: 160px; }
#sim-controls button {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}
#sim-controls button:hover { background: rgba(102, 200, 255, 0.12); border-color: var(--accent); }
#narration {
  font-size: 13px;
  color: var(--fg-dim);
  display: flex;
  gap: 8px;
  align-items: center;
}
#narration-text { color: var(--fg); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}
.modal {
  background: var(--bg-panel-solid);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 28px;
  max-width: 560px;
  width: 92%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { margin-top: 0; color: var(--accent); }
.modal h3 { margin: 12px 0 4px; font-size: 15px; color: var(--accent-warm); }
.modal p { line-height: 1.55; }
.modal .footer-note { color: var(--fg-dim); font-size: 12px; margin-top: 16px; }
.modal button.close {
  float: right;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
}
.glossary-entry {
  padding: 10px 12px;
  margin: 6px 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.glossary-entry h3 { margin: 0 0 4px; }
.glossary-entry p { margin: 0; font-size: 13.5px; line-height: 1.5; }

/* Star status badge (sim1) */
.star-status {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(10, 12, 25, 0.82);
  border: 1px solid rgba(180, 200, 255, 0.25);
  border-radius: 12px;
  padding: 10px 14px 12px;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.3;
  backdrop-filter: blur(8px);
  z-index: 6;
  min-width: 200px;
  pointer-events: none;
}
.star-status .label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  margin-bottom: 8px;
}
.star-status .label .badge-icon { font-size: 18px; }
.star-status .fuel-wrap {
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 4px;
}
.star-status .fuel-bar {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}
.star-status .fuel-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease, background-color 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px auto 1fr 130px;
    grid-template-areas:
      "topbar"
      "sidebar"
      "stage"
      "controls";
  }
  #sidebar { max-height: 200px; padding: 8px; }
  #sim-nav { flex-direction: row; overflow-x: auto; }
  .sim-tab { white-space: nowrap; }
  #sim-blurb { display: none; }
}
