:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #141b24;
  --panel-2: #1b2430;
  --line: #26313f;
  --text: #e8eef6;
  --muted: #8fa1b5;
  --accent: #4f8cff;
  --accent-2: #2f6be0;
  --danger: #ff8f88;
  --ok: #38c172;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #17263c 0%, var(--bg) 55%);
  color: var(--text);
  font:
    15px/1.45 ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

[hidden] {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.85);
  backdrop-filter: blur(10px);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tag {
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.status.connected {
  color: var(--ok);
  border-color: rgba(56, 193, 114, 0.4);
}

.status.connecting,
.status.reconnecting {
  color: #ffcc66;
  border-color: rgba(255, 204, 102, 0.4);
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px;
}

.lobby {
  display: grid;
  gap: 18px;
  max-width: 760px;
  margin: 24px auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-head h2 {
  margin: 0;
}

.field {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

input {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 10px 14px;
  background: var(--panel-2);
  color: var(--text);
}

button:hover:not(:disabled) {
  border-color: #3a4b60;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-2);
}

button.danger {
  background: transparent;
  border-color: #5a2a2a;
  color: var(--danger);
}

button.ghost {
  background: transparent;
}

button.small {
  padding: 6px 10px;
  font-size: 13px;
}

.create-row {
  display: flex;
  gap: 10px;
}

.create-row input {
  margin-top: 0;
  flex: 1;
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}

.room-item strong {
  display: block;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.room-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.room-head h2 {
  margin-bottom: 2px;
}

.room-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.room-body {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 14px;
  height: calc(100dvh - 165px);
  min-height: 420px;
}

.participants {
  overflow: auto;
}

.participants ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.participant {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.p-name {
  font-weight: 600;
  font-size: 14px;
}

.p-icons {
  margin-left: auto;
  font-size: 13px;
}

.badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
}

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  max-width: 85%;
}

.message .who {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

.message .text {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 8px 11px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.mine {
  align-self: flex-end;
}

.message.mine .who {
  text-align: right;
}

.message.mine .text {
  background: #1d3358;
  border-color: #2c4a7a;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer input {
  margin-top: 0;
}

.call-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(720px, calc(100vw - 36px));
  max-height: calc(100dvh - 36px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.call-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}

.call-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.call-tile {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #000;
  border-radius: 10px;
}

.call-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.call-name {
  position: absolute;
  left: 6px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 12px;
}

.call-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.call-actions button {
  flex: 1;
  padding: 8px 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 30;
  background: #e9eef7;
  color: #10151c;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
}

@media (max-width: 760px) {
  main {
    padding: 12px;
  }

  .room-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: calc(100dvh - 175px);
  }

  .participants {
    padding: 10px;
  }

  .participants ul {
    display: flex;
    overflow-x: auto;
    gap: 8px;
  }

  .participant {
    min-width: max-content;
  }

  .call-panel {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}

/* ---- reactions ---- */

.call-actions .reaction-button {
  flex: 0 0 auto;
  padding: 6px 8px;
  font-size: 18px;
  line-height: 1;
}

.reaction {
  position: absolute;
  left: 50%;
  bottom: 34px;
  font-size: 34px;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
  animation: reaction-float 2.4s ease-out forwards;
}

@keyframes reaction-float {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.6);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.15);
  }
  70% {
    opacity: 1;
    transform: translate(-50%, -8px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -30px) scale(0.95);
  }
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.message.mine .msg-reactions {
  justify-content: flex-end;
}

.chip {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

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

.chip.mine {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.18);
}

.chip.add {
  color: var(--muted);
}

.reaction-picker {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.message.mine .reaction-picker {
  justify-content: flex-end;
}

/* ---- voice notes ---- */

.message .text audio {
  display: block;
  width: 100%;
  min-width: 220px;
  max-width: 280px;
}

#recordBtn.recording {
  border-color: #e5484d;
  color: #e5484d;
}

.voice-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}

.voice-preview audio {
  flex: 1;
  min-width: 0;
  height: 34px;
}

.voice-preview button {
  flex: 0 0 auto;
  padding: 6px 10px;
}

.outbox-notice {
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}

/* ---- mentions ---- */

mark.mention {
  background: rgba(79, 140, 255, 0.28);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
}

.mention-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}

.mention-option {
  font: inherit;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

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

.message.mentioned {
  background: rgba(79, 140, 255, 0.12);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 6px 8px;
  max-width: 88%;
}

/* ---- Discord-style grouping + hover reactions ---- */

.message.grouped {
  margin-top: -6px;
}

/* Reactions stay out of the way until you hover the message. */
.msg-reactions {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.message:hover .msg-reactions,
.message:focus-within .msg-reactions,
.msg-reactions.has-reactions {
  opacity: 1;
  pointer-events: auto;
}

/* The "+" is the action, so it only appears on hover even when chips are shown. */
.msg-reactions .chip.add {
  opacity: 0;
  transition: opacity 0.12s ease;
}

.message:hover .msg-reactions .chip.add,
.message:focus-within .msg-reactions .chip.add {
  opacity: 1;
}

.room-actions-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

/* ---- plans, usage and ads ---- */

.field select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.usage {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
}

.usage-line {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.usage button {
  justify-self: start;
}

.ad-slot {
  margin-top: 14px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: rgba(79, 140, 255, 0.06);
}

.ad-tag {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ad-slot p {
  margin: 6px 0 8px;
  font-size: 12px;
  line-height: 1.4;
}
