:root {
  --bg: #14161a;
  --bg-elevated: #1c1f26;
  --bg-input: #22262e;
  --border: #2c313a;
  --text: #e6e8eb;
  --text-dim: #8b929e;
  --accent: #4f8cff;
  --accent-hover: #6b9dff;
  --danger: #e5484d;
  --danger-hover: #ff6169;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- Chat page ---------- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.chat-header h1 {
  font-size: 1.1rem;
  margin: 0;
}

.nick-badge {
  font-size: 0.85rem;
  color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
  padding: 4px 10px;
  border-radius: 999px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.account-area {
  display: flex;
  align-items: center;
}

.account-logged-in {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-email {
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

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

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  width: 100%;
  max-width: 380px;
}

.modal-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}

.modal-tab {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.modal-tab.active {
  color: var(--text);
  background: var(--bg-input);
}

.modal-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  min-width: 30px;
}

.modal-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0 0 12px;
  line-height: 1.4;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-form input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.9rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  color: var(--danger-hover);
  font-size: 0.82rem;
  margin: 0;
}

.auth-error.hidden {
  display: none;
}

/* ---------- Avatar studio ---------- */

.avatar-modal {
  max-width: 440px;
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.avatar-status {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin: 0 0 10px;
  min-height: 1.2em;
  line-height: 1.4;
}

.avatar-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 12px;
}

.avatar-video,
.avatar-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-video.hidden,
.avatar-canvas.hidden {
  display: none;
}

.avatar-video {
  transform: scaleX(-1);
}

.avatar-stage.paired {
  aspect-ratio: 2 / 1;
  display: flex;
  gap: 4px;
}

.avatar-stage.paired .avatar-canvas {
  position: static;
  flex: 1;
  width: 50%;
  height: 100%;
}

.avatar-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.avatar-controls .btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.swatch-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  width: 100%;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.4);
}

.swatch-style {
  width: auto;
  height: auto;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  background: var(--bg-input);
  color: var(--text);
}

.swatch-style.selected {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  max-width: min(560px, 90%);
  align-self: flex-start;
}

.message-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.msg-nick {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.85rem;
}

.msg-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex: 1;
}

.report-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.report-btn:hover {
  color: var(--danger);
  background: rgba(229, 72, 77, 0.1);
}

.msg-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.msg-text:empty {
  display: none;
}

.msg-media img,
.msg-media video {
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
  margin-top: 6px;
  display: block;
}

.live-message {
  border-color: var(--danger);
}

.live-badge {
  color: var(--danger-hover);
  font-weight: 600;
  font-size: 0.78rem;
}

.end-live-btn {
  background: var(--danger);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

.end-live-btn.hidden {
  display: none;
}

.live-video-wrap {
  position: relative;
  margin-top: 6px;
}

.live-video {
  width: 100%;
  max-height: 360px;
  border-radius: 8px;
  background: #000;
  display: block;
}

.unmute-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
}

.unmute-btn.hidden {
  display: none;
}

.report-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.report-form.hidden,
.file-preview.hidden,
.error-bar.hidden {
  display: none;
}

.report-reason-input {
  flex: 1;
  min-width: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 0.85rem;
}

.system-message {
  align-self: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-dim);
}

.error-bar {
  padding: 8px 16px;
  background: rgba(229, 72, 77, 0.15);
  color: var(--danger-hover);
  font-size: 0.85rem;
  text-align: center;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
}

.composer input[type="text"] {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  min-width: 0;
}

.composer input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- Buttons ---------- */

.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-small {
  padding: 5px 10px;
  font-size: 0.78rem;
  border-radius: 6px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}

.attach-btn {
  margin: 0;
}

/* ---------- Admin page ---------- */

.admin-body {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.reports-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 24px;
}

.section-title {
  font-size: 1rem;
  color: var(--text-dim);
  margin: 0 0 10px;
}

.loading,
.error {
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
}

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

.report-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.report-card.resolved {
  opacity: 0.55;
}

.report-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.report-reason {
  font-style: italic;
  color: var(--text-dim);
  margin: 4px 0;
}

.report-content {
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.media-preview {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 6px;
  display: block;
}

.report-ips {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 10px 0 0;
}

.report-ips dd {
  margin: 0;
  color: var(--text);
  word-break: break-all;
}

.report-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  .message {
    max-width: 100%;
  }

  .admin-body {
    padding: 10px;
  }

  .report-actions {
    flex-direction: column;
  }

  .report-actions .btn {
    width: 100%;
  }
}
