/* ===============================
   RESET & BASE
================================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ===============================
   THEME VARIABLES
================================= */
:root {
  --bg: #0f0f13;
  --bg-secondary: #16161d;
  --bg-message: #1e1e28;
  --bg-own: #3730a3;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --border: #252530;
  --input-bg: #1a1a22;
  --accent: #6366f1;
}

body.light {
  --bg: #e8e8ed;
  --bg-secondary: #ffffff;
  --bg-message: #e4e4e7;
  --bg-own: #6366f1;
  --text: #18181b;
  --text-muted: #52525b;
  --border: #a1a1aa;
  --input-bg: #ffffff;
  --accent: #4f46e5;
}

/* ===============================
   LANDING PAGE
================================= */

/* ===============================
   LANDING PAGE
================================= */
#landing-screen {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: background 0.6s ease;
}

.main-title {
  font-family: "Night Shift", "Arial Black", Impact, sans-serif;
  font-size: clamp(4rem, 12vw, 8rem);
  color: #ef4444;
  margin: 0;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.35s ease;
  -webkit-text-stroke: 0px transparent;
  user-select: none;
  z-index: 10;
}

.main-title:hover {
  color: transparent;
  -webkit-text-stroke: 2px #ef4444;
  transform: scale(1.08);
}

.landing-subtitle {
  margin-top: 1.2rem;
  font-size: 1.25rem;
  color: var(--text-muted);
  opacity: 0.85;
  letter-spacing: 1px;
  transition: opacity 0.3s ease;
  z-index: 10;
}

#landing-screen:hover .landing-subtitle {
  opacity: 1;
}

/* Expanding circle */
#expand-circle {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  background: #ef4444;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  opacity: 1;
  pointer-events: none;
  z-index: 50;
  transition: transform 1.15s cubic-bezier(0.65, 0, 0.35, 1),
              opacity 0.9s ease 0.25s;
}

#expand-circle.active {
  transform: translate(-50%, -50%) scale(90);
  opacity: 0;
}

/* After expansion */
#after-expand {
  position: fixed;
  inset: 0;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
}

#after-expand.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Theme button */
#theme-btn-landing {
  position: absolute;
  top: 1.8rem;
  right: 1.8rem;
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(15px);
  transition: all 0.5s ease;
  z-index: 70;
}

#theme-btn-landing.show {
  opacity: 1;
  transform: translateY(0);
}

#theme-btn-landing:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Question */
.love-question {
  position: absolute;
  top: 28%;
  left: 28%;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  font-weight: 600;
  color: var(--text);
  max-width: 420px;
  line-height: 1.3;
  opacity: 0;
  transform: translateY(25px);
  transition: all 0.5s ease;
  white-space: nowrap;
}

.love-question.show {
  opacity: 1;
  transform: translateY(0);
}

/* Mini bubble */
.mini-bubble {
  position: absolute;
  top: 28.5%;
  left: 60%;
  background: var(--bg-message);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.9rem 1.2rem;
  width: min(85vw, 360px);
  opacity: 0;
  transform: translateY(25px);
  transition: all 0.5s ease;
}

.mini-bubble.show {
  opacity: 1;
  transform: translateY(0);
}

.mini-bubble input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 1rem;
  color: var(--text);
}

/* When expanded */
#landing-screen.expanded .main-title,
#landing-screen.expanded .landing-subtitle {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
/* ===============================
   JOIN SCREEN
================================= */
#join-screen {
  width: 100%;
  max-width: 420px;
  padding: 2rem 1.5rem;
  text-align: center;
}

#join-screen h1 {
  font-size: 1.8rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.subtitle {
  font-size: 1rem;
  opacity: 0.75;
  margin-bottom: 1.5rem;
  margin-top: -0.3rem;
}

#join-screen .hint {
  font-size: 0.9rem;
  opacity: 0.65;
  margin-top: 1.5rem;
  line-height: 1.4;
}

#join-screen input {
  width: 100%;
  padding: 0.9rem 1rem;
  margin: 0.45rem 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

#join-screen input:focus {
  border-color: var(--accent);
}

#join-screen button {
  width: 100%;
  padding: 0.95rem;
  margin-top: 0.8rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

#join-screen button:hover {
  background: #4f46e5;
}

.theme-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1.2rem;
}

#theme-btn-join {
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

#theme-btn-join:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  transform: scale(1.05);
}

/* ===============================
   CHAT SCREEN
================================= */
#chat-screen {
  width: 100%;
  max-width: 520px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

