/* ==========================================================
   style.css  —  Gesture-Driven Variable Type Animator

   Эстетика: тёмный кинематографический HUD.
   Тёмный фон, видео-фид как атмосфера позади,
   гигантский текст по центру, боковые панели данных.

   CSS-переменные (обновляются из font-controller.js):
     --gta-wght-norm   [0..1]   нормализованный weight
     --gta-slnt-norm   [0..1]   нормализованный slant
     --gta-casl-norm   [0..1]   нормализованный casual
     --gta-mono-norm   [0..1]   нормализованный mono
     --gta-glow-color  <color>  цвет подсветки (HSL)
     --gta-wght-val    <num>    реальное значение wght
     --gta-slnt-val    <num>    реальное значение slnt
     --gta-casl-val    <num>    реальное значение CASL
     --gta-mono-val    <num>    реальное значение MONO
========================================================== */

/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Палитра */
  --bg:           #080808;
  --bg-panel:     rgba(10, 10, 10, 0.82);
  --border:       rgba(255, 255, 255, 0.07);
  --border-light: rgba(255, 255, 255, 0.14);
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-dim:     rgba(255, 255, 255, 0.35);
  --text-muted:   rgba(255, 255, 255, 0.18);
  --accent:       #f5c518;
  --accent-dim:   rgba(245, 197, 24, 0.15);
  --accent-glow:  rgba(245, 197, 24, 0.40);
  --danger:       rgba(255, 80, 80, 0.85);

  /* Шрифты */
  --font-ui:      'Courier New', 'Lucida Console', monospace;
  --font-display: 'Recursive', monospace;

  /* Переменные жеста (дефолтные, перезаписывает JS) */
  --gta-wght-norm:  0.29;
  --gta-slnt-norm:  1;
  --gta-casl-norm:  0;
  --gta-mono-norm:  0;
  --gta-glow-color: rgba(245, 197, 24, 0.3);
  --gta-wght-val:   500;
  --gta-slnt-val:   0;
  --gta-casl-val:   0;
  --gta-mono-val:   0;

  /* Переходы */
  --transition-fast:   0.12s ease;
  --transition-medium: 0.30s ease;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  cursor: none; /* Кастомный курсор скрыт — рука = курсор */
}

/* ── Видео-фон ────────────────────────────────────────── */
#video-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);         /* зеркало — как у selfie-камеры */
  opacity: 0.18;                 /* очень приглушённый */
  filter: brightness(0.6) saturate(0.5);
  z-index: 0;
  pointer-events: none;
}

/* ── Canvas для скелета руки ──────────────────────────── */
#overlay-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* ── Основной контейнер сцены ─────────────────────────── */
#scene {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}

/* ── Glow за текстом ──────────────────────────────────── */
#text-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity var(--transition-medium);
  /* background задаётся из font-controller.js */
}

/* ── Обёртка текста ───────────────────────────────────── */
#text-wrapper {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  pointer-events: all;
}

/* ── Главный отображаемый текст ───────────────────────── */
#display-text {
  font-family: var(--font-display);
  font-size: clamp(4rem, 15vw, 18rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  color: #ffffff;
  white-space: nowrap;
  user-select: none;

  /* Начальные настройки вариативного шрифта */
  font-variation-settings: '"wght" 500, "slnt" 0, "CASL" 0, "MONO" 0';
  font-weight: 500;

  /* Текстовый тень — статичная + динамичный glow */
  text-shadow:
    0 0 80px var(--gta-glow-color),
    0 0 160px var(--gta-glow-color),
    0 2px 4px rgba(0, 0, 0, 0.8);

  /* Плавная смена цвета тени */
  transition: text-shadow var(--transition-fast);

  /* Нет transition на font-variation — реалтайм */
}

/* ── Редактируемое поле ввода ─────────────────────────── */
#text-input {
  position: absolute;
  bottom: -3.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-light);
  outline: none;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-align: center;
  width: 280px;
  padding: 6px 0;
  text-transform: uppercase;
  caret-color: var(--accent);
  pointer-events: all;
  transition: border-color var(--transition-medium), color var(--transition-medium);
}

#text-input::placeholder {
  color: var(--text-muted);
  letter-spacing: 0.15em;
}

#text-input:focus {
  border-bottom-color: var(--accent);
  color: var(--text-primary);
}

/* ── HUD: боковые панели ──────────────────────────────── */
.hud-panel {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 200px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 20px 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#hud-left {
  left: 24px;
  border-right: 2px solid var(--border);
}

#hud-right {
  right: 24px;
  border-left: 2px solid var(--border);
}

/* Угловые декораторы панелей */
.hud-panel::before,
.hud-panel::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--accent);
  border-style: solid;
  opacity: 0.6;
}

#hud-left::before  { top: -1px; left: -1px;  border-width: 1px 0 0 1px; }
#hud-left::after   { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
#hud-right::before { top: -1px; right: -1px; border-width: 1px 1px 0 0; }
#hud-right::after  { bottom: -1px; left: -1px; border-width: 0 0 1px 1px; }

/* ── HUD: заголовок панели ────────────────────────────── */
.hud-title {
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── HUD: строка оси ──────────────────────────────────── */
.axis-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.axis-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.axis-name {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.axis-value {
  font-size: 0.8rem;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
  transition: color var(--transition-fast);
}

/* ── Полоска прогресса оси ────────────────────────────── */
.axis-bar-track {
  width: 100%;
  height: 3px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

.axis-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  width: 0%;
  /* transition нет — обновляется каждый кадр, JS делает плавно */
  box-shadow: 0 0 6px var(--accent-glow);
}

/* ── HUD: подсказки жестов ────────────────────────────── */
.gesture-hint {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.gesture-axis-tag {
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
  opacity: 0.8;
}

.gesture-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  line-height: 1.4;
}

/* ── HUD: статус камеры/руки ──────────────────────────── */
#status-bar {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  padding: 8px 16px;
  z-index: 10;
  white-space: nowrap;
}

#status-bar::before,
#status-bar::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-color: var(--border-light);
  border-style: solid;
}

