/* ===========================
   DESIGN TOKENS
   =========================== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(255, 255, 255, 0.15);
  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;
  --accent-primary: #7c5cfc;
  --accent-secondary: #5c9cfc;
  --accent-gradient: linear-gradient(135deg, #7c5cfc, #5c9cfc);
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-color: 800ms cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(124, 92, 252, 0.15);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  overflow-x: hidden;
  line-height: 1.5;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

.screen {
  display: none;
  min-height: 100dvh;
}

.screen.active {
  display: flex;
}

/* LOBBY */
.lobby-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 2rem;
  gap: 4rem;
}

.logo-area {
  text-align: center;
}

.logo-icon {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  width: 56px;
  height: 56px;
  margin: 0 auto 1.5rem;
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

.dot {
  border-radius: 50%;
  animation: dotPulse 2s ease-in-out infinite;
}

.dot-1 {
  background: #E74C3C;
  animation-delay: 0s;
}

.dot-2 {
  background: #3498DB;
  animation-delay: 0.5s;
}

.dot-3 {
  background: #2ECC71;
  animation-delay: 1s;
}

.dot-4 {
  background: #F1C40F;
  animation-delay: 1.5s;
}

@keyframes dotPulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(0.85);
    opacity: 0.7;
  }
}

.logo-area h1 {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-top: 0.25rem;
}

.lobby-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 60px rgba(124, 92, 252, 0.25);
}

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

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 14px 20px;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.join-group {
  display: flex;
  gap: 0.5rem;
}

.input-code {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  transition: border-color var(--transition-fast);
}

.input-code::placeholder {
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-muted);
  font-weight: 400;
}

.input-code:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.15);
}

/* ROOM */
.room-container {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.room-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.btn-icon.small {
  width: 28px;
  height: 28px;
}

.room-id-display {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.room-id-display .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.room-id-display .code {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-secondary);
  letter-spacing: 0.1em;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.status-badge.connected {
  background: rgba(46, 204, 113, 0.1);
  color: var(--success);
}

.status-badge.connected .status-dot {
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

.status-badge.waiting {
  background: rgba(243, 156, 18, 0.1);
  color: var(--warning);
}

.status-badge.waiting .status-dot {
  background: var(--warning);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-badge.disconnected {
  background: rgba(231, 76, 60, 0.1);
  color: var(--danger);
}

.status-badge.disconnected .status-dot {
  background: var(--danger);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

.room-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  gap: 2rem;
}

.partner-area {
  flex: 1;
  display: flex;
  min-height: 0;
}

.color-display {
  width: 100%;
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-color);
  min-height: 140px;
}

.color-display.has-color {
  border-color: transparent;
}

.color-label {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  opacity: 0;
  transition: opacity var(--transition-normal);
  pointer-events: none;
  white-space: nowrap;
}

.color-display.has-color .color-label {
  opacity: 1;
}

.waiting-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  z-index: 2;
  transition: opacity var(--transition-normal);
}

.waiting-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.waiting-overlay p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
}

.share-hint {
  font-size: 0.8rem !important;
  color: var(--text-muted) !important;
  font-weight: 400 !important;
}

.pulse-ring {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--accent-primary);
  animation: pulseRing 2s ease-in-out infinite;
}

@keyframes pulseRing {
  0% {
    transform: scale(0.8);
    opacity: 0.5;
  }

  50% {
    transform: scale(1.1);
    opacity: 1;
  }

  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
}

.your-colors {
  padding-bottom: env(safe-area-inset-bottom, 1rem);
}

.section-label {
  text-align: center;
  color: #6f44ff;
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.section-label .char {
  display: inline-block;
  white-space: pre;
}

@keyframes colorShift {
  0% { color: #ffffff; opacity: 0; }
  33% { color: #ff0055; opacity: 1; }
  66% { color: #00ccff; opacity: 1; }
  100% { color: #ffffff; opacity: 1; }
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.color-btn {
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  background: var(--btn-color);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border: 2px solid transparent;
}

.color-btn:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 24px var(--btn-glow), 0 0 0 2px var(--btn-color);
}

.color-btn:active {
  transform: translateY(0) scale(0.95);
  transition-duration: 80ms;
}

.color-btn.pressed {
  animation: btnPress 400ms ease-out;
}

@keyframes btnPress {
  0% {
    transform: scale(0.9);
  }

  40% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}

.color-btn .ripple {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.4) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
}

.color-btn:active .ripple {
  opacity: 1;
}

.color-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
  filter: grayscale(0.5);
}

.color-display .flash-circle {
  position: absolute;
  width: 0;
  height: 0;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: flashExpand 600ms ease-out forwards;
  z-index: 1;
}

@keyframes flashExpand {
  0% {
    width: 0;
    height: 0;
    opacity: 0.8;
  }

  100% {
    width: 200%;
    height: 200%;
    opacity: 0;
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  opacity: 0;
  transition: all var(--transition-normal);
  pointer-events: none;
  white-space: nowrap;
}

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

/* CHAT AREA */
.chat-area {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-md);
  margin-top: auto;
}

.chat-messages {
  height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-accent);
  border-radius: 4px;
}

.chat-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
  animation: bubblePop 200ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  transform: scale(0.9);
  opacity: 0;
  transform-origin: bottom;
}

@keyframes bubblePop {
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.chat-bubble.me {
  align-self: flex-end;
  background: var(--accent-primary);
  color: white;
  border-bottom-right-radius: 4px;
  transform-origin: bottom right;
}

.chat-bubble.partner {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  transform-origin: bottom left;
}

.chat-form {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
  padding: 4px 4px 4px 16px;
  border: 1px solid var(--border-subtle);
}

.chat-form input {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-primary);
}

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

.chat-form button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.chat-form input:disabled,
.chat-form button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

@media (max-width: 420px) {
  .logo-area h1 {
    font-size: 2rem;
  }

  .room-header {
    padding: 0.5rem 1rem;
  }

  .room-main {
    padding: 1rem;
  }

  .color-grid {
    gap: 0.5rem;
  }

  .color-display {
    min-height: 110px;
  }
}

@media (min-height: 700px) {
  .color-display {
    min-height: 160px;
  }
}

@media (min-height: 900px) {
  .color-display {
    min-height: 200px;
  }
}

body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 20%, rgba(124, 92, 252, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(92, 156, 252, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}