/**
 * style.css - Основные стили макета, сенсорного управления и адаптивности
 */

:root {
  --primary-color: #2563eb;
  --primary-dark: #1d4ed8;
  --accent-color: #10b981;
  --bg-dark: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.82);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --touch-target-size: 58px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
}

/* Главный контейнер */
#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
}

/* Сцена 16:9 с автоматическим вписыванием в экран и поддержкой Container Queries */
#stage {
  position: relative;
  aspect-ratio: 16 / 9;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  max-width: 100vw;
  max-height: 100vh;
  background-color: #ffffff;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.65);
  border-radius: 6px;
  touch-action: pan-y pinch-zoom;
  container-type: size;
  container-name: stage;
}

/* Контейнер слайдов */
#slides-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
}

.slide.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 10;
}

/* Компактная сенсорная зона перелистывания по краям (только тонкие полупрозрачные маркеры) */
.touch-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 60px;
  background: rgba(15, 23, 42, 0.2);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  z-index: 90;
  transition: all 0.2s ease;
  border-radius: 8px;
  opacity: 0.3;
}

.touch-nav-btn:hover, .touch-nav-btn:active {
  opacity: 0.9;
  background: rgba(37, 99, 235, 0.7);
  color: #ffffff;
}

.touch-nav-prev {
  left: 6px;
}

.touch-nav-next {
  right: 6px;
}

/* Компактная панель управления в правом нижнем углу */
#control-bar {
  position: absolute;
  bottom: 14px;
  right: 18px;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 5px 10px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 110;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#control-bar.hidden {
  opacity: 0.15;
  pointer-events: auto;
}

#control-bar.hidden:hover {
  opacity: 1;
}

.ctrl-btn {
  background: transparent;
  border: none;
  color: #e2e8f0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.ctrl-btn:active {
  transform: scale(0.9);
}

/* Прогресс-бар фоновой предзагрузки в нижней панели */
.preload-bar-group {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 220px;
  overflow: hidden;
  transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1),
              max-width 0.6s cubic-bezier(0.4, 0, 0.2, 1),
              margin 0.6s ease,
              padding 0.6s ease;
  opacity: 1;
}

.preload-bar-group.loaded {
  opacity: 0;
  max-width: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.preload-bar-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: preload-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.preload-bar-spinner.success {
  border-color: #22c55e;
  background: #22c55e;
  animation: none;
  position: relative;
}

.preload-bar-spinner.success::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 9px;
  font-weight: 900;
}

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

.preload-bar-text {
  font-size: 12px;
  font-weight: 700;
  color: #e2e8f0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
}

.preload-bar-track {
  width: 55px;
  height: 5px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.preload-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #0ea5e9);
  border-radius: 3px;
  transition: width 0.25s ease-out;
  box-shadow: 0 0 6px rgba(56, 189, 248, 0.5);
}

.preload-bar-sep {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.15);
  margin-left: 2px;
  flex-shrink: 0;
}

/* Кнопки игры внутри нижней панели переключения слайдов */
.game-ctrl-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.game-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  transition: all 0.18s ease;
  touch-action: manipulation;
  white-space: nowrap;
}

.game-bar-btn:hover {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
  transform: translateY(-1px);
}

.game-bar-btn:active {
  transform: scale(0.94);
}

.game-bar-btn-solve {
  background: rgba(234, 179, 8, 0.25);
  border-color: rgba(234, 179, 8, 0.5);
  color: #fef08a;
}

.game-bar-btn-solve:hover {
  background: rgba(234, 179, 8, 0.4);
  color: #ffffff;
}

.game-bar-sep {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 4px;
}

/* Минималистичный компактный индикатор слайда */
.slide-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background 0.2s;
  user-select: none;
}

.slide-indicator:hover {
  background: rgba(37, 99, 235, 0.4);
}

.slide-indicator-sep {
  color: #94a3b8;
  margin: 0 1px;
}

.slide-indicator-total {
  color: #94a3b8;
  font-size: 12px;
}

/* Компактный таймер занятия */
.lesson-timer {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #94a3b8;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  padding-left: 8px;
  margin-left: 2px;
}

.lesson-timer-icon {
  font-size: 14px;
}

/* Выдвижное меню списка слайдов (Drawer) */
#slides-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--panel-border);
  padding: 20px 24px;
  z-index: 150;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
  max-height: 45vh;
  display: flex;
  flex-direction: column;
}

#slides-drawer.open {
  transform: translateY(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.drawer-title {
  color: #f8fafc;
  font-size: 18px;
  font-weight: 700;
}

.drawer-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

.drawer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding-bottom: 8px;
}

.drawer-item {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.drawer-item:hover {
  background: rgba(37, 99, 235, 0.25);
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.drawer-item.current {
  background: rgba(37, 99, 235, 0.4);
  border-color: #60a5fa;
  box-shadow: 0 0 12px rgba(96, 165, 250, 0.4);
}

.drawer-item-num {
  font-size: 13px;
  font-weight: 800;
  color: #60a5fa;
}

.drawer-item-title {
  font-size: 12px;
  color: #e2e8f0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Прогресс-бар в самом верху сцены */
#top-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 4px;
  background: linear-gradient(90deg, #2563eb, #10b981);
  width: 5%;
  z-index: 120;
  transition: width 0.3s ease;
}
