/* === Global font === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap');

/* === Light theme variables === */
:root {
  --bg: #f4f6f9;
  --text: #333;
  --card-bg: #fff;
  --border: #e0e0e0;
  --muted: #667085;
  --panel: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(248,250,252,0.98));
  --panel-strong: linear-gradient(135deg, #0f172a, #1e293b);
  --shadow-soft: 0 16px 40px rgba(15, 23, 42, 0.08);
  --shadow-hover: 0 20px 44px rgba(37, 99, 235, 0.18);

  --bubble-me-bg: #2563eb;
  --bubble-me-text: #fff;
  --bubble-other-bg: #eef2f7;
  --bubble-other-text: #111827;

  --composer-bg: #fff;
  --composer-border: #ddd;
  --emoji-panel-bg: #fff;

  --link: #0077ff;
  --link-hover: #005fcc;
  --success: #28a745;
  --error: #dc3545;
}

/* === Dark theme overrides === */
html.dark-mode {
  --bg: #121212;
  --text: #f0f0f0;
  --card-bg: #1e1e1e;
  --border: #333;
  --muted: #a3adc2;
  --panel: linear-gradient(180deg, rgba(30,30,30,0.95), rgba(23,23,23,0.98));
  --panel-strong: linear-gradient(135deg, #111827, #1f2937);
  --shadow-soft: 0 18px 44px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 20px 44px rgba(59, 130, 246, 0.25);

  --bubble-me-bg: #3b82f6;
  --bubble-me-text: #fff;
  --bubble-other-bg: #2c2c2c;
  --bubble-other-text: #f0f0f0;

  --composer-bg: #1e1e1e;
  --composer-border: #444;
  --emoji-panel-bg: #1e1e1e;

  --link: #60a5fa;
  --link-hover: #3b82f6;
}

/* === Base === */
body {
  font-family: 'Inter', sans-serif;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.14), transparent 32%),
    var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 15px;
  color: var(--text);
}

/* === Wrapper === */
.chat-wrap {
  max-width: 800px;
  margin: 20px auto;
  background: var(--panel);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  padding: 24px;
  box-sizing: border-box;
  backdrop-filter: blur(12px);
}

/* === Navigation === */
.nav {
  margin-bottom: 20px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.nav a {
  text-decoration: none;
  font-weight: 600;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(148, 163, 184, 0.2);
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.nav a:hover {
  text-decoration: none;
  color: var(--link);
  background: rgba(255,255,255,0.08);
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
}

/* === Chat layout === */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 70vh;
}

/* === Messages === */
#chat-box {
  flex: 1;
  min-height: 280px;
  overflow-y: auto;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  margin-bottom: 15px;
  font-size: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 72%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* Me (right) */
.msg.me {
  align-self: flex-end;
  background: var(--bubble-me-bg);
  color: var(--bubble-me-text);
  border-bottom-right-radius: 6px;
}

.msg.me .time {
  align-self: flex-end;
}

/* Others (left) */
.msg.other {
  align-self: flex-start;
  background: var(--bubble-other-bg);
  color: var(--bubble-other-text);
  border-bottom-left-radius: 6px;
}

.msg.other .username {
  font-weight: 600;
  margin-bottom: 2px;
}

/* Timestamps */
.msg .time {
  font-size: 0.75rem;
  margin-top: 2px;
  display: block;
}

html:not(.dark-mode) .msg .time {
  color: #555; /* visible in light theme */
}

html.dark-mode .msg .time {
  color: rgba(255,255,255,0.7); /* soft white in dark theme */
}

/* === Composer === */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  flex-wrap: wrap;
}

.composer input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 10px;
  font-size: 0.95rem;
  border: 1px solid var(--composer-border);
  border-radius: 8px;
  background: var(--composer-bg);
  color: var(--text);
}

#emoji-btn, #send-btn {
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
  flex: 0 0 auto;
}

#emoji-btn {
  background: #f0f0f0;
}

#emoji-btn:hover {
  background: #e0e0e0;
}

#send-btn {
  background: var(--link);
  color: #fff;
}

#send-btn:hover {
  background: var(--link-hover);
}

/* === Emoji panel === */
#emoji-panel {
  display: none;
  position: absolute;
  bottom: 60px;
  right: 0;
  background: var(--emoji-panel-bg);
  border: 1px solid var(--composer-border);
  padding: 8px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  flex-wrap: wrap;
  gap: 6px;
  max-width: 220px;
  width: min(220px, calc(100vw - 48px));
  z-index: 1000;
}

#emoji-panel span {
  cursor: pointer;
  font-size: 1.2rem;
}

/* === Forms === */
form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

form input[type="text"],
form input[type="email"],
form input[type="password"] {
  padding: 12px;
  border: 1px solid var(--composer-border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--composer-bg);
  color: var(--text);
  box-sizing: border-box;
  width: 100%;
}

