/* ========================================
   RETRO PIXEL ART THEME - "Есть Гудок!"
   ======================================== */

/* CSS Variables - Retro Color Palette */
:root {
  --cream: #F5E6D3;
  --beige: #D4A574;
  --tan: #C4976B;
  --brown: #6B4423;
  --dark-brown: #4A3728;
  --teal: #5FBDBD;
  --black: #2C2C2C;
  --white: #FFFFFF;
  --red-brown: #8B4513;
  --red: #D32F2F;
}

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

html, body {
  /* Support iPhone safe areas - only left/right for home screen */
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

body {
  font-family: 'VT323', monospace;
  background: var(--cream);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Pixel noise texture */
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,.03) 2px, rgba(0,0,0,.03) 4px),
    repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0,0,0,.03) 2px, rgba(0,0,0,.03) 4px);
}

.container {
  width: 100%;
  max-width: 1200px;
  padding: 20px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* ========================================
   HOME SCREEN - RETRO STYLE
   ======================================== */

#home-screen {
  text-align: center;
  padding: 10px 20px 20px 20px;
}

.logo {
  margin-bottom: 15px;
}

.logo-image {
  width: 180px;
  height: auto;
  margin: 0 auto 10px;
  display: block;
  /* Pixel-perfect scaling */
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* Subtle drop shadow for depth */
  filter: drop-shadow(4px 4px 0px rgba(0, 0, 0, 0.15));
}

.logo h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 2rem;
  color: var(--dark-brown);
  margin-bottom: 0;
  text-shadow: 3px 3px 0px var(--beige);
  line-height: 1.4;
}

.logo p {
  font-family: 'VT323', monospace;
  font-size: 1.8rem;
  color: var(--brown);
  margin-bottom: 20px;
  letter-spacing: 1px;
}

.actions {
  margin: 10px 0;
}

/* ========================================
   STATS DISPLAY - RETRO PIXEL COUNTER
   ======================================== */

.stats-display {
  margin: 30px auto 20px;
  padding: 20px 30px;
  background: var(--dark-brown);
  border: 4px solid var(--brown);
  box-shadow:
    inset 0 0 0 2px var(--beige),
    6px 6px 0px var(--brown);
  max-width: 500px;
  position: relative;
  /* Pixel-perfect rendering */
  image-rendering: pixelated;
}

.stats-display::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 255, 255, 0.03) 2px,
      rgba(255, 255, 255, 0.03) 4px
    );
  pointer-events: none;
}

.stats-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-direction: column;
}

.stat-icon {
  font-size: 1.8rem;
  filter: drop-shadow(2px 2px 0px rgba(0, 0, 0, 0.3));
}

.stat-value {
  font-family: 'Press Start 2P', cursive;
  font-size: 2rem;
  color: var(--cream);
  text-shadow:
    2px 2px 0px var(--brown),
    4px 4px 0px rgba(0, 0, 0, 0.2);
  letter-spacing: 3px;
  min-width: 80px;
  text-align: center;
  /* Animated counter effect */
  animation: pulse 2s ease-in-out infinite;
}

.stat-label {
  font-family: 'VT323', monospace;
  font-size: 1.1rem;
  color: var(--beige);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-top: -4px;
}

.stat-separator {
  font-family: 'Press Start 2P', cursive;
  font-size: 1.5rem;
  color: var(--beige);
  opacity: 0.6;
  margin: 0 10px;
  padding-bottom: 20px;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    text-shadow:
      2px 2px 0px var(--brown),
      4px 4px 0px rgba(0, 0, 0, 0.2);
  }
  50% {
    opacity: 0.9;
    text-shadow:
      2px 2px 0px var(--brown),
      4px 4px 0px rgba(0, 0, 0, 0.2),
      0 0 10px var(--beige);
  }
}

/* Loading state */
.stats-display.loading .stat-value {
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0.3; }
}

.btn {
  padding: 20px 50px;
  font-size: 1.4rem;
  font-family: 'VT323', monospace;
  border: 4px solid var(--dark-brown);
  cursor: pointer;
  transition: all 0.1s ease;
  font-weight: 400;
  box-shadow: 6px 6px 0px var(--dark-brown);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.btn-primary {
  background: var(--beige);
  color: var(--dark-brown);
}

.btn-primary:hover {
  background: var(--tan);
  transform: translate(2px, 2px);
  box-shadow: 4px 4px 0px var(--dark-brown);
}

.btn-primary:active {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0px var(--dark-brown);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  background: #CCC;
  color: #666;
  border-color: #999;
  box-shadow: 6px 6px 0px #999;
}

.btn-secondary {
  background: var(--teal);
  color: var(--white);
  padding: 15px 30px;
  font-size: 1.2rem;
  border: 3px solid var(--dark-brown);
  box-shadow: 4px 4px 0px var(--dark-brown);
}

.btn-secondary:hover {
  background: #4EACAC;
  transform: translate(1px, 1px);
  box-shadow: 3px 3px 0px var(--dark-brown);
}

.btn-secondary:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px var(--dark-brown);
}

