:root {
  --bg-color: linear-gradient(135deg, #2c003e, #5a006a, #ff5aab);
  --glass-bg: rgba(255, 255, 255, 0.1);
  --text-color: #f5f5f5;
  --header-color: #ffd6f7;
  --accent-color: #ff5aab;
  --button-gradient: linear-gradient(90deg, #ff5aab, #8a2be2);
  --success-color: #4CAF50;
  --mobile-breakpoint: 768px;
}

* { 
  box-sizing: border-box; 
  /* Touch оптимизация - убираем нежелательные выделения */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html {
  /* Safe area поддержка для устройств с вырезами */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-color);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-color);
  margin:0; padding:0;
  transition: background 0.3s ease;
  position: relative;
  overflow-x: hidden;
  
  /* Mobile-first оптимизации */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Touch-action оптимизация для всех интерактивных элементов */
button, .btn, input, textarea, a, [role="button"] {
  touch-action: manipulation;
  min-height: 44px; /* Минимальный размер для touch targets */
  min-width: 44px;
}

/* Убираем hover эффекты на touch устройствах */
@media (hover: none) and (pointer: coarse) {
  button:hover, .card:hover, a:hover {
    transform: none !important;
    box-shadow: inherit !important;
    filter: none !important;
  }
  
  button:hover::before, .card:hover::before {
    opacity: 0 !important;
  }
}

/* Ripple эффект для кнопок */
.ripple {
  position: relative;
  overflow: hidden;
}

.ripple::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.3s, height 0.3s;
}

.ripple:active::before {
  width: 200px;
  height: 200px;
}

#particle-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}

h1 { margin-top: 24px; font-size: 2rem; color: var(--header-color); text-shadow: 0 2px 8px rgba(0,0,0,0.5); z-index: 100; position: relative;}
.container { width: 90%; max-width: 800px; margin: 16px auto; padding-bottom: 120px; z-index: 100; position: relative;}
.card { 
  background: var(--glass-bg); 
  border-radius: 16px; 
  padding: 20px; 
  margin-bottom: 16px; 
  box-shadow: 0 8px 20px rgba(0,0,0,0.4); 
  backdrop-filter: blur(4px); 
  transition: transform 0.4s, box-shadow 0.4s;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  background: linear-gradient(45deg, transparent, rgba(255,90,171,0.3), transparent);
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: -1;
}

/* Заменяем hover на focus-visible */
.card:focus-visible::before { opacity: 1; }
.card:focus-visible { 
  transform: translateY(-2px); 
  box-shadow: 0 12px 24px rgba(0,0,0,0.6);
  outline: 2px solid rgba(255, 90, 171, 0.5);
  outline-offset: 2px;
}

/* Touch feedback для карточек */
@media (hover: none) and (pointer: coarse) {
  .card:active {
    transform: translateY(1px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
  }
}

textarea, input { 
  width: 100%; 
  margin: 6px 0; 
  padding: 12px 16px; 
  border-radius: 10px; 
  border: none; 
  background: rgba(255,255,255,0.2); 
  color: #fff; 
  font-family: 'Roboto Mono', monospace; 
  font-size: 16px; /* Предотвращает zoom на iOS */
  transition: all 0.6s;
  touch-action: manipulation;
  
  /* Mobile оптимизации */
  -webkit-appearance: none;
  appearance: none;
  
  /* Минимальная высота для лучшего touch */
  min-height: 44px;
}

textarea:focus, input:focus { 
  outline: none; 
  background: rgba(255,255,255,0.25); 
  box-shadow: 0 0 15px rgba(255,90,171,0.5);
  border: 2px solid rgba(255,90,171,0.3);
}

/* Active состояние для input */
textarea:active, input:active {
  background: rgba(255,255,255,0.3);
}

/* Специальные стили для чат инпута */
#chat-input {
  position: relative;
  z-index: 10;
  margin: 0;
  padding: 12px 16px;
  min-height: 44px;
  font-size: 16px; /* Предотвращает zoom на iOS */
  border-radius: 25px;
  
  /* Избегаем наложения с виртуальной клавиатурой */
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

button { 
  background: var(--button-gradient); 
  color: #fff; 
  border: none; 
  border-radius: 12px; 
  padding: 14px 20px; 
  margin: 4px; 
  cursor: pointer; 
  font-weight: 600; 
  transition: all 0.4s; 
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
  
  /* Минимальный размер для touch devices */
  min-height: 44px;
  min-width: 44px;
}

/* Заменяем hover на focus-visible для accessibility */
button:focus-visible { 
  outline: 2px solid rgba(255, 90, 171, 0.8);
  outline-offset: 2px;
  transform: translateY(-2px); 
  box-shadow: 0 8px 20px rgba(0,0,0,0.5); 
  filter: brightness(1.1);
}

/* Active состояние для touch */
button:active { 
  transform: translateY(1px) scale(0.98);
  transition: all 0.3s;
}

/* Touch feedback */
@media (hover: none) and (pointer: coarse) {
  button:active {
    background: linear-gradient(90deg, #ff75c4, #a64ddb);
    transform: translateY(1px) scale(0.95);
  }
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

/* Ripple эффект применяем ко всем кнопкам */
button, .choice-btn, .game-btn, #send-btn, #voice-btn, #theme-toggle {
  position: relative;
  overflow: hidden;
}

button::after, .choice-btn::after, .game-btn::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease;
  pointer-events: none;
}

button:active::after, .choice-btn:active::after, .game-btn:active::after {
  width: 200px;
  height: 200px;
}

/* Touch active состояние */
.touch-active {
  transform: scale(0.95);
  filter: brightness(0.9);
  transition: all 0.1s ease;
}

/* Keyboard open состояние */
.keyboard-open {
  --keyboard-height: 300px;
}

.keyboard-open .container {
  padding-bottom: calc(80px + var(--keyboard-height, 0px) + env(safe-area-inset-bottom, 0px));
}

.keyboard-open .chat-input-area {
  transform: translateY(calc(-1 * var(--keyboard-height, 0px)));
  transition: transform 0.3s ease;
}

/* CSS переменные для динамических значений */
:root {
  --keyboard-height: 0px;
  --safe-area-inset-bottom: 0px;
  --safe-area-inset-top: 0px;
  --safe-area-inset-left: 0px;
  --safe-area-inset-right: 0px;
}

/* Вычисляем safe-area значения */
@supports (padding: max(0px)) {
  :root {
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
  }
}

/* CSS для предотвращения text selection на мобильных */
@media (max-width: 768px) {
  button, .btn, [role="button"] {
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* Но разрешаем selection для текстовых элементов */
  textarea, input, [contenteditable] {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Оптимизация для устройств с высоким DPI */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  #sans-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Темная тема оптимизации */
@media (prefers-color-scheme: dark) {
  .card {
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  input, textarea {
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
}

.row { display:flex; gap:8px; flex-wrap:wrap; margin-top:8px; }

/* CHAT PAGE */
#chat-page {
  min-height: 60vh;
}

#chat-page .card {
  margin-bottom: 20px;
}

.chat-status {
  font-size: 0.9rem;
  color: var(--header-color);
  margin: 10px 0;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  border-left: 4px solid var(--accent-color);
  text-align: center;
}

.typing-indicator {
  padding: 10px 15px;
  background: rgba(255,255,255,0.1);
  border-radius: 15px;
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 5px;
  animation: fadeIn 0.8s;
}

.typing-indicator.show {
  display: flex;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--accent-color);
  border-radius: 50%;
  animation: typingBounce 2.5s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.5s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-10px); }
}

#chat-messages {
  min-height: 400px;
  max-height: 600px;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(0,0,0,0.2);
  border-radius: 15px;
  margin: 15px 0;
}

.message {
  max-width: 80%;
  padding: 10px 15px;
  border-radius: 15px;
  word-wrap: break-word;
  animation: messageIn 1.0s;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Custom Voice Message Player */
.voice-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  min-width: 200px;
  max-width: 280px;
  position: relative;
}

.voice-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.4s;
  flex-shrink: 0;
}

