/* =============================================
   INTERACTIVE LEARNING LAB — Layout & Styling
   Extends main.css design tokens
   ============================================= */

/* ── LAB TOPBAR ── */
.lab-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  height: 56px;
  padding: 0 var(--content-padding);
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: var(--border-subtle);
}

.lab-topbar-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-md);
  color: var(--text-primary);
  white-space: nowrap;
  letter-spacing: -0.02em;
  transition: color var(--duration-fast);
  /* touch target — back button easily tap hona chahiye mobile pe */
  min-height: 44px;
}

.lab-topbar-name:hover {
  color: var(--accent);
}

.lab-topbar-name svg {
  opacity: 0.5;
  transition: opacity var(--duration-fast), transform var(--duration-fast);
}

.lab-topbar-name:hover svg {
  opacity: 1;
  transform: translateX(-2px);
}

.lab-topbar-divider {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.lab-topbar-page {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.lab-topbar-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: var(--border-subtle);
}

/* ── LAB CONTENT ── */
.lab-content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--content-padding);
}

/* ── LAB HERO ── */
.lab-hero {
  padding: var(--space-3xl) 0 var(--space-2xl);
}

.lab-hero .game-badge {
  margin-bottom: var(--space-md);
  display: inline-block;
}

.lab-hero-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  letter-spacing: -0.03em;
}

.lab-hero-subtitle {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 650px;
}

/* ── CATEGORY SECTIONS ── */
.lab-category {
  padding: var(--space-2xl) 0;
  border-top: var(--border-subtle);
}

.lab-category-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.lab-category-accent {
  width: 4px;
  height: 32px;
  border-radius: 2px;
  flex-shrink: 0;
  margin-top: 4px;
}

.lab-category-header h2 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.lab-category-desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  max-width: 600px;
}

/* ── Category Accent Colors ── */

/* Physics — amber */
.lab-category[data-accent="physics"] .lab-category-accent {
  background: #f59e0b;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}
.lab-category[data-accent="physics"] .game-badge {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.15);
}

/* AI — blue */
.lab-category[data-accent="ai"] .lab-category-accent {
  background: #4a9eff;
  box-shadow: 0 0 12px rgba(74, 158, 255, 0.3);
}
.lab-category[data-accent="ai"] .game-badge {
  color: #4a9eff;
  background: rgba(74, 158, 255, 0.08);
  border-color: rgba(74, 158, 255, 0.15);
}

/* Control — green */
.lab-category[data-accent="control"] .lab-category-accent {
  background: #10b981;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.3);
}
.lab-category[data-accent="control"] .game-badge {
  color: #10b981;
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.15);
}

/* Robotics — orange */
.lab-category[data-accent="robotics"] .lab-category-accent {
  background: #f97316;
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.3);
}
.lab-category[data-accent="robotics"] .game-badge {
  color: #f97316;
  background: rgba(249, 115, 22, 0.08);
  border-color: rgba(249, 115, 22, 0.15);
}

/* Signal — cyan */
.lab-category[data-accent="signal"] .lab-category-accent {
  background: #22d3ee;
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.3);
}
.lab-category[data-accent="signal"] .game-badge {
  color: #22d3ee;
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.15);
}

/* Math — purple */
.lab-category[data-accent="math"] .lab-category-accent {
  background: #a78bfa;
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.3);
}
.lab-category[data-accent="math"] .game-badge {
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.08);
  border-color: rgba(167, 139, 250, 0.15);
}

/* ── SIM INFO DROPDOWN (native <details>) ── */
.sim-info {
  margin-top: var(--space-xs);
  margin-bottom: var(--space-sm);
  border: var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-code);
  overflow: hidden;
}

.sim-info summary {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  /* padding badhaya — 44px touch target milega "How it works" button ko */
  padding: 12px 14px;
  min-height: 44px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color var(--duration-fast), background var(--duration-fast);
  list-style: none;
}

.sim-info summary::-webkit-details-marker { display: none; }

