/* Reset */
* {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, 'Helvetica Neue', 'Roboto', Arial, sans-serif;
  background: #0a0a0a;
  color: #ffffff;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  margin: 0;
}

/* Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  -webkit-transition: opacity 0.5s ease;
  transition: opacity 0.5s ease;
}

.screen.active {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
}

/* ===== CODE SCREEN ===== */
.code-container {
  text-align: center;
  padding: 20px;
}

.logo {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 20px;
  color: #667eea;
  background: -webkit-linear-gradient(45deg, #667eea, #764ba2);
  background: linear-gradient(45deg, #667eea, #764ba2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.instruction {
  font-size: 24px;
  color: #aaaaaa;
  margin-bottom: 40px;
}

.code-digits {
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-flex-wrap: nowrap;
  flex-wrap: nowrap;
  max-width: 720px;
  max-width: 92vw;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 40px;
}

.code-digits .digit {
  margin: 0 8px;
}

.digit {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  width: 80px;
  height: 100px;
  background: #1a1a2e;
  border: 2px solid #333366;
  border-radius: 12px;
  font-size: 48px;
  font-weight: 700;
  color: #ffffff;
  font-family: 'Courier New', monospace;
}

/* Fire TV / старые TV: фиксированные размеры */
@media (max-width: 1280px), (max-height: 900px) {
  .code-digits {
    margin-bottom: 24px;
  }

  .code-digits .digit {
    margin: 0 6px;
  }
}

/* Маленькие экраны / старые WebKit */
@media (max-width: 960px), (max-height: 720px) {
  .digit {
    width: 50px;
    height: 66px;
    font-size: 34px;
  }
}

.digit.filled {
  border-color: #667eea;
  background: #1a1a3e;
  -webkit-animation: digitPulse 0.3s ease;
  animation: digitPulse 0.3s ease;
}

@-webkit-keyframes digitPulse {
  0% { -webkit-transform: scale(1); }
  50% { -webkit-transform: scale(1.1); }
  100% { -webkit-transform: scale(1); }
}

@keyframes digitPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.sub-instruction {
  font-size: 16px;
  color: #666666;
  margin-bottom: 20px;
}

.status {
  font-size: 14px;
  color: #888888;
  padding: 0;
  border-radius: 20px;
  background: #111122;
  display: inline-block;
}

.status.connected {
  color: #4caf50;
  background: #0a1f0a;
}

.status.error {
  color: #f44336;
  background: #1f0a0a;
}

/* ===== CONNECTED SCREEN ===== */
.connected-container {
  text-align: center;
  padding: 40px;
}

.connected-icon {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #1b5e20;
  color: #4caf50;
  font-size: 60px;
  line-height: 120px;
  margin: 0 auto 30px;
}

.connected-container h1 {
  font-size: 36px;
  margin-bottom: 10px;
}

.connected-container p {
  font-size: 50px;
  color: #fff;
  max-width: 900px;
  margin: 20px auto;
}

.status-detail {
  color: #667eea !important;
  font-size: 16px !important;
}

/* ===== BROADCAST SCREEN ===== */
.broadcast-container {
  width: 100%;
  height: 100%;
  background: #000000;
  position: relative;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  overflow: hidden;
}

#broadcast-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  -webkit-object-fit: contain;
  -o-object-fit: contain;
  object-fit: contain;
  background-color: #000;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  display: block;
}

/* Кнопка fullscreen — в правом нижнем углу, поверх контента */
#btn-fullscreen {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 100;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-transition: background 0.2s;
  transition: background 0.2s;
  outline: none;
  /* Скрываем пока не в режиме трансляции — показывается через JS */
  opacity: 0.7;
}

#btn-fullscreen:hover,
#btn-fullscreen:focus {
  background: rgba(255,255,255,0.2);
  opacity: 1;
  outline: 2px solid #667eea;
}

/* width/height 100% + object-fit: contain.
   fitToContainer отключён — чисто для проверки что Tizen покажет. */
#broadcast-video {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 100%;
  height: 100%;
  -webkit-object-fit: contain;
  -o-object-fit: contain;
  object-fit: contain;
  background-color: #000;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: contain;
  display: none;
}

/* ===== UNMUTE BANNER ===== */
/* Живёт прямо в #broadcast-container, поэтому не боится native video layer.
   will-change: transform принудительно поднимает элемент в отдельный GPU-слой,
   что гарантирует его рендер поверх <video> на мобильных браузерах. */
#unmute-banner {
  display: none; /* показывается через JS → display:-webkit-flex / display:flex */
  position: absolute;
  bottom: 48px;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  -webkit-align-items: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  padding: 14px 28px;
  z-index: 300;
  cursor: pointer;
  white-space: nowrap;
  will-change: transform;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  /* Мягкое появление */
  -webkit-animation: unmute-pulse 2s ease-in-out infinite;
  animation: unmute-pulse 2s ease-in-out infinite;
}

