:root {
  --mint: #a8f0c4;
  --bg: #06070d;
  --ink: #eef1ff;
  --muted: #8a90b0;
  --cyan: #4de8ff;
  --violet: #a46bff;
  --line: rgba(238, 241, 255, .16);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter Tight', system-ui, -apple-system, sans-serif;
  font-weight: 300;
}

/* ---- lớp 3D ---- */
#css3d {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

#css3d > div { pointer-events: none; }

canvas.webgl {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: block;
}

#css2d {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
}

/* ---- nhãn & bong bóng ---- */
.person-label {
  font-size: 12px;
  line-height: 1;
  color: var(--ink);
  background: rgba(6, 7, 13, .62);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px 7px;
  white-space: nowrap;
  transform: translateY(-6px);
}

/* tên người khác mờ 20%, sáng khi đang nói; tên của mình luôn sáng */
.person-label { opacity: .2; transition: opacity 300ms ease-out; }
.person-label.talking,
.person-label.self { opacity: 1; }

.person-label.self {
  color: var(--cyan);
  border-color: rgba(77, 232, 255, .4);
}

.person-label.hidden { visibility: hidden; }

.bubble {
  width: 0;
  height: 0;
  visibility: hidden;
}

.bubble.on { visibility: visible; }

.bubble .txt {
  position: absolute;
  bottom: 14px;
  left: 0;
  transform: translateX(-50%);
  width: max-content;
  max-width: 220px;
  background: rgba(6, 7, 13, .85);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  color: #fff;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* ---- HUD ---- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#hud button,
#hud input,
#hud a {
  font-family: inherit;
  font-weight: 300;
  color: var(--ink);
}

.hud-topleft {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-back {
  pointer-events: auto;
  font-size: 14px;
  text-decoration: none;
  background: rgba(6, 7, 13, .55);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  transition: border-color 200ms ease-out, background 200ms ease-out;
}

.hud-back:hover,
.hud-back:focus-visible {
  border-color: var(--cyan);
  background: rgba(77, 232, 255, .08);
  outline: none;
}

.hud-people { font-size: 13px; color: var(--muted); }

#hud .hud-invite {
  pointer-events: auto;
  font-size: 13px;
  padding: 7px 12px;
  background: rgba(164, 107, 255, .1);
  border: 1px solid rgba(164, 107, 255, .45);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 200ms ease-out, background 200ms ease-out;
}

#hud .hud-invite:hover,
#hud .hud-invite:focus-visible {
  border-color: var(--violet);
  background: rgba(164, 107, 255, .2);
  outline: none;
}

.invite-note { font-size: 12px; color: var(--mint); }

.hud-cams {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
}

.hud-cams button,
.hud-panel button,
.panel-open,
.hud-chat button {
  pointer-events: auto;
  background: rgba(6, 7, 13, .55);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 200ms ease-out, background 200ms ease-out, box-shadow 200ms ease-out;
}

.hud-cams button:hover { border-color: rgba(164, 107, 255, .5); }

.hud-cams button.active {
  border-color: var(--cyan);
  color: var(--cyan);
}

/* ---- panel hàng chờ ---- */
.hud-panel {
  pointer-events: auto;
  position: absolute;
  top: 14px;
  right: 16px;
  bottom: 14px;
  width: 300px;
  background: rgba(6, 7, 13, .78);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.icon-btn {
  padding: 2px 9px !important;
  font-size: 15px !important;
}

.now-playing {
  border: 1px solid rgba(164, 107, 255, .28);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.np-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--violet);
}

.np-title {
  font-size: 14px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.np-by { font-size: 12px; color: var(--muted); }

#np-skip {
  align-self: flex-start;
  border-color: rgba(77, 232, 255, .4);
}

#np-skip:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(77, 232, 255, .25);
}

#queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#queue-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(238, 241, 255, .07);
  font-size: 13px;
}

#queue-list .idx { color: var(--muted); font-size: 12px; }

#queue-list .t {
  flex: 1;
  overflow-wrap: anywhere;
}

#queue-list .by { color: var(--muted); font-size: 12px; }

#queue-list .rm {
  padding: 2px 8px !important;
  font-size: 11px !important;
  border-color: rgba(255, 107, 107, .35) !important;
  color: #ff9d9d;
}

.queue-empty {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 6px 0;
}

#q-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#q-form #q-url { flex: 1; width: auto; min-width: 0; }
#q-form .q-error { flex-basis: 100%; }

/* ---- kết quả tìm YouTube: khung nhỏ cuộn được ---- */
.q-results {
  pointer-events: auto;
  flex-basis: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 7, 13, .75);
  overflow: hidden;
}

.q-results[hidden] { display: none; }

.q-results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 10px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid rgba(238, 241, 255, .07);
}

#q-results-list {
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#q-results-list .r {
  pointer-events: auto;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  width: 100%;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 200ms ease-out, background 200ms ease-out;
}

#q-results-list .r:hover,
#q-results-list .r:focus-visible {
  border-color: rgba(77, 232, 255, .4);
  background: rgba(77, 232, 255, .06);
  outline: none;
}

#q-results-list img {
  flex: none;
  width: 72px;
  height: 40px;
  object-fit: cover;
  border-radius: 5px;
  background: rgba(255, 255, 255, .05);
}

#q-results-list .rt {
  font-size: 13px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#q-results-list .rm2 { font-size: 11px; color: var(--muted); margin-top: 2px; }

#q-results-list .note { font-size: 12px; color: var(--muted); padding: 8px 6px; }

#q-url,
#chat-form input,
#join-name {
  background: rgba(255, 255, 255, .03);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
  outline: none;
  width: 100%;
}

