:root {
  /* Palette: neutral dark slate with a single blue accent */
  --ink: #0f1115;
  --surface: #171a21;
  --raised: #222630;
  --line: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa1ad;
  --accent: #3b82f6;
  --accent-strong: #5b96f8;
  --on-accent: #ffffff;
  --accent-ring: rgba(59, 130, 246, 0.25);
  --live: #22c55e;
  --danger: #ef5350;
  --field: #0b0d11;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --chat-width: 350px;
  --chat-collapsed-width: 45px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  background: var(--ink);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1,
h2 {
  line-height: 1.2;
  letter-spacing: -0.015em;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-strong);
}

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

input {
  font: inherit;
}

input[type="text"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--text);
  font-size: 15px;
}

input[type="text"]::placeholder {
  color: #5f6673;
}

input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring);
}

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  transition: background-color 0.15s;
}

button:hover {
  background: var(--line);
}

.button-primary {
  background: var(--accent);
  color: var(--on-accent);
}

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

.button-link {
  display: inline-block;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-decoration: none;
}

.button-link:hover {
  background: var(--accent-strong);
  color: var(--on-accent);
}

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

/* ---------- Top bar & brand ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:hover {
  color: inherit;
}

.brand-icon {
  color: var(--accent);
  flex-shrink: 0;
}

/* The "meeting is live" indicator used in the room bar and the landing preview */
.live-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
}

/* ---------- Landing ---------- */

.landing {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 64px;
}

.landing-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  align-items: center;
  gap: 56px;
  padding: 80px 0 88px;
}