.voice-play-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.05);
}

/* Touch-friendly voice player */
.voice-play-btn:focus-visible {
  outline: 2px solid rgba(255, 90, 171, 0.8);
  outline-offset: 2px;
  transform: scale(1.05);
}

@media (hover: none) and (pointer: coarse) {
  .voice-play-btn:active {
    background: rgba(255,255,255,0.4);
    transform: scale(0.9);
  }
}

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

.message.sent .voice-play-btn {
  background: rgba(0,0,0,0.3);
}

.message.sent .voice-play-btn:hover {
  background: rgba(0,0,0,0.4);
}

.voice-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 32px;
  position: relative;
}

.voice-wave-bar {
  width: 3px;
  background: rgba(255,255,255,0.4);
  border-radius: 2px;
  transition: all 0.15s;
}

.message.sent .voice-wave-bar {
  background: rgba(255,255,255,0.6);
}

.voice-wave-bar.active {
  background: rgba(255,255,255,0.9);
}

.message.sent .voice-wave-bar.active {
  background: rgba(255,255,255,1);
}

.voice-duration {
  font-size: 0.75rem;
  opacity: 0.7;
  font-family: 'Roboto Mono', monospace;
  min-width: 35px;
  text-align: right;
}

.voice-player audio {
  display: none;
}

