/* ==========================================================================
   Topic Media Gallery - World-Class Pluggable Picture & Movie Gallery Component
   Zero-dependency, fully responsive, dark glassmorphism styling
   ========================================================================== */

:root {
  --tmg-bg-overlay: rgba(10, 15, 29, 0.88);
  --tmg-glass-bg: rgba(18, 25, 44, 0.78);
  --tmg-glass-border: rgba(255, 255, 255, 0.12);
  --tmg-glass-border-glow: rgba(56, 189, 248, 0.4);
  --tmg-text-main: #f8fafc;
  --tmg-text-muted: #94a3b8;
  --tmg-accent: #0ea5e9;
  --tmg-accent-hover: #38bdf8;
  --tmg-accent-glow: rgba(14, 165, 233, 0.35);
  --tmg-emerald: #10b981;
  --tmg-emerald-glow: rgba(16, 185, 129, 0.35);
  --tmg-card-bg: rgba(24, 33, 58, 0.65);
  --tmg-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(14, 165, 233, 0.15);
  --tmg-radius-lg: 16px;
  --tmg-radius-md: 10px;
  --tmg-radius-sm: 6px;
  --tmg-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --tmg-transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Modal Overlay Container */
.tmg-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--tmg-bg-overlay);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  box-sizing: border-box;
  font-family: var(--tmg-font);
}

.tmg-modal-backdrop.tmg-active {
  opacity: 1;
  visibility: visible;
}

/* Main Gallery Window Frame */
.tmg-gallery-container {
  width: 100%;
  max-width: 1380px;
  height: 92vh;
  max-height: 900px;
  background: var(--tmg-glass-bg);
  border: 1px solid var(--tmg-glass-border);
  box-shadow: var(--tmg-shadow);
  border-radius: var(--tmg-radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  transform: scale(0.96) translateY(12px);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  color: var(--tmg-text-main);
}

.tmg-modal-backdrop.tmg-active .tmg-gallery-container {
  transform: scale(1) translateY(0);
}

/* Standalone Embedded Mode */
.tmg-gallery-container.tmg-embedded {
  position: relative;
  height: 820px;
  max-height: 85vh;
  margin: 0 auto;
}

/* Top Master Header & Control Strip */
.tmg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(15, 23, 42, 0.75);
  border-bottom: 1px solid var(--tmg-glass-border);
  position: relative;
  z-index: 10;
  gap: 16px;
  flex-wrap: wrap;
}

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

.tmg-brand-badge {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  box-shadow: 0 0 15px var(--tmg-accent-glow);
}

.tmg-brand-titles {
  display: flex;
  flex-direction: column;
}

.tmg-brand-name {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tmg-brand-name span.tmg-version-chip {
  font-size: 11px;
  font-weight: 600;
  background: rgba(14, 165, 233, 0.2);
  color: #38bdf8;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.tmg-brand-sub {
  font-size: 12px;
  color: var(--tmg-text-muted);
}

/* Header Action Controls (Auto-Play, Speed, Close) */
.tmg-header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Auto-Play Toggle Button */
.tmg-autoplay-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--tmg-glass-border);
  color: #f8fafc;
  padding: 7px 14px;
  border-radius: var(--tmg-radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--tmg-transition);
}

.tmg-autoplay-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.tmg-autoplay-btn.tmg-playing {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.3));
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
  box-shadow: 0 0 12px var(--tmg-emerald-glow);
}

.tmg-autoplay-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  transition: var(--tmg-transition);
}

.tmg-autoplay-btn.tmg-playing .tmg-autoplay-indicator {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: tmgPulse 1.6s infinite ease-in-out;
}

@keyframes tmgPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* Interval Configuration Selector */
.tmg-interval-control {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--tmg-glass-border);
  border-radius: var(--tmg-radius-sm);
  padding: 4px 8px 4px 10px;
}

.tmg-interval-label {
  font-size: 12px;
  color: var(--tmg-text-muted);
  font-weight: 500;
}

.tmg-interval-select {
  background: transparent;
  color: #38bdf8;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  font-family: inherit;
}

.tmg-interval-select option {
  background: #0f172a;
  color: #f8fafc;
}

/* Fullscreen Button */
.tmg-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--tmg-radius-sm);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--tmg-glass-border);
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--tmg-transition);
}

.tmg-icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}

/* Prominent Close (Cross) Button */
.tmg-close-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--tmg-transition);
  margin-left: 6px;
}

.tmg-close-btn:hover {
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  border-color: #ef4444;
  transform: rotate(90deg) scale(1.08);
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.45);
}

/* Real-Time Auto-Play Countdown Progress Bar */
.tmg-timer-progress-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

.tmg-timer-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0ea5e9, #38bdf8, #10b981);
  box-shadow: 0 0 10px var(--tmg-accent-glow);
  transition: width linear;
}

