:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-glass: rgba(15, 23, 42, 0.6);
  --bg-panel: rgba(30, 41, 59, 0.85);
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.2);
  --text: #f8fafc;
  --muted: #cbd5f5;
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 30px 60px rgba(15, 23, 42, 0.45);
  --blur: 18px;
  font-family: 'Tajawal', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
}

body.home,
body.room {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(56, 189, 248, 0.1), transparent 60%),
    radial-gradient(circle at bottom, rgba(129, 140, 248, 0.15), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: inherit;
  overflow-x: hidden;
}

.room {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.home .hero {
  padding: 6rem 1.5rem 4rem;
  display: flex;
  justify-content: center;
}

.hero__content {
  max-width: 520px;
  background: var(--bg-glass);
  backdrop-filter: blur(var(--blur));
  border-radius: 28px;
  padding: 2.5rem 3rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.hero__content h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
}

.hero__content p {
  margin: 0 auto 2.5rem;
  line-height: 1.8;
  color: var(--muted);
  font-size: 1.1rem;
}

.hero__actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.hero__btn {
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.9rem;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.7), rgba(37, 99, 235, 0.8));
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 15px 30px rgba(56, 189, 248, 0.25);
}

.hero__btn:hover,
.hero__btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 20px 40px rgba(56, 189, 248, 0.35);
}

.hero__btn--chat {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.75), rgba(244, 63, 94, 0.8));
  box-shadow: 0 15px 30px rgba(244, 63, 94, 0.25);
}

.hero__btn--chat:hover,
.hero__btn--chat:focus-visible {
  box-shadow: 0 20px 40px rgba(244, 63, 94, 0.35);
}

.chat-panel {
  position: fixed;
  top: 0;
  inset-inline-end: 0;
  height: 100vh;
  width: min(360px, 90vw);
  background: var(--bg-panel);
  backdrop-filter: blur(var(--blur));
  box-shadow: -24px 0 60px rgba(15, 23, 42, 0.45);
  transform: translateX(100%);
  transition: transform 0.35s ease;
  display: flex;
  flex-direction: column;
  z-index: 120;
}

.chat-panel[aria-hidden='false'] {
  transform: translateX(0);
}

.chat-panel__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(calc(var(--blur) / 2));
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 110;
}

.chat-panel__backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 0.75rem;
}

.chat-panel__header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.chat-panel__close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

.chat-panel__search {
  display: flex;
  gap: 0.75rem;
  padding: 0 1.5rem 1rem;
  align-items: center;
}

.chat-panel__search input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  padding: 0.65rem 1.1rem;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
  font-size: 0.95rem;
}

.chat-panel__search input::placeholder {
  color: rgba(226, 232, 240, 0.55);
}

.chat-panel__create {
  border-radius: 999px;
  padding: 0.5rem 1rem;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: transparent;
  color: rgba(148, 163, 184, 0.6);
  cursor: not-allowed;
}

.chat-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.75rem 2rem;
}

.chat-panel__empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: rgba(226, 232, 240, 0.7);
}

.chat-room {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-radius: 18px;
  border: 1px solid transparent;
  background: rgba(15, 23, 42, 0.35);
  margin: 0.5rem 0;
  cursor: pointer;
  transition: transform 0.2s ease, border 0.2s ease, background 0.2s ease;
}

.chat-room:hover,
.chat-room:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.16);
}

.chat-room__info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.chat-room__name {
  font-size: 1.05rem;
  font-weight: 600;
}

.chat-room__count {
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.65);
}

.chat-room__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  font-size: 0.85rem;
}

.chat-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 140;
}

.chat-modal[hidden] {
  display: none;
}

.chat-modal__dialog {
  width: min(420px, 90vw);
  background: rgba(15, 23, 42, 0.88);
  padding: 2.5rem 2rem 2rem;
  border-radius: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(calc(var(--blur) * 1.2));
  position: relative;
  text-align: center;
}

.chat-modal__close {
  position: absolute;
  inset-inline-end: 1rem;
  inset-block-start: 1rem;
  border: none;
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-modal__room {
  margin: 0.5rem 0 1.5rem;
  font-weight: 500;
  color: var(--accent);
}

.chat-modal__label {
  display: block;
  margin-bottom: 0.5rem;
  text-align: start;
}

.chat-modal__dialog input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 0.8rem 1rem;
  font-size: 1rem;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text);
}

.chat-modal__hint {
  margin: 0.75rem 0 0;
  color: rgba(226, 232, 240, 0.65);
  font-size: 0.85rem;
}

.chat-modal__error {
  margin: 0.75rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.chat-modal__submit {
  margin-top: 1.5rem;
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 0.85rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.9), rgba(37, 99, 235, 0.85));
  color: var(--text);
  box-shadow: 0 20px 40px rgba(37, 99, 235, 0.25);
}

.chat-modal__submit:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-modal__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(calc(var(--blur) * 0.8));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 130;
}

.chat-modal__backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