.message.sent {
  align-self: flex-end;
  background: linear-gradient(135deg, #ff5aab, #8a2be2);
  border-bottom-right-radius: 5px;
}

.message.received {
  align-self: flex-start;
  background: rgba(255,255,255,0.15);
  border-bottom-left-radius: 5px;
}

.message-time {
  font-size: 0.7rem;
  opacity: 0.6;
  margin-top: 3px;
}

.chat-input-area {
  padding: 15px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  gap: 10px;
  align-items: center;
}

#chat-input {
  flex: 1;
  margin: 0;
}

#send-btn, #voice-btn, #call-btn {
  width: 50px;
  height: 50px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

#voice-btn {
  background: linear-gradient(135deg, #8a2be2, #ff5aab);
}

#voice-btn.recording {
  background: #ff0000;
  animation: recordPulse 2s infinite;
}

#call-btn {
  background: linear-gradient(135deg, #00ff00, #008000);
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.1); }
}

/* Room Setup */
#room-setup {
  padding: 20px;
  text-align: center;
  background: rgba(255,255,255,0.05);
  border-radius: 15px;
  margin: 15px 0;
}

#room-code-display {
  font-family: 'Roboto Mono', monospace;
  font-size: 1.5rem;
  color: var(--accent-color);
  margin: 15px 0;
  padding: 15px;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.6s;
}

#room-code-display:hover {
  background: rgba(255,255,255,0.15);
  transform: scale(1.05);
}

/* Menu */
#menu-btn {
  position: fixed;
  top: 15px; left: 15px;
  z-index: 2000;
  min-width: 90px; height: 50px;
  font-size: 1.1rem;
  padding: 0 15px;
  border-radius: 25px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  color: var(--header-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

#nav-menu {
  position: fixed;
  top: 70px; left: 15px;
  z-index: 1999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 15px;
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
  transform: translateX(-150%);
  opacity: 0;
  transition: transform 0.6s ease-out, opacity 0.6s;
}
#nav-menu.active {
  transform: translateX(0);
  opacity: 1;
}
#nav-menu button {
  width: 150px;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: none;
  border-radius: 10px;
}
#nav-menu button.active {
  background: var(--button-gradient);
}

.page {
  display: none;
  width: 100%;
  animation: fadeIn 0.8s;
}
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Sans */
#sans-container {
  position: relative;
  display: inline-block;
}
#sans-image {
  width: 50px; height: 50px;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.6s;
  box-shadow: 0 0 10px rgba(255,255,255,0.3);
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
#sans-image:hover {
  transform: scale(1.2) rotate(15deg);
  box-shadow: 0 0 20px rgba(255,90,171,0.8);
}
#sans-counter {
  position: absolute;
  top: -5px; right: -5px;
  background: #ff5aab;
  color: white;
  border-radius: 50%;
  width: 20px; height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.3s;
}
#sans-counter.show { opacity: 1; }

#socks-message {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  padding: 30px 50px;
  background: rgba(0,0,0,0.95);
  color: #fff000;
  font-size: 3rem;
  font-family: 'Roboto Mono', monospace;
  border: 5px solid #ff5aab;
  box-shadow: 0 0 50px #ff5aab;
  border-radius: 20px;
  z-index: 3500;
  opacity: 0;
  transition: all 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
  text-align: center;
  animation: rainbow 3s linear infinite;
}
#socks-message.active {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

