/* ==========================================================================
   Protein Tales — Step 1 Viewer Styles
   Dark aesthetic, glassmorphic panels, rich typography
   ========================================================================== */

:root {
  --bg-primary: #0a0e17;
  --bg-surface: rgba(16, 24, 40, 0.82);
  --bg-surface-hover: rgba(24, 34, 56, 0.95);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(56, 189, 248, 0.35);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #38bdf8;
  --accent-cyan-glow: rgba(56, 189, 248, 0.25);
  --accent-gold: #fbbf24;
  --accent-gold-glow: rgba(251, 191, 36, 0.2);
  --accent-emerald: #34d399;
  --accent-rose: #f43f5e;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-hud: 0 20px 40px -15px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
  --blur-hud: blur(20px);
}

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

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

#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Header */
.app-header {
  height: 60px;
  background: rgba(10, 14, 23, 0.75);
  backdrop-filter: var(--blur-hud);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.series-tag {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
  background: var(--accent-cyan-glow);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-accent);
}

.divider {
  color: var(--text-muted);
  font-weight: 300;
}

.episode-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.pdb-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--accent-gold);
  border: 1px solid rgba(251, 191, 36, 0.2);
  margin-left: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main Viewport & Story Panel Layout: view + panel side by side (panel on the right),
   stacked (panel below) on phones -- see the max-width: 768px query at the bottom. */
.main-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

.viewport-container {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  background: radial-gradient(circle at center, #111827 0%, #070a10 100%);
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 23, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 30;
  transition: opacity 0.4s ease, visibility 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(56, 189, 248, 0.15);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Narrative Story Panel: a dedicated sidebar next to the viewport (not layered over it),
   so 3D drag/rotate/zoom never fights with reading or clicking the panel's controls. */
.hud-card {
  position: relative;
  flex: 0 0 400px;
  width: 400px;
  max-width: 45vw;
  height: 100%;
  background: var(--bg-surface);
  backdrop-filter: var(--blur-hud);
  -webkit-backdrop-filter: var(--blur-hud);
  border: none;
  border-left: 1px solid var(--border-subtle);
  border-radius: 0;
  box-shadow: -20px 0 40px -15px rgba(0, 0, 0, 0.5);
  padding: 24px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Tiny progress stripe pinned to the top of the story panel: one thin segment per
   stage, filling in as you advance. Replaces the old "Stage X of 8" text readout. */
.progress-stripe {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
}

.progress-seg {
  flex: 1;
  height: 4px;
  padding: 0;
  border: none;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 0.3s;
}

.progress-seg:hover {
  background: rgba(255, 255, 255, 0.2);
}

.progress-seg.completed {
  background: rgba(56, 189, 248, 0.5);
}

.progress-seg.active {
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.stage-title {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.25;
  color: #fff;
  letter-spacing: -0.02em;
}

.stage-body {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.highlight-callout {
  background: rgba(56, 189, 248, 0.08);
  border-left: 3px solid var(--accent-cyan);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #e2e8f0;
  font-size: 0.88rem;
}

.gold-callout {
  background: rgba(251, 191, 36, 0.08);
  border-left: 3px solid var(--accent-gold);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #fef08a;
  font-size: 0.88rem;
}

/* Hands-on "try this in Mol*" prompts -- kept visually distinct (green) from the
   cyan/gold informational callouts above, since these ask the reader to go DO
   something in the viewer rather than just read a fact. */
.exercise-callout {
  background: rgba(52, 211, 153, 0.08);
  border-left: 3px solid var(--accent-emerald);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: #a7f3d0;
  font-size: 0.88rem;
}

.exercise-callout ul {
  margin: 6px 0 0;
  padding-left: 1.2em;
}

.exercise-callout li {
  margin-bottom: 4px;
}

.stage-body details.explainer {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.stage-body details.explainer > summary {
  cursor: pointer;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-cyan);
  list-style: none;
  user-select: none;
}

.stage-body details.explainer > summary::-webkit-details-marker {
  display: none;
}

.stage-body details.explainer > summary::before {
  content: '\25B8';
  display: inline-block;
  width: 1em;
  transition: transform 0.15s ease;
}

.stage-body details.explainer[open] > summary::before {
  transform: rotate(90deg);
}

.stage-body details.explainer > summary:hover {
  color: var(--text-primary);
}

.stage-body details.explainer .highlight-callout {
  margin: 0 14px 12px;
}

.stage-actions {
  flex: 0 0 auto;
  display: flex;
}

.stage-actions button {
  width: 100%;
  justify-content: center;
}

/* Playback & Button Controls */
.card-footer {
  flex: 0 0 auto;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
}

.playback-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

button {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent-cyan);
  color: #04101e;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 8px 18px;
  font-weight: 600;
  box-shadow: 0 4px 12px var(--accent-cyan-glow);
}

.btn-primary:hover:not(:disabled) {
  background: #7dd3fc;
  box-shadow: 0 6px 16px rgba(56, 189, 248, 0.4);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 8px 14px;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-secondary.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid transparent;
  padding: 6px 12px;
}

.btn-ghost:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-subtle);
}

/* Mol* adjustments */
.msp-layout-standard {
  background: transparent !important;
}

@media (max-width: 768px) {
  .main-container {
    flex-direction: column;
  }
  .viewport-container {
    flex: 1 1 auto;
  }
  .hud-card {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    height: 42vh;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    box-shadow: 0 -20px 40px -15px rgba(0, 0, 0, 0.5);
    padding: 16px;
  }
  .stage-title {
    font-size: 1.15rem;
  }
  .stage-body {
    font-size: 0.85rem;
  }
}
