/* ============================================
   GLOBAL STYLES
============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", system-ui, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
}

body {
  background: radial-gradient(circle at top, #0b0f1a, #000);
  color: #eaeaea;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ============================================
   INTRO SCREEN
============================================ */
#intro {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.intro-text {
  font-size: clamp(24px, 8vw, 48px);
  font-weight: 700;
  letter-spacing: 3px;
  color: #9bb6ff;
  z-index: 10;
  animation: fadeIn 1s ease forwards;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.6;
}

.orb1 {
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, #5b7cff, transparent);
  top: -50px;
  left: -50px;
  animation: float 6s ease-in-out infinite;
}

.orb2 {
  width: 150px;
  height: 150px;
  background: radial-gradient(circle, #4ecdc4, transparent);
  bottom: 10%;
  right: 10%;
  animation: float 8s ease-in-out infinite reverse;
}

.orb3 {
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, #fd79a8, transparent);
  bottom: -50px;
  right: -50px;
  animation: float 7s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#intro.fade-out {
  animation: fadeOut 1s ease forwards;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ============================================
   NAME SELECTION SCREEN
============================================ */
#name-select {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 1s ease forwards;
}

#name-select h2 {
  font-size: clamp(22px, 5vw, 32px);
  letter-spacing: 2px;
  color: #9bb6ff;
  margin-bottom: clamp(20px, 5vw, 40px);
  font-weight: 700;
}

.name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: clamp(12px, 4vw, 20px);
  width: 90%;
  max-width: 900px;
}

.name-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(155, 182, 255, 0.25);
  color: #eaeaea;
  padding: clamp(14px, 3vw, 20px);
  font-size: clamp(13px, 3vw, 16px);
  letter-spacing: 0.5px;
  cursor: pointer;
  border-radius: 10px;
  backdrop-filter: blur(8px);
  transition: all 0.3s ease;
  font-weight: 500;
}

.name-card:hover:not(.fade-away):not(.selected) {
  transform: translateY(-4px) scale(1.02);
  border-color: #9bb6ff;
  box-shadow: 0 0 15px rgba(155, 182, 255, 0.3);
}

.name-card.selected {
  transform: scale(1.05);
  box-shadow: 0 0 25px rgba(155, 182, 255, 0.6);
  border-color: #c7d4ff;
  background: rgba(155, 182, 255, 0.15);
}

.name-card.fade-away {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

/* ============================================
   PASSWORD SCREEN
============================================ */
#password-screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.8s ease forwards;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: clamp(20px, 5vw, 32px);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(155, 182, 255, 0.25);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.login-card h2 {
  font-size: clamp(20px, 4vw, 24px);
  margin-bottom: clamp(16px, 3vw, 24px);
  font-weight: 700;
  letter-spacing: 1px;
}

.login-card input {
  width: 100%;
  padding: clamp(10px, 2vw, 14px);
  margin-bottom: clamp(12px, 2vw, 16px);
  font-size: clamp(13px, 2vw, 15px);
  border: 1px solid rgba(155, 182, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #eaeaea;
  border-radius: 8px;
  outline: none;
  transition: border 0.2s;
}

.login-card input:focus {
  border-color: rgba(155, 182, 255, 0.5);
}

.login-card button {
  width: 100%;
  padding: clamp(11px, 2vw, 14px);
  font-size: clamp(13px, 2vw, 15px);
  font-weight: 600;
  background: linear-gradient(135deg, #5b7cff, #7ba3ff);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.login-card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(91, 124, 255, 0.3);
}

.login-card button:active {
  transform: translateY(0);
}

#passwordError {
  font-size: clamp(11px, 2vw, 13px);
  color: #ff6b6b;
  margin-top: clamp(10px, 2vw, 12px);
  min-height: 14px;
}

/* ============================================
   LOBBY LAYOUT
============================================ */
#lobby {
  width: 100%;
  height: 100dvh;
  display: flex;
  overflow: hidden;
}

.lobby-container {
  display: grid;
  grid-template-columns: 220px 1fr;
  width: 100%;
  height: 100%;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, rgba(25, 35, 60, 0.6), rgba(15, 20, 40, 0.5));
  border-right: 1px solid rgba(155, 182, 255, 0.1);
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar h3 {
  font-size: 11px;
  color: #7ba3ff;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
  margin-bottom: 10px;
}