@keyframes rainbow {
  0% { border-color: #ff0000; }
  16% { border-color: #ff7f00; }
  33% { border-color: #ffff00; }
  50% { border-color: #00ff00; }
  66% { border-color: #0000ff; }
  83% { border-color: #8b00ff; }
  100% { border-color: #ff0000; }
}

#confetti-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 3400;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 10px; height: 10px;
  opacity: 0;
  animation-duration: 3s;
  animation-fill-mode: forwards;
  animation-timing-function: cubic-bezier(.17,.67,.83,.67);
}
@keyframes fall-left {
  0% { left: 0; top: 50%; transform: translate(-100%, -50%) rotate(0deg); opacity: 1; }
  100% { left: 50%; top: 100vh; transform: translate(-50%, 0) rotate(720deg); opacity: 0; }
}
@keyframes fall-right {
  0% { right: 0; top: 50%; transform: translate(100%, -50%) rotate(0deg); opacity: 1; }
  100% { right: 50%; top: 100vh; transform: translate(50%, 0) rotate(-720deg); opacity: 0; }
}

.socks-mode {
  background: linear-gradient(135deg, #ff69b4, #ff1493, #ff69b4) !important;
  animation: socksGradient 3s ease infinite !important;
  background-size: 200% 200% !important;
}
@keyframes socksGradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

#toast-container { position: fixed; top:20px; right:20px; z-index:9999;}
.toast { 
  background: rgba(255,255,255,0.2); 
  color: #fff; 
  padding: 12px 18px; 
  margin-top: 8px; 
  border-radius: 12px; 
  box-shadow:0 4px 12px rgba(0,0,0,0.5); 
  backdrop-filter: blur(5px); 
  font-weight:500; 
  transition: all 0.6s; 
  opacity:0; 
  transform: translateX(100px);
  border-left: 4px solid var(--accent-color);
}
.toast.show {
  opacity: 1;
  transform: translateX(0);
}

footer {
  width:100%;
  text-align:center;
  margin:24px 0;
  padding-bottom: 20px;
  position: relative;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
}
a { 
  color: var(--accent-color); 
  text-decoration: none; 
  transition: all 0.4s;
  touch-action: manipulation;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Заменяем hover на focus-visible для ссылок */
a:focus-visible { 
  color: #fff; 
  transform: scale(1.1);
  outline: 2px solid rgba(255, 90, 171, 0.8);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (hover: none) and (pointer: coarse) {
  a:active {
    color: #fff;
    transform: scale(0.95);
    background: rgba(255, 90, 171, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
  }
}

.rainbow-mode {
  animation: rainbowBg 5s linear infinite;
}
@keyframes rainbowBg {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

/* Touch-Friendly элементы */
.touch-friendly {
  min-height: 44px;
  min-width: 44px;
  padding: 12px 16px;
  touch-action: manipulation;
  cursor: pointer;
}

/* Voice player оптимизации */
.voice-play-btn {
  touch-action: manipulation;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
}

/* Navigation menu улучшения */
#menu-btn, #nav-menu button {
  touch-action: manipulation;
  min-height: 44px;
}

/* Extra padding для кликабельных областей */
.choice-btn, .game-btn {
  touch-action: manipulation;
  min-height: 48px;
  padding: 14px 24px;
  font-size: 1.1rem;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
  h1 {
    font-size: 1.6rem;
    margin-top: 16px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  
  .container {
    width: 95%;
    margin: 12px auto;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    
    /* Безопасные зоны для устройств с вырезами */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  .card {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 12px;
    
    /* Touch-friendly */
    touch-action: manipulation;
  }
  
  #menu-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: calc(10px + env(safe-area-inset-left, 0px));
    min-width: 80px;
    height: 45px;
    font-size: 1rem;
    z-index: 2000;
  }
  
  #nav-menu {
    top: calc(60px + env(safe-area-inset-top, 0px));
    left: calc(10px + env(safe-area-inset-left, 0px));
    padding: 12px;
    backdrop-filter: blur(15px);
  }
  
  #nav-menu button {
    width: 140px;
    padding: 12px 16px;
    min-height: 44px;
    touch-action: manipulation;
  }
  
  #chat-messages {
    padding: 12px;
    min-height: 300px;
    max-height: 50vh; /* Ограничиваем высоту для лучшего UX */
    -webkit-overflow-scrolling: touch;
  }
  
  .message {
    max-width: 85%;
    padding: 10px 14px;
    margin-bottom: 8px;
  }
  
  .chat-input-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(10px);
    
    /* Фиксируем внизу экрана */
    position: sticky;
    bottom: 0;
    
    /* Safe area для устройств с вырезами */
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  #chat-input {
    font-size: 16px; /* Предотвращает zoom на iOS */
    min-height: 44px;
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  
  #send-btn, #voice-btn {
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    touch-action: manipulation;
  }
  
  /* Room Status Indicator */
  .room-status-indicator {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 2001;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    border-radius: 25px;
    padding: 8px 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: all 0.3s ease;
    opacity: 0;
    pointer-events: none;
    
    /* Безопасные зоны */
    padding-left: max(16px, calc(16px + env(safe-area-inset-left)));
    padding-right: max(16px, calc(16px + env(safe-area-inset-right)));
  }
  
  .room-status-indicator.show {
    opacity: 1;
    pointer-events: all;
  }
  
  .room-status-ball {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff5aab;
    animation: pulse 3s infinite;
    box-shadow: 0 0 8px rgba(255,90,171,0.6);
    flex-shrink: 0;
  }
  
  .room-status-ball.online {
    background: #4CAF50;
    box-shadow: 0 0 8px rgba(76,175,80,0.6);
  }
  
  .room-status-ball.offline {
    background: #f44336;
    box-shadow: 0 0 8px rgba(244,67,54,0.6);
  }
  
  .room-name {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9rem;
    color: var(--header-color);
    font-weight: 600;
  }
  
  .participants-count {
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.8;
  }
  
  /* Mobile Footer */
  footer {
    margin: 16px 0;
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  
  .footer-links {
    gap: 15px;
    touch-action: manipulation;
  }
  
  #sans-image {
    width: 40px;
    height: 40px;
    touch-action: manipulation;
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Better mobile scrolling */
  .page {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  
  /* Mobile toast positioning */
  #toast-container {
    top: calc(15px + env(safe-area-inset-top, 0px));
    right: max(15px, env(safe-area-inset-right, 0px));
    left: max(15px, env(safe-area-inset-left, 0px));
    z-index: 10000;
  }
  
  .toast {
    margin-top: 5px;
    touch-action: manipulation;
    padding: 14px 18px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  h1 {
    font-size: 1.4rem;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  
  .container {
    width: 98%;
    margin: 8px auto;
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  
  .card {
    padding: 14px;
    border-radius: 10px;
    margin-bottom: 10px;
  }
  
  button {
    padding: 12px 16px;
    font-size: 0.95rem;
    min-height: 44px;
  }
  
  #send-btn, #voice-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }
  
  #chat-input {
    font-size: 16px; /* Предотвращает zoom */
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }
  
  .choice-btn, .game-btn {
    padding: 14px 20px;
    font-size: 1rem;
    min-height: 48px;
    min-width: 120px;
  }
  
  .room-status-indicator {
    padding: 6px 12px;
    border-radius: 20px;
  }
  
  .room-name {
    font-size: 0.85rem;
  }
  
  .participants-count {
    font-size: 0.75rem;
  }
  
  .voice-player {
    min-width: 180px;
    max-width: 250px;
    padding: 8px;
  }
  
  .voice-play-btn {
    width: 40px;
    height: 40px;
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Sans button optimization */
  #sans-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
  }
  
  #sans-image {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
}

/* Desktop устройства (НЕ мобильные) */
.desktop-device .container {
  padding-bottom: 140px; /* Увеличиваем отступ для desktop */
}

.desktop-device #chat-messages {
  padding-bottom: 120px; /* Место для поля ввода */
  max-height: 500px; /* Ограничиваем высоту для лучшего UX */
}

.desktop-device .chat-input-area {
  position: static !important; /* Убираем sticky на desktop */
  padding: 20px;
  background: rgba(0,0,0,0.2);
  border-top: 1px solid rgba(255,255,255,0.1);
  border-radius: 0 0 15px 15px;
}

/* Отключаем keyboard-open эффект на desktop */
.desktop-device.keyboard-open .chat-input-area {
  transform: none !important;
}

/* Улучшаем hover эффекты на desktop */
.desktop-device .chat-input-area:hover {
  background: rgba(0,0,0,0.25);
}

/* Desktop cursor effects */
.desktop-device button:hover, .desktop-device .card:hover {
  transform: translateY(-2px);
  transition: all 0.6s;
}

/* Мобильные устройства - оставляем sticky позиционирование */
.mobile-device .chat-input-area {
  position: sticky;
  bottom: 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(10px);
}

/* Theme Toggle Button (in footer) */
#theme-toggle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(255,90,171,0.5);
  background: var(--button-gradient);
  transition: all 0.6s;
  border: none;
  cursor: pointer;
  color: white;
}

#theme-toggle:hover {
  transform: translateY(-3px) scale(1.1);
  box-shadow: 0 8px 25px rgba(255,90,171,0.7);
}

#theme-toggle:focus-visible {
  outline: 2px solid rgba(255, 90, 171, 0.8);
  outline-offset: 2px;
  transform: translateY(-2px) scale(1.05);
}

/* HACKER THEME - Matrix Style */
.hacker-theme {
  --bg-color: linear-gradient(180deg, #000000, #0a0a0a, #001a00);
  --glass-bg: rgba(0, 20, 0, 0.7);
  --text-color: #00ff41;
  --header-color: #00ff41;
  --accent-color: #00ff41;
  --button-gradient: linear-gradient(90deg, #003300, #00ff41);
  --success-color: #00ff41;
}

.hacker-theme body {
  background: var(--bg-color);
  color: var(--text-color);
}

.hacker-theme .card,
.hacker-theme .room-status-indicator,
.hacker-theme #nav-menu,
.hacker-theme #menu-btn,
.hacker-theme #theme-toggle {
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  border: 1px solid rgba(0, 255, 65, 0.4);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.1);
}

.hacker-theme h1,
.hacker-theme h2,
.hacker-theme h3,
.hacker-theme .room-name,
.hacker-theme .participants-count {
  color: var(--header-color);
  text-shadow: 0 0 15px rgba(0, 255, 65, 0.8), 0 0 30px rgba(0, 255, 65, 0.4);
  font-family: 'Roboto Mono', monospace;
}

.hacker-theme button {
  background: var(--button-gradient);
  color: #000;
  border: 1px solid var(--accent-color);
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.3);
  font-family: 'Roboto Mono', monospace;
  font-weight: 700;
}

.hacker-theme button:hover {
  box-shadow: 0 0 30px rgba(0, 255, 65, 0.6);
  filter: brightness(1.3);
}

.hacker-theme input,
.hacker-theme textarea {
  background: rgba(0, 20, 0, 0.6);
  border: 1px solid rgba(0, 255, 65, 0.5);
  color: var(--text-color);
  font-family: 'Roboto Mono', monospace;
}

.hacker-theme input:focus,
.hacker-theme textarea:focus {
  background: rgba(0, 30, 0, 0.8);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.4);
  outline: none;
}

.hacker-theme .message.sent {
  background: linear-gradient(135deg, #003300, #005500);
  border: 1px solid rgba(0, 255, 65, 0.3);
}

.hacker-theme .message.received {
  background: rgba(0, 20, 0, 0.8);
  border: 1px solid rgba(0, 255, 65, 0.2);
}

/* Matrix Rain Effect */
.hacker-theme::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(0, 255, 65, 0.03) 0px,
      transparent 1px,
      transparent 2px,
      rgba(0, 255, 65, 0.03) 3px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(0, 255, 65, 0.03) 0px,
      transparent 1px,
      transparent 2px,
      rgba(0, 255, 65, 0.03) 3px
    );
  z-index: 0;
  opacity: 0.3;
  pointer-events: none;
}

.hacker-theme::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.4) 100%);
  z-index: 0;
  pointer-events: none;
}

