:root {
  --accent: #F63449;
  --accent-soft: rgba(246, 52, 73, 0.16);
  --bg: #0b0b0f;
  --bg-2: #131318;
  --bg-3: #1c1c24;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f4f4f6;
  --muted: #9a9aa6;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  height: 100dvh;
  overflow: hidden;
  position: fixed;
  inset: 0;
}

.hidden { display: none !important; }

button, input { font-family: inherit; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 22px rgba(246, 52, 73, 0.35); }
.btn-primary:active { background: #e12a3e; }
.btn-lg { padding: 15px 26px; font-size: 17px; border-radius: 14px; width: 100%; }
.btn-ghost { background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--bg-3); }
.btn-tiny { padding: 6px; border-radius: 9px; }
.btn-icon { padding: 11px; flex-shrink: 0; }

.text-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.text-input:focus { border-color: var(--accent); background: #101015; }
.text-input::placeholder { color: var(--muted); }

.landing, .gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #17171f 0%, var(--bg) 60%);
  z-index: 40;
  overflow-y: auto;
}
.landing-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 30px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.logo { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 16px var(--accent); }
.landing-sub { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.45; }

.create-form { display: flex; flex-direction: column; gap: 12px; }

.rooms { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 16px; }
.rooms-head { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.rooms-list { display: flex; flex-direction: column; gap: 8px; }
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease;
  text-align: left;
  width: 100%;
}
.room-item:active { transform: scale(0.98); }
.room-item:hover { border-color: var(--accent); }
.room-item-main { flex: 1; min-width: 0; }
.room-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.room-item-count { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.rooms-empty { margin: 0; color: var(--muted); font-size: 14px; text-align: center; padding: 6px 0; }

.app { height: var(--app-h, 100dvh); display: flex; flex-direction: column; }

.stage { display: flex; flex-direction: column; flex-shrink: 0; }

body.kbd .controls,
body.kbd .chat-head { display: none; }

.player-host {
  position: sticky;
  top: 0;
  z-index: 2;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
}
.player-host iframe,
.player-host video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

.player-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}
.player-empty-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.player-empty p { margin: 0; font-size: 14px; max-width: 220px; }

.start-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 6;
}
.start-overlay .btn { width: auto; }
.start-hint { margin: 0; color: var(--muted); font-size: 13px; }

.notice {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  background: rgba(20, 20, 26, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  z-index: 7;
  animation: rise 0.25s ease;
}

.reaction-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.floaty {
  position: absolute;
  bottom: 8%;
  font-size: 34px;
  animation: floatUp 2.4s ease-out forwards;
  will-change: transform, opacity;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translateY(0) scale(0.6); }
  15% { opacity: 1; transform: translateY(-10px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-220px) scale(1); }
}