#status-bar::before { top: -1px; left: -1px;  border-width: 1px 0 0 1px; }
#status-bar::after  { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }

#status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition-medium), box-shadow var(--transition-medium);
}

#status-dot.active {
  background: #7effa0;
  box-shadow: 0 0 8px rgba(126, 255, 160, 0.6);
  animation: pulse-dot 2s ease-in-out infinite;
}

#status-dot.hand-detected {
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

#status-dot.error {
  background: var(--danger);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

#status-text {
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ── FPS счётчик ──────────────────────────────────────── */
#fps-counter {
  position: fixed;
  top: 20px;
  right: 240px;
  font-size: 0.6rem;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  z-index: 10;
  font-variant-numeric: tabular-nums;
}

/* ── Нижний бейдж — имя шрифта ────────────────────────── */
#font-badge {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  text-transform: uppercase;
  z-index: 10;
  border: 1px solid var(--border);
  padding: 5px 14px;
  background: var(--bg-panel);
  backdrop-filter: blur(8px);
}

/* ── Экран загрузки ───────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  z-index: 100;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

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

.loading-logo {
  font-family: var(--font-display);
  font-size: clamp(3rem, 10vw, 8rem);
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.02em;
  font-variation-settings: '"wght" 900, "CASL" 0.5';
  animation: loading-pulse 2.4s ease-in-out infinite;
  text-shadow: 0 0 60px rgba(245, 197, 24, 0.4);
}

@keyframes loading-pulse {
  0%, 100% { opacity: 1;    font-variation-settings: '"wght" 900, "CASL" 0.0'; }
  50%       { opacity: 0.6; font-variation-settings: '"wght" 300, "CASL" 1.0'; }
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#loading-message {
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  text-transform: uppercase;
  text-align: center;
}

/* Прогресс-бар загрузки модели */
#loading-bar-track {
  width: 240px;
  height: 2px;
  background: var(--border);
  position: relative;
  overflow: hidden;
}

#loading-bar-fill {
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: var(--accent);
  animation: loading-bar 1.8s ease-in-out infinite;
  box-shadow: 0 0 8px var(--accent-glow);
}

@keyframes loading-bar {
  0%   { left: -100%; }
  100% { left: 100%;  }
}

/* ── Кнопка START ─────────────────────────────────────── */
#btn-start {
  position: relative;
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 14px 40px;
  cursor: pointer;
  transition:
    border-color var(--transition-medium),
    color var(--transition-medium),
    box-shadow var(--transition-medium);
  outline: none;
}

#btn-start::before,
#btn-start::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--accent);
  border-style: solid;
  transition: opacity var(--transition-medium);
}

#btn-start::before { top: -1px; left: -1px;  border-width: 1px 0 0 1px; }
#btn-start::after  { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }

#btn-start:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 24px var(--accent-dim), inset 0 0 24px var(--accent-dim);
}

#btn-start:active {
  transform: scale(0.98);
}

#btn-start:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Overlay: инструкция при первом запуске ───────────── */
#instructions-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 80px;
  z-index: 5;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

#instructions-overlay.hidden {
  opacity: 0;
}

.instructions-inner {
  display: flex;
  gap: 32px;
  align-items: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  padding: 12px 24px;
}

.instruction-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.62rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.instruction-icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* ── Декоративная сетка (тонкая, атмосферная) ─────────── */
#grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black 30%, transparent 100%);
}

/* ── Угловые декораторы экрана ────────────────────────── */
.screen-corner {
  position: fixed;
  width: 20px;
  height: 20px;
  border-color: rgba(255, 255, 255, 0.12);
  border-style: solid;
  z-index: 20;
  pointer-events: none;
}

.screen-corner.tl { top: 12px;    left: 12px;   border-width: 1px 0 0 1px; }
.screen-corner.tr { top: 12px;    right: 12px;  border-width: 1px 1px 0 0; }
.screen-corner.bl { bottom: 12px; left: 12px;   border-width: 0 0 1px 1px; }
.screen-corner.br { bottom: 12px; right: 12px;  border-width: 0 1px 1px 0; }

/* ── Scanline-эффект (очень тонкий) ──────────────────── */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.04) 2px,
    rgba(0, 0, 0, 0.04) 4px
  );
  pointer-events: none;
  z-index: 30;
}

/* ── Ошибка камеры ────────────────────────────────────── */
#error-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid rgba(255, 60, 60, 0.3);
  color: var(--danger);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 16px 28px;
  text-align: center;
  z-index: 200;
  display: none;
  max-width: 380px;
  line-height: 1.6;
}

#error-message.visible {
  display: block;
}

/* ── Анимация появления сцены ─────────────────────────── */
@keyframes scene-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

#scene {
  animation: scene-in 0.8s ease both;
  animation-play-state: paused;
}

#scene.active {
  animation-play-state: running;
}

/* ── Адаптивность ─────────────────────────────────────── */
@media (max-width: 900px) {
  #hud-left, #hud-right {
    display: none;
  }

  #display-text {
    font-size: clamp(3.5rem, 22vw, 8rem);
  }

  #fps-counter {
    right: 16px;
  }

  .instructions-inner {
    flex-direction: column;
    gap: 12px;
  }
}