@keyframes matrix-rain {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(100vh);
  }
}

/* Game Modal Styles */
.game-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 5000;
  backdrop-filter: blur(5px);
}

.game-modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-content {
  background: var(--glass-bg);
  border-radius: 20px;
  padding: 0;
  max-width: 500px;
  width: 90%;
  max-height: 90%;
  overflow: hidden;
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.game-header h3 {
  margin: 0;
  color: var(--header-color);
}

.close-game {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-color);
  cursor: pointer;
  transition: all 0.6s;
}

.close-game:hover {
  background: rgba(255, 90, 171, 0.5);
  transform: scale(1.1);
}

.game-body {
  padding: 30px;
  text-align: center;
}

.game-status {
  font-size: 1.2rem;
  margin-bottom: 20px;
  padding: 15px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  border-left: 4px solid var(--accent-color);
}

.round-info,
.score-info {
  font-size: 1.1rem;
  margin: 15px 0;
  font-weight: 600;
}

.game-choices {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin: 25px 0;
  flex-wrap: wrap;
}

.choice-btn {
  padding: 15px 25px;
  border: 2px solid var(--accent-color);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-color);
  border-radius: 15px;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  transition: all 0.6s;
  min-width: 120px;
}

.choice-btn:hover {
  background: var(--button-gradient);
  color: #fff;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

/* Touch optimization для choice-btn */
@media (hover: none) and (pointer: coarse) {
  .choice-btn:active {
    background: var(--button-gradient);
    color: #fff;
    transform: translateY(1px) scale(0.95);
  }
}

.choice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.game-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin: 25px 0;
  flex-wrap: wrap;
}