.btn-share {
  background: transparent;
  color: var(--dark-brown);
  padding: 12px;
  font-size: 1.4rem;
  border: 2px solid var(--dark-brown);
  box-shadow: none;
  min-width: auto;
  transition: all 0.2s ease;
}

.btn-share:hover {
  background: rgba(95, 189, 189, 0.1);
  transform: scale(1.05);
}

.btn-share:active {
  transform: scale(0.95);
}

.btn-share i {
  display: block;
  line-height: 1;
}

.hidden {
  display: none !important;
}

#room-link-container {
  margin-top: 10px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.room-link-box {
  background: var(--white);
  padding: 20px;
  border: 5px solid var(--dark-brown);
  box-shadow: 8px 8px 0px var(--dark-brown);
  max-width: 600px;
  margin: 0 auto;
}

.room-link-box p {
  font-family: 'VT323', monospace;
  color: var(--dark-brown);
  font-size: 1.4rem;
  margin-bottom: 10px;
}

.link-display {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

#room-link-input {
  flex: 1;
  padding: 12px;
  border: 3px solid var(--dark-brown);
  font-size: 1rem;
  font-family: 'Courier New', monospace;
  background: var(--cream);
}

.status-text {
  color: var(--brown);
  font-weight: 400;
  font-size: 1.3rem;
  animation: blink 2s infinite;
}

@keyframes blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ========================================
   CALL SCREEN - RETRO TV STYLE
   ======================================== */

#call-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: var(--black);
}

/* Lock call screen - prevent scrolling */
#call-screen.active {
  overflow: hidden;
  touch-action: none;
}

/* Lock body when on call screen - prevent page scrolling */
body.on-call {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100vh;
}

.video-container {
  position: relative;
  width: 100%;
  /* Full screen - FaceTime style */
  height: 100vh;
  background: #000;
  border: none;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* Portrait video - fill screen with cropping (FaceTime-like) */
#remote-video.portrait {
  object-fit: cover;
}

/* Landscape video - show full video (current behavior) */
#remote-video.landscape {
  object-fit: contain;
}

#local-video {
  position: fixed;
  /* Position above floating controls */
  bottom: calc(145px + env(safe-area-inset-bottom));
  right: calc(20px + env(safe-area-inset-right));
  width: 140px;
  height: 105px;
  object-fit: cover;
  border: 4px solid var(--beige);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 150;
  border-radius: 8px;
  /* Pixel-perfect video */
  image-rendering: -webkit-optimize-contrast;
}

.status-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 5;
}

.status-overlay.hidden {
  display: none;
}

.status-message {
  font-family: 'Press Start 2P', cursive;
  color: var(--beige);
  font-size: 1.4rem;
  text-align: center;
  padding: 0 20px;
  line-height: 1.6;
  text-shadow: 2px 2px 0px var(--dark-brown);
}

.status-message::before {
  content: '';
  display: block;
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  border: 6px solid var(--dark-brown);
  border-top-color: var(--beige);
  animation: rotate 1.5s linear infinite;
}

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

/* ========================================
   CONTROL BUTTONS - PIXEL ART STYLE
   ======================================== */

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 25px;
  /* Floating controls - FaceTime style */
  padding: 0 20px calc(25px + env(safe-area-inset-bottom)) 20px;
  background: transparent;
  border: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
}

.control-btn {
  /* SQUARE BUTTONS - RETRO STYLE */
  width: 90px;
  height: 90px;
  border: 4px solid var(--black);
  background: rgba(212, 165, 116, 0.95);
  color: var(--dark-brown);
  font-size: 2rem;
  cursor: pointer;
  transition: all 0.1s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.6);
  /* NO ROUNDED CORNERS! */
  border-radius: 0;
  backdrop-filter: blur(5px);
  padding: 0;
}

.control-btn i {
  font-size: 2.4rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.4rem;
  width: 2.4rem;
}

.btn-label {
  font-family: 'VT323', monospace;
  font-size: 0.9rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 0;
  line-height: 1;
}

.control-btn:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px var(--black);
}

.control-btn:active {
  transform: translate(4px, 4px);
  box-shadow: 0px 0px 0px var(--black);
}

/* Active/Enabled state - GREEN/TEAL */
.control-btn.active,
.control-btn:not(.disabled) {
  background: rgba(95, 189, 189, 0.95);
  color: var(--white);
  border-color: var(--dark-brown);
}

/* Disabled/Muted state - RED */
.control-btn.disabled {
  background: rgba(211, 47, 47, 0.95);
  color: var(--white);
  border-color: var(--dark-brown);
}

/* End call button - Always RED (same size as others) */
.btn-danger {
  background: rgba(211, 47, 47, 0.95) !important;
  border-color: var(--dark-brown) !important;
  width: 90px !important;
  height: 90px !important;
  color: var(--white) !important;
  backdrop-filter: blur(5px);
}

