:root {
  color-scheme: dark;
  font-family: Inter, "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  background: #0b0d12;
  color: #f4f6fb;
  --surface: #131720;
  --surface-soft: #191e29;
  --border: #29303d;
  --muted: #9aa4b4;
  --accent: #ff3b5f;
  --accent-soft: rgba(255, 59, 95, 0.14);
  --success: #72d6a0;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at 85% 0%, rgba(255, 59, 95, 0.09), transparent 30rem), #0b0d12;
}
button, input { font: inherit; }

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 56px;
}
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}
h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.7rem); line-height: 1.15; letter-spacing: -0.035em; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 112px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}
.status-dot { width: 9px; height: 9px; border: 2px solid currentColor; border-radius: 50%; }
.status-live { color: #ff6a82; border-color: rgba(255, 59, 95, 0.42); background: var(--accent-soft); }
.status-live .status-dot {
  border: 0;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(255, 59, 95, 0.12);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 60%, 100% { box-shadow: 0 0 0 10px rgba(255, 59, 95, 0); } }

.quiet-button {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  cursor: pointer;
}
.quiet-button:hover { color: #f4f6fb; border-color: #465064; }

.stream-card {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "video chat" "composer chat";
  height: clamp(480px, 48vw, 680px);
  max-height: calc(100dvh - 180px);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}
.video-frame {
  grid-area: video;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #050608;
}
video { display: block; width: 100%; height: 100%; object-fit: contain; background: #050608; }
.stream-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.offline-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  background: linear-gradient(145deg, #0d1016, #08090c);
}
.offline-panel.hidden, .play-hint.hidden { display: none; }
.offline-icon { margin-bottom: 16px; color: #687386; font-size: 3.1rem; line-height: 1; }
.offline-panel p { margin: 0 0 8px; font-size: 1.2rem; font-weight: 700; }
.offline-panel span { color: var(--muted); font-size: 0.95rem; }
.play-hint {
  position: absolute;
  left: 50%;
  bottom: 62px;
  z-index: 3;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 10, 14, 0.82);
  color: #eef1f6;
  font-size: 0.86rem;
  text-align: center;
  pointer-events: none;
}

.chat-panel {
  grid-area: chat;
  display: flex;
  height: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--border);
  background: var(--surface-soft);
}
.chat-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}
.chat-header h2 { margin: 0 0 3px; font-size: 1rem; }
.connection-status { color: #7f8999; font-size: 0.72rem; }
.connection-status.connected { color: var(--success); }
.online-count { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.chat-messages {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 18px 18px;
  scrollbar-color: #465064 transparent;
  scrollbar-width: thin;
}
.chat-empty { margin: 28px 0; color: #7f8999; font-size: 0.88rem; text-align: center; }
.chat-message { padding: 12px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.055); }
.chat-message-meta { display: flex; align-items: baseline; gap: 7px; }
.chat-username { color: #f4f6fb; font-size: 0.9rem; }
.chat-time { margin-left: auto; color: var(--muted); font-size: 0.72rem; }
.chat-message-content { margin: 5px 0 0; color: #cbd2dd; font-size: 0.92rem; line-height: 1.5; overflow-wrap: anywhere; }

.chat-composer {
  grid-area: composer;
  position: relative;
  display: flex;
  gap: 10px;
  min-width: 0;
  padding: 14px 14px 28px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-composer input, .fullscreen-chat-composer input, .login-card input {
  min-width: 0;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: #0c0f14;
  color: #dbe1eb;
}
.chat-composer input, .fullscreen-chat-composer input { flex: 1; }
.chat-composer input:focus, .fullscreen-chat-composer input:focus, .login-card input:focus { border-color: #58657a; box-shadow: 0 0 0 3px rgba(117, 132, 158, 0.12); }
.chat-composer input:disabled, .fullscreen-chat-composer input:disabled { opacity: 0.58; }
.chat-feedback {
  position: absolute;
  left: 16px;
  bottom: 7px;
  color: #ff9aae;
  font-size: 0.72rem;
}
button:not(.quiet-button) {
  padding: 11px 20px;
  border: 0;
  border-radius: 9px;
  background: #f2f4f8;
  color: #11141a;
  font-weight: 750;
  cursor: pointer;
}
button:not(.quiet-button):hover { background: #fff; }
button:disabled { cursor: default; opacity: 0.55; }
button:focus-visible { outline: 3px solid rgba(255, 255, 255, 0.3); outline-offset: 2px; }

.stream-fullscreen-button {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 6;
  width: 42px;
  height: 42px;
  padding: 0 !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 10px !important;
  background: rgba(8, 10, 14, 0.76) !important;
  color: #f4f6fb !important;
  font-size: 1.35rem;
  line-height: 1;
  opacity: 1;
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease, transform 180ms ease, background 180ms ease;
}
.stream-fullscreen-button:hover { background: rgba(24, 29, 39, 0.92) !important; }
.fullscreen-chat-composer {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--fullscreen-keyboard-offset, 0px));
  z-index: 6;
  width: min(720px, calc(100% - 32px));
  min-width: 0;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: rgba(12, 15, 20, 0.84);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
  opacity: 1;
  transition: opacity 180ms ease, transform 180ms ease;
}
.fullscreen-chat-feedback {
  position: absolute;
  left: 16px;
  top: -24px;
  color: #ff9aae;
  font-size: 0.78rem;
  text-shadow: 0 1px 5px #000;
}
.stream-fullscreen-container:fullscreen,
.stream-fullscreen-container:-webkit-full-screen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  overflow: hidden;
  background: #000;
}
.stream-fullscreen-container:fullscreen .fullscreen-chat-composer,
.stream-fullscreen-container:-webkit-full-screen .fullscreen-chat-composer { display: flex; }
.stream-fullscreen-container:fullscreen .stream-fullscreen-button,
.stream-fullscreen-container:-webkit-full-screen .stream-fullscreen-button {
  top: max(14px, env(safe-area-inset-top, 0px));
  right: max(14px, env(safe-area-inset-right, 0px));
}
.stream-fullscreen-container.fullscreen-controls-hidden:fullscreen .stream-fullscreen-button,
.stream-fullscreen-container.fullscreen-controls-hidden:-webkit-full-screen .stream-fullscreen-button,
.stream-fullscreen-container.fullscreen-controls-hidden:fullscreen .fullscreen-chat-composer,
.stream-fullscreen-container.fullscreen-controls-hidden:-webkit-full-screen .fullscreen-chat-composer {
  opacity: 0;
  pointer-events: none;
}
.stream-fullscreen-container.fullscreen-controls-hidden:fullscreen .fullscreen-chat-composer,
.stream-fullscreen-container.fullscreen-controls-hidden:-webkit-full-screen .fullscreen-chat-composer {
  transform: translate(-50%, 18px);
}

.login-page { display: grid; place-items: center; padding: 28px 16px; }
.login-shell { width: min(440px, 100%); }
.login-heading { margin-bottom: 24px; }
.login-card {
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}
.login-card form { display: grid; gap: 10px; }
.login-card label { margin-top: 7px; color: #d9dee7; font-size: 0.88rem; font-weight: 650; }
.field-help { color: var(--muted); font-size: 0.76rem; }
.form-message { min-height: 1.35em; margin: 3px 0 0; color: #ff8aa0; font-size: 0.84rem; }
.primary-button { width: 100%; margin-top: 3px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 760px) {
  .shell { width: min(100% - 20px, 1220px); padding: 28px 0; }
  .topbar { align-items: flex-start; }
  .stream-card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, clamp(250px, 38vh, 340px)) auto;
    grid-template-areas: "video" "chat" "composer";
    height: auto;
    max-height: none;
  }
  .video-frame { aspect-ratio: 16 / 9; }
  .chat-panel { height: 100%; max-height: 100%; border-top: 1px solid var(--border); border-left: 0; }
}
@media (max-width: 500px) {
  .topbar { flex-direction: column; gap: 16px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .chat-header { min-height: 58px; padding: 0 14px; }
  .chat-messages { padding: 6px 14px 14px; }
  .chat-composer { gap: 8px; padding: 10px 10px 26px; }
  .chat-composer button { padding-inline: 17px; }
  .fullscreen-chat-composer {
    width: calc(100% - 20px);
    gap: 8px;
    padding: 10px;
  }
  .fullscreen-chat-composer button { padding-inline: 17px; }
  .login-card { padding: 22px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .status-live .status-dot { animation: none; }
  .stream-fullscreen-button, .fullscreen-chat-composer { transition: none; }
}
