/* =====================================================================
 * Giao diện "bước vào căn phòng": phòng tràn màn hình, bạn bè / nhân vật / cài đặt nằm trong ngăn kéo (☰),
 * nút điều khiển nổi mờ trên căn phòng, thanh chat kính mờ, dải nút hoạt động tự ẩn, vòng menu trên nhân vật.
 * Máy tính (≥ 821px): mọi thứ nổi trên căn phòng. Điện thoại: xếp dọc như cũ.
 * Cửa sổ nổi ("Thả ra màn hình"): căn phòng tràn cả cửa sổ, nút chỉ hiện khi rê chuột — xem cuối file.
 * ===================================================================== */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.stage-home {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: flex;
}

.stage-wrap {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.stage-keys {
  display: none;
}

/* ---------------- Ngăn kéo ---------------- */
.drawer {
  position: fixed;
  z-index: 90;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(380px, 92vw);
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 40px rgba(0, 0, 0, 0.3);
  transform: translateX(-104%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.3, 0.8, 0.3, 1), visibility 0s linear 0.28s;
}

.drawer-open .drawer {
  transform: none;
  visibility: visible;
  transition: transform 0.28s cubic-bezier(0.3, 0.8, 0.3, 1);
}

.drawer-scrim {
  position: fixed;
  z-index: 89;
  inset: 0;
  background: rgba(10, 10, 25, 0.35);
  animation: scrim-in 0.25s ease;
}

@keyframes scrim-in {
  from { opacity: 0; }
}

.drawer-head {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 -16px 6px;
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.drawer-close {
  padding: 6px 11px;
}

.drawer .tabs {
  flex: none;
}

.drawer .tab.active {
  flex: 1 0 auto;
}

.drawer-foot {
  position: sticky;
  z-index: 2;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px -16px 0;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

.drawer-foot .btn {
  flex: 1 1 auto;
  justify-content: center;
  text-align: center;
}

/* ---------------- Nút ☰ ---------------- */
.hud-btn {
  position: relative;
  flex: none;
  width: 38px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--field);
  color: var(--text);
  font: 700 17px/1 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

.hud-btn:hover {
  border-color: var(--accent);
}

.menu-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.menu-btn[data-net="online"] .menu-dot {
  background: #34d399;
}

.menu-btn[data-net="connecting"] .menu-dot,
.menu-btn[data-net="reconnecting"] .menu-dot {
  background: #fbbf24;
  animation: pulse 1.2s ease-in-out infinite;
}

body.pip .menu-btn {
  display: none;
}

/* ---------------- Dải nút hoạt động: biểu tượng + tên khi rê chuột ---------------- */
.action-bar .act-btn {
  position: relative;
}

.action-bar .act-btn .ic {
  font: 18px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.action-bar .act-btn .lbl {
  margin-left: 5px;
}

.action-bar .act-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------------- Nhân vật của bạn bè bấm được (vòng menu) ---------------- */
.actor.peer .figure svg *,
.actor.peer .figure canvas,
.actor.peer .nametag {
  pointer-events: auto;
  cursor: pointer;
}

.actor.peer .figure svg * {
  pointer-events: visiblePainted;
}

.actor.peer:hover .figure {
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9)) drop-shadow(0 3px 6px rgba(0, 0, 0, 0.22));
}

.stage-wrap.editing .actor.peer * {
  pointer-events: none !important;
}

.radial {
  position: absolute;
  z-index: 52;
  width: 0;
  height: 0;
}

.radial[hidden] {
  display: none;
}

.radial-name {
  position: absolute;
  left: 0;
  top: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(22, 24, 44, 0.85);
  color: #ffffff;
  font: 700 12px/1.3 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: radial-in 0.2s ease both;
}

.radial-item {
  position: absolute;
  left: 0;
  top: 0;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  background: rgba(30, 28, 52, 0.82);
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transform: translate(-50%, -50%) rotate(var(--a)) translateX(70px) rotate(calc(-1 * var(--a)));
  animation: radial-pop 0.26s cubic-bezier(0.3, 1.4, 0.5, 1) var(--d) both;
}

.radial-item:hover:not(:disabled) {
  border-color: #ffd166;
  background: rgba(60, 50, 100, 0.92);
}

.radial-item:disabled {
  opacity: 0.4;
  cursor: default;
}

.ri-ic {
  font: 20px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.ri-lbl {
  font: 600 9.5px/1 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
}

@keyframes radial-pop {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(var(--a)) translateX(10px) rotate(calc(-1 * var(--a))) scale(0.4);
  }
}

@keyframes radial-in {
  from { opacity: 0; }
}

/* =====================================================================
 * Máy tính: căn phòng tràn màn hình, mọi nút nổi trên phòng
 * ===================================================================== */
@media (min-width: 821px) {
  .stage-wrap {
    position: relative;
  }

  .stage {
    position: absolute;
    inset: 0;
    min-height: 0;
    --floor-inset: 66px; /* chừa chỗ cho thanh chat: nhân vật không đứng lấp sau thanh chat */
    --top-inset: 64px; /* màn chiếu rạp phim bắt đầu dưới cụm nút góc trên */
  }

  /* Cụm nút góc trên bên trái (bên phải là chỗ TV — không được che khung phát YouTube) */
  .stage-bar {
    position: absolute;
    z-index: 30;
    top: 10px;
    left: 10px;
    max-width: min(560px, calc(100% - 20px));
    gap: 6px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 16px;
    background: rgba(24, 22, 40, 0.42);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    backdrop-filter: blur(12px) saturate(1.3);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  }

  .stage-bar select,
  .stage-bar .btn,
  .stage-bar .hud-btn {
    border: 1px solid rgba(255, 255, 255, 0.24);
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
  }

  .stage-bar select {
    max-width: 250px;
    padding: 6px 10px;
    border-radius: 11px;
  }

  .stage-bar select option {
    background: #1e2030;
    color: #eceef8;
  }

  .stage-bar .btn:hover,
  .stage-bar .hud-btn:hover,
  .stage-bar select:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.24);
  }

  .stage-bar .voice-btn {
    border-color: transparent;
    background: var(--accent);
  }

  /* Thanh chat kính mờ nổi trên sàn gỗ */
  .chatbar {
    position: absolute;
    z-index: 30;
    left: 50%;
    bottom: 12px;
    width: min(680px, calc(100% - 24px));
    gap: 6px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 999px;
    background: rgba(28, 24, 44, 0.34);
    -webkit-backdrop-filter: blur(14px) saturate(1.35);
    backdrop-filter: blur(14px) saturate(1.35);
    box-shadow: 0 8px 26px rgba(0, 0, 0, 0.2);
    transform: translateX(-50%);
    transition: background 0.2s ease, box-shadow 0.2s ease;
  }

  .chatbar:hover,
  .chatbar:focus-within {
    background: rgba(28, 24, 44, 0.6);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  }

  .chatbar input,
  .chatbar select {
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #ffffff;
  }

  .chatbar input {
    padding: 8px 12px;
  }

  .chatbar input::placeholder {
    color: rgba(255, 255, 255, 0.78);
  }

  .chatbar input:focus {
    outline: none;
    box-shadow: none;
  }

  .chatbar select {
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.14);
  }

  .chatbar select option {
    background: #1e2030;
    color: #eceef8;
  }

  .chatbar .emote-toggle {
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
  }

  .chatbar button[type="submit"] {
    border-radius: 999px;
    padding-inline: 16px;
  }

  .emote-pop {
    left: 50%;
    bottom: 70px;
    transform: translateX(-50%);
  }

  /* Dải nút hoạt động: nổi trên thanh chat, tự ẩn khi không rê chuột ở dưới */
  .action-bar {
    position: absolute;
    z-index: 29;
    left: 50%;
    bottom: 70px;
    flex-wrap: nowrap;
    gap: 4px;
    max-width: calc(100% - 24px);
    padding: 5px 7px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px;
    background: rgba(24, 22, 40, 0.5);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    backdrop-filter: blur(12px) saturate(1.3);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translate(-50%, 10px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
  }

  .action-bar.show,
  .action-bar:focus-within {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
  }

  .action-bar .act-btn {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
  }

  .action-bar .act-btn:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.24);
  }

  .action-bar .act-btn.on {
    border-color: #a5a8ff;
    background: rgba(124, 128, 255, 0.5);
    color: #ffffff;
  }

  .action-bar .act-btn .lbl {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 9px);
    margin: 0;
    padding: 4px 9px;
    border-radius: 8px;
    background: rgba(22, 24, 44, 0.92);
    color: #ffffff;
    font: 600 12px/1.2 "Segoe UI", system-ui, sans-serif;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(-50%);
    pointer-events: none;
    transition: opacity 0.15s ease;
  }

  .action-bar .act-btn:hover .lbl,
  .action-bar .act-btn:focus-visible .lbl {
    opacity: 1;
  }

  .action-bar .act-sep {
    height: 26px;
    background: rgba(255, 255, 255, 0.3);
  }

  /* Không có chuột (màn cảm ứng to): dải nút luôn hiện */
  @media (hover: none) {
    .action-bar {
      opacity: 1;
      transform: translate(-50%, 0);
      pointer-events: auto;
    }
  }

  /* Bảng xem gần (album, thư, Bíp, bảng ghim…) không nằm dưới cụm nút / thanh chat */
  .qa-zoom,
  .bp-zoom,
  .album-zoom,
  .cork-zoom {
    padding-top: 60px;
    padding-bottom: 72px;
  }

  .toasts {
    bottom: 76px;
  }

  /* Bảng vẽ chung phóng to: nằm giữa cụm nút trên và thanh chat */
  .board-overlay {
    inset: 66px 5% 74px;
  }

  /* Rạp phim: bảng đếm giờ Pomodoro thu vào góc trái, dưới cụm nút */
  .room-on.room-cinema .pomo-clock {
    top: 72px;
  }
}

