/* ============================================================
   CSS Variables & Reset
   ============================================================ */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --accent: #ec4899;
  --accent-hover: #db2777;
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* Utility classes */
.hidden {
  display: none !important;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ============================================================
   Screen Management
   ============================================================ */
.screen {
  display: none;
  width: 100%;
  height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.btn-accent {
  background: var(--accent);
  color: white;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-input);
  color: var(--text);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
}

.btn-lg {
  padding: 16px 40px;
  font-size: 18px;
  border-radius: var(--radius);
}

/* ============================================================
   Home Screen
   ============================================================ */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 20px;
  height: 100vh;
  text-align: center;
}

.home-logo {
  text-align: center;
  margin-bottom: 60px;
}

.home-logo .logo-emoji {
  font-size: 96px;
  display: block;
  margin-bottom: 20px;
  animation: wave 2s ease-in-out infinite;
}

.home-title {
  font-size: 64px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 16px;
}

.home-tagline {
  color: var(--text-secondary);
  font-size: 20px;
  margin-top: 8px;
}

.home-btn {
  padding: 20px 60px;
  font-size: 24px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.home-btn:hover:not(:disabled) {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 15px 30px -5px rgba(0, 0, 0, 0.5);
}

/* ============================================================
   Home Header
   ============================================================ */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

/* ============================================================
   Profile Panel
   ============================================================ */
.profile-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  border-left: 1px solid var(--border);
}

.profile-panel.show {
  transform: translateX(0);
}

.profile-panel-content {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.profile-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.profile-body {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

.avatar-section {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
}

.avatar-large {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.avatar-info h4 {
  font-size: 18px;
  margin-bottom: 4px;
}

.avatar-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.profile-section {
  margin-bottom: 32px;
}

.profile-section h4 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.profile-actions {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Auth Screen
   ============================================================ */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 20px;
}

.logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-emoji {
  font-size: 64px;
  display: block;
  margin-bottom: 12px;
  animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(20deg); }
  75% { transform: rotate(-15deg); }
}

.logo h1 {
  font-size: 42px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 16px;
  margin-top: 8px;
}

.auth-form {
  display: none;
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.auth-form.active {
  display: block;
}

.auth-form h2 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  transition: var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.auth-form .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.auth-switch {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.error-msg {
  color: var(--error);
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  min-height: 20px;
}

/* ============================================================
   Lobby Screen
   ============================================================ */
.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
}

.logo-small {
  font-size: 18px;
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: 20px;
}

.online-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

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

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
}

.lobby-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-content {
  text-align: center;
  max-width: 500px;
  width: 100%;
}

.match-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 32px;
  box-shadow: var(--shadow-lg);
}

.match-card h2 {
  font-size: 24px;
  margin-bottom: 12px;
}

.match-card p {
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.6;
}

.match-illustration {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 32px;
}

.match-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px auto;
  font-size: 40px;
  font-weight: 800;
  color: white;
  box-shadow: 0 0 40px rgba(99, 102, 241, 0.3);
}

.floating-emoji {
  position: absolute;
  font-size: 24px;
  animation: float 3s ease-in-out infinite;
  animation-delay: var(--delay);
  left: calc(50% + var(--x));
  top: calc(50% + var(--y));
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* Matching State */
.matching-state {
  padding: 48px 32px;
}

.matching-state.hidden {
  display: none;
}

.matching-state h3 {
  font-size: 22px;
  margin: 24px 0 8px;
}

.matching-state p {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 1s linear infinite;
}

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

/* ============================================================
   Chat Screen
   ============================================================ */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-partner-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.typing-indicator {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}

.typing-indicator.hidden {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-welcome {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.chat-welcome p {
  background: var(--bg-card);
  display: inline-block;
  padding: 10px 20px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 75%;
  animation: messageIn 0.3s ease;
}

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

.message.sent {
  align-self: flex-end;
}

.message.received {
  align-self: flex-start;
}

.message .bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.message.sent .bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .bubble {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message.sent .meta {
  text-align: right;
}

.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px;
}

.system-message span {
  background: var(--bg-input);
  padding: 6px 16px;
  border-radius: 20px;
}

/* Chat Input */
.chat-input-area {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-wrapper input {
  flex: 1;
  padding: 14px 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: var(--transition);
}

.input-wrapper input:focus {
  border-color: var(--primary);
}

.input-wrapper input::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  padding: 0;
  flex-shrink: 0;
}

/* ============================================================
   Toast Notification
   ============================================================ */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 14px 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  font-size: 14px;
  z-index: 1000;
  transition: transform 0.3s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.hidden {
  display: block;
  transform: translateX(-50%) translateY(100px);
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 640px) {
  .lobby-header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .header-right {
    gap: 8px;
  }

  .match-card {
    padding: 32px 20px;
  }

  .btn-lg {
    padding: 14px 28px;
    font-size: 16px;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .message {
    max-width: 85%;
  }
}

/* ============================================================
   User Profile Dropdown
   ============================================================ */
.user-profile-container {
  position: relative;
  display: inline-block;
}

.user-info.clickable {
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
}

.user-info.clickable:hover {
  background: var(--bg-input);
}

.dropdown-arrow {
  font-size: 10px;
  margin-left: 4px;
  color: var(--text-secondary);
  transition: transform 0.2s ease;
}

.user-info.clickable.active .dropdown-arrow {
  transform: rotate(180deg);
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  overflow: hidden;
}

.profile-dropdown.hidden {
  display: none;
}

.dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.avatar-medium {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.dropdown-user-info h4 {
  font-size: 16px;
  margin-bottom: 4px;
  color: var(--text);
}

.dropdown-user-info p {
  font-size: 14px;
  color: var(--text-secondary);
}

.dropdown-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.dropdown-section:last-child {
  border-bottom: none;
}

.dropdown-section h5 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-option {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-option:hover {
  transform: scale(1.1);
}

.color-option.selected {
  border-color: var(--text);
  transform: scale(1.1);
}

.nickname-edit {
  display: flex;
  gap: 8px;
}

.gender-select {
  margin-bottom: 8px;
}

.gender-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

#dropdown-nickname-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

#dropdown-gender-select {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

#dropdown-gender-select:focus {
  border-color: var(--primary);
}

#dropdown-nickname-input:focus {
  border-color: var(--primary);
}

.dropdown-actions {
  padding: 12px 16px;
  display: flex;
  justify-content: flex-end;
  background: var(--bg-secondary);
}

@media (max-width: 640px) {
  .profile-dropdown {
    width: 260px;
    right: -10px;
  }
}