#room-name {
  font-weight: 600;
  font-size: 1.05rem;
}

#users-count {
  font-size: 0.85rem;
  opacity: 0.7;
  background: var(--border);
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
}

/* Header buttons */
#users-btn,
#theme-btn,
#leave-btn {
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
}

#invite-btn {
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--border);
  height: 36px;
  padding: 0 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  min-width: 70px;
}

#users-btn:hover,
#theme-btn:hover,
#invite-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#leave-btn:hover {
  background: #7f1d1d;
  border-color: #7f1d1d;
  color: white;
}

#leave-btn.confirm {
  background: #dc2626;
  border-color: #dc2626;
  color: white;
  transform: scale(1.08);
}

#leave-btn svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message {
  background: var(--bg-message);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message.own {
  align-self: flex-end;
  background: var(--bg-own);
  color: white;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
  gap: 0.5rem;
}

.message-header strong {
  font-weight: 700;
  font-size: 0.85rem;
  opacity: 0.9;
}

.message-content {
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-content a {
  color: #93c5fd;
  text-decoration: underline;
}

.message.own .message-content a {
  color: #c7d2fe;
}

.timestamp {
  font-size: 0.7rem;
  opacity: 0.55;
  white-space: nowrap;
}

.system {
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.6;
  margin: 0.3rem 0;
  color: var(--text-muted);
}

.typing {
  font-size: 0.85rem;
  opacity: 0.7;
  font-style: italic;
  padding: 0.25rem 0.5rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Message form */
#message-form {
  display: flex;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#message-form input {
  flex: 1;
  padding: 0.85rem 1.1rem;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

#message-form input:focus {
  border-color: var(--accent);
}

#message-form button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#message-form button:hover {
  background: #4f46e5;
}

/* ===============================
   POPUPS
================================= */
#users-popup,
#link-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#users-popup {
  z-index: 100;
}

#link-popup {
  z-index: 200;
}

.users-popup-content,
.link-popup-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 90%;
  max-width: 360px;
  padding: 1.5rem;
  color: var(--text);
}

.users-popup-content {
  max-width: 320px;
  padding: 1.2rem;
}

.users-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-weight: 600;
}

#close-users-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}

#users-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

#users-list li {
  padding: 0.6rem 0.8rem;
  background: var(--bg-message);
  border-radius: 10px;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

.link-popup-content {
  text-align: center;
}

.link-popup-content h3 {
  margin-bottom: 0.8rem;
  font-size: 1.2rem;
}

.link-popup-content p {
  margin-bottom: 0.7rem;
  font-size: 0.95rem;
  line-height: 1.4;
}

.link-url {
  background: var(--bg-message);
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  font-size: 0.85rem;
  word-break: break-all;
  color: var(--accent);
}

.warning-text {
  font-size: 0.85rem !important;
  opacity: 0.8;
  color: #f87171;
}

.link-popup-buttons {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.4rem;
}

.link-popup-buttons button {
  flex: 1;
  padding: 0.7rem;
  border-radius: 10px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

#link-cancel-btn {
  background: var(--border);
  color: var(--text);
}

#link-cancel-btn:hover {
  background: #3f3f46;
}

#link-confirm-btn {
  background: #dc2626;
  color: white;
}

#link-confirm-btn:hover {
  background: #b91c1c;
}

#link-confirm-btn.confirm {
  background: #ef4444;
  transform: scale(1.03);
}

/* ===============================
   MOBILE
================================= */
@media (max-width: 600px) {
  body {
    height: 100dvh;
  }

  #chat-screen {
    height: 100dvh;
    max-width: 100%;
  }

  #join-screen {
    padding: 1.5rem 1.2rem;
  }

  header {
    padding: 0.75rem 1rem;
  }

  #messages {
    padding: 0.9rem;
  }

  .message {
    max-width: 88%;
  }

  #message-form {
    padding: 0.7rem 0.9rem;
    gap: 0.5rem;
  }

  #message-form input {
    padding: 0.75rem 1rem;
    font-size: 16px;
  }

  #message-form button,
  #leave-btn,
  #theme-btn,
  #users-btn {
    width: 42px;
    height: 42px;
  }

  #chat-screen {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (max-width: 600px) {
  .love-question {
    top: 22%;
    left: 8%;
    font-size: 1.6rem;
  }

  .mini-bubble {
    top: 38%;
    left: 8%;
    width: 84vw;
  }

  #theme-btn-landing {
    top: 1.2rem;
    right: 1.2rem;
  }
}