:root {
  --surface-color: #ffffff;
  --text-color: #1e293b;
  --accent-color: var(--accent);
  --contrast-color: var(--accent-contrast);
}

body.dark-mode {
  --surface-color: #1a1a22;
  --text-color: #e2e8f0;
  --accent-color: var(--accent);
  --contrast-color: var(--accent-contrast);
}

body {
  background: linear-gradient(180deg, #f2f2f7 0%, #e5e5ea 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overscroll-behavior-x: none;
}

body.dark-mode {
  background: linear-gradient(180deg, #0d0d0f 0%, #1a1a1e 100%);
}

#main {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 580px;
  height: 100vh;
  background: rgba(255,255,255,0.68);
  backdrop-filter: blur(60px) saturate(1.8);
  -webkit-backdrop-filter: blur(60px) saturate(1.8);
  box-shadow:
    0 0 0 0.5px rgba(0,0,0,0.03),
    0 0 0 1px rgba(255,255,255,0.5) inset,
    0 8px 40px rgba(0,0,0,0.08),
    0 2px 8px rgba(0,0,0,0.04),
    0 16px 60px rgba(0,0,0,0.04);
  overflow: hidden;
  position: relative;
  animation: matchBurst 0.6s cubic-bezier(0.34,1.56,0.64,1);
}

#main::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.8), transparent);
  z-index: 10;
}

body.dark-mode #main {
  background: rgba(22,22,28,0.72);
  backdrop-filter: blur(60px) saturate(1.8);
  -webkit-backdrop-filter: blur(60px) saturate(1.8);
  box-shadow:
    0 0 0 0.5px rgba(255,255,255,0.04),
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 8px 40px rgba(0,0,0,0.3),
    0 2px 8px rgba(0,0,0,0.15),
    0 16px 60px rgba(0,0,0,0.15);
}

body.dark-mode #main::before {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

/* ============================================================
   MESSAGE AREA
   ============================================================ */
#message-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

body.dark-mode #message-area {
  background: rgba(18,18,22,0.6);
}

#messages {
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
  gap: 8px;
}

/* ============================================================
   MESSAGE BUBBLE — CAPSULE WITH ACCENT TOP BAND
   ============================================================ */
.message {
  position: relative;

  min-width: 0;
  max-width: 70%;
  padding: 18px 32px;

  border-radius: 25px / 50px;

  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
  margin-bottom: 8px;

  font-size: var(--msg-font-size, 1rem);

  transition:
    background-color .2s ease,
    border-color .2s ease,
    box-shadow .2s ease;

  animation-fill-mode: forwards;
}

/* Top band */
.message::before {
  content: "";

  position: absolute;

  top: 0;
  left: 0;
  right: 0;

  height: 14px;

  border-radius: 22px 22px 0 0;

  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════
   YOU — white capsule, accent top band + border
   ═══════════════════════════════════════════════════════════ */
.message.you {
  align-self: flex-end;
  margin-left: auto;

  background: white;
  color: #000;
  border: 3px solid var(--accent);

  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.2),
    0 2px 8px rgba(0,0,0,0.15);

  animation: slideInRight 0.35s cubic-bezier(0.16,1,0.3,1) forwards;
}
.message.you::before {
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--accent) 30%, white) 0%,
    var(--accent) 100%
  );
}

/* ═══════════════════════════════════════════════════════════
   STRANGER — white capsule, #c25762 top band + border
   ═══════════════════════════════════════════════════════════ */
.message.strange {
  align-self: flex-start;
  margin-right: auto;

  background: white;
  color: #000;
  border: 3px solid #c25762;

  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.2),
    0 2px 8px rgba(0,0,0,0.15);

  animation: slideInLeft 0.35s cubic-bezier(0.16,1,0.3,1) forwards;
}
.message.strange::before {
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, #c25762 30%, white) 0%,
    #c25762 100%
  );
}

.message-status {
  color: #000;
}
body.dark-mode .message-status {
  color: #ccc;
}

.message img {
  max-width: 100%;
  border-radius: 12px;
  display: block;
}

/* Timestamp — inside bubble at bottom-right */
.message .msg-ts {
  position: absolute;
  bottom: 6px;
  right: 14px;
  font-size: 0.55rem;
  opacity: 0.4;
  line-height: 1;
  letter-spacing: 0.02em;
  color: inherit;
  pointer-events: none;
}

/* ============================================================
   MESSAGE REACTIONS
   ============================================================ */
.message .reaction-bar {
  position: absolute;
  bottom: -48px;
  z-index: 10;
  display: none;
  gap: 6px;
  padding: 6px 10px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  white-space: nowrap;
  animation: popIn 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.message .reaction-bar span {
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.15s;
}
.message .reaction-bar span:hover {
  transform: scale(1.3);
}

body.dark-mode .message .reaction-bar {
  background: rgba(50,50,55,0.95) !important;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3) !important;
}

/* Reaction badges */
[class*="reaction-badge-"] {
  font-size: 1.1rem;
  background: #fff;
  border-radius: 10px;
  padding: 0 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  line-height: 1.4;
  position: absolute;
  bottom: -10px;
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 5;
}
.reaction-badge-self { right: -4px; }
.reaction-badge-stranger { left: -4px; }

