/* Mobile & touch optimizations — Android / iPhone */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

body.is-mobile .btn,
body.is-mobile .overlay-btn,
body.is-mobile .fullscreen-btn {
  min-height: 48px;
  min-width: 48px;
}

body.is-mobile .field input,
body.is-mobile .field select {
  font-size: 16px;
  min-height: 48px;
  padding: 12px 14px;
}

body.is-mobile input[type="range"] {
  height: 32px;
  accent-color: var(--accent);
}

body.is-mobile .container {
  width: calc(100% - 24px);
  padding: 16px 0 calc(24px + env(safe-area-inset-bottom));
}

body.is-mobile .card {
  padding: 16px;
}

body.is-mobile .topbar,
body.is-mobile .watch-header {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

body.is-mobile .topbar-actions,
body.is-mobile .watch-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

body.is-mobile .btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

body.is-mobile .btn-row .btn {
  width: 100%;
}

body.is-mobile .file-item {
  flex-direction: column;
  align-items: stretch;
}

body.is-mobile .file-item .btn {
  width: 100%;
}

body.is-mobile .toast-container {
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
}

body.is-mobile .toast {
  min-width: unset;
  max-width: unset;
  width: 100%;
}

/* Watch pages — cinema layout */

html.page-watch-root,
body.page-watch.is-mobile {
  overflow-x: hidden;
  max-width: 100%;
}

body.page-watch.is-mobile .container-watch {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: calc(100% - 24px);
  max-width: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: visible;
}

body.page-watch.is-mobile .watch-video-block,
body.page-watch.is-mobile .video-shell-priority {
  margin-top: 0 !important;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  max-height: min(40dvh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  height: auto;
  position: relative;
  z-index: 1;
}

body.page-watch.is-mobile .watch-header,
body.page-watch.is-mobile .status-bar,
body.page-watch.is-mobile .watch-wizard,
body.page-watch.is-mobile .watch-video-block,
body.page-watch.is-mobile .chat-panel,
body.page-watch.is-mobile .watch-queue-below-chat,
body.page-watch.is-mobile .settings-toggle {
  position: relative;
  z-index: 5;
}

body.page-watch.is-mobile.is-watching .video-shell-priority {
  flex: 0 0 auto;
  max-height: min(42dvh, calc(100vw * 9 / 16));
  min-height: 0;
}

body.page-watch.is-ios .video-shell-priority {
  max-height: min(38dvh, calc(100vw * 9 / 16));
}

body.page-watch.is-ios.is-watching .video-shell-priority {
  max-height: min(40dvh, calc(100vw * 9 / 16));
}

body.page-watch.is-mobile.is-watching .watch-video-block {
  flex: 0 0 auto;
  order: 1;
}

body.page-watch.is-mobile.is-watching .chat-panel-below-stream {
  flex: 0 0 auto;
  order: 2;
}

body.page-watch.is-mobile.is-watching .watch-queue-below-chat {
  flex: 0 0 auto;
  order: 3;
}

body.page-watch.is-mobile .watch-header h1 {
  font-size: 1.25rem;
}

body.page-watch.is-mobile .watch-header p {
  font-size: 0.9rem;
}

body.page-watch.is-mobile.is-watching .watch-header {
  margin-bottom: 0;
  flex: 0 0 auto;
}

body.page-watch.is-mobile.is-watching .watch-settings.is-collapsed {
  display: none;
}

body.page-watch.is-mobile.is-watching .watch-settings:not(.is-collapsed) {
  order: 2;
}

body.page-watch.is-watching .status-bar:not(.status-bar-error) {
  display: none;
}

body.page-watch.is-watching .watch-wizard {
  display: none;
}

@media (min-width: 769px) {
  body.page-watch .container-watch {
    max-width: 960px;
    margin: 0 auto;
  }

  body.page-watch.is-watching .video-shell-priority {
    flex: 1 1 auto;
    min-height: 420px;
    max-height: none;
  }
}

@media (max-width: 768px) {
  body.page-watch.is-mobile .watch-header-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  body.page-watch.is-mobile .video-shell-priority {
    border-radius: 12px;
  }

  body.page-watch.is-mobile.is-watching .chat-panel {
    margin-bottom: env(safe-area-inset-bottom);
  }
}

body.page-watch.is-mobile .settings-toggle {
  width: 100%;
  margin-top: 8px;
}

/* Video overlay controls */

.video-overlay-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  gap: 8px;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  opacity: 1;
  transition: opacity 0.25s ease;
}

body.is-mobile.is-watching .video-shell:not(.show-controls) .video-overlay-controls {
  opacity: 0;
  pointer-events: none;
}

body.is-mobile.is-watching .video-shell.show-controls .video-overlay-controls {
  opacity: 1;
  pointer-events: auto;
}

.overlay-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  cursor: pointer;
}

.overlay-btn:disabled {
  opacity: 0.45;
}

.overlay-btn:active {
  background: rgba(99, 102, 241, 0.6);
}

.overlay-btn-full {
  flex: 1.2;
}

.tap-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.65);
  padding: 24px;
}

.tap-overlay[hidden] {
  display: none !important;
}

.tap-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  max-width: 280px;
}

.btn-tap {
  min-height: 52px;
  padding: 14px 24px;
  font-size: 1rem;
}

/* Fullscreen & landscape cinema */

body.is-mobile .fullscreen-btn,
body.is-mobile .overlay-btn-full {
  min-height: 48px;
}

@media (max-width: 768px) {
  .video-shell:fullscreen,
  .video-shell:-webkit-full-screen {
    width: 100vw;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }

  .video-shell:fullscreen .video-overlay-controls,
  .video-shell:-webkit-full-screen .video-overlay-controls {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
}

@media (max-width: 768px) and (orientation: landscape) {
  body.page-watch.is-watching .watch-header,
  body.page-watch.is-watching .watch-settings,
  body.page-watch.is-watching .landscape-hint,
  body.page-watch.is-watching #hostControls,
  body.page-watch.is-watching #viewerControls {
    display: none !important;
  }

  body.page-watch.is-watching .container-watch {
    width: 100%;
    padding: 0;
    max-width: none;
  }

  body.page-watch.is-watching .video-shell-priority {
    position: fixed;
    inset: 0;
    z-index: 200;
    min-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    border: none;
    aspect-ratio: unset;
  }
}

.landscape-hint {
  display: none;
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.92);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.landscape-hint.is-visible {
  display: block;
}

/* Hide desktop-only inline controls on mobile watch */
body.is-mobile.is-watching .watch-settings .controls-inline-mobile-hide {
  display: none;
}

/* Отдельный audio для WebRTC: не display:none — иначе Safari/Chrome могут не играть звук */
.stream-audio-offscreen {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
}

body.is-pwa {
  padding-top: env(safe-area-inset-top);
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.brand-mark img,
.brand-mark svg {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(99, 102, 241, 0.28);
}

.pwa-install-hint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(20, 24, 36, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.pwa-install-hint-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex: 0 0 auto;
}

.pwa-install-hint-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 0.82rem;
  line-height: 1.3;
  color: var(--muted);
}

.pwa-install-hint-text strong {
  color: var(--text);
  font-size: 0.92rem;
}

.pwa-install-hint-close {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

@media (display-mode: standalone) {
  .pwa-install-hint {
    display: none;
  }
}