/* gap не поддерживается в старых браузерах — используем margin */
#unmute-banner > * {
  margin: 0 5px;
}

#unmute-banner > *:first-child {
  margin-left: 0;
}

#unmute-banner > *:last-child {
  margin-right: 0;
}

#unmute-banner:focus {
  border-color: rgba(255, 255, 255, 0.8);
}

#unmute-icon {
  font-size: 26px;
  line-height: 1;
}

#unmute-text {
  color: #fff;
  font-size: 20px;
  font-family: sans-serif;
}

@-webkit-keyframes unmute-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}
@keyframes unmute-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ===== LEGACY SAFARI / OLD WEBKIT FALLBACKS ===== */
/* Safari 5.0 / старые WebKit: object-fit не поддерживается,
   используем background-size как fallback через JS */
.no-objectfit #broadcast-image,
.no-objectfit #broadcast-video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}

.broadcast-title {
  position: absolute;
  top: 20px;
  left: 20px;
  background: rgba(0,0,0,0.7);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  color: #ffffff;
  display: none;
}

.broadcast-title.visible {
  display: block;
}

/* ===== AUDIO PLAYER ===== */
#audio-player {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  width: 520px;
  max-width: 90vw;
  background: rgba(20, 20, 40, 0.95);
  border: 1px solid rgba(102, 126, 234, 0.4);
  border-radius: 20px;
  padding: 40px 36px 32px;
  text-align: center;
  z-index: 10;
}

.audio-art {
  font-size: 80px;
  margin-bottom: 20px;
  line-height: 1;
  color: #667eea;
}

.audio-title {
  font-size: 22px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 28px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-progress-wrap {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: 28px;
}

.audio-progress-wrap > * {
  margin: 0 6px;
}

.audio-progress-wrap span {
  font-size: 13px;
  color: #aaa;
  min-width: 36px;
  font-family: 'Courier New', monospace;
}

.audio-progress-bg {
  -webkit-flex: 1;
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}

.audio-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  border-radius: 3px;
  -webkit-transition: width 0.5s linear;
  transition: width 0.5s linear;
}

.audio-controls {
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;
}

.audio-controls button {
  margin: 0 8px;
  background: rgba(102, 126, 234, 0.2);
  border: 1px solid rgba(102, 126, 234, 0.5);
  border-radius: 10px;
  color: #fff;
  font-size: 15px;
  padding: 10px 20px;
  cursor: pointer;
  -webkit-transition: background 0.2s;
  transition: background 0.2s;
  outline: none;
}

.audio-controls button:focus,
.audio-controls button:hover {
  background: rgba(102, 126, 234, 0.5);
  outline: 2px solid #667eea;
}

#audio-btn-play {
  width: 64px;
  height: 64px;
  border-radius: 50% !important;
  font-size: 24px !important;
  padding: 0 !important;
  background: #667eea !important;
  border-color: #667eea !important;
}

#audio-btn-play:focus,
#audio-btn-play:hover {
  background: #764ba2 !important;
}

/* ===== DISCONNECTED SCREEN ===== */
.disconnected-container {
  text-align: center;
  padding: 40px;
}

.disconnected-icon {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #4a1111;
  color: #f44336;
  font-size: 60px;
  line-height: 120px;
  margin: 0 auto 30px;
}

.disconnected-container h1 {
  font-size: 36px;
  margin-bottom: 10px;
}

.disconnected-container p {
  font-size: 20px;
  color: #aaaaaa;
  margin-bottom: 30px;
}

.btn-reconnect {
  padding: 16px 40px;
  font-size: 18px;
  background: #667eea;
  color: #ffffff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn-reconnect:hover {
  background: #5a6fd6;
}

.btn-reconnect:focus {
  outline: 2px solid #ffffff;
}

/* ===== ANDROID TV / TCL FALLBACK ===== */
/* Старые Android TV WebView не поддерживают SVG — показываем PNG */
.layout-android-tv .step-content-img img[src$=".svg"],
.layout-android-tv .step-content-img img[src*="smile"] {
  display: none;
}

.layout-android-tv .step-content-img::after {
  content: '';
  display: inline-block;
  width: 40px;
  height: 40px;
  background: url('/img/smile.png') no-repeat center center;
  background-size: contain;
  vertical-align: middle;
  margin-left: 10px;
}

/* ===== SMALL SCREEN / SCALED-UP VIEWPORT FIX ===== */
/* Android TV часто запускает браузер с 125% масштабом.
   При этом viewport (window.innerWidth/Height) может быть БОЛЬШЕ
   физического разрешения screen.width/height. Без этих фиксов
   блок с цифрами уезжает за нижний край экрана. */