body.dark-mode [class*="reaction-badge-"] {
  background: rgba(50,50,55,0.95) !important;
}

/* Reaction burst confetti */
.reaction-burst {
  position: absolute;
  pointer-events: none;
  z-index: 20;
}
.reaction-burst-particle {
  position: absolute;
  font-size: 0.8rem;
  animation: burstFly 0.8s ease-out forwards;
}
@keyframes burstFly {
  0% { opacity: 1; transform: translate(0, 0) scale(0); }
  40% { opacity: 1; transform: translate(var(--bx), var(--by)) scale(1.2); }
  100% { opacity: 0; transform: translate(var(--bx), calc(var(--by) - 20px)) scale(0.6); }
}

/* ============================================================
   TYPING INDICATOR — Enhanced Bouncing Dots
   ============================================================ */
#typing {
  font-size: 13px;
  color: #8e8e93;
  font-style: italic;
  padding: 2px 18px;
  display: flex;
  align-items: center;
  gap: 4px;
  animation: fadeUp 0.3s ease forwards;
}

#typing .dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
}

#typing .dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8e8e93;
  animation: typingDot 1.4s infinite;
}
#typing .dots span:nth-child(1) { animation-delay: 0s; }
#typing .dots span:nth-child(2) { animation-delay: 0.2s; }
#typing .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============================================================
   ONLINE BAR
   ============================================================ */
#online-bar {
  text-align: center;
  font-size: 0.7rem;
  padding: 5px 0;
  border-bottom: 0.5px solid rgba(60,60,67,0.06);
  color: #8e8e93;
}

body.dark-mode #online-bar {
  color: var(--accent);
  border-bottom-color: rgba(255,255,255,0.04);
}

body.dark-mode #live-count {
  background: var(--accent-light);
  color: var(--accent);
}

/* ============================================================
   TOP BAR
   ============================================================ */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 18px;
  min-height: 50px;
  box-sizing: border-box;
  border-bottom: 0.5px solid rgba(60,60,67,0.06);
}

body.dark-mode #top-bar {
  border-bottom-color: rgba(255,255,255,0.04);
}

#logo {
  display: flex;
  align-items: center;
  height: 30px;
}

#logo img {
  height: 100%;
  width: auto;
}

#top-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#darkModeToggle {
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  opacity: 0.65;
  transition: opacity 0.2s;
}

#darkModeToggle:hover { opacity: 1; }

body.dark-mode #darkModeToggle { color: #ffd700; }

/* ============================================================
   INPUT AREA — Glowing Focus Ring
   ============================================================ */
#input-area {
  display: flex;
  gap: 6px;
  padding: 10px 14px 14px;
  align-items: center;
  border-top: 0.5px solid rgba(60,60,67,0.06);
  background: transparent;
  position: relative;
  overflow: visible;
}

body.dark-mode #input-area {
  border-top-color: rgba(255,255,255,0.04);
}

#message-input {
  flex: 1;
  height: 40px;
  padding: 0 18px;
  border: 0.5px solid rgba(60,60,67,0.1);
  border-radius: 20px;
  font-size: 15px;
  outline: none;
  background: rgba(120,120,128,0.08);
  transition: border-color 0.2s, background 0.2s, box-shadow 0.3s;
  box-sizing: border-box;
}

#message-input:focus {
  border-color: var(--accent);
  background: rgba(255,255,255,0.5);
  box-shadow: 0 0 0 3px var(--accent-light), 0 0 24px var(--accent-light);
}

body.dark-mode #message-input {
  background: rgba(120,120,128,0.12);
  border-color: rgba(255,255,255,0.08);
  color: #eee;
}

body.dark-mode #message-input:focus {
  border-color: var(--accent);
  background: rgba(60,60,65,0.5);
  box-shadow: 0 0 0 3px var(--accent-light), 0 0 24px var(--accent-light);
}

/* ============================================================
   CHAT BUTTONS
   ============================================================ */
#skip-btn, #upload-btn, #gif-btn, #send-btn {
  margin: 0;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1),
              background 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

#upload-btn, #gif-btn {
  background: var(--accent);
  color: #fff;
}

#upload-btn:hover, #gif-btn:hover {
  opacity: 0.85;
  transform: scale(1.08);
}

body.dark-mode #upload-btn, body.dark-mode #gif-btn {
  background: var(--accent);
  color: #fff;
}

#skip-btn {
  width: auto;
  min-width: 64px;
  padding: 0 14px;
  border-radius: 20px;
  font-size: 14px;
  background: var(--accent);
  color: #fff;
  transition: all 0.25s cubic-bezier(0.34,1.56,0.64,1);
}

#skip-btn:hover {
  opacity: 0.85;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-shadow);
}

body.dark-mode #skip-btn {
  background: var(--accent);
  color: #fff;
}

/* Skip confirmation pulse */
#skip-btn.confirming {
  animation: pulse 0.8s ease-in-out 3;
  background: #ef4444;
}

/* Send button */
#send-btn {
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  box-shadow: 0 2px 8px var(--accent-shadow);
  transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s, background 0.2s;
}

