:root {
  --bg: #0b0d12;
  --stage: #12151c;
  --chat: #141820;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef1f7;
  --muted: #9aa3b5;
  --accent: #ff4d6d;
  --streamer: #7dd3fc;
  --viewer: #d7dde8;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Noto Sans SC", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}
body { overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  height: 100dvh;
  max-height: 100vh;
}

.stage {
  position: relative;
  background: var(--stage);
  overflow: hidden;
  min-height: 0;
}

.stage-bg { position: absolute; inset: 0; }
.bg-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.9) brightness(0.55);
}
.bg-veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 70%, rgba(20, 24, 40, 0.15), rgba(8, 10, 16, 0.72) 70%),
    linear-gradient(180deg, rgba(0,0,0,0.25), transparent 30%, rgba(0,0,0,0.45));
}

.stage-hud {
  position: absolute;
  z-index: 3;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 40, 70, 0.92);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 0 rgba(255,255,255,0.7);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.55); }
  70% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}
.hud-meta {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  font-size: 13px;
  color: var(--muted);
}
.hud-meta span { color: #fff; font-weight: 600; }

.character-wrap {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: end center;
  padding: 0 4% 4%;
  pointer-events: none;
}
.character-poster,
.character-video {
  grid-area: 1 / 1;
  width: min(78vh, 640px);
  height: auto;
  max-height: 92%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 18px 40px rgba(0,0,0,0.45));
}
.character-poster {
  opacity: 1;
  transition: opacity 0.3s ease;
}
.character-poster.is-hidden { opacity: 0; }
.character-video {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.character-video.is-active { opacity: 1; }

.stage-caption {
  position: absolute;
  z-index: 3;
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(10,12,18,0.55);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
}
.stage-caption strong { font-size: 15px; }
.stage-caption span { font-size: 12px; color: var(--muted); }

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--chat);
  border-left: 1px solid var(--line);
}
.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.chat-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}
.chat-sub {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.room-tag {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(125, 211, 252, 0.12);
  color: var(--streamer);
  font-size: 12px;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.msg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  align-items: baseline;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg .name {
  font-size: 12px;
  font-weight: 650;
  color: #a8b3c7;
}
.msg.is-streamer .name { color: var(--streamer); }
.msg .badge {
  display: inline-block;
  margin-right: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(125, 211, 252, 0.18);
  color: var(--streamer);
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
}
.msg .body {
  grid-column: 2;
  font-size: 14px;
  line-height: 1.45;
  color: var(--viewer);
  word-break: break-word;
}
.msg.is-system .name { color: #fbbf24; }
.msg.is-system .body { color: #fde68a; font-size: 13px; }

.chat-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 14px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(0,0,0,0.18);
}
.chat-input input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}
.chat-input button {
  border: 0;
  border-radius: 12px;
  padding: 0 16px;
  background: rgba(255,255,255,0.08);
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(48vh, 56vh) minmax(42vh, 1fr);
    height: auto;
    min-height: 100dvh;
  }
  .chat { border-left: 0; border-top: 1px solid var(--line); }
  .character-poster,
  .character-video {
    width: min(78vw, 420px);
    max-height: 85%;
  }
}