@media (max-height: 620px), (max-width: 1000px) {
  .code-digits {
    margin-bottom: 12px;
  }

  .digit {
    width: 44px;
    height: 58px;
    font-size: 28px;
  }
}

@media (max-height: 500px) {
  .digit {
    width: 36px;
    height: 48px;
    font-size: 22px;
  }
}

.layout-scaled-up .code-digits {
  margin-bottom: 14px;
}

.layout-scaled-up .digit {
  width: 48px;
  height: 62px;
  font-size: 30px;
}

.layout-small-screen .code-digits {
  margin-bottom: 10px;
}

.layout-small-screen .digit {
  width: 40px;
  height: 54px;
  font-size: 26px;
}

/* ===== FIRE TV / FIRE STICK FALLBACK ===== */
/* Fire TV Silk/Chrome на старых WebKit имеет проблемы с clamp/min/flex */
.layout-fire-tv .code-digits,
.layout-fire-tv .digit {
  display: inline-block;
  vertical-align: middle;
}

.layout-fire-tv .digit {
  width: 65px;
  height: 88px;
  line-height: 88px;
  font-size: 44px;
  text-align: center;
}

.layout-fire-tv .main-table {
  height: auto;
  min-height: 60vh;
}

.layout-fire-tv .gradient-footer {
  position: relative;
  bottom: auto;
  left: auto;
  height: auto;
  margin-top: 20px;
}

.layout-fire-tv .column-right {
  padding: 20px 30px;
}

.layout-fire-tv .instructions {
  padding: 20px 24px;
  border-radius: 24px;
  overflow: visible;
}

.layout-fire-tv .step {
  display: block;
  margin-bottom: 16px;
  overflow: hidden;
}

.layout-fire-tv .step-number {
  float: left;
  display: block;
  width: 48px;
  height: 48px;
  line-height: 44px;
  text-align: center;
  margin-right: 16px;
  font-size: 24px;
}

.layout-fire-tv .step-content {
  display: block;
  margin-left: 0;
  overflow: hidden;
}

.layout-fire-tv .step-content h3 {
  font-size: 22px;
  line-height: 1.3;
}

.layout-fire-tv .qr-code img {
  width: 140px;
  height: 140px;
}

/* ===== SAFARI 5 / OLD WEBKIT FALLBACK ===== */
/* Safari 5 (WebKit <= 534) не поддерживает -webkit-flex, только -webkit-box */
.layout-safari-5 .screen.active {
  display: block !important;
  -webkit-box-align: center;
  -webkit-box-pack: center;
}

.layout-old-chrome .screen.active {
  display: block !important;
  -webkit-box-align: center;
  -webkit-box-pack: center;
}

.layout-safari-5 .code-digits,
.layout-safari-5 .digit {
  display: inline-block;
  vertical-align: middle;
}

.layout-safari-5 .digit {
  width: 65px;
  height: 88px;
  line-height: 88px;
  font-size: 44px;
  text-align: center;
}

.layout-safari-5 .step {
  display: block !important;
  margin-bottom: 22px;
  overflow: hidden;
}

.layout-safari-5 .step-number {
  float: left;
  display: block;
  width: 56px;
  height: 56px;
  line-height: 52px;
  text-align: center;
  margin-right: 20px;
}

.layout-safari-5 .step-content {
  display: block;
  margin-left: 0;
  overflow: hidden;
}

.layout-safari-5 .connected-container,
.layout-safari-5 .disconnected-container {
  display: block;
  text-align: center;
  padding-top: 10vh;
}

.layout-safari-5 .broadcast-container {
  display: block;
  text-align: center;
}

.layout-safari-5 #broadcast-image,
.layout-safari-5 #broadcast-video {
  display: inline-block;
  vertical-align: middle;
}

/* ===== OLD CHROME (< 25) FALLBACK ===== */
/* Chrome 21-24: поддерживает -webkit-flex, но НЕ object-fit, clamp(), WebRTC */
.layout-old-chrome .code-digits,
.layout-old-chrome .digit {
  display: inline-block;
  vertical-align: middle;
}

.layout-old-chrome .digit {
  width: 72px;
  height: 92px;
  line-height: 88px;
  font-size: 44px;
  text-align: center;
}

.layout-old-chrome .step {
  display: block !important;
  margin-bottom: 22px;
  overflow: hidden;
}

.layout-old-chrome .step-number {
  float: left;
  display: block;
  width: 56px;
  height: 56px;
  line-height: 52px;
  text-align: center;
  margin-right: 20px;
}

.layout-old-chrome .step-content {
  display: block;
  margin-left: 0;
  overflow: hidden;
}

.layout-old-chrome #step4Title {
  display: block !important;
  height: auto !important;
}

.layout-old-chrome #broadcast-image,
.layout-old-chrome #broadcast-video {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
}
