@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --bg: #2a1713;
  --bg-deep: #1b0d0a;
  --bg-raised: #382019;
  --panel: #43281e;
  --border: #805334;
  --text: #f8efe0;
  --muted: #c4a98c;
  --accent: #d49b5d;
  --accent-hover: #e3b678;
  --accent-ink: #2b160e;
  --sunny: #e8c27f;
  --danger: #FF6B6B;
  --radius: 14px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --display: 'Fredoka', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
  --pop-shadow: 4px 4px 0 rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background-color: #2a1713;
  background-image:
    radial-gradient(circle at 8% 0%, rgba(213,151,82,0.28) 0%, transparent 32%),
    radial-gradient(circle at 92% 20%, rgba(126,61,35,0.34) 0%, transparent 42%),
    linear-gradient(135deg, #3d2119 0%, #2a1713 48%, #1f100d 100%);
  color: var(--text);
  font-family: var(--body);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

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

/* ---------- Background texture (shared) ---------- */
.landing, .room-body {
  position: relative;
  background: transparent;
}
.landing::before, .room-body::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: radial-gradient(rgba(255,255,255,0.045) 1px, transparent 1px);
  background-size: 18px 18px;
  z-index: 0;
}

/* ---------- Topbar ---------- */
.topbar, .room-topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  padding: 8px 24px 0;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 0 auto;
  padding-top: 0;
}
.brand.small { font-size: 1.05rem; }

.brand-logo {
  display: block;
  width: min(520px, 76vw);
  height: auto;
  filter: none;
}

.brand-logo-wrap {
  width: min(520px, 76vw);
  height: 185px;
  overflow: hidden;
  position: relative;
}
.brand-logo-wrap .brand-logo {
  position: absolute;
  top: -150px;
  left: 0;
}

.brand-logo-small {
  width: min(180px, 32vw);
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--sunny));
  box-shadow: var(--pop-shadow);
  transform: rotate(-6deg);
  flex-shrink: 0;
}

/* ---------- Landing ---------- */
.landing {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px 56px;
  text-align: center;
}
.landing > * { position: relative; z-index: 1; }

.decor {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  user-select: none;
  object-fit: contain;
  filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.35));
}
.decor-left {
  width: 190px;
  left: max(12px, calc(50% - 570px));
  top: 235px;
}
.decor-right {
  width: 260px;
  right: max(12px, calc(50% - 570px));
  top: 410px;
}

.kicker {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--accent-ink);
  background: var(--sunny);
  border-radius: 999px;
  padding: 5px 14px;
  transform: rotate(-2deg);
  margin: 0 0 12px;
  box-shadow: var(--pop-shadow);
}

.hero h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}
.hero h1 .hl {
  color: #db754d;
  display: inline-block;
  transform: rotate(-2deg);
}

.lede {
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 24px;
}

.hero {
  max-width: 760px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 20px;
  max-width: 610px;
  margin: 0 auto;
  padding: 22px 24px;
  text-align: left;
  box-shadow: var(--pop-shadow);
}

.discord-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 18px;
  width: 100%;
  padding: 12px 18px;
  border-radius: 12px;
  background: #684b9b;
  color: #fff8ed;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: var(--pop-shadow);
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}

input {
  width: 100%;
  background: var(--bg-raised);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 0.98rem;
  outline: none;
  transition: border-color 0.15s ease;
}
input:focus-visible {
  border-color: var(--accent);
}
input::placeholder { color: #59648A; }

.code-input {
  font-family: var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.btn {
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 0.98rem;
  font-weight: 600;
  font-family: var(--display);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translate(2px, 2px); box-shadow: none !important; }
.btn:disabled { opacity: 0.6; cursor: default; }

.btn.primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--pop-shadow);
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.large { padding: 16px 28px; font-size: 1.05rem; }

.btn.secondary {
  background: var(--bg-raised);
  color: var(--text);
  border: 2px solid var(--border);
}
.btn.secondary:hover { border-color: var(--accent); }

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 2px solid var(--border);
  font-family: var(--body);
  font-weight: 600;
}
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }

.btn.danger {
  background: rgba(255, 107, 107, 0.14);
  color: var(--danger);
  border: 2px solid rgba(255, 107, 107, 0.35);
  font-family: var(--body);
  font-weight: 600;
}
.btn.danger:hover { background: rgba(255, 107, 107, 0.22); }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  margin: 16px 0;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--border);
}

.join-row { display: flex; gap: 10px; }
.join-row .code-input { flex: 1; }
.join-row .btn { width: auto; white-space: nowrap; }

.form-error {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 500;
}

.how {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  max-width: 760px;
  margin: 34px auto 0;
  text-align: left;
}
.how-item {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.how-num {
  display: block;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--sunny);
  margin-bottom: 8px;
}
.how-item p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0;
}

@media (max-width: 640px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .brand-logo-wrap {
    width: min(440px, 90vw);
    height: 150px;
  }
  .brand-logo-wrap .brand-logo {
    top: -128px;
  }
  .landing { padding-left: 16px; padding-right: 16px; }
  .decor { display: none; }
  .hero h1 { font-size: clamp(2rem, 10vw, 2.8rem); }
  .lede { font-size: 0.98rem; }
  .panel { padding: 18px; }
  .how { grid-template-columns: 1fr; }
  .join-row { flex-direction: column; }

  .room-topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 14px;
  }
  .room-topbar .brand { grid-column: 1 / -1; justify-content: center; }
  .room-topbar .room-code-chip { justify-self: start; }
  .room-topbar .room-actions { justify-self: end; gap: 6px; }
  .room-topbar .status { display: none; }
  .room-topbar .btn { padding: 9px 10px; font-size: 0.82rem; }
  .room-layout { min-height: 0; }
  .sidebar { width: 150px; padding: 16px 12px; }
  .stage { padding: 18px 12px; }
}

/* ---------- Room ---------- */
.room-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.room-body > * { position: relative; z-index: 1; }

.room-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: center;
  position: relative;
  border-bottom: 2px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
  background: rgba(31, 20, 16, 0.82);
  backdrop-filter: blur(6px);
}
.room-topbar .room-code-chip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
.room-topbar .room-actions { grid-column: 3; justify-self: end; }

.room-code-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  background: var(--bg-raised);
  border: 2px solid var(--border);
  border-radius: 999px;
  padding: 7px 8px 7px 16px;
}
.room-code-chip button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: normal;
  cursor: pointer;
}

.room-actions { display: flex; align-items: center; gap: 12px; }

.status {
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 500;
}
.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status.online { color: var(--text); }
.status.online::before { background: #4ADE80; box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.2); }

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

.sidebar {
  width: 310px;
  flex-shrink: 0;
  border-right: 2px solid var(--border);
  padding: 22px 18px;
  overflow-y: auto;
  background: rgba(67, 40, 30, 0.24);
}
.sidebar h2 {
  font-family: var(--display);
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 14px;
}

.user-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.user-list-header,
.user-row {
  display: grid;
  grid-template-columns: 28px 54px minmax(0, 1fr) 48px auto;
  align-items: center;
  gap: 6px;
}
.user-list-header {
  padding: 0 4px 8px;
  border-bottom: 1px solid rgba(128, 83, 52, 0.65);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.03em;
}
.user-row {
  display: flex;
  font-size: 0.9rem;
  font-weight: 500;
}
.user-row { display: grid; }
.presence-icon,
.share-icon {
  color: #806f63;
  text-align: center;
  font-size: 0.9rem;
}
.presence-icon.on { color: #4ade80; }
.share-icon.on { color: var(--sunny); }
.user-name {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.ping-value {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.63rem;
  text-align: right;
  white-space: nowrap;
}
.watch-btn {
  justify-self: end;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--bg-raised);
  color: var(--muted);
  font-size: 0.68rem;
  cursor: pointer;
}
.watch-btn:hover { color: var(--text); border-color: var(--accent); }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--sunny));
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  transform: rotate(-4deg);
}
.live-tag {
  margin-left: auto;
  font-size: 0.68rem;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--sunny);
  border-radius: 999px;
  padding: 3px 9px;
}

