:root {
  color-scheme: dark;
  --bg: #0b0c10;
  --panel: #14161c;
  --text: #f5f6f8;
  --muted: #a4a8b3;
  --line: rgba(255, 255, 255, 0.08);
  --red: #ff3b5c;
  --green: #3dd68c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

button, input { font: inherit; }

.hidden { display: none !important; }

.room {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #000;
}

.stage {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.like-btn, .overlay {
  position: absolute;
  z-index: 5;
}

.stage-top {
  position: absolute;
  z-index: 8;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}

.title-block {
  min-width: 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
}

.room-title {
  font-size: 16px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-count, .badge, .like-btn {
  color: #fff;
  font-size: 13px;
}

.viewer-count { color: var(--muted); margin-top: 2px; }

.badge {
  position: static;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
}

.badge::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 59, 92, 0.18);
}

.like-btn {
  border: 0;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.5);
}

.stage-actions {
  position: absolute;
  z-index: 12;
  right: 12px;
  bottom: 92px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  min-width: 52px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 13px;
  line-height: 30px;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
}

.icon-btn.is-off {
  color: #a4a8b3;
}

.room.is-portrait {
  display: block;
}

.room.is-portrait video {
  object-fit: cover;
  object-position: center;
}

.room.is-portrait .stage {
  height: 100dvh;
  aspect-ratio: auto;
  margin: 0 auto;
  max-width: min(100%, calc(100dvh * 9 / 16));
}

.room.is-portrait .chat {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 38%;
  background: linear-gradient(to top, rgba(8, 9, 12, 0.62) 22%, rgba(8, 9, 12, 0.18) 58%, rgba(8, 9, 12, 0));
}

.room.is-portrait .like-btn {
  bottom: calc(38% + 12px);
}

.room.is-portrait .stage-actions {
  bottom: calc(38% + 88px);
}

.room.is-portrait .heart {
  bottom: 42%;
}

.like-btn {
  right: 12px;
  bottom: 16px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.like-btn strong { font-size: 13px; }

.overlay {
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 22vh 24px 0;
  background: rgba(0, 0, 0, 0.38);
  text-align: center;
}

.overlay p {
  margin: 0;
  max-width: 520px;
  font-size: 20px;
  line-height: 1.5;
}

.chat {
  position: relative;
  z-index: 4;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom);
}

.chat-head, .chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.chat-head { color: var(--muted); font-size: 13px; }
.chat-head span:first-child { color: var(--text); font-weight: 650; }
#online-count { margin-right: auto; }

.chat-head button, .chat-form button {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 0 12px 8px;
}

.msg {
  margin: 6px 0;
  line-height: 1.45;
  word-break: break-word;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}
.nick { color: #8eb6ff; }

.chat-form input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  outline: none;
}

.chat-form button { background: var(--red); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
}

.modal-card {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 16px;
  background: #1b1d24;
}

.modal-card h2 { margin: 0 0 8px; font-size: 20px; }
.modal-card p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

.nick-row {
  display: flex;
  gap: 8px;
}

.modal-card input {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #101116;
  color: var(--text);
}

.modal-card #nick-roll {
  flex: none;
  width: auto;
  margin-top: 0;
  background: #2a2d36;
}

.modal-card button {
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 10px;
  padding: 12px;
  background: var(--red);
  color: white;
  cursor: pointer;
}

.my-nick {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.hearts { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.heart {
  position: absolute;
  bottom: 18%;
  color: #ff6b84;
  font-size: 22px;
  animation: float 1s ease-out forwards;
}

@keyframes float {
  to { transform: translateY(-120px); opacity: 0; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.8);
}

.home { min-height: 100dvh; padding: 28px 16px 48px; }
.home-head h1 { margin: 0; font-size: 28px; }
.home-head p { color: var(--muted); }
.empty { color: var(--muted); }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  overflow: hidden;
  border-radius: 14px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}
.cover {
  height: 132px;
  background: #23262f center/cover no-repeat;
}
.card-body { display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.card-body span { color: var(--muted); font-size: 13px; }

@media (min-width: 960px) {
  .room {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    background: var(--bg);
  }
  .stage { height: 100dvh; aspect-ratio: auto; }
  .chat {
    position: static;
    height: 100dvh;
    background: var(--panel);
    border-left: 1px solid var(--line);
  }
  .stage-top { padding-right: 0; }
  .like-btn { bottom: 18px; }
  .stage-actions { bottom: 94px; }
  .room.is-portrait {
    display: flex;
    justify-content: center;
    background: #000;
  }
  .room.is-portrait .stage {
    width: min(100%, calc(100dvh * 9 / 16));
    height: 100dvh;
  }
  .room.is-portrait .chat {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(100%, calc(100dvh * 9 / 16));
    height: 38%;
    background: linear-gradient(to top, rgba(8, 9, 12, 0.62) 22%, rgba(8, 9, 12, 0.18) 58%, rgba(8, 9, 12, 0));
    border-left: 0;
  }
  .room.is-portrait .like-btn {
    bottom: calc(38% + 12px);
  }
  .room.is-portrait .stage-actions {
    bottom: calc(38% + 88px);
  }
  .overlay { align-items: center; padding-top: 0; }
  .badge { position: static; }
  .stage-top .badge { pointer-events: none; }
}