.btn-danger i {
  font-size: 2.4rem !important;
  height: 2.4rem;
  width: 2.4rem;
}

.btn-danger:hover {
  transform: translate(2px, 2px) !important;
  box-shadow: 2px 2px 0px var(--black) !important;
}

.btn-danger::after {
  display: none !important;
}

/* ========================================
   INFO BAR - RETRO DIGITAL CLOCK STYLE
   ======================================== */

.info-bar {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 12px;
  border: none;
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'VT323', monospace;
  font-size: 0.95rem;
  font-weight: 400;
  z-index: 100;
  border-radius: 20px;
  backdrop-filter: blur(10px);
}

#connection-status {
  display: none;
}

.info-bar::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4CAF50;
  flex-shrink: 0;
}

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

#call-duration {
  font-weight: 400;
  letter-spacing: 2px;
}

/* ========================================
   RESPONSIVE - MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
  #home-screen {
    padding: 5px 15px 15px 15px;
  }

  .logo {
    margin-bottom: 10px;
  }

  .logo h1 {
    font-size: 1.6rem;
    margin-bottom: 0;
  }

  .logo p {
    font-size: 1.4rem;
    margin-bottom: 15px;
  }

  .logo-image {
    width: 150px;
    margin-bottom: 8px;
  }

  .actions {
    margin: 8px 0;
  }

  .btn {
    font-size: 1.2rem;
    padding: 15px 35px;
  }

  #room-link-container {
    margin-top: 8px;
  }

  .room-link-box {
    padding: 15px;
  }

  #local-video {
    width: 110px;
    height: 82px;
    /* Position above floating controls on tablet */
    bottom: calc(125px + env(safe-area-inset-bottom));
    right: calc(15px + env(safe-area-inset-right));
    border: 3px solid var(--beige);
  }

  .controls {
    gap: 18px;
    /* Floating controls on mobile */
    padding: 0 15px calc(20px + env(safe-area-inset-bottom)) 15px;
  }

  .control-btn {
    width: 75px;
    height: 75px;
    font-size: 1.8rem;
  }

  .control-btn i {
    font-size: 2.2rem;
    height: 2.2rem;
    width: 2.2rem;
  }

  .btn-label {
    font-size: 0.75rem;
  }

  .btn-danger {
    width: 75px !important;
    height: 75px !important;
  }

  .btn-danger i {
    font-size: 2.2rem !important;
    height: 2.2rem;
    width: 2.2rem;
  }

  .room-link-box {
    padding: 20px;
    border: 4px solid var(--dark-brown);
  }

  .link-display {
    flex-direction: column;
  }

  .info-bar {
    font-size: 0.85rem;
    padding: 6px 10px;
    gap: 8px;
    top: calc(15px + env(safe-area-inset-top));
    right: calc(15px + env(safe-area-inset-right));
  }

  .info-bar::before {
    width: 6px;
    height: 6px;
  }
}

@media (max-width: 480px) {
  #home-screen {
    padding: 5px 10px 10px 10px;
  }

  .logo {
    margin-bottom: 8px;
  }

  .logo h1 {
    font-size: 1.4rem;
    margin-bottom: 0;
  }

  .logo p {
    font-size: 1.2rem;
    margin-bottom: 12px;
  }

  .logo-image {
    width: 130px;
    margin-bottom: 6px;
  }

  .actions {
    margin: 6px 0;
  }

  .btn {
    padding: 12px 30px;
  }

  #room-link-container {
    margin-top: 6px;
  }

  .room-link-box {
    padding: 12px;
  }

  .room-link-box p {
    font-size: 1.2rem;
    margin-bottom: 8px;
  }

  #local-video {
    width: 100px;
    height: 75px;
    /* Position above floating controls on small phones */
    bottom: calc(115px + env(safe-area-inset-bottom));
    right: calc(12px + env(safe-area-inset-right));
    border: 3px solid var(--beige);
  }

  .controls {
    gap: 12px;
    /* Floating controls on small phones */
    padding: 0 10px calc(15px + env(safe-area-inset-bottom)) 10px;
  }

  .control-btn {
    /* Minimum touch target for iOS: 44x44px */
    width: 70px;
    height: 70px;
    border: 3px solid var(--black);
  }

  .control-btn i {
    font-size: 2rem;
    height: 2rem;
    width: 2rem;
  }

  .btn-label {
    font-size: 0.7rem;
  }

  .btn-danger {
    width: 70px !important;
    height: 70px !important;
  }

  .btn-danger i {
    font-size: 2rem !important;
    height: 2rem;
    width: 2rem;
  }

  .info-bar {
    font-size: 0.8rem;
    padding: 5px 8px;
    gap: 6px;
    top: calc(12px + env(safe-area-inset-top));
    right: calc(12px + env(safe-area-inset-right));
  }

  .info-bar::before {
    width: 5px;
    height: 5px;
  }
}

/* ========================================
   PIXEL PERFECT - CRISP RENDERING
   ======================================== */

img, video {
  -ms-interpolation-mode: nearest-neighbor;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}