/* Topic Bar (Horizontal Topic Switcher) */
.tmg-topic-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(15, 23, 42, 0.5);
  border-bottom: 1px solid var(--tmg-glass-border);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.tmg-topic-bar::-webkit-scrollbar {
  height: 4px;
}
.tmg-topic-bar::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.tmg-topic-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  color: var(--tmg-text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--tmg-transition);
}

.tmg-topic-pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.tmg-topic-pill.tmg-active {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(2, 132, 199, 0.35));
  border-color: var(--tmg-accent);
  color: #fff;
  box-shadow: 0 0 14px var(--tmg-accent-glow);
  font-weight: 600;
}

.tmg-topic-pill .tmg-pill-badge {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.12);
  padding: 2px 6px;
  border-radius: 8px;
  color: #e2e8f0;
}

.tmg-topic-pill.tmg-active .tmg-pill-badge {
  background: var(--tmg-accent);
  color: #fff;
}

/* Gallery Body (Media Canvas + Topic Narrative Sidebar) */
.tmg-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Left/Main Media Viewport */
.tmg-media-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: radial-gradient(circle at center, #1e293b 0%, #0b0f19 100%);
  overflow: hidden;
}

.tmg-media-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 16px;
  overflow: hidden;
}

/* Media Item Rendering */
.tmg-media-item {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--tmg-radius-md);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.32s ease, transform 0.32s ease;
  user-select: none;
}

.tmg-media-item.tmg-visible {
  opacity: 1;
  transform: scale(1);
}

/* Interactive Movie / Video Simulator Player */
.tmg-video-wrapper {
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 9;
  background: #090d16;
  border-radius: var(--tmg-radius-md);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--tmg-glass-border);
  position: relative;
}

.tmg-video-canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tmg-video-element {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tmg-simulated-video {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tmg-video-overlay-scanline {
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
  background-size: 100% 3px, 6px 100%;
  pointer-events: none;
}

.tmg-video-big-play-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(14, 165, 233, 0.9);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 25px var(--tmg-accent-glow);
  transition: var(--tmg-transition);
  border: 2px solid white;
}

.tmg-video-big-play-btn:hover {
  transform: scale(1.12);
  background: #0ea5e9;
}

.tmg-video-controls-bar {
  background: rgba(10, 15, 26, 0.92);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.tmg-video-scrubber {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}

.tmg-video-scrubber-filled {
  height: 100%;
  width: 0%;
  background: #38bdf8;
  border-radius: 3px;
  box-shadow: 0 0 8px #38bdf8;
  position: relative;
}

.tmg-video-time-label {
  font-size: 11px;
  font-family: monospace;
  color: var(--tmg-text-muted);
}

/* Nav Arrows (Previous / Next) */
.tmg-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--tmg-glass-border);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: var(--tmg-transition);
}

.tmg-nav-arrow:hover {
  background: var(--tmg-accent);
  border-color: #38bdf8;
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 0 16px var(--tmg-accent-glow);
}

.tmg-nav-prev { left: 20px; }
.tmg-nav-next { right: 20px; }

/* Sub-Sequence Step Indicators (Step 1 of N dots) */
.tmg-sequence-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  background: rgba(10, 15, 26, 0.85);
  border-top: 1px solid var(--tmg-glass-border);
}

.tmg-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: var(--tmg-transition);
}

.tmg-step-dot:hover {
  background: rgba(255, 255, 255, 0.5);
  transform: scale(1.2);
}

.tmg-step-dot.tmg-active {
  width: 26px;
  border-radius: 999px;
  background: var(--tmg-accent);
  border-color: #38bdf8;
  box-shadow: 0 0 10px var(--tmg-accent-glow);
}

.tmg-step-counter {
  font-size: 12px;
  font-weight: 600;
  color: var(--tmg-text-muted);
  margin-left: 10px;
}