.sim-info summary::before {
  content: '▸';
  font-size: 0.7rem;
  transition: transform var(--duration-fast);
}

.sim-info[open] summary::before {
  transform: rotate(90deg);
}

.sim-info summary:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
}

/* keyboard focus — sim info pe bhi dikhna chahiye */
.sim-info summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sim-info-content {
  padding: var(--space-sm) var(--space-md) var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  border-top: var(--border-subtle);
  animation: sim-info-reveal 0.2s ease-out;
}

@keyframes sim-info-reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.sim-info-content strong {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 2px;
}

.sim-info-content p {
  font-size: var(--text-xs);
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0;
}

/* ── LAB SIM CONTAINERS ── */
.lab-sim {
  margin-bottom: var(--space-xl);
  /* browser-native viewport optimization — off-screen sims ka rendering skip karo */
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
  /* default full opacity — JS add karega in-viewport class */
  /* pehle 0.35 tha but first load pe sab dim dikhta tha */
  opacity: 1;
  transition: opacity 0.5s ease-out;
}

/* viewport se door jaaye toh dim karo */
.lab-sim.out-of-viewport {
  opacity: 0.35;
}

.lab-sim:last-child {
  margin-bottom: 0;
}

/* ── LAB FOOTER ── */
.lab-footer {
  padding: var(--space-2xl) 0 var(--space-3xl);
  border-top: var(--border-subtle);
  text-align: center;
}

.lab-footer-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-muted);
  transition: color var(--duration-fast);
  /* touch target 44px — footer link bhi finger-friendly hona chahiye */
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);
}

.lab-footer-link:hover {
  color: var(--accent);
}

.lab-footer-link svg {
  transition: transform var(--duration-fast);
}

.lab-footer-link:hover svg {
  transform: translateX(-3px);
}

/* ── SEARCH/FILTER BAR ── */
/* hero ke baad, sticky — scroll karte waqt hamesha dikhega */
.lab-search-bar {
  position: sticky;
  top: 56px; /* topbar ke neeche chipkao */
  z-index: 90;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  padding: var(--space-md) 0;
  margin-bottom: var(--space-md);
  border-bottom: var(--border-subtle);
}

.lab-search-inner {
  position: relative;
  display: flex;
  align-items: center;
}

.lab-search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--duration-fast);
}

/* focus state pe icon bhi accent color ho jaaye */
.lab-search-input:focus ~ .lab-search-icon,
.lab-search-inner:focus-within .lab-search-icon {
  color: var(--accent);
}

.lab-search-input {
  width: 100%;
  padding: 12px 44px 12px 42px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  /* touch target 44px minimum */
  min-height: 44px;
}

.lab-search-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.lab-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15);
}

/* clear button — input ke andar right side pe */
.lab-search-clear {
  position: absolute;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
  padding: 0;
  line-height: 1;
}

.lab-search-clear:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* result count text */
.lab-search-count {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-sm);
  transition: color var(--duration-fast);
}

/* no results message — jab kuch na mile */
.lab-no-results {
  text-align: center;
  padding: var(--space-3xl) var(--space-md);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  display: none; /* JS toggle karega */
}

.lab-no-results span {
  display: block;
  font-size: var(--text-2xl);
  margin-bottom: var(--space-md);
}

/* search active hone pe hide karo category headers agar koi match nahi */
.lab-category.lab-category--hidden {
  display: none;
}

/* sim hide karo search mein */
.lab-sim.lab-sim--hidden {
  display: none;
}

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .lab-hero {
    padding: var(--space-2xl) 0 var(--space-xl);
  }

  .lab-hero-title {
    font-size: var(--text-2xl);
  }

  .lab-topbar-count {
    display: none;
  }

  .lab-category {
    padding: var(--space-xl) 0;
  }

  /* search bar — mobile pe thoda compact karo */
  .lab-search-bar {
    padding: var(--space-sm) 0;
  }
}

@media (max-width: 480px) {
  .lab-topbar-divider,
  .lab-topbar-page {
    display: none;
  }
}

