:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --text-primary: #ffffff;
  --text-secondary: #8e8e93;
  --accent: #0a84ff;
  --accent-hover: #0066cc;
  --bubble-me: linear-gradient(135deg, #0a84ff 0%, #0066cc 100%);
  --bubble-peer: #2c2c2e;
  --bubble-text-me: #ffffff;
  --bubble-text-peer: #ffffff;
  --border: #2c2c2e;
  --shadow: rgba(0, 0, 0, 0.3);
  --glow: rgba(10, 132, 255, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#warning {
  background: #dc3545;
  color: white;
  padding: 12px;
  text-align: center;
  display: none;
}

#header {
  background: linear-gradient(135deg, #0a84ff 0%, #0066cc 100%);
  color: white;
  padding: 16px 20px;
  padding-top: calc(16px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 4px 20px var(--glow);
  backdrop-filter: blur(20px);
  position: relative;
}

#header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

#header h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.8px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#status {
  font-size: 12px;
  font-weight: 600;
  background: rgba(255,255,255,0.25);
  padding: 6px 14px;
  border-radius: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  letter-spacing: 0.3px;
}

#call-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: rgba(255,255,255,0.25);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

#call-btn:hover {
  background: rgba(255,255,255,0.35);
  transform: scale(1.05);
}

#call-btn:active {
  transform: scale(0.95);
}

#call-btn.calling {
  background: linear-gradient(135deg, #ff3b30 0%, #ff1744 100%);
  animation: pulse 1.5s infinite;
  box-shadow: 0 4px 16px rgba(255,59,48,0.4);
}

#call-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#call-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.95);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  flex-direction: column;
  gap: 40px;
}

#call-overlay.show {
  display: flex;
}

.call-info {
  text-align: center;
  color: white;
}

.call-status {
  font-size: 18px;
  margin-bottom: 8px;
  opacity: 0.8;
}

.call-duration {
  font-size: 48px;
  font-weight: 300;
  letter-spacing: 2px;
}

.call-controls {
  display: flex;
  gap: 24px;
}

.call-control-btn {
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

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

.call-control-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
}

.call-control-btn.mute {
  background: rgba(255,255,255,0.2);
}

.call-control-btn.mute.active {
  background: #ff3b30;
}

.call-control-btn.hangup {
  background: #ff3b30;
}

.incoming-call {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6), 0 0 0 1px var(--border);
  z-index: 1500;
  display: none;
  flex-direction: column;
  gap: 18px;
  min-width: 300px;
  animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(20px);
}

.incoming-call.show {
  display: flex;
}

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

.incoming-call-text {
  text-align: center;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.incoming-call-actions {
  display: flex;
  gap: 12px;
}

.incoming-call-actions button {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.3px;
}

.incoming-call-actions button:hover {
  transform: translateY(-2px);
}

.incoming-call-actions button:active {
  transform: translateY(0);
}

.accept-call {
  background: linear-gradient(135deg, #34c759 0%, #30d158 100%);
  color: white;
  box-shadow: 0 4px 16px rgba(52, 199, 89, 0.4);
}

.accept-call:hover {
  box-shadow: 0 6px 24px rgba(52, 199, 89, 0.5);
}

.reject-call {
  background: linear-gradient(135deg, #ff3b30 0%, #ff1744 100%);
  color: white;
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.4);
}

.reject-call:hover {
  box-shadow: 0 6px 24px rgba(255, 59, 48, 0.5);
}

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

#chat-container::-webkit-scrollbar {
  width: 6px;
}

#chat-container::-webkit-scrollbar-track {
  background: transparent;
}

#chat-container::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 3px;
}

#chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

.message-bubble {
  max-width: 75%;
  padding: 14px 18px;
  border-radius: 22px;
  word-wrap: break-word;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 15px;
  line-height: 1.5;
  box-shadow: 0 2px 12px var(--shadow);
  position: relative;
  animation: messageSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.message-bubble.me {
  align-self: flex-end;
  background: var(--bubble-me);
  color: var(--bubble-text-me);
  border-bottom-right-radius: 6px;
  box-shadow: 0 4px 16px var(--glow);
}

.message-bubble.me::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 22px;
  border-bottom-right-radius: 6px;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 100%);
  pointer-events: none;
}

.message-bubble.peer {
  align-self: flex-start;
  background: var(--bubble-peer);
  color: var(--bubble-text-peer);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border);
}

.message-bubble img {
  max-width: 100%;
  border-radius: 14px;
  margin-top: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.file-card {
  background: rgba(255,255,255,0.1);
  padding: 12px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-icon {
  width: 32px;
  height: 32px;
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.download-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.1s;
}

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

#input-bar {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  backdrop-filter: blur(20px);
  box-shadow: 0 -2px 20px rgba(0,0,0,0.2);
}

#message-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: inherit;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#message-input:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
  box-shadow: 0 0 0 3px var(--glow);
}

#message-input::placeholder {
  color: var(--text-secondary);
}

.icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: none;
  background: var(--bg-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.icon-btn:hover {
  background: var(--border);
  transform: scale(1.05);
}

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

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: var(--accent);
  transition: fill 0.2s;
}