.controls {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.source-bar { display: flex; gap: 8px; align-items: center; }
.source-toggle { padding: 9px; flex-shrink: 0; }
.source-form { display: flex; gap: 8px; flex: 1; min-width: 0; }
.source-form .text-input { flex: 1; min-width: 0; padding: 9px 12px; }
.source-bar.collapsed .source-form { display: none; }

.controls-row { display: flex; align-items: center; gap: 10px; }
.reactions { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.reactions::-webkit-scrollbar { display: none; }
.reaction-btn {
  font-size: 22px;
  line-height: 1;
  padding: 5px;
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 10px;
  transition: transform 0.1s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.reaction-btn:active { transform: scale(1.3); background: var(--bg-3); }

.members { display: flex; align-items: center; flex-shrink: 0; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  border: 2px solid var(--bg);
  margin-left: -8px;
  cursor: default;
}
.avatar:first-child { margin-left: 0; }
.avatar.me { cursor: pointer; }

.chat {
  flex: 1;
  min-height: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.room-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-icon { padding: 7px; flex-shrink: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 88%;
  animation: rise 0.2s ease;
  touch-action: pan-y;
}
.msg:not(.mine) { padding-right: 36px; }
.msg.mine { padding-left: 36px; }
.msg-inner { transition: transform 0.18s ease; position: relative; }
.msg.swiping .msg-inner { transition: none; }
.msg-meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.msg-name { font-weight: 700; }
.msg-body {
  background: var(--bg-3);
  border-radius: 4px 14px 14px 14px;
  padding: 9px 12px;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .msg-body { background: var(--accent); color: #fff; border-radius: 14px 4px 14px 14px; }

.msg-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 5px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  max-width: 100%;
}
.msg.mine .msg-quote { border-left-color: rgba(255, 255, 255, 0.7); background: rgba(0, 0, 0, 0.18); }
.msg-quote-name { font-weight: 700; display: block; }
.msg-quote-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.msg.mine .msg-quote-text { color: rgba(255, 255, 255, 0.85); }

.msg-reply-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--muted);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.msg-reply-btn:hover { color: var(--text); background: var(--bg); border-color: var(--accent); }
.msg.mine .msg-reply-btn { right: auto; left: 2px; }

.msg-media {
  display: block;
  margin-top: 4px;
  max-width: 240px;
  max-height: 280px;
  width: auto;
  border-radius: 10px;
  background: #000;
}
.msg-audio { display: block; margin-top: 4px; width: 230px; height: 40px; }
.msg-body.media-only { padding: 4px; background: transparent; }
.msg.mine .msg-body.media-only { background: transparent; }

.msg.system { align-self: center; max-width: 92%; padding: 0; }
.msg-system {
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
  padding: 4px 12px;
  text-align: center;
  animation: rise 0.2s ease;
}

.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
  margin-top: 2px;
}
.voice-play {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease;
}
.msg:not(.mine) .voice-play { background: var(--accent); }
.voice-play:active { transform: scale(0.92); }
.voice-main { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  cursor: pointer;
}
.voice-wave .bar {
  flex: 1;
  min-width: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.28);
  transition: background 0.1s linear;
}
.msg:not(.mine) .voice-wave .bar { background: rgba(246, 52, 73, 0.3); }
.voice-wave .bar.played { background: #fff; }
.msg:not(.mine) .voice-wave .bar.played { background: var(--accent); }
.voice-time { font-size: 11px; color: rgba(255, 255, 255, 0.8); font-variant-numeric: tabular-nums; }
.msg:not(.mine) .voice-time { color: var(--muted); }

.rec-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  transform: scale(1);
  will-change: transform;
}
.rec-wave {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  height: 28px;
  overflow: hidden;
}
.rec-wave .bar {
  width: 3px;
  min-height: 3px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}
.rec-time { font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.rec-hint { font-size: 12px; color: var(--muted); flex-shrink: 0; }

.voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.voice-bar .voice { flex: 1; min-width: 0; }
.voice-bar .voice-play { background: var(--bg-3); }
.voice-bar .voice-wave .bar { background: rgba(255, 255, 255, 0.24); }
.voice-bar .voice-wave .bar.played { background: var(--accent); }
.voice-bar-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
}
.voice-bar-del { background: var(--bg-3); color: var(--muted); }
.voice-bar-send { background: var(--accent); }
.voice-bar-btn:active { transform: scale(0.92); }

.chat-icon.recording {
  color: #fff;
  background: var(--accent);
}
.mic-hold { touch-action: none; user-select: none; -webkit-user-select: none; }

.flash { animation: flash 1s ease; }
@keyframes flash { 0%, 100% { background: var(--bg-3); } 30% { background: var(--accent-soft); } }

.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.reply-preview-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; }
.reply-preview-name { font-size: 12px; font-weight: 700; color: var(--accent); display: block; }
.reply-preview-text { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.chat-form .text-input { flex: 1; min-width: 0; }
.btn-send { padding: 11px 14px; flex-shrink: 0; }
.chat-form .chat-icon { flex-shrink: 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
  max-width: 90vw;
  text-align: center;
}

@media (hover: hover) {
  .msg:hover .msg-reply-btn { display: flex; }
}

@media (min-width: 900px) {
  .app { flex-direction: row; padding: 18px; gap: 16px; }
  .stage { flex: 1; min-width: 0; gap: 12px; justify-content: flex-start; }
  .player-host { border-radius: var(--radius); box-shadow: var(--shadow); }
  .controls { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); }
  .chat {
    flex: 0 0 370px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    border-top: 1px solid var(--line);
  }
  .chat-head { border-radius: var(--radius) var(--radius) 0 0; }
}