/* Right Detail Sidebar (2-3 Lines Narrative + Metadata) */
.tmg-sidebar {
  width: 380px;
  background: rgba(15, 23, 42, 0.8);
  border-left: 1px solid var(--tmg-glass-border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  box-sizing: border-box;
}

.tmg-sidebar-badge {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(14, 165, 233, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  margin-bottom: 12px;
}

.tmg-topic-title {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
  margin: 0 0 14px 0;
}

.tmg-narrative-box {
  background: var(--tmg-card-bg);
  border: 1px solid var(--tmg-glass-border);
  border-radius: var(--tmg-radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.tmg-narrative-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #38bdf8;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tmg-narrative-text {
  font-size: 14px;
  line-height: 1.6;
  color: #cbd5e1;
  margin: 0;
}

/* Media Item Caption / Step Details */
.tmg-step-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--tmg-radius-md);
  padding: 14px;
  margin-bottom: 18px;
}

.tmg-step-heading {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  margin: 0 0 6px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tmg-step-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.tmg-step-desc {
  font-size: 13px;
  color: var(--tmg-text-muted);
  line-height: 1.5;
  margin: 0;
}

/* Feature Highlights Checklist */
.tmg-highlights-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tmg-highlights-list li {
  font-size: 13px;
  color: #cbd5e1;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}

.tmg-highlights-list li svg {
  flex-shrink: 0;
  color: #10b981;
  margin-top: 2px;
}

/* Quick Action / Launch CTA in Gallery */
.tmg-sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--tmg-glass-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tmg-cta-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: white;
  border: none;
  border-radius: var(--tmg-radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--tmg-transition);
  text-decoration: none;
}

.tmg-cta-btn:hover {
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  box-shadow: 0 0 16px var(--tmg-accent-glow);
  transform: translateY(-1px);
}

.tmg-keyboard-help {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  color: #64748b;
}

.tmg-kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 5px;
  color: #94a3b8;
  font-family: monospace;
}

/* ==========================================================================
   Comprehensive Mobile & Tablet Compatibility Breakpoints
   ========================================================================== */
@media (max-width: 1024px) {
  .tmg-body {
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tmg-media-viewport {
    min-height: 340px;
    max-height: 52vh;
    flex-shrink: 0;
  }
  .tmg-sidebar {
    width: 100%;
    max-height: none;
    border-left: none;
    border-top: 1px solid var(--tmg-glass-border);
    flex-shrink: 0;
    overflow-y: visible;
  }
}

@media (max-width: 768px) {
  .tmg-modal-backdrop {
    padding: 0;
  }
  .tmg-gallery-container {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .tmg-header {
    padding: 8px 12px;
    gap: 8px;
  }
  .tmg-brand-area {
    gap: 8px;
  }
  .tmg-brand-badge {
    width: 30px;
    height: 30px;
    font-size: 16px;
    border-radius: 8px;
  }
  .tmg-brand-name {
    font-size: 14px;
  }
  .tmg-brand-sub {
    display: none; /* Conserve vertical space on mobile */
  }
  .tmg-header-controls {
    gap: 6px;
    margin-left: auto;
  }
  .tmg-autoplay-btn {
    padding: 5px 10px;
    font-size: 12px;
    gap: 5px;
  }
  .tmg-interval-control {
    padding: 2px 6px;
  }
  .tmg-interval-label {
    display: none;
  }
  .tmg-interval-select {
    font-size: 12px;
  }
  .tmg-icon-btn {
    width: 32px;
    height: 32px;
  }
  .tmg-close-btn {
    width: 34px;
    height: 34px;
    margin-left: 2px;
  }

  /* Touch-friendly Topic Bar */
  .tmg-topic-bar {
    padding: 6px 10px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tmg-topic-bar::-webkit-scrollbar {
    display: none;
  }
  .tmg-topic-pill {
    padding: 6px 10px;
    font-size: 12px;
    gap: 6px;
  }

  /* Media viewport sizing for phones */
  .tmg-media-viewport {
    min-height: 240px;
    max-height: 44vh;
    max-height: 44dvh;
  }
  .tmg-media-stage {
    padding: 8px;
  }
  .tmg-nav-prev {
    left: 6px;
    width: 36px;
    height: 36px;
  }
  .tmg-nav-next {
    right: 6px;
    width: 36px;
    height: 36px;
  }

  /* Sequence indicators touch area */
  .tmg-sequence-bar {
    padding: 6px 10px;
  }
  .tmg-step-dot {
    width: 12px;
    height: 12px;
    position: relative;
  }
  .tmg-step-dot::after {
    content: '';
    position: absolute;
    inset: -8px; /* Expand touch area to 28px+ */
  }

  /* Narrative Sidebar on Mobile */
  .tmg-sidebar {
    padding: 14px 16px 24px 16px;
  }
  .tmg-topic-title {
    font-size: 18px;
    margin-bottom: 10px;
  }
  .tmg-narrative-box {
    padding: 12px;
    margin-bottom: 12px;
  }
  .tmg-narrative-text {
    font-size: 13px;
    line-height: 1.5;
  }
  .tmg-step-box {
    padding: 10px 12px;
    margin-bottom: 12px;
  }
  .tmg-keyboard-help {
    display: none; /* Keyboard shortcuts not needed on touchscreens */
  }
}

@media (max-width: 480px) {
  .tmg-header-controls {
    flex-wrap: nowrap;
  }
  #tmg-autoplay-text {
    display: none; /* Show only icon on very small phones */
  }
  .tmg-autoplay-btn {
    padding: 6px 8px;
  }
  .tmg-media-viewport {
    min-height: 200px;
    max-height: 40vh;
  }
}