/* =====================================================================
 * Điện thoại / cửa sổ hẹp: xếp dọc (cụm nút trên, dải nút, căn phòng, ô chat)
 * ===================================================================== */
@media (max-width: 820px) {
  .stage-home {
    height: auto;
    padding: 0;
  }

  .stage {
    min-height: 0;
  }

  .action-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .action-bar .act-btn .lbl {
    font-size: 12px;
  }
}

/* =====================================================================
 * Cửa sổ nổi ("Thả ra màn hình", Document Picture-in-Picture)
 * Khung và thanh tiêu đề do trình duyệt vẽ, trang không đổi được. Phần còn lại: căn phòng tràn cả cửa sổ,
 * không viền / bo / bóng; mọi nút nổi mờ và chỉ hiện khi rê chuột (trừ lúc có cuộc gọi đang đổ chuông).
 * Luật đặt ở đây (file nạp sau cùng) và viết rõ từng thuộc tính nên đúng ở mọi cỡ cửa sổ, kể cả khi người dùng kéo rộng quá 820px.
 * ===================================================================== */
body.pip {
  margin: 0;
  height: 100vh;
  overflow: hidden;
}

body.pip .stage-wrap {
  position: relative;
  display: block;
  height: 100vh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

body.pip .stage {
  position: absolute;
  inset: 0;
  min-height: 0;
  --floor-inset: 12px; /* chừa chút chỗ cho bảng tên dưới chân nhân vật */
  --top-inset: 8px;
}

body.pip .stage-hint,
body.pip .stage-keys {
  display: none;
}

body.pip .pip-only {
  display: inline-grid;
}

/* ---- Cụm nút trên (góc trái; góc phải là chỗ TV — không được che khung phát YouTube) ---- */
body.pip .stage-bar {
  position: absolute;
  z-index: 40;
  top: 6px;
  left: 6px;
  right: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  max-width: calc(100% - 12px);
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  background: rgba(24, 22, 40, 0.55);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.pip .stage-wrap:hover .stage-bar,
body.pip .stage-wrap:focus-within .stage-bar,
body.pip .stage-bar:has(.call-pill.ringing, .call-pill.calling) {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

body.pip .stage-bar #btn-menu,
body.pip .stage-bar #room-select,
body.pip .stage-bar #btn-decorate {
  display: none;
}

/* Đang trong cuộc gọi thì viên thuốc cuộc gọi (đồng hồ · micro · kết thúc) thay cho nút "Nói chuyện" */
body.pip .stage-bar:has(.call-pill:not([hidden])) .voice-btn {
  display: none;
}

/* Đang mời / đổ chuông: nhường chỗ cho nút Nghe · Từ chối · Huỷ, bỏ tạm nút đổi cỡ và về trang */
body.pip .stage-bar:has(.call-pill.ringing, .call-pill.calling) .pip-only {
  display: none;
}

body.pip .stage-bar .btn,
body.pip .stage-bar .hud-btn {
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

body.pip .stage-bar .btn {
  padding: 5px 10px;
}

body.pip .stage-bar .hud-btn {
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 10px;
  font-size: 15px;
}

body.pip .stage-bar .btn:hover,
body.pip .stage-bar .hud-btn:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.26);
}

body.pip .stage-bar .voice-btn {
  border-color: transparent;
  background: var(--accent);
}

/* ---- Thanh chat kính mờ dưới đáy (hiện khi rê chuột / đang gõ) ---- */
body.pip .chatbar {
  position: absolute;
  z-index: 40;
  left: 50%;
  bottom: 6px;
  width: min(520px, calc(100% - 12px));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 999px;
  background: rgba(28, 24, 44, 0.55);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  backdrop-filter: blur(12px) saturate(1.35);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.pip .stage-wrap:hover .chatbar,
body.pip .stage-wrap:focus-within .chatbar {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

body.pip .chatbar input,
body.pip .chatbar select {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #ffffff;
}

body.pip .chatbar input {
  min-width: 0;
  padding: 6px 10px;
}

body.pip .chatbar input::placeholder {
  color: rgba(255, 255, 255, 0.78);
}

body.pip .chatbar input:focus {
  outline: none;
  box-shadow: none;
}

body.pip .chatbar select {
  max-width: 96px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.14);
}

body.pip .chatbar select option {
  background: #1e2030;
  color: #eceef8;
}

body.pip .chatbar select[data-single] {
  display: none; /* chỉ có một người nhận thì khỏi hiện ô chọn */
}

body.pip .chatbar .emote-toggle {
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
}

body.pip .chatbar button[type="submit"] {
  border-radius: 999px;
  padding-inline: 14px;
}

body.pip .emote-pop {
  left: 50%;
  bottom: 46px;
  grid-template-columns: repeat(5, 54px);
  max-height: calc(100% - 58px);
  overflow-y: auto;
  transform: translateX(-50%);
}

/* ---- Dải nút hoạt động: chỉ biểu tượng, nằm trên thanh chat, hiện khi rê chuột gần đáy ---- */
body.pip .action-bar {
  position: absolute;
  z-index: 39;
  left: 50%;
  bottom: 46px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 3px;
  max-width: calc(100% - 12px);
  padding: 3px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  background: rgba(24, 22, 40, 0.55);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
  backdrop-filter: blur(10px) saturate(1.3);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.pip .action-bar::-webkit-scrollbar {
  display: none;
}

body.pip .action-bar.show,
body.pip .action-bar:focus-within {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

body.pip .action-bar .act-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

body.pip .action-bar .act-btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.24);
}

body.pip .action-bar .act-btn.on {
  border-color: #a5a8ff;
  background: rgba(124, 128, 255, 0.5);
}

body.pip .action-bar .act-btn .ic {
  font-size: 16px;
}

body.pip .action-bar .act-btn .lbl {
  display: none; /* tên nằm ở thuộc tính title (rê chuột là thấy) */
}

body.pip .action-bar .act-sep {
  flex: none;
  height: 20px;
  background: rgba(255, 255, 255, 0.3);
}