.landing-hero h1 {
  margin: 0 0 20px;
  font-size: clamp(36px, 4.6vw, 56px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.hero-lede {
  max-width: 34em;
  margin: 0 0 32px;
  font-size: 18px;
  color: var(--muted);
}

.create-room {
  max-width: 560px;
}

.create-room-label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.create-room-fields {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.create-room input {
  flex: 1;
  min-width: 0;
  padding: 13px 14px;
  font-size: 16px;
}

.create-room button {
  padding: 13px 22px;
  font-size: 16px;
  white-space: nowrap;
}

.create-room-terms {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.cf-turnstile {
  margin-bottom: 16px;
}

/* A small, static picture of the room the form creates */
.room-preview {
  padding: 14px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.6);
}

.room-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 14px;
  font-weight: 600;
  min-width: 0;
}

.room-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preview-tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: var(--raised);
}

.preview-tile-you {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.preview-initial {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 18px;
  font-weight: 600;
}

.preview-label {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 1px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.5);
  font-size: 12px;
}

.room-preview-link {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-preview-link span {
  color: var(--text);
}

.landing-features {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 56px;
}

.feature {
  padding: 22px 0 26px;
  border-top: 1px solid var(--line);
}

.feature h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
}

.feature p {
  max-width: 36em;
  margin: 0;
  color: var(--muted);
}

.landing-steps {
  margin-bottom: 72px;
}

.landing-steps h2 {
  margin: 0 0 24px;
  font-size: 24px;
  font-weight: 600;
}

.landing-steps ol {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.landing-steps li {
  counter-increment: step;
  color: var(--muted);
}

.landing-steps li::before {
  content: counter(step);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  background: var(--raised);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.landing-steps li strong {
  display: block;
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 860px) {
  .landing-hero {
    grid-template-columns: 1fr;
    gap: 48px;
    padding: 48px 0 64px;
  }

  .room-preview {
    max-width: 440px;
    }

  .landing-features {
    grid-template-columns: 1fr;
  }

  .landing-steps ol {
    grid-template-columns: 1fr;
    gap: 24px;
  }
}

@media (max-width: 480px) {
  .landing {
    padding: 0 16px 48px;
  }

  .topbar {
    padding: 12px 16px;
  }

  .create-room-fields {
    flex-direction: column;
  }
}

/* ---------- Footer, legal, 404 ---------- */

.site-footer {
  padding: 24px 16px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 16px 56px;
  line-height: 1.65;
  color: var(--muted);
}

.legal h1,
.legal h2 {
  color: var(--text);
}

.legal h1 {
  font-size: 40px;
  letter-spacing: -0.02em;
}

.legal h2 {
  margin-top: 32px;
  font-size: 21px;
}

.legal li {
  margin-bottom: 8px;
}

.legal-updated {
  font-size: 14px;
}

.auth-container {
  max-width: 380px;
  margin: 80px auto;
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius-lg);
}

.auth-container h1 {
  margin-top: 0;
  font-size: 48px;
  color: var(--text);
}

/* ---------- Cookie banner ---------- */

.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 16px 24px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 32px -16px rgba(0, 0, 0, 0.6);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.cookie-banner.is-visible {
  transform: translateY(0);
}

.cookie-banner[hidden] {
  display: none;
}

.cookie-banner-text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.cookie-banner-actions {
  display: flex;
  gap: 8px;
}

.cookie-banner-actions button {
  padding: 8px 18px;
  font-size: 14px;
}

@media (max-width: 480px) {
  .cookie-banner {
    padding: 14px 16px;
  }

  .cookie-banner-actions {
    width: 100%;
  }

  .cookie-banner-actions button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cookie-banner {
    transition: none;
  }
}

/* ---------- Room ---------- */

/* The room page fills the viewport so the video grid can size to the space left */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.room-topbar {
  padding: 10px 16px 10px 20px;
  background: var(--surface);
}

.room-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.room-name {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invite-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.invite-bar label {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}

.invite-bar input {
  flex: 1;
  min-width: 0;
  max-width: 320px;
  padding: 7px 10px;
  font-size: 14px;
}

.invite-bar button {
  padding: 7px 14px;
  font-size: 14px;
}

.leave-link {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(239, 83, 80, 0.5);
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.leave-link:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

@media (max-width: 760px) {
  .room-topbar {
    flex-wrap: wrap;
  }

  .room-title {
    flex: 1;
  }

  .invite-bar {
    order: 3;
    flex-basis: 100%;
  }

  .invite-bar input {
    max-width: none;
  }
}

.room {
  display: flex;
  gap: 20px;
  padding: 20px;
  align-items: flex-start;
}

.room-page .room {
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

.room-stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.video-grid-wrap {
  flex: 1;
  min-height: 0;
  container-type: size;
  overflow-y: auto;
}

.video-grid {
  --grid-gap: 12px;
  /* --grid-cols/--grid-rows are set from room-client.js based on the number of tiles.
     Each tile is as wide as fits both across and down the available space at 4:3. */
  --tile-width: min(
    (100cqw - (var(--grid-cols, 2) - 1) * var(--grid-gap)) / var(--grid-cols, 2),
    (100cqh - (var(--grid-rows, 1) - 1) * var(--grid-gap)) / var(--grid-rows, 1) * 4 / 3
  );
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 2), var(--tile-width));
  justify-content: center;
  align-content: center;
  min-height: 100%;
  gap: var(--grid-gap);
}

.video-tile {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

/* Your own tile gets an accent edge */
.video-tile.has-controls {
  box-shadow: inset 0 0 0 2px var(--accent);
}

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

.video-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.video-tile .controls {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  gap: 8px;
  margin-top: 0;
}

.video-tile .controls button {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
}

.video-tile .controls button:hover {
  background: var(--accent);
  color: var(--on-accent);
}

/* Controls stay hidden until they're moved onto the local tile and its video loads */
.room-stage > .controls,
.video-tile.loading .controls {
  display: none;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}

.video-tile.loading .video-placeholder {
  display: flex;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }

  button {
    transition: none;
  }
}

/* Move the name label to the top so it doesn't collide with the controls */
.video-tile.has-controls .video-label {
  top: 10px;
  bottom: auto;
}

/* ---------- Chat panel ---------- */

/* Sits flush against the right edge, spanning the room's full height */
.chat {
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  width: var(--chat-width);
  margin: -20px -20px -20px 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: hidden;
}

.room.chat-collapsed .chat {
  width: var(--chat-collapsed-width);
}

.room.chat-collapsed .chat-messages,
.room.chat-collapsed .chat-form {
  display: none;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  height: var(--chat-collapsed-width);
  padding: 0 8px 0 20px;
  border-bottom: 1px solid var(--line);
}

/* Collapsed: a narrow strip with the toggle on top and "Chat" running down */
.room.chat-collapsed .chat-header {
  flex-direction: column-reverse;
  justify-content: flex-end;
  gap: 10px;
  height: auto;
  padding: 8px 0;
  border-bottom: none;
}

/* Collapsed: the two-bubble icon stands in for the "Chat" label */
.chat-icon {
  display: none;
}

.room.chat-collapsed .chat-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.room.chat-collapsed .chat-icon {
  display: block;
  color: var(--muted);
}

.room.chat-collapsed .chat-label {
  display: none;
}

.room.chat-collapsed .chat-unread {
  margin: 0;
}

.chat-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.chat-unread {
  display: inline-block;
  min-width: 20px;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
}

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

.chat-toggle {
  padding: 4px 12px;
  background: none;
  color: var(--muted);
  font-size: 14px;
}

.chat-toggle:hover {
  background: none;
  color: var(--text);
}

.chat-messages {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 12px 20px;
  overflow-y: auto;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

.chat-meta {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
}

.chat-author {
  font-weight: 600;
  color: var(--text);
}

.chat-time {
  color: var(--muted);
  font-size: 12px;
}

.chat-text {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
}

.chat-form button {
  padding: 8px 16px;
  background: var(--accent);
  color: var(--on-accent);
}

.chat-form button:hover {
  background: var(--accent-strong);
}

.chat-form button:disabled {
  opacity: 0.6;
  cursor: default;
}

.chat-form .chat-attach {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  color: var(--muted);
}

.chat-form .chat-attach:hover {
  background: var(--raised);
  color: var(--text);
}

.chat-form .chat-attach:disabled:hover {
  background: none;
}

.chat-attachment {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-basis: 100%;
  min-width: 0;
  padding: 4px 4px 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--raised);
  font-size: 13px;
}

.chat-attachment[hidden],
.chat-attachment-remove[hidden] {
  display: none;
}

.chat-attachment-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-form .chat-attachment-remove {
  padding: 0 8px;
  background: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.4;
}

.chat-form .chat-attachment-remove:hover {
  background: none;
  color: var(--text);
}

.chat-file {
  display: flex;
  align-items: baseline;
  gap: 8px;
  max-width: 100%;
  margin-top: 2px;
  text-decoration: none;
}

.chat-file:hover .chat-file-name {
  text-decoration: underline;
}

.chat-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-file-size {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 800px) {
  .room {
    flex-direction: column;
    align-items: stretch;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Too narrow for a side column: the chat slides over the video from the right */
  .chat {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    width: min(var(--chat-width), 100vw);
    margin: 0;
  }

  .room.chat-collapsed .chat {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    border: 1px solid var(--line);
    border-right: none;
    border-radius: var(--radius) 0 0 var(--radius);
  }
}

/* ---------- Name prompt ---------- */

.name-prompt {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
}

.name-prompt-box {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px -24px rgba(0, 0, 0, 0.8);
}

.name-prompt-box h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.name-prompt-hint {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
}

.name-prompt-box label {
  display: block;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 600;
}

.name-prompt-box input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font-size: 16px;
}

.name-prompt-box button {
  width: 100%;
  padding: 12px 18px;
  font-size: 16px;
}