#q-url:focus,
#chat-form input:focus,
#join-name:focus {
  border-color: var(--cyan);
  background: rgba(77, 232, 255, .06);
}

#q-form > button {
  border-color: rgba(77, 232, 255, .4);
  background: rgba(77, 232, 255, .07);
}

#q-form > button:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(77, 232, 255, .25);
}

.q-error {
  font-size: 12px;
  color: #ff9d9d;
}

.now-playing { cursor: pointer; transition: border-color 200ms ease-out, background 200ms ease-out; }
.now-playing:hover,
.now-playing:focus-visible {
  border-color: rgba(164, 107, 255, .6);
  background: rgba(164, 107, 255, .06);
  outline: none;
}
.np-more { color: var(--muted); letter-spacing: 0; }
.np-more::after { content: " ▾"; }
.hud-panel:not(.collapsed) .np-more::after { content: " ▴"; }

/* ---- panel thu gọn (máy tính): chỉ tên bài 2 dòng + ô dán link ---- */
@media (min-width: 760px) {
  .hud-panel.collapsed { bottom: auto; }
  .hud-panel.collapsed .panel-head,
  .hud-panel.collapsed .np-by,
  .hud-panel.collapsed #np-skip,
  .hud-panel.collapsed #queue-list,
  .hud-panel.collapsed .queue-empty { display: none !important; }
  .hud-panel.collapsed .np-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* ---- nút mở ngăn kéo (mobile) ---- */
#panel-open { display: none; }

/* ---- thả cảm xúc ---- */
.react-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.hud-chat .react-bar button {
  padding: 4px 0;
  width: 38px;
  font-size: 18px;
  line-height: 1.2;
  transition: transform 120ms ease-out, border-color 200ms ease-out, background 200ms ease-out;
}

.hud-chat .react-bar button:hover { border-color: rgba(164, 107, 255, .6); background: rgba(164, 107, 255, .1); }
.hud-chat .react-bar button:active { transform: scale(.88); }

/* emoji bay trên màn chiếu (vị trí tính theo màn trong JS) */
#react-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}

.react-fly {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 34px;
  line-height: 1;
  will-change: transform, opacity;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .5));
}

/* emoji nhỏ bật lên trên đầu người thả */
.react-head { width: 0; height: 0; }

.react-pop {
  position: absolute;
  bottom: 22px;
  left: 0;
  font-size: 18px;
  line-height: 1;
  transform: translateX(-50%);
  animation: react-pop 1400ms ease-out forwards;
}

@keyframes react-pop {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(.6); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
  30% { transform: translate(-50%, -4px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(1); }
}

/* ---- chat ---- */
.hud-chat {
  position: absolute;
  bottom: 14px;
  left: 16px;
  width: 330px;
}

#chat-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.msg {
  background: rgba(6, 7, 13, .7);
  border: 1px solid rgba(238, 241, 255, .1);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13px;
  overflow-wrap: anywhere;
  transition: opacity 200ms ease-out;
}

.msg .who { font-size: 12px; margin-right: 4px; }

.msg:nth-last-child(n+5) { opacity: .6; }
.msg:nth-last-child(n+7) { opacity: .35; }
.msg:nth-last-child(n+9) { opacity: .2; }

#chat-form {
  display: flex;
  gap: 8px;
}

#chat-form input { flex: 1; pointer-events: auto; }

#chat-form button { padding: 8px 14px; }

/* ---- màn vào rạp ---- */
#join {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(640px 480px at 82% 78%, rgba(164, 107, 255, .1), transparent 70%), var(--bg);
}

.join-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  text-align: center;
  padding: 24px;
}

.join-inner h1 {
  margin: 0;
  font-weight: 200;
  font-size: clamp(34px, 6vw, 64px);
  letter-spacing: -0.02em;
}

#join-name {
  width: min(300px, 84vw);
  text-align: center;
  font-size: 15px;
}

#join-go {
  pointer-events: auto;
  font-size: 15px;
  padding: 10px 28px;
  background: rgba(77, 232, 255, .07);
  border: 1px solid rgba(77, 232, 255, .4);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 200ms ease-out, background 200ms ease-out, box-shadow 200ms ease-out;
}

#join-go:hover,
#join-go:focus-visible {
  border-color: var(--cyan);
  background: rgba(77, 232, 255, .12);
  box-shadow: 0 0 0 1px var(--cyan), 0 0 28px rgba(77, 232, 255, .35);
  outline: none;
}

/* ---- mobile ---- */
@media (max-width: 759.98px) {
  .hud-topleft { left: 12px; right: 12px; gap: 8px; flex-wrap: wrap; }
  .invite-note { flex-basis: 100%; }

  .hud-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 0;
    width: auto;
    max-height: 62vh;
    border-radius: 14px 14px 0 0;
    transform: translateY(calc(100% + 24px));
    transition: transform 240ms ease-out;
  }

  .hud-panel.open { transform: none; }

  #panel-open {
    display: block;
    position: absolute;
    right: 12px;
    bottom: 66px;
    border-color: rgba(164, 107, 255, .45);
  }

  .hud-chat {
    width: min(300px, calc(100vw - 24px));
    bottom: 12px;
    left: 12px;
  }

  .hud-cams { top: auto; bottom: 12px; left: 12px; transform: none; }

  .hud-cams button { padding: 7px 9px; font-size: 12px; }

  .hud-back { padding: 7px 10px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ô nhập & nút không tự kế thừa màu/font */
input, button { color: var(--ink); font: inherit; }
#join-name, #join-go { color: var(--mint); }
#join-name::placeholder { color: rgba(168, 240, 196, .5); }
