:root {
  color-scheme: dark;
  --bg: #0a0c10;
  --surface: #12151c;
  --surface-2: #1a1f2b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef2ff;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #a855f7;
  --success: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 14px;
  font-family: "Segoe UI", Inter, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  background-image:
    radial-gradient(circle at 10% 0%, rgba(99, 102, 241, 0.12), transparent 30%),
    radial-gradient(circle at 90% 10%, rgba(168, 85, 247, 0.1), transparent 25%);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  font-size: 1.75rem;
}

.brand strong {
  display: block;
  font-size: 1.1rem;
}

.brand-tag {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.brand .live-count {
  margin-top: 0.25rem;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.live-count {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.live-count.subtle {
  font-size: 0.75rem;
  opacity: 0.7;
  padding: 0.3rem 0.6rem;
  background: transparent;
  border: none;
}

.live-count.subtle .count-dot {
  width: 4px;
  height: 4px;
  box-shadow: none;
}

.count-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.btn-small {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
}

.header-stats .btn-secondary {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
}

.connection-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 360px;
}

.connection-badge.large {
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  max-width: 300px;
  justify-content: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot[data-level="connected"],
.connection-badge[data-level="connected"] .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.status-dot[data-level="connecting"],
.connection-badge[data-level="connecting"] .status-dot {
  background: var(--warn);
  animation: pulse 1.2s infinite;
}

.status-dot[data-level="error"],
.connection-badge[data-level="error"] .status-dot {
  background: var(--error);
}

.status-dot[data-level="warn"],
.connection-badge[data-level="warn"] .status-dot {
  background: var(--warn);
}

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

#status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Layout */
.workspace {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1rem;
  align-items: start;
}

.view-section {
  width: 100%;
}

.connected-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 900px;
  margin: 0 auto;
}

.connected-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.match-info h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.match-info p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.audio-controls {
  display: flex;
  gap: 0.5rem;
}

.chat-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.chat-section h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Button row */
.button-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.button-row .btn-primary,
.button-row .btn-secondary {
  flex: 1;
  padding: 0.75rem 1rem;
}

/* Profile published state */
.profile-published {
  padding: 1rem;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* History card */
.history-card {
  min-height: 200px;
}

.history-list {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  padding: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-item strong {
  display: block;
  margin-bottom: 0.25rem;
}

.history-item .history-time {
  font-size: 0.75rem;
  color: var(--muted);
}

.history-item .history-preview {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  
  .topbar {
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
  }
  
  .brand {
    order: 1;
    flex: 0 0 auto;
    min-width: 120px;
  }
  
  .brand strong {
    font-size: 1rem;
  }
  
  .brand-tag {
    font-size: 0.75rem;
  }
  
  .brand .live-count {
    font-size: 0.7rem;
    margin-top: 0.15rem;
  }
  
  .header-stats {
    order: 2;
    flex: 0 0 auto;
  }
  
  .header-stats .btn-secondary {
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
  }
  
  .connection-badge.large {
    order: 3;
    flex: 1;
    min-width: 0;
    font-size: 0.7rem;
    padding: 0.35rem 0.6rem;
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .connection-badge.large .status-dot {
    width: 6px;
    height: 6px;
  }
  
  .connection-badge:not(.large) {
    font-size: 0.75rem;
    padding: 0.4rem 0.7rem;
  }
  
  .connected-header {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .audio-controls {
    justify-content: center;
  }
  
  .field-row {
    grid-template-columns: 1fr;
  }
  
  .button-row {
    flex-direction: column;
  }
  
  .toggle-column {
    gap: 0.3rem;
  }
  
  .toggle-row.compact {
    white-space: nowrap;
    font-size: 0.75rem;
  }
  
  .toggle-row.compact .toggle-text {
    font-size: 0.75rem;
  }
  
  .modal-content {
    margin: 1rem;
    max-height: 90vh;
  }
}

/* Chat messages */
.chat-message {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--surface-2);
}

.chat-message.local {
  background: rgba(99, 102, 241, 0.1);
}

.chat-message.local strong {
  color: var(--accent);
}

.chat-message.remote strong {
  color: var(--accent-2);
}

.chat-message strong {
  flex-shrink: 0;
}

.chat-message span {
  word-break: break-word;
}

.sidebar,
.main-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.card-head h2 {
  margin: 0;
}

.queue-count {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Form */
form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 0.5rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.looking-for-block {
  display: grid;
  gap: 0.5rem;
}

.field-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  cursor: pointer;
}

.checkbox-grid input {
  width: auto;
  accent-color: var(--accent);
}

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch {
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}

.toggle-row input:checked + .toggle-switch {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-row input:checked + .toggle-switch::after {
  transform: translateX(16px);
  background: #fff;
}

.toggle-text {
  font-size: 0.88rem;
}

/* Interest section - groups interest elements */
.interest-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

/* Interest row — tags + toggle column side by side */
.interest-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.65rem;
  align-items: start;
}

.toggle-column {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toggle-row.compact {
  padding-top: 0.35rem;
  white-space: nowrap;
}
  gap: 0.5rem;
}

.interest-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.interest-field-full {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}

.interest-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.interest-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.35rem 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.35);
  font-size: 0.78rem;
  color: #c7d2fe;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.2rem;
  font-size: 1rem;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--error);
}

.interest-field input {
  flex: 1;
  min-width: 100px;
  border: none;
  background: transparent;
  padding: 0.25rem 0.4rem;
}

.interest-field input:focus {
  box-shadow: none;
}

.field-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.field-hint[data-level="active"] {
  color: #a5b4fc;
}

.suggested-interests {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.suggested-chip {
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.suggested-chip:hover {
  border-color: var(--accent);
  color: #c7d2fe;
}

/* Buttons */
button {
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.btn-secondary {
  color: #fff;
  background: var(--accent);
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
}

/* Profile queue */
.profile-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.empty-queue {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.profile-card {
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.profile-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.profile-head strong {
  font-size: 0.9rem;
}

.profile-head span {
  font-size: 0.75rem;
  color: var(--muted);
}

.profile-interests {
  margin: 0.35rem 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.profile-meta {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.tag-hot {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

/* Match panel */
.match-card {
  flex: 0 0 auto;
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.match-header h2 {
  margin-bottom: 0.35rem;
}

.match-status {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.match-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.audio-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.audio-block label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

audio {
  width: 100%;
  border-radius: 8px;
  background: var(--surface-2);
}

/* Chat */
.chat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.chat-area {
  flex: 1;
  min-height: 280px;
  max-height: 480px;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
}

.chat-placeholder {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

.chat-message {
  max-width: 75%;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

.chat-message strong {
  display: block;
  font-size: 0.7rem;
  margin-bottom: 0.15rem;
  opacity: 0.7;
}

.chat-message.local {
  margin-left: auto;
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.chat-message.remote {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

/* Donations */
.donation-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.donation-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.75rem;
}

.donation-row code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

/* Responsive */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .audio-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .match-header {
    flex-direction: column;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .connection-badge {
    max-width: 100%;
  }
}