form button {
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
  background: var(--link);
  color: #fff;
  transition: background 0.2s;
}

form button:hover {
  background: var(--link-hover);
}

.auth-form {
  width: min(100%, 420px);
  margin: 0 auto;
}

.chat-wrap h1 {
  text-align: center;
  margin-bottom: 20px;
}

.chat-wrap p {
  text-align: center;
}

.chat-wrap a {
  color: var(--link);
  text-decoration: none;
}

.chat-wrap a:hover {
  text-decoration: underline;
  color: var(--link-hover);
}

.success {
  color: var(--success);
  text-align: center;
  margin-bottom: 15px;
}

.error {
  color: var(--error);
  text-align: center;
  margin-bottom: 15px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  margin: 0 0 10px;
}

.lobby-hero {
  padding: 18px 0 10px;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  margin-bottom: 16px;
  box-shadow: none;
}

.lobby-hero h1,
.lobby-hero p {
  color: var(--text);
  text-align: left;
}

.lobby-hero h1 {
  margin: 0 0 10px;
  font-size: 2.2rem;
}

.lobby-subtitle {
  margin: 0;
  max-width: 44rem;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--muted);
}

.lobby-section {
  margin-top: 24px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
}

.section-kicker {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.room-grid {
  display: grid;
  gap: 14px;
}

.room-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: none;
  color: var(--text);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease, background 0.22s ease;
}

.room-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  border-color: rgba(37, 99, 235, 0.24);
  background: rgba(255,255,255,0.08);
  text-decoration: none;
}

.room-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(96, 165, 250, 0.14);
  color: #60a5fa;
  font-size: 1.2rem;
  font-weight: 800;
  flex: 0 0 auto;
}

.room-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.room-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.room-description {
  font-size: 0.92rem;
  color: var(--muted);
}

.room-arrow {
  margin-left: auto;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
}

.lobby-form {
  display: flex;
  flex-direction: row;
  gap: 12px;
  align-items: center;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.lobby-form input[type="text"] {
  flex: 1;
}

.lobby-form button {
  white-space: nowrap;
  padding-left: 18px;
  padding-right: 18px;
}

.empty-state {
  padding: 22px;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  border-radius: 18px;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
}

/* === Theme toggle switch === */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  margin-right: 10px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0;
  right: 0; bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 28px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 4px; bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--link);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 20px 0;
  flex-wrap: wrap;
}

/* === Chat layout with sidebar === */
.chat-layout {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

.chat-section {
  flex: 3;
  display: flex;
  flex-direction: column;
}

.online-panel {
  flex: 1;
  border-left: 1px solid var(--border);
  padding-left: 15px;
  min-width: 180px;
}

.online-panel h2 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.online-user {
  margin-bottom: 6px;
  font-weight: 500;
  cursor: pointer;
}

.online-user:hover {
  text-decoration: underline;
}

/* === Context menu === */
.context-menu {
  position: absolute;
  display: none;
  list-style: none;
  margin: 0;
  padding: 5px 0;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 2000;
  min-width: 180px;
}

.context-menu li {
  padding: 8px 14px;
  cursor: pointer;
  color: var(--text);
}

.context-menu li:hover {
  background: var(--bubble-other-bg);
}

/* === Profile cards === */
.profile-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  line-height: 1.6;
}

.profile-card p {
  margin: 8px 0;
}

.profile-actions {
  text-align: center;
  margin-top: 20px;
}

.profile-actions .btn {
  display: inline-block;
  padding: 10px 18px;
  background: var(--link);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.2s;
}

.profile-actions .btn:hover {
  background: var(--link-hover);
}

/* === Inbox === */
.inbox-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
  padding: 10px;
}

.inbox-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
  color: var(--text);
}

.inbox-item:hover {
  background: var(--bubble-other-bg);
}

.inbox-count {
  background: #dc3545; /* red badge */
  color: #fff;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 12px;
}

.nav-inbox {
  position: relative;
}

.nav-inbox .inbox-count {
  margin-left: 6px;
  background: #dc3545;
  color: #fff;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 12px;
  vertical-align: middle;
}