.game-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.6s;
  min-width: 120px;
}

.game-btn.primary {
  background: var(--button-gradient);
  color: #fff;
}

.game-btn.secondary {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-color);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

/* Touch optimization для game-btn */
@media (hover: none) and (pointer: coarse) {
  .game-btn:active {
    transform: translateY(1px) scale(0.95);
  }
}

.timer {
  margin-top: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 15px;
  position: relative;
  overflow: hidden;
}

.timer-bar {
  height: 8px;
  background: linear-gradient(90deg, var(--accent-color), #ff5aab);
  border-radius: 4px;
  transition: width 1s linear;
  width: 100%;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: bold;
  color: var(--text-color);
  background: rgba(0, 0, 0, 0.7);
  padding: 5px 10px;
  border-radius: 5px;
}

/* Homepage Images */
.homepage-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin: 30px 0;
}

.homepage-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 15px;
  transition: all 0.6s;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.homepage-image:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

/* Touch optimization для изображений */
@media (hover: none) and (pointer: coarse) {
  .homepage-image:active {
    transform: scale(0.98);
    transition: transform 0.3s ease;
  }
}

/* Mobile responsive for new elements */
@media (max-width: 768px) {
  #theme-toggle {
    width: 45px;
    height: 45px;
    font-size: 1.1rem;
  }
  
  .game-content {
    width: 95%;
    margin: 20px;
  }
  
  .game-body {
    padding: 20px;
  }
  
  .game-choices {
    flex-direction: column;
    align-items: center;
  }
  
  .choice-btn {
    width: 100%;
    max-width: 200px;
  }
  
  .game-actions {
    flex-direction: column;
    align-items: center;
  }
  
  .game-btn {
    width: 100%;
    max-width: 200px;
  }
  
  .homepage-images {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
  }
  
  .homepage-image {
    height: 120px;
  }
}