.stage {
  flex: 1;
  min-width: 0;
  padding: 40px;
  overflow: hidden;
  display: flex;
  position: relative;
  align-items: center;
  justify-content: center;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(560px, calc(100% - 80px));
  margin: 0;
  text-align: center;
  transform: translate(-50%, -50%);
}
.empty-title { font-family: var(--display); font-weight: 600; font-size: 1.2rem; margin: 0 0 8px; }
.empty-sub { color: var(--muted); font-size: 0.95rem; margin: 0 auto 28px; line-height: 1.5; max-width: 460px; }
.empty-state .btn.large { width: min(360px, 100%); padding: 18px 32px; font-size: 1.08rem; margin: 0 auto; }
.media-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.media-actions .btn.large { width: auto; margin: 0; }
.media-message { color: var(--danger); font-size: 0.86rem; line-height: 1.4; margin: 14px auto 0; max-width: 480px; }
.active-media-actions {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 2;
  display: flex;
  gap: 8px;
  max-width: calc(100% - 24px);
  overflow-x: auto;
  transform: translateX(-50%);
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(31, 20, 16, 0.9);
  backdrop-filter: blur(6px);
}
.active-media-actions[hidden] { display: none; }
.active-media-actions button[hidden] { display: none; }
.active-media-actions .btn { white-space: nowrap; }

body[data-device="mobile"] .room-topbar { padding-left: 12px; padding-right: 12px; }
body[data-device="mobile"] .active-media-actions { bottom: 10px; gap: 6px; }
body[data-device="mobile"] .active-media-actions .btn { padding: 9px 11px; font-size: 0.78rem; }
body[data-device="mobile"] .media-actions { flex-direction: column; }
body[data-device="mobile"] .media-actions .btn.large { width: 100%; }

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 16px;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  align-content: start;
  overflow: hidden;
}

.tile {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  height: 100%;
  max-width: 100%;
  box-shadow: var(--pop-shadow);
}
.tile video {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}
.tile .tile-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(11, 18, 32, 0.8);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tile .tile-label::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--sunny);
}
.tile-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(11, 18, 32, 0.8);
  color: var(--text);
  font-size: 0.72rem;
  cursor: pointer;
}
.tile-close:hover { background: var(--danger); color: #fff; }

@media (max-width: 640px) {
  .room-topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px 14px;
  }
  .room-topbar .room-code-chip { grid-column: 1; position: static; transform: none; justify-self: center; }
  .room-topbar .room-actions { grid-column: 1; justify-self: center; gap: 6px; }
  .room-topbar .status { display: none; }
  .room-topbar .btn { padding: 9px 10px; font-size: 0.82rem; }
  .room-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 170px;
    padding: 12px 10px;
    border-right: 0;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
    overflow-y: auto;
  }
  .sidebar h2 { margin-bottom: 9px; }
  .user-list-header { display: none; }
  .user-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 8px;
  }
  .user-row {
    min-height: 38px;
    padding: 4px 6px;
    border: 1px solid rgba(128, 83, 52, 0.55);
    border-radius: 10px;
    background: rgba(67, 40, 30, 0.42);
  }
  .stage {
    width: 100%;
    min-height: 0;
    flex: 1;
    padding: 10px;
  }
  .video-grid {
    grid-template-columns: 1fr;
    height: auto;
    max-height: 100%;
    align-content: start;
  }
  .tile { height: auto; }
  .tile video { height: auto; aspect-ratio: 16 / 9; }
  .active-media-actions {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
    transform: none;
    justify-content: flex-start;
  }
  .active-media-actions .btn { flex: 0 0 auto; }
  .empty-state { width: calc(100% - 28px); }
}