.sidebar ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar li {
  padding: 8px 10px;
  font-size: 12px;
  background: rgba(155, 182, 255, 0.06);
  border: 1px solid rgba(155, 182, 255, 0.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #c0c7d4;
  transition: all 0.2s;
}

.sidebar li:hover {
  background: rgba(155, 182, 255, 0.12);
  border-color: rgba(155, 182, 255, 0.25);
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Chat Area */
.chat {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 68px 18px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(155, 182, 255, 0.3);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(155, 182, 255, 0.5);
}

/* Message User Header */
.message-user {
  font-size: 11px;
  font-weight: 700;
  margin-top: 12px;
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}

/* Message Bubble */
.message-bubble {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 2px;
  max-width: 86%;
  word-wrap: break-word;
  border: 1px solid;
  backdrop-filter: blur(4px);
}

.message-bubble.message-other {
  align-self: flex-start;
  border-radius: 10px 10px 10px 2px;
}

.message-bubble.message-own {
  align-self: flex-end;
  border-radius: 10px 10px 2px 10px;
  margin-left: auto;
}

.message-text {
  font-size: 13px;
  line-height: 1.4;
  flex: 1;
}

.message-time {
  font-size: 10px;
  opacity: 0.6;
  white-space: nowrap;
  flex-shrink: 0;
}

/* System Message */
.system {
  text-align: center;
  opacity: 0.55;
  font-size: 12px;
  padding: 6px 0;
  margin: 8px 0;
  color: #7ba3ff;
  font-style: italic;
  animation: fadeIn 0.3s ease;
}

/* Typing Container */
.typing-container {
  padding: 8px 16px;
  min-height: 24px;
  border-top: 1px solid rgba(155, 182, 255, 0.1);
  background: rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.typing-indicator {
  font-size: 12px;
  color: #7ba3ff;
  font-style: italic;
  display: none;
}

.typing-indicator.active {
  display: block;
}

/* Input Area */
.input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(12, 16, 30, 0.95);
  border-top: 1px solid rgba(155, 182, 255, 0.12);
  flex-shrink: 0;
  align-items: center;
  z-index: 20;
}

.emoji-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: rgba(155, 182, 255, 0.08);
  border: 1px solid rgba(155, 182, 255, 0.2);
  border-radius: 7px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all 0.15s;
}

.emoji-btn:hover {
  background: rgba(155, 182, 255, 0.15);
}

.emoji-btn:active {
  background: rgba(155, 182, 255, 0.25);
  transform: scale(0.92);
}

#messageInput {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(155, 182, 255, 0.18);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  color: #eaeaea;
  font-size: 13px;
  outline: none;
  transition: border 0.2s;
  font-family: inherit;
}

#messageInput:focus {
  border-color: rgba(155, 182, 255, 0.4);
}

#messageInput::placeholder {
  color: rgba(200, 210, 220, 0.35);
}

#sendBtn {
  flex-shrink: 0;
  padding: 10px 16px;
  background: linear-gradient(135deg, #5b7cff, #7ba3ff);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

#sendBtn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(91, 124, 255, 0.3);
}

#sendBtn:active {
  transform: translateY(0);
}

/* Emoji Picker */
.emoji-picker {
  position: absolute;
  bottom: 56px;
  left: 12px;
  right: 12px;
  background: rgba(8, 12, 22, 0.98);
  border: 1px solid rgba(155, 182, 255, 0.2);
  border-radius: 9px;
  padding: 10px;
  max-height: 200px;
  z-index: 1000;
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
  animation: popIn 0.2s ease;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.emoji-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: rgba(155, 182, 255, 0.08);
  border: 1px solid rgba(155, 182, 255, 0.15);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s;
}

.emoji-item:hover {
  background: rgba(155, 182, 255, 0.2);
  transform: scale(1.1);
}

.emoji-item:active {
  transform: scale(0.95);
}

/* New Messages Indicator */
.new-messages-indicator {
  position: absolute;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: #5b7cff;
  color: #fff;
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
}

.new-messages-indicator.show {
  display: block;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================
   MOBILE RESPONSIVE
============================================ */
@media (max-width: 600px) {
  body {
    overflow: hidden;
    font-size: 14px;
  }

  .lobby-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100dvh;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid rgba(155, 182, 255, 0.08);
    padding: 8px 10px;
    max-height: 48px;
    flex-direction: row;
  }

  .sidebar h3 {
    font-size: 9px;
    margin-bottom: 0;
    margin-right: 8px;
  }

  .sidebar ul {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sidebar li {
    padding: 4px 8px;
    font-size: 10px;
    border-radius: 4px;
  }

  .messages {
    padding: 10px 8px 66px 8px;
  }

  .message-bubble {
    padding: 6px 10px;
    gap: 4px;
    max-width: 88%;
  }

  .message-text {
    font-size: 12px;
  }

  .message-time {
    font-size: 9px;
  }

  .system {
    font-size: 11px;
  }

  .typing-container {
    padding: 6px 10px;
    min-height: 22px;
  }

  .typing-indicator {
    font-size: 10px;
  }

  .input-area {
    gap: 6px;
    padding: 8px;
    min-height: 54px;
  }

  .emoji-btn {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }

  #messageInput {
    padding: 8px 10px;
    font-size: 12px;
  }

  #sendBtn {
    padding: 8px 12px;
    font-size: 11px;
  }

  .emoji-picker {
    bottom: 54px;
    left: 8px;
    right: 8px;
    max-height: 160px;
  }

  .emoji-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    max-height: 140px;
  }

  .emoji-item {
    font-size: 14px;
  }

  .new-messages-indicator {
    bottom: 63px;
    padding: 6px 12px;
    font-size: 11px;
  }

  .name-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .name-card {
    padding: 12px;
    font-size: 12px;
  }

  .login-card {
    max-width: 90%;
    padding: 20px;
  }

  .login-card input,
  .login-card button {
    font-size: 14px;
    padding: 10px 12px;
  }
}
