:root {
  --bg: #F6F4F0;
  --bg-recessed: #EFECE6;
  --card: #FFFFFF;
  --text: #1F2430;
  --text-muted: #6B7280;
  --border: #E7E2D9;
  --brand: #3B82D6;
  --brand-hover: #2F6BB0;
  --brand-contrast: #FFFFFF;
  --danger: #D64545;
  --shadow: 0 10px 30px -12px rgba(31, 36, 48, 0.18);
  --bubble-other-bg: #F1EEE8;
  --bubble-other-text: #1F2430;

  --slot-0: #3B82D6;
  --slot-1: #1A9BAE;
  --slot-2: #D97D3D;
  --slot-3: #2F9E63;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Linear.app-style dark theme: deep neutral (not warm, not blue-black) base with
       subtly layered surfaces and a signature indigo accent. */
    --bg: #0A0A0B;
    --bg-recessed: #08090A;
    --card: #131315;
    --text: #F7F8F8;
    --text-muted: #93949D;
    --border: #232326;
    --brand: #4F9DFF;
    --brand-hover: #6BAFFF;
    --brand-contrast: #F7F8F8;
    --danger: #EF5A52;
    --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
    --bubble-other-bg: #1A1A1D;
    --bubble-other-text: #E1E1E2;

    --slot-0: #4F9DFF;
    --slot-1: #3FBEDB;
    --slot-2: #E2994D;
    --slot-3: #4CB782;
  }
}

@font-face {
  font-family: 'CNN Sans Display';
  src: url('/fonts/CNN-Sans-Display-Thin.ttf') format('truetype');
  font-weight: 100;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'CNN Sans Display';
  src: url('/fonts/CNN-Sans-Display-Light.ttf') format('truetype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'CNN Sans Display';
  src: url('/fonts/CNN-Sans-Display-LightItalic.ttf') format('truetype');
  font-weight: 300;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'CNN Sans Display';
  src: url('/fonts/CNN-Sans-Display-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'CNN Sans Display', 'Quicksand', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- Centered card views ---------- */

.center-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--card);
  border-radius: 24px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

#view-home .card {
  max-width: 500px;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.brand-stacked {
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}
.brand-sm { margin-bottom: 12px; }
.brand-mark {
  height: 34px;
  width: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.brand-mark-lg { height: 84px; width: 84px; }
.brand h1 { font-size: 27px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

.room-title {
  font-size: 23px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 26px;
}

.subtitle-tagline {
  white-space: nowrap;
  font-size: 14.5px;
}
@media (max-width: 480px) {
  .subtitle-tagline { font-size: 10.5px; }
}

.icon-btn {
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 46px;
  height: 46px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--border); }
.icon-btn:active { transform: scale(0.94); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--brand);
  color: var(--brand-contrast);
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn-secondary {
  background: var(--bg-recessed);
  color: var(--text);
  border: 1px solid var(--border);
  width: auto;
  white-space: nowrap;
}
.btn-secondary:hover { background: var(--border); }

.btn-text {
  background: transparent;
  color: var(--text-muted);
  margin-top: 12px;
  padding: 8px;
  font-weight: 500;
}
.btn-text:hover { color: var(--text); }

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 22px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.divider span { padding: 0 12px; }

.error-text {
  color: var(--danger);
  font-size: 13.5px;
  margin: 14px 0 0;
  text-align: center;
}

.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Chat view ---------- */

.chat-view {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chat-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-brand-icon {
  height: 24px;
  width: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.chat-room-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-room-name::before { content: '🎬 '; }

.participants {
  display: flex;
  gap: 10px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.participant-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.participant-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.participant-dot.offline { opacity: 0.3; }

.chat-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-pill {
  background: var(--bg-recessed);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.btn-pill:hover { background: var(--border); }
.btn-pill-muted { color: var(--text-muted); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  margin-bottom: 12px;
  position: relative;
}
.msg-row.own { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }

.msg-sender {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 4px;
  padding: 0 4px;
}

.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.own .msg-bubble, .other .msg-bubble {
  background: var(--bubble-other-bg);
}
.own .msg-bubble { color: var(--text-muted); border-bottom-right-radius: 5px; }
.other .msg-bubble { color: var(--bubble-other-text); border-bottom-left-radius: 5px; }

.msg-bubble.image-bubble, .msg-bubble.file-bubble {
  padding: 6px;
  background: var(--bubble-other-bg);
}

.msg-image {
  max-width: 260px;
  max-height: 320px;
  border-radius: 12px;
  display: block;
  cursor: pointer;
  object-fit: cover;
}

.file-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  text-decoration: none;
  color: inherit;
  min-width: 180px;
}
.file-icon { font-size: 24px; flex-shrink: 0; }
.file-meta { display: flex; flex-direction: column; min-width: 0; }
.file-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.file-size { font-size: 12px; opacity: 0.7; }

.link-preview-card {
  display: block;
  width: 260px;
  max-width: 100%;
  margin-top: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}
.link-preview-card:hover { border-color: var(--brand); }
.link-preview-image {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--bg-recessed);
}
.link-preview-body { padding: 10px 12px; }
.link-preview-site {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.link-preview-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-preview-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.msg-bubble a { color: inherit; text-decoration: underline; }

.react-trigger {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
  filter: grayscale(1);
  transition: opacity 0.15s ease, background 0.15s ease;
  flex-shrink: 0;
}
.react-trigger:hover, .react-trigger.force-visible { opacity: 1; background: var(--bg-recessed); }

@media (hover: none), (pointer: coarse) {
  .react-trigger { width: 30px; height: 30px; font-size: 15px; }
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  padding-bottom: 3px;
  flex-shrink: 0;
}

.reactions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 5px;
  padding: 0 4px;
}

.reaction-pill {
  background: var(--bubble-other-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s ease;
}
.reaction-pill.mine {
  background: color-mix(in srgb, var(--brand) 18%, var(--bubble-other-bg));
  border-color: var(--brand);
}
.reaction-pill:hover { filter: brightness(0.96); }

.reaction-popover {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  width: 248px;
  z-index: 200;
}

.reaction-popover button {
  background: none;
  border: none;
  font-size: 19px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.1s ease;
}
.reaction-popover button:hover { background: var(--bg-recessed); transform: scale(1.15); }

@media (hover: none), (pointer: coarse) {
  .reaction-popover { width: 280px; }
  .reaction-popover button { width: 40px; height: 40px; font-size: 20px; }
}

.system-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 10px 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.text-input {
  flex: 1;
  background: var(--bg-recessed);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 18px;
  resize: none;
  overflow-y: auto;
  max-height: 140px;
  line-height: 1.4;
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease;
}
.text-input:focus { border-color: var(--brand); }
.text-input::placeholder { color: var(--text-muted); }

.composer .icon-btn, .composer .send-btn {
  margin-bottom: 1px;
}

.send-btn {
  background: var(--brand);
  color: var(--brand-contrast);
  border: none;
  border-radius: 50%;
}
.send-btn:hover { background: var(--brand-hover); }

@media (max-width: 480px) {
  .card { padding: 28px 22px; border-radius: 18px; }
  .msg-row { max-width: 86%; }
}