body.modal-open {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.room-layout {
  display: flex;
  flex: 1;
  min-height: 100vh;
}

.room-users {
  width: 280px;
  background: rgba(15, 23, 42, 0.78);
  border-inline-start: 1px solid rgba(148, 163, 184, 0.12);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(var(--blur));
  box-shadow: -10px 0 40px rgba(15, 23, 42, 0.35);
  z-index: 5;
}

.room-users__toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.35);
  color: var(--muted);
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.room-users__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 1.25rem 1rem;
}

.room-users__header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.room-users__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  font-size: 0.9rem;
}

.room-users__list {
  flex: 1;
  overflow-y: auto;
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.room-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.9rem;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.45);
  border: 1px solid transparent;
  transition: border 0.2s ease;
}

.room-user__name {
  font-weight: 500;
}

.room-user__status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.75);
}

.room-user__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.5);
}

.room-user.is-typing {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.12);
}

.room-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 2rem 2.5rem 1.5rem;
  gap: 1.5rem;
}

.room-chat__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.room-chat__header h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

.room-chat__status {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(226, 232, 240, 0.7);
}

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

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.75);
}

.sound-toggle input {
  accent-color: var(--accent);
}

.room-chat__leave {
  border: none;
  border-radius: 12px;
  padding: 0.45rem 1.1rem;
  font-size: 0.95rem;
  background: rgba(248, 113, 113, 0.25);
  color: #fecaca;
  cursor: pointer;
}

.room-chat__messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding-inline-end: 0.25rem;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-width: min(80%, 520px);
  margin-inline-start: auto;
  text-align: start;
}

.message--other {
  margin-inline-start: 0;
  margin-inline-end: auto;
}

.message__author {
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.7);
}

.message--continued .message__author {
  display: none;
}

.message__bubble {
  padding: 0.85rem 1rem;
  border-radius: 18px 4px 18px 18px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.32), rgba(59, 130, 246, 0.25));
  color: var(--text);
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}

.message--other .message__bubble {
  border-radius: 4px 18px 18px 18px;
  background: rgba(15, 23, 42, 0.65);
}

.message__meta {
  display: flex;
  justify-content: flex-end;
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.55);
}

.message--other .message__meta {
  justify-content: flex-start;
}

.message--mention .message__bubble {
  border: 1px solid rgba(248, 250, 252, 0.35);
  box-shadow: 0 0 18px rgba(248, 113, 113, 0.2);
}

.mention {
  color: var(--accent);
  font-weight: 600;
}

.message--system {
  align-items: center;
  margin: 0 auto;
  text-align: center;
  max-width: 60%;
}

.message--system .message__bubble {
  background: rgba(148, 163, 184, 0.18);
  color: rgba(226, 232, 240, 0.8);
  border-radius: 12px;
  font-size: 0.9rem;
}

.room-chat__typing {
  font-size: 0.85rem;
  color: rgba(226, 232, 240, 0.7);
  min-height: 1.2rem;
}

.room-chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 18px;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: inset 0 0 30px rgba(15, 23, 42, 0.35);
  position: relative;
}

.room-chat__composer textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 160px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.7;
  font-family: inherit;
}

.room-chat__composer textarea:focus {
  outline: none;
}

.composer__emoji {
  border: none;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
  cursor: pointer;
  color: rgba(226, 232, 240, 0.9);
}

.emoji-popover {
  position: absolute;
  inset-inline-start: 0;
  inset-block-end: 100%;
  transform: translateY(-0.75rem);
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: var(--shadow);
}

.emoji-popover[hidden] {
  display: none;
}

.emoji-popover button {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}

.composer__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.composer__counter {
  font-size: 0.75rem;
  color: rgba(226, 232, 240, 0.6);
}

.composer__send {
  border: none;
  border-radius: 12px;
  padding: 0.5rem 1.2rem;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.8), rgba(59, 130, 246, 0.8));
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

.composer__send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  inset-inline-end: 1.5rem;
  inset-block-end: 1.5rem;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 14px;
  padding: 0.85rem 1.1rem;
  box-shadow: var(--shadow);
  color: var(--danger);
  font-size: 0.9rem;
  z-index: 80;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 600px) {
  .hero__content {
    padding: 2rem 1.75rem;
  }

  .hero__content p {
    font-size: 1rem;
  }

  .hero__actions {
    gap: 0.75rem;
  }

  .hero__btn {
    flex: 1 1 auto;
  }

  .room-layout {
    flex-direction: column;
  }

  .room-users {
    position: fixed;
    inset-inline-start: 0;
    inset-inline-end: 0;
    inset-block-start: 0;
    width: 100%;
    height: 100%;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 40;
  }

  .room-users.is-visible {
    transform: translateY(0);
  }

  .room-users__toggle {
    display: inline-flex;
  }

  .room-chat {
    padding: 1.5rem 1rem;
  }

  .room-chat__messages {
    max-height: calc(100vh - 280px);
  }

  .toast {
    inset-inline: 1rem;
    inset-block-end: 1rem;
  }
}