/* === Preview bubbles on account page === */
.preview-bubbles {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-bubbles .msg {
  max-width: 70%;
}

/* === Private messages === */
.pm-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pm-chat {
  min-height: 300px;
  max-height: 65vh;
  overflow-y: auto;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pm-composer {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pm-composer input[type="text"] {
  flex: 1;
  min-width: 0;
}

.preview-bubbles .preview-me {
  align-self: flex-end; /* your bubble on right */
}

.preview-bubbles .preview-other {
  align-self: flex-start; /* others on left */
}

/* === User Colour Picker === */
.color-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(32px, 1fr));
  gap: 12px;
  margin: 10px 0 20px;
  max-width: 300px; /* keeps it from stretching too wide */
}

.color-picker input[type="radio"] {
  display: none; /* hide default radio buttons */
}

.color-swatch {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #ccc;
  cursor: pointer;
  transition: transform 0.2s, border 0.2s;
}

.color-picker input[type="radio"]:checked + .color-swatch {
  border: 3px solid var(--link); /* highlight chosen colour */
  transform: scale(1.15);
}

/* === Responsive === */
@media (max-width: 900px) {
  .chat-layout {
    flex-direction: column;
  }

  .online-panel {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-left: 0;
    padding-top: 14px;
    min-width: 0;
  }
}

@media (max-width: 600px) {
  .chat-wrap {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 22px 16px 28px;
  }

  .lobby-hero {
    padding: 20px 18px;
    border-radius: 18px;
  }

  .lobby-hero h1 {
    font-size: 2rem;
  }

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

  .room-card {
    padding: 16px;
    border-radius: 16px;
  }

  .room-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .lobby-form {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }

  .lobby-form button {
    width: 100%;
  }

  .nav {
    justify-content: stretch;
    text-align: center;
    margin-bottom: 22px;
    gap: 10px;
  }

  .nav a {
    flex: 1 1 calc(50% - 10px);
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bubble-other-bg);
    font-size: 1rem;
    font-weight: 600;
  }

  .nav-inbox .inbox-count {
    margin-left: 8px;
    font-size: 0.82rem;
    padding: 3px 8px;
  }

  h1 {
    font-size: 1.85rem;
    line-height: 1.25;
    margin-bottom: 18px;
  }

  h2 {
    font-size: 1.35rem;
    line-height: 1.3;
    margin-bottom: 14px;
  }

  body,
  .chat-wrap p,
  .chat-wrap a,
  .online-user,
  .inbox-item,
  .profile-card,
  form input[type="text"],
  form input[type="email"],
  form input[type="password"] {
    font-size: 1.12rem;
    line-height: 1.45;
  }

  .chat {
    min-height: calc(100dvh - 200px);
  }

  #chat-box,
  .pm-chat {
    min-height: 320px;
    max-height: 50dvh;
    padding: 16px 14px;
    font-size: 1.1rem;
    border-radius: 14px;
  }

  .msg,
  .preview-bubbles .msg {
    max-width: 94%;
    padding: 15px 16px;
    font-size: 1.08rem;
    line-height: 1.6;
    border-radius: 20px;
  }

  .msg .username {
    font-size: 1rem;
  }

  .msg .time {
    font-size: 0.92rem;
  }

  .composer,
  .pm-composer {
    gap: 10px;
    align-items: stretch;
  }

  .composer input[type="text"],
  .pm-composer input[type="text"] {
    font-size: 16px;
    min-height: 56px;
    padding: 16px;
    border-radius: 14px;
  }

  #emoji-btn,
  #send-btn,
  .pm-composer button {
    min-height: 56px;
    font-size: 1.05rem;
    border-radius: 14px;
  }

  #emoji-btn {
    min-width: 56px;
  }

  #send-btn,
  .pm-composer button {
    padding-left: 20px;
    padding-right: 20px;
  }

  .auth-form {
    width: min(100%, 320px);
    gap: 10px;
  }

  .auth-form input[type="text"],
  .auth-form input[type="email"],
  .auth-form input[type="password"] {
    min-height: 46px;
    padding: 12px 14px;
    font-size: 1rem;
    border-radius: 12px;
  }

  .auth-form button {
    min-height: 46px;
    padding: 12px 16px;
    font-size: 1rem;
    border-radius: 12px;
  }

  #emoji-panel {
    bottom: calc(100% + 8px);
    right: 0;
    width: min(260px, calc(100vw - 32px));
    max-width: none;
    padding: 10px;
    border-radius: 14px;
  }

  .inbox-list {
    padding: 0;
    gap: 14px;
  }

  .inbox-item {
    padding: 16px;
    border-radius: 14px;
  }

  .profile-card {
    padding: 18px;
    border-radius: 14px;
  }

  .theme-toggle {
    justify-content: center;
  }

  .online-panel {
    padding-top: 18px;
  }

  .online-user {
    padding: 10px 0;
    font-size: 1.08rem;
  }

  .color-picker {
    max-width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(42px, 1fr));
    gap: 14px;
  }

  .color-swatch {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 420px) {
  .composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 56px;
    grid-template-areas:
      "input emoji"
      "send send";
  }

  .composer input[type="text"] {
    grid-area: input;
  }

  #emoji-btn {
    grid-area: emoji;
  }

  #send-btn {
    grid-area: send;
    width: 100%;
  }

  .pm-composer {
    flex-direction: column;
  }

  .pm-composer button {
    width: 100%;
  }

  .context-menu {
    min-width: 160px;
    max-width: calc(100vw - 24px);
  }

  .nav a {
    flex-basis: 100%;
  }
}