#send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px var(--accent-shadow);
}

#send-btn:active {
  transform: scale(0.9);
}

body.dark-mode #send-btn {
  background: var(--accent);
  box-shadow: 0 2px 8px var(--accent-shadow);
}

/* ============================================================
   FILE PREVIEW
   ============================================================ */
#file-preview {
  position: absolute;
  bottom: 100%;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  padding: 6px 10px;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.06);
  margin-bottom: 8px;
  border: 0.5px solid rgba(255,255,255,0.8);
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

body.dark-mode #file-preview {
  background: rgba(40,40,45,0.7);
  border-color: rgba(255,255,255,0.04);
  box-shadow: 0 -2px 16px rgba(0,0,0,0.2);
}

#file-preview img {
  max-height: 48px;
  border-radius: 8px;
}

/* ============================================================
   GIF MODAL — Card Flip Reveal
   ============================================================ */
#gif-search {
  font-size: 16px;
}
body.dark-mode #gif-modal {
  background: rgba(40,40,45,0.95);
  backdrop-filter: blur(30px);
}

body.dark-mode #gif-search {
  background: rgba(60,60,65,0.6);
  border-color: rgba(255,255,255,0.08);
  color: #eee;
}

/* ============================================================
   SEARCHING FOR STRANGER — Cinematic Animation
   ============================================================ */
.searching-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  animation: fadeScale 0.4s ease forwards;
}
.searching-ring .pulse-ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulseRing 1.5s ease-in-out infinite;
}
.searching-ring .orbit-container {
  position: absolute;
  width: 56px;
  height: 56px;
}
.searching-ring .orbit-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  top: 50%;
  left: 50%;
  animation: orbit 2s linear infinite;
}
.searching-ring .orbit-dot:nth-child(2) { animation-delay: -0.7s; animation-duration: 2.5s; }
.searching-ring .orbit-dot:nth-child(3) { animation-delay: -1.4s; animation-duration: 3s; }
.searching-ring .status-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-dim);
}
.searching-ring .status-text::after {
  content: '|';
  animation: blink 1s step-end infinite;
  color: var(--accent);
}

/* ============================================================
   KEYFRAMES
   ============================================================ */
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0); }
  70% { transform: scale(1.15); }
  85% { transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeScale {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes matchBurst {
  0% { transform: scale(0.6); opacity: 0; }
  50% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
@keyframes pulseRing {
  0%, 100% { transform: scale(0.85); opacity: 0.4; }
  50% { transform: scale(1.2); opacity: 1; }
}
@keyframes orbit {
  from { transform: rotate(0deg) translateX(36px) rotate(0deg); }
  to { transform: rotate(360deg) translateX(36px) rotate(-360deg); }
}
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-4px); }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media only screen and (max-width: 730px) {
  body {
    background: #f2f2f7;
    display: block;
    min-height: auto;
    padding: 0;
  }

  body.dark-mode {
    background: #0d0d0f;
    overscroll-behavior-x: none;
  }

  #main {
    max-width: none;
    height: 100vh;
    border-radius: 0;
    background: rgba(255,255,255,0.8);
    backdrop-filter: blur(40px) saturate(1.4);
    -webkit-backdrop-filter: blur(40px) saturate(1.4);
    box-shadow: none;
  }

  body.dark-mode #main {
    background: rgba(18,18,22,0.8);
    backdrop-filter: blur(40px) saturate(1.4);
    -webkit-backdrop-filter: blur(40px) saturate(1.4);
    box-shadow: none;
  }

  #main::before { display: none; }

  .message {
    min-width: 0;
    max-width: 85%;
    padding: 14px 24px;
  }

  #message-input {
    height: 46px;
    font-size: 16px;
    padding: 0 16px;
  }

  #input-area {
    gap: 5px;
    padding: 8px 10px 12px;
  }

  #skip-btn, #upload-btn, #gif-btn, #send-btn {
    width: 46px;
    height: 46px;
  }
  #skip-btn {
    width: auto;
    min-width: 78px;
    height: 46px;
    font-size: 15px;
    padding: 0 18px;
  }
}

/* ============================================================
   UPLOAD DRAWER — slides above input bar
   ============================================================ */
.upload-drawer {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 10px;
  right: 10px;
  z-index: 100;
}
.upload-drawer.open {
  display: block;
  animation: slideUp 0.2s ease forwards;
}
@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.upload-drawer-content {
  background: var(--surface, #1c1c1e);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}
.upload-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-radius: 10px;
  transition: background 0.15s;
}
.upload-option:hover {
  background: rgba(255,255,255,0.06);
}
.upload-option:active {
  transform: scale(0.98);
}
.upload-option-icon {
  font-size: 1.3rem;
  line-height: 1;
}
.upload-option-label {
  font-size: 0.85rem;
  color: var(--text, #fff);
  font-weight: 500;
}
body:not(.dark-mode) .upload-drawer-content {
  background: #fff;
  border-color: rgba(0,0,0,0.06);
}
body:not(.dark-mode) .upload-option-label {
  color: #1c1c1e;
}