/* ═══════════════════════════════════════════ */
/* SIM TOGGLE — Settings Panel & Gear Button  */
/* ═══════════════════════════════════════════ */

/* sim disabled state — initSimToggle lagata hai */
.lab-sim.lab-sim--disabled {
  display: none;
}

/* ── Gear Button (topbar mein) ── */
.sim-toggle-gear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: var(--space-sm);
  padding: 0;
  background: transparent;
  border: var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast),
              border-color var(--duration-fast), transform var(--duration-normal);
  flex-shrink: 0;
}

.sim-toggle-gear:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.16);
}

.sim-toggle-gear:hover svg {
  transform: rotate(45deg);
}

.sim-toggle-gear:active {
  transform: scale(0.92);
}

/* ── Overlay ── */
.sim-toggle-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal), visibility var(--duration-normal);
  display: flex;
  justify-content: flex-end;
}

.sim-toggle-overlay--open {
  opacity: 1;
  visibility: visible;
}

/* ── Panel (slide-in from right) ── */
.sim-toggle-panel {
  width: min(400px, 90vw);
  height: 100%;
  background: var(--bg-surface);
  border-left: var(--border-subtle);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--duration-normal) cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

.sim-toggle-overlay--open .sim-toggle-panel {
  transform: translateX(0);
}

/* ── Panel Header ── */
.sim-toggle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-lg) var(--space-md);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}

.sim-toggle-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sim-toggle-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  letter-spacing: -0.02em;
}

.sim-toggle-count-badge {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.sim-toggle-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  font-size: 1.4rem;
  color: var(--text-muted);
  background: transparent;
  border: var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}

.sim-toggle-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ── Bulk Actions ── */
.sim-toggle-actions {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-bottom: var(--border-subtle);
  flex-shrink: 0;
}

.sim-toggle-action-btn {
  flex: 1;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast),
              border-color var(--duration-fast);
}

.sim-toggle-action-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: rgba(255, 255, 255, 0.16);
}

/* ── Scrollable Sim List ── */
.sim-toggle-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm) 0;
  /* custom scrollbar — dark theme ke saath match karo */
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

.sim-toggle-list::-webkit-scrollbar {
  width: 6px;
}

.sim-toggle-list::-webkit-scrollbar-track {
  background: transparent;
}

.sim-toggle-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

.sim-toggle-list::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Category Headers (in panel) ── */
.sim-toggle-cat-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg) var(--space-xs);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: var(--space-xs);
}

.sim-toggle-cat-header:first-child {
  margin-top: 0;
}

.sim-toggle-cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sim-toggle-cat-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
}

/* ── Sim Toggle Items ── */
.sim-toggle-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 8px var(--space-lg) 8px calc(var(--space-lg) + 16px);
  cursor: pointer;
  transition: background var(--duration-fast);
  user-select: none;
  /* 44px touch target */
  min-height: 40px;
}

.sim-toggle-item:hover {
  background: var(--bg-hover);
}

/* native checkbox chhupao */
.sim-toggle-checkbox {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* custom checkmark */
.sim-toggle-checkmark {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  position: relative;
}

/* checked state — accent color filled box with checkmark */
.sim-toggle-checkbox:checked + .sim-toggle-checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.sim-toggle-checkbox:checked + .sim-toggle-checkmark::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translateY(-1px);
}

/* unchecked — thoda dim with strikethrough name */
.sim-toggle-checkbox:not(:checked) ~ .sim-toggle-item-name {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.15);
}

/* focus visible for keyboard nav */
.sim-toggle-checkbox:focus-visible + .sim-toggle-checkmark {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sim-toggle-item-name {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-primary);
  transition: color var(--duration-fast);
  line-height: 1.4;
}

/* ── Responsive — mobile pe panel full width ── */
@media (max-width: 480px) {
  .sim-toggle-panel {
    width: 100vw;
  }

  .sim-toggle-gear {
    margin-left: var(--space-xs);
  }
}
