/* === Base Reset === */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* === Landing Page (iMessage-style) === */
.landing {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #f2f2f7;
}

.landing-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.landing-header .header-spacer {
  width: 40px;
}

.landing-header h1 {
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.compose-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  cursor: pointer;
  color: #007AFF;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
}

.compose-btn:active {
  background: rgba(0, 122, 255, 0.1);
}

/* Search */
.search-wrap {
  padding: 0 16px 8px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
}

.search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: none;
  border-radius: 10px;
  background: #e5e5ea;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238e8e93' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.156a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

/* Room List */
.room-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.room-row {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: white;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
  gap: 12px;
  transition: background 0.15s;
}

.room-row:active {
  background: #e5e5ea;
}

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

.room-info {
  flex: 1;
  min-width: 0;
}

.room-info-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.room-row-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-time {
  font-size: 14px;
  color: #8e8e93;
  flex-shrink: 0;
  margin-left: 8px;
}

.room-preview {
  font-size: 14px;
  color: #8e8e93;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.room-chevron {
  color: #c7c7cc;
  flex-shrink: 0;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 32px;
  text-align: center;
  color: #8e8e93;
}

.empty-state .empty-icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 15px;
  max-width: 260px;
}

/* Username Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-card {
  background: white;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.modal-card h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.modal-card p {
  font-size: 14px;
  color: #8e8e93;
  margin-bottom: 18px;
}

.modal-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  margin-bottom: 14px;
  text-align: center;
}

.modal-card input:focus {
  border-color: #007AFF;
}

.modal-card button {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  background: #007AFF;
  color: white;
  cursor: pointer;
  font-family: inherit;
}

.modal-card button:active {
  opacity: 0.85;
}

/* Compose Bottom Sheet */
.compose-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.compose-overlay.hidden {
  display: none;
}

.compose-sheet {
  background: white;
  border-radius: 14px 14px 0 0;
  width: 100%;
  max-width: 500px;
  padding: 16px 20px 28px;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.compose-sheet .sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: #d1d1d6;
  margin: 0 auto 16px;
}

.compose-tabs {
  display: flex;
  background: #e5e5ea;
  border-radius: 8px;
  padding: 2px;
  margin-bottom: 20px;
}

.compose-tabs button {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: #666;
  cursor: pointer;
  font-family: inherit;
}

.compose-tabs button.active {
  background: white;
  color: #1a1a1a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.compose-panel {
  display: none;
}

.compose-panel.active {
  display: block;
}

.compose-panel input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  margin-bottom: 12px;
}

.compose-panel input:focus {
  border-color: #007AFF;
}

.compose-panel button[type="submit"] {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  background: #007AFF;
  color: white;
  cursor: pointer;
  font-family: inherit;
}

.compose-panel button[type="submit"]:active {
  opacity: 0.85;
}

.compose-error {
  color: #ff3b30;
  font-size: 13px;
  text-align: center;
  margin-bottom: 10px;
  min-height: 18px;
}

/* === Chat Page === */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: #f5f5f5;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.back-btn {
  font-size: 28px;
  color: #007AFF;
  text-decoration: none;
  margin-right: 8px;
  line-height: 1;
  font-weight: 300;
}

.header-info {
  flex: 1;
  text-align: center;
}

.room-name {
  font-size: 16px;
  font-weight: 600;
}

.room-code {
  font-size: 12px;
  color: #8e8e93;
  letter-spacing: 1px;
}

.copy-code-btn {
  background: none;
  border: 1px solid #007AFF;
  color: #007AFF;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}

/* Messages — flex-end so they anchor to bottom */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.message-wrapper {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  max-width: 78%;
  flex-shrink: 0;
}

.message-wrapper.sent {
  align-self: flex-end;
  align-items: flex-end;
  margin-left: auto;
}

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

.msg-username {
  font-size: 11px;
  color: #8e8e93;
  margin-bottom: 2px;
  padding: 0 12px;
  font-weight: 500;
}

/* Bubbles */
.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  max-width: 100%;
  word-wrap: break-word;
  position: relative;
}

.bubble.sent {
  background: #007AFF;
  color: white;
  border-bottom-right-radius: 4px;
}

.bubble.received {
  background: #E9E9EB;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.msg-text {
  font-size: 16px;
  line-height: 1.35;
}

.msg-time {
  font-size: 11px;
  opacity: 0.6;
  text-align: right;
  margin-top: 4px;
}

/* Music Card */
.music-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.bubble.sent .music-card {
  color: #1a1a1a;
}

.music-card-top {
  display: flex;
  padding: 10px;
  gap: 10px;
  align-items: center;
}

.album-art {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.song-info {
  flex: 1;
  min-width: 0;
}

.song-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-artist {
  font-size: 13px;
  color: #8e8e93;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lyrics-snippet {
  padding: 8px 12px;
  font-size: 13px;
  color: #555;
  background: #fafafa;
  border-top: 1px solid #f0f0f0;
  white-space: pre-line;
  line-height: 1.4;
  font-style: italic;
  max-height: 100px;
  overflow-y: auto;
}

.lyrics-snippet strong {
  font-weight: 700;
  color: #1a1a1a;
  font-style: normal;
}

/* === Waveform Player (Voice Memo Style) === */
.wave-player {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 4px 0;
}

.wave-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #007AFF;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.wave-play-btn:active {
  transform: scale(0.9);
}

.bubble.received .wave-play-btn {
  background: #007AFF;
  color: white;
}

.wave-track {
  flex: 1;
  height: 32px;
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
  border-radius: 4px;
}

.wave-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: rgba(0, 122, 255, 0.15);
  border-radius: 4px;
  transition: width 0.1s linear;
  z-index: 1;
}

.wave-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
  width: 100%;
  z-index: 2;
  position: relative;
}

.wave-bar {
  flex: 1;
  min-width: 2px;
  max-width: 4px;
  border-radius: 2px;
  background: #8e8e93;
  transition: background 0.15s;
}

.bubble.sent .wave-bar {
  background: rgba(255, 255, 255, 0.5);
}

.bubble.sent .wave-fill {
  background: rgba(255, 255, 255, 0.25);
}

.bubble.sent .wave-play-btn {
  background: white;
  color: #007AFF;
}

.wave-time {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.7;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Hidden YouTube player */
#ytPlayer {
  width: 1px;
  height: 1px;
  position: absolute;
  left: -9999px;
  opacity: 0.01;
}

/* Input Bar */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.input-bar input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  background: #f0f0f0;
}

.input-bar input:focus {
  background: white;
  border-color: #c0c0c0;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #007AFF;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}

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

/* Searching Indicator */
.searching-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 14px;
  color: #8e8e93;
  font-style: italic;
  flex-shrink: 0;
}

.dot-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8e8e93;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Notification */
.notification {
  text-align: center;
  font-size: 13px;
  color: #8e8e93;
  padding: 8px 0;
  flex-shrink: 0;
}

/* === Mobile === */
@media (max-width: 600px) {
  .message-wrapper {
    max-width: 85%;
  }

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