.icon-btn:hover svg {
  fill: var(--accent-hover);
}

#send-btn {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  height: 40px;
  border-radius: 20px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
  white-space: nowrap;
  box-shadow: 0 4px 12px var(--glow);
  letter-spacing: 0.3px;
}

#send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--glow);
}

#send-btn:active {
  transform: translateY(0);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: 20px;
  padding: 28px;
  max-width: 500px;
  width: calc(100% - 32px);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  animation: modalSlide 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlide {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.modal-body textarea {
  width: 100%;
  min-height: 200px;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: 14px;
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
  font-size: 11px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  resize: vertical;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  line-height: 1.6;
}

.modal-body textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 15px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.3px;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  box-shadow: 0 4px 16px var(--glow);
}

.btn-primary:hover {
  box-shadow: 0 6px 24px var(--glow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

#connection-panel {
  padding: 32px 20px;
  text-align: center;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: radial-gradient(circle at center, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

#connection-panel h2 {
  font-size: 28px;
  margin-bottom: 32px;
  color: var(--text-primary);
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #ffffff 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.connection-mode {
  display: flex;
  gap: 8px;
  max-width: 420px;
  margin: 0 auto 32px;
  background: var(--bg-tertiary);
  padding: 6px;
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 20px var(--shadow);
}

.mode-btn {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
  letter-spacing: 0.3px;
}

.mode-btn:hover {
  color: var(--text-primary);
}

.mode-btn.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  box-shadow: 0 4px 16px var(--glow);
  transform: scale(1.02);
}

.connection-btns {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 420px;
  margin: 0 auto;
  padding: 0 4px;
}

.connection-btns button {
  padding: 18px 24px;
  border: none;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: white;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px var(--glow);
  letter-spacing: 0.3px;
  position: relative;
  overflow: hidden;
}

.connection-btns button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.connection-btns button:hover::before {
  left: 100%;
}

.connection-btns button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--glow);
}

.connection-btns button:active {
  transform: translateY(0);
}

.room-input-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.room-input-group input {
  width: 100%;
  padding: 20px;
  border: 2px solid var(--border);
  border-radius: 16px;
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 8px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px var(--shadow);
}

.room-input-group input:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
  box-shadow: 0 0 0 4px var(--glow), 0 4px 20px var(--shadow);
  transform: scale(1.02);
}

.room-input-group input::placeholder {
  font-size: 14px;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--text-secondary);
}

.room-input-group button {
  width: 100%;
}

.divider {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  margin: 4px 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

#room-info {
  margin-top: 24px;
  padding: 28px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  border: 2px solid var(--accent);
  box-shadow: 0 8px 32px var(--glow);
  position: relative;
  overflow: hidden;
}

#room-info::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

#room-info > div:first-child {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

#my-room-code {
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, #00d4ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 12px 0;
  text-shadow: 0 4px 20px var(--glow);
  animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}

#room-info > div:last-child {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 16px;
  line-height: 1.6;
  font-weight: 500;
}

input[type="file"] {
  display: none;
}

/* 移动端优化 */
@media (max-width: 767px) {
  .message-bubble {
    max-width: 85%;
    font-size: 15px;
    padding: 12px 16px;
  }
  
  #connection-panel {
    padding: 24px 16px;
  }
  
  #connection-panel h2 {
    font-size: 24px;
    margin-bottom: 24px;
  }
  
  .mode-btn {
    font-size: 13px;
    padding: 10px 12px;
  }
  
  #my-room-code {
    font-size: 40px;
    letter-spacing: 8px;
  }
  
  #input-bar {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 8px;
  }
  
  .icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }
  
  .icon-btn svg {
    width: 20px;
    height: 20px;
  }
  
  #send-btn {
    padding: 10px 14px;
    height: 36px;
    font-size: 13px;
  }
  
  #message-input {
    padding: 10px 14px;
    font-size: 15px;
  }
  
  .modal-content {
    padding: 20px;
  }
  
  .incoming-call {
    min-width: 260px;
    padding: 20px;
  }
}

/* 桌面端优化 */
@media (min-width: 768px) {
  #app {
    flex-direction: row;
  }
  
  #chat-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px;
  }
  
  #connection-panel {
    padding: 48px 32px;
  }
  
  .message-bubble {
    max-width: 65%;
  }
  
  #input-bar {
    padding: 16px 20px;
  }
  
  .modal-content {
    max-width: 600px;
  }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
  #header h1 {
    font-size: 18px;
  }
  
  #status {
    font-size: 11px;
    padding: 5px 10px;
  }
  
  #connection-panel h2 {
    font-size: 22px;
  }
  
  .room-input-group input {
    font-size: 22px;
    letter-spacing: 6px;
    padding: 16px;
  }
  
  #my-room-code {
    font-size: 36px;
    letter-spacing: 6px;
  }
  
  .connection-btns button {
    padding: 16px 20px;
    font-size: 15px;
  }
}

/* 大屏幕优化 */
@media (min-width: 1200px) {
  #chat-container {
    max-width: 1000px;
  }
  
  .message-bubble {
    max-width: 60%;
  }
}