@media (max-width: 480px) {
  #theme-toggle {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
  
  .homepage-images {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .homepage-image {
    height: 100px;
  }
}

/* ============ AMBIENT GLOW (свечение внизу) ============ */
body::after {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 300px;
  background: radial-gradient(ellipse at bottom, rgba(255, 90, 171, 0.3) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

/* Для хакерской темы другое свечение */
.hacker-theme body::after {
  background: radial-gradient(ellipse at bottom, rgba(0, 255, 65, 0.2) 0%, transparent 70%);
}

/* ============ SCROLL REVEAL ANIMATIONS ============ */
.scroll-reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.scroll-reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Разные задержки для последовательного появления */
.scroll-reveal:nth-child(1) { transition-delay: 0.3s; }
.scroll-reveal:nth-child(2) { transition-delay: 0.5s; }
.scroll-reveal:nth-child(3) { transition-delay: 0.3s; }
.scroll-reveal:nth-child(4) { transition-delay: 0.4s; }
.scroll-reveal:nth-child(5) { transition-delay: 0.5s; }
.scroll-reveal:nth-child(6) { transition-delay: 0.6s; }

/* Альтернативная анимация - появление слева */
.scroll-reveal-left {
  opacity: 0;
  transform: translateX(-50px);
  transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}

.scroll-reveal-left.revealed {
  opacity: 1;
  transform: translateX(0);
}

/* Альтернативная анимация - появление справа */
.scroll-reveal-right {
  opacity: 0;
  transform: translateX(50px);
  transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}

.scroll-reveal-right.revealed {
  opacity: 1;
  transform: translateX(0);
}

/* Анимация масштабирования */
.scroll-reveal-scale {
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.scroll-reveal-scale.revealed {
  opacity: 1;
  transform: scale(1);
}

/* Финальные мобильные улучшения */

/* Производительность анимаций */
@media (max-width: 768px) {
  * {
    animation-duration: 0.5s !important;
    transition-duration: 0.2s !important;
  }
  
  /* Упрощенные анимации для мобильных */
  .card, button, .choice-btn, .game-btn {
    transition: transform 0.15s ease;
  }
  
  .page {
    animation: fadeIn 0.3s ease-out;
  }
}

/* Предотвращение overscroll на мобильных */
body {
  overscroll-behavior: contain;
}

.page {
  overscroll-behavior: contain;
}

/* Улучшенный scroll для мобильных */
@media (max-width: 768px) {
  #chat-messages {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
  }
}

/* Оптимизация для landscape ориентации */
@media (max-width: 768px) and (orientation: landscape) {
  .container {
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
  }
  
  #chat-messages {
    max-height: 40vh;
  }
  
  .card {
    padding: 12px;
  }
  
  h1 {
    font-size: 1.4rem;
    margin-top: 8px;
  }
}

/* Специальные стили для очень больших экранов */
@media (min-width: 1200px) {
  .container {
    max-width: 900px;
  }
  
  .card {
    padding: 24px;
  }
}

/* Print styles */
@media print {
  .card {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
  
  button, #menu-btn, #nav-menu, footer {
    display: none !important;
  }
}

/* Анимация загрузки для PWA */
.loading {
  opacity: 0.7;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1.5s linear infinite;
}

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

/* Touch capable optimizations */
.touch-capable {
  /* Дополнительные touch оптимизации для устройств с поддержкой касаний */
}

.touch-capable button,
.touch-capable .choice-btn,
.touch-capable .game-btn {
  /* Убираем outline на мобильных для чистого вида */
}

.touch-capable button:focus:not(:focus-visible) {
  outline: none;
}

/* No touch optimizations - возвращаем hover эффекты */
.no-touch button:hover,
.no-touch .choice-btn:hover,
.no-touch .game-btn:hover {
  background: linear-gradient(90deg, #ff75c4, #a64ddb);
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
  filter: brightness(1.1);
}

.no-touch .card:hover::before {
  opacity: 1;
}

.no-touch .card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.6);
}

.no-touch a:hover {
  color: #fff;
  transform: scale(1.1);
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid var(--accent-color);
  }
  
  button {
    border: 2px solid rgba(255, 255, 255, 0.3);
  }
}

/* Focus indicators для keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Skip to main content link для accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--accent-color);
  color: white;
  padding: 8px;
  text-decoration: none;
  border-radius: 4px;
  z-index: 10000;
}

.skip-link:focus {
  top: 6px;
}

/* Call Modal Styles */
.call-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 6000;
  backdrop-filter: blur(5px);
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.call-modal.active {
  display: flex;
}

.call-content {
  background: var(--glass-bg);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.call-status {
  font-size: 1.5rem;
  margin-bottom: 20px;
  color: var(--header-color);
}

.call-timer {
  font-size: 1.2rem;
  margin-bottom: 30px;
  color: var(--text-color);
  font-family: 'Roboto Mono', monospace;
}

.call-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.call-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.call-btn.accept {
  background: #4CAF50;
}

.call-btn.decline, .call-btn.end {
  background: #f44336;
}

.call-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

@media (max-width: 480px) {
  .call-content {
    padding: 30px;
  }
  
  .call-status {
    font-size: 1.3rem;
  }
  
  .call-timer {
    font-size: 1rem;
  }
  
  .call-btn {
    width: 50px;
    height: 50px;
    font-size: 1.3rem;
  }
}
