:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1d2033;
  --muted: #676c89;
  --line: #e3e5f0;
  --field: #f6f7fc;
  --hover: #eef0fa;
  --accent: #5b5ff0;
  --accent-soft: #ecedff;
  --accent-text: #ffffff;
  --good: #16a36a;
  --warn: #d97706;
  --bad: #d64545;
  --bad-soft: #fdecec;
  --stage-a: #eef1ff;
  --stage-b: #fdf4ff;
  --shadow: 0 1px 2px rgba(20, 20, 60, 0.04), 0 6px 20px rgba(20, 20, 60, 0.06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151f;
    --card: #1e2030;
    --text: #eceef8;
    --muted: #a2a7c2;
    --line: #2e3145;
    --field: #252839;
    --hover: #26293b;
    --accent: #7c80ff;
    --accent-soft: #2b2d4d;
    --good: #34d399;
    --warn: #fbbf24;
    --bad: #ff7676;
    --bad-soft: #3a2327;
    --stage-a: #1b1d2e;
    --stage-b: #221b2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
}

h3 {
  margin: 0 0 6px;
  font-size: 14.5px;
}

p {
  margin: 4px 0 10px;
}

/* ---------------- Nút & ô nhập ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  filter: brightness(1.06);
}

.btn:disabled,
.btn.busy {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.btn.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.btn.danger {
  background: var(--bad);
  color: #fff;
}

.btn.danger-ghost {
  background: transparent;
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 35%, transparent);
}

.btn.small {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
}

.btn.block {
  width: 100%;
}

input:not([type="checkbox"]),
select {
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  outline: none;
  min-width: 0;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.field > span {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.copy-row {
  display: flex;
  gap: 8px;
}

.copy-row input {
  flex: 1;
}

.form-error {
  color: var(--bad);
  font-size: 13px;
  margin-bottom: 10px;
}

.form-error:empty {
  display: none;
}

.warn-text {
  color: var(--warn);
  font-size: 12.5px;
}

.error-text {
  color: var(--bad);
  font-size: 13px;
}

/* ---------------- Đăng nhập ---------------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(900px 500px at 50% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-hero {
  text-align: center;
}

.auth-hero h1 {
  margin: 4px 0 2px;
  font-size: 22px;
}

/* Link "Hướng dẫn" (trang huong-dan.html) */
a.btn {
  text-decoration: none;
}

.guide-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.guide-link:hover {
  text-decoration: underline;
}

.auth-avatar {
  width: 110px;
  height: 138px;
  margin: 0 auto;
}

.invite-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.invite-banner .mini {
  width: 44px;
  height: 55px;
  flex: none;
}

.segmented {
  display: flex;
  padding: 3px;
  margin: 12px 0 16px;
  border-radius: 11px;
  background: var(--field);
  border: 1px solid var(--line);
}

.seg {
  flex: 1;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.seg.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ---------------- Khung ứng dụng ---------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-avatar {
  width: 34px;
  height: 42px;
  flex: none;
}

.brand-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
}

.status.online .status-dot {
  background: var(--good);
}

.status.reconnecting .status-dot,
.status.connecting .status-dot {
  background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.35; }
}

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.panel {
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--card);
  padding: 12px 16px 24px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}

.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--good);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

.block {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.block:first-of-type {
  border-top: 0;
}

.invite-box {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.countdown {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.invite-preview {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.invite-preview .mini {
  width: 50px;
  height: 62px;
  flex: none;
}

.invite-preview .actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.list-empty {
  padding: 6px 0;
  color: var(--muted);
  font-size: 13px;
}

.friend {
  border-top: 1px solid var(--line);
}

.friend:first-child {
  border-top: 0;
}

.friend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}

.friend-row .mini {
  width: 34px;
  height: 42px;
  flex: none;
}

.mini .sb-root,
.mini .sb-eyes,
.thumb .sb-root,
.thumb .sb-eyes {
  animation: none;
}

.friend-info {
  flex: 1;
  min-width: 0;
}

.friend-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.presence::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
}

.presence.on {
  color: var(--good);
}

.presence.on::before {
  background: var(--good);
}

.friend-actions {
  display: flex;
  gap: 4px;
}

.history {
  margin: 0 0 10px 44px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  border-radius: 10px;
  background: var(--field);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg {
  max-width: 85%;
  padding: 5px 9px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  align-self: flex-start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.msg.mine {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: transparent;
}

.msg time {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
}

/* ---------------- Tạo nhân vật ---------------- */
.opt-group {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.opt-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
}

.thumb.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.thumb .art {
  width: 50px;
  height: 50px;
}

.thumb .art .sb-avatar {
  overflow: hidden;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 5px 12px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--field);
  cursor: pointer;
  font-size: 13px;
}

.chip.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--card);
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
  padding: 0;
}

.swatch.selected {
  box-shadow: 0 0 0 2px var(--accent);
}

.custom-color {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: conic-gradient(#f43f5e, #f59e0b, #84cc16, #06b6d4, #6366f1, #d946ef, #f43f5e);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
  cursor: pointer;
}

.custom-color input {
  position: absolute;
  inset: -8px;
  width: 42px;
  height: 42px;
  opacity: 0;
  cursor: pointer;
  padding: 0;
}

/* ---------------- Sân khấu ---------------- */
.stage-home {
  min-width: 0;
  min-height: 0;
  padding: 16px;
  display: flex;
}

.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.stage {
  position: relative;
  isolation: isolate; /* mọi lớp bên trong sân khấu không đè lên thông báo của trang */
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 110%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 45%),
    linear-gradient(160deg, var(--stage-a), var(--stage-b));
  touch-action: none;
}

.stage-hint {
  position: absolute;
  z-index: 9;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 6px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  pointer-events: none;
}

/* Nhân vật nằm trong lớp xếp theo độ sâu của căn phòng; --s = tỉ lệ thu nhỏ (đứng xa thì nhỏ),
   co quanh bàn chân. z-index do web.js đặt theo vị trí đứng (ai ở trước thì che người ở sau). */
.actor {
  position: absolute;
  width: 104px;
  height: 150px;
  user-select: none;
  -webkit-user-select: none;
  transform: scale(var(--s, 1));
  transform-origin: 50% 100%;
  transition: left 0.18s linear, top 0.18s linear, transform 0.18s linear;
}

.actor.self {
  cursor: grab;
  transition: none;
}

/* Đang ngồi sau bàn làm việc: tên đã hiện trên bảng đếm giờ Pomodoro */
.actor.seated .nametag {
  display: none;
}

/* Nhân vật của bạn bè không bấm được → bấm xuyên qua tới đồ đạc phía sau (giá vẽ, máy hát…).
   Nhân vật của mình: chỉ phần có hình (người, bảng tên) mới bắt chuột, khoảng trống trong khung thì bấm xuyên qua. */
.actor:not(.self),
.actor.self,
.actor.self .figure svg {
  pointer-events: none;
}

.actor.self .figure svg *,
.actor.self .figure canvas,
.actor.self .nametag {
  pointer-events: auto;
}

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

.actor.self.dragging {
  cursor: grabbing;
}

.actor .figure {
  position: relative;
  width: 104px;
  height: 130px;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.22));
}

.actor .nametag {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) scale(calc(0.45 + 0.55 / var(--s, 1)));
  transform-origin: 50% 100%;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 160px;
  padding: 1px 8px 2px 6px;
  border-radius: 999px;
  background: rgba(22, 24, 38, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.actor .nametag span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.actor .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #34d399;
  flex: none;
}

.actor.self .dot {
  background: var(--accent);
}

.actor.offline .figure {
  filter: grayscale(0.85);
  opacity: 0.55;
}

.actor.offline .dot {
  background: #9ca3af;
}

.actor .zzz {
  position: absolute;
  top: 0;
  right: -4px;
  display: none;
  font: 700 14px/1 "Segoe UI", sans-serif;
  color: #6b7280;
}

.actor.offline .zzz {
  display: block;
}

.bubble {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 14px);
  width: max-content;
  max-width: 210px;
  padding: 7px 11px;
  border-radius: 14px;
  background: #ffffff;
  color: #1f2233;
  font-size: 13px;
  line-height: 1.38;
  text-align: center;
  box-shadow: 0 6px 18px rgba(20, 20, 50, 0.25);
  opacity: 0;
  transform: translate(-50%, 8px) scale(calc(0.85 / var(--s, 1)));
  transform-origin: 50% 100%;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.3, 1.4, 0.5, 1);
  pointer-events: none;
  overflow-wrap: anywhere;
  z-index: 3;
}

.bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 7px 7px 0 7px;
  border-style: solid;
  border-color: #ffffff transparent transparent transparent;
}

.bubble.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(calc(1 / var(--s, 1)));
}

.bubble .text {
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bubble .meta {
  margin-top: 2px;
  font-size: 10.5px;
  color: #7a7f99;
}

.bubble .meta:empty {
  display: none;
}

.chatbar {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

.chatbar select {
  max-width: 140px;
}

.chatbar input {
  flex: 1;
}

/* ---------------- Cửa sổ nổi (Picture-in-Picture) ----------------
 * Giao diện riêng của cửa sổ nổi (căn phòng tràn cửa sổ, nút hiện khi rê chuột) nằm cuối immersive.css. */
.pip-only {
  display: none;
}

/* Trong app desktop: app lo đăng xuất; cửa sổ nổi của trình duyệt không dùng (đã có nhân vật nổi trên màn hình) */
.in-app #btn-popout,
.in-app #btn-logout {
  display: none;
}

.stage-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

/* ---------------- Thông báo & hộp thoại ---------------- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.toast {
  max-width: 340px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #22253a;
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  font-size: 13px;
}

.toast.error {
  background: #b93838;
}

.toast.success {
  background: #13855a;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 22px;
  background: var(--card);
  color: var(--text);
  width: min(420px, 90vw);
}

dialog::backdrop {
  background: rgba(10, 10, 25, 0.45);
}

dialog h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

dialog p {
  color: var(--muted);
  margin: 0 0 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------------- Điện thoại ---------------- */
@media (max-width: 820px) {
  .app {
    height: auto;
    min-height: 100vh;
  }
  .layout {
    display: flex;
    flex-direction: column-reverse;
  }
  .panel {
    border-right: 0;
    border-top: 1px solid var(--line);
  }
  .stage-home {
    height: 62vh;
    padding: 10px;
  }
  #btn-popout {
    display: none;
  }
  .topbar {
    padding: 8px 12px;
  }
}

/* ---------------- Chọn phòng / trang trí ---------------- */
.stage-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.stage-bar select {
  flex: 1;
  min-width: 0;
  max-width: 320px;
}

/* Đang trang trí: nhân vật mờ đi và không chặn chuột để kéo đồ bên dưới. */
.stage-wrap.editing .actor,
.stage-wrap.editing .actor * {
  opacity: 0.45;
  pointer-events: none !important;
}

.stage-wrap.editing .actor * {
  opacity: 1;
}

/* ---------------- Biểu cảm ---------------- */
.stage-wrap {
  position: relative;
}

.emote-toggle {
  flex: none;
  padding-inline: 10px;
  font: 18px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.emote-pop {
  position: absolute;
  z-index: 70;
  left: 10px;
  bottom: 62px;
  display: grid;
  grid-template-columns: repeat(5, 62px);
  gap: 4px;
  padding: 8px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.3);
}

.emote-pop[hidden] {
  display: none;
}

.emote-pop .emote {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.emote-pop .emote:hover {
  background: var(--hover);
}

.emote-pop .emoji {
  font: 22px/1.1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}

.emote-pop .label {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------------- Kiểu nhân vật + ảnh mặt ---------------- */
.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.mode-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.mode-icon {
  font-size: 20px;
  line-height: 1.2;
}

.face-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.face-thumb {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--field);
  border: 2px solid var(--line);
}

.face-thumb.photo {
  border-color: var(--accent);
}

.face-thumb img,
.face-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.face-hair {
  margin-top: 8px;
}

.face-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* ---------------- Điều khiển bằng phím + ôm ---------------- */
.stage-keys {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stage-keys kbd,
.hug-btn kbd {
  display: inline-block;
  min-width: 18px;
  margin: 0 1px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--field);
  color: var(--text);
  font: 600 11px/16px "Segoe UI", system-ui, sans-serif;
  text-align: center;
}

.hug-btn {
  position: absolute;
  z-index: 9;
  transform: translate(-50%, -100%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff6f91, #ff9671);
  color: #ffffff;
  font: 700 13px/1.2 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(255, 90, 120, 0.45);
  cursor: pointer;
  animation: hug-pop 0.25s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.hug-btn:hover {
  filter: brightness(1.06);
}

.hug-btn[hidden] {
  display: none;
}

.hug-btn kbd {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  color: #ffffff;
}

.stage-wrap.editing .hug-btn {
  display: none;
}

@keyframes hug-pop {
  from { opacity: 0; transform: translate(-50%, -80%) scale(0.7); }
  to { opacity: 1; transform: translate(-50%, -100%) scale(1); }
}

@media (max-width: 820px) {
  .stage-keys {
    display: none;
  }
}

.prompt-input {
  width: 100%;
  margin: 0 0 16px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font: inherit;
}

/* ---------------- 🎙 Nói chuyện bằng giọng ---------------- */
.voice-btn {
  flex: none;
}

.voice-btn[hidden] {
  display: none;
}

.call-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 3px 4px 3px 12px;
  border-radius: 999px;
  background: #16a36a;
  color: #ffffff;
  font: 600 12.5px/1.2 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(22, 163, 106, 0.35);
}

.call-pill[hidden] {
  display: none;
}

.call-pill.calling,
.call-pill.connecting {
  background: #4f46e5;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.call-pill.ringing {
  background: #e8590c;
  animation: call-ring 1s ease-in-out infinite;
}

@keyframes call-ring {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.call-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.call-btn {
  flex: none;
  padding: 5px 11px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  font: 700 12px/1.2 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
}

.call-btn:hover {
  background: rgba(255, 255, 255, 0.32);
}

.call-btn.ok {
  background: #ffffff;
  color: #16a36a;
}

.call-btn.end {
  background: #e03131;
}

.call-btn.end:hover {
  background: #c92a2a;
}

.call-btn.mute {
  padding: 5px 8px;
}

.call-btn.mute.on {
  background: #ffffff;
  color: #e03131;
}

/* Nhân vật đang nói: bảng tên sáng xanh; tắt micro: biểu tượng 🔇 cạnh tên */
.actor.speaking .nametag {
  background: #16a36a;
  box-shadow: 0 0 0 3px rgba(22, 163, 106, 0.35), 0 0 12px rgba(22, 163, 106, 0.6);
}

.actor.mic-off .nametag::after {
  content: "🔇";
  font-size: 10px;
}

@media (max-width: 820px) {
  .call-pill .call-text {
    max-width: 110px;
  }
}

/* ---------------- 🎬 Rạp phim: hộp bắp rang + bong bóng thì thầm ---------------- */
.actor .popcorn {
  position: absolute;
  left: 50%;
  top: 78px;
  width: 26px;
  height: 32px;
  margin-left: -13px;
  display: none;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)) brightness(0.94);
}

.actor.cine-seated .popcorn {
  display: block;
  animation: pc-in 0.45s cubic-bezier(0.3, 1.5, 0.5, 1);
}

.popcorn svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.popcorn .pc-heap circle,
.popcorn .pc-pop {
  fill: #fff4cf;
  stroke: #e8b453;
  stroke-width: 0.8;
}

/* Thỉnh thoảng một hạt bắp bay lên miệng */
.popcorn .pc-pop {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
  animation: pc-munch 6.5s ease-in-out infinite;
}

.actor.seat-1 .popcorn .pc-pop {
  animation-delay: -3.2s;
}

@keyframes pc-in {
  from { opacity: 0; transform: translateY(8px) scale(0.6); }
}

@keyframes pc-munch {
  0%, 78% { opacity: 0; transform: translate(0, 0); }
  80% { opacity: 1; transform: translate(0, 0); }
  90% { opacity: 1; transform: translate(-1px, -24px) scale(0.9); }
  95%, 100% { opacity: 0; transform: translate(-1px, -28px) scale(0.5); }
}

/* Thì thầm: bong bóng nhỏ, mờ hơn */
.cinema-quiet .bubble {
  max-width: 160px;
  padding: 5px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 11.5px;
  box-shadow: 0 4px 12px rgba(10, 10, 30, 0.25);
}

.cinema-quiet .bubble::after {
  border-top-color: rgba(255, 255, 255, 0.88);
}

.cinema-quiet .bubble.show {
  opacity: 0.9;
}

.cinema-quiet .bubble .text {
  -webkit-line-clamp: 3;
}

/* Ngồi ghế lười: thì thầm sang bên cạnh, ngang đầu (không bay lên che màn chiếu) */
.cinema-quiet .actor.cine-seated .bubble {
  top: 22px;
  bottom: auto;
  transform: translateY(4px) scale(calc(0.85 / var(--s, 1)));
}

.cinema-quiet .actor.cine-seated .bubble.show {
  transform: translateY(0) scale(calc(1 / var(--s, 1)));
}

.cinema-quiet .actor.cine-seated.seat-0 .bubble {
  left: auto;
  right: calc(100% - 22px);
  transform-origin: 100% 50%;
}

.cinema-quiet .actor.cine-seated.seat-1 .bubble {
  left: calc(100% - 22px);
  transform-origin: 0 50%;
}

.cinema-quiet .actor.cine-seated .bubble::after {
  display: none;
}

/* Đứng ngay dưới màn chiếu: hạ bong bóng xuống ngang người */
.cinema-quiet .bubble.bubble-low {
  bottom: auto;
  top: 58px;
}

.cinema-quiet .bubble.bubble-low::after {
  display: none;
}

/* ---------------- Thẻ hỏi: người kia xin xem màn hình của mình ---------------- */
.ask-card {
  position: absolute;
  z-index: 80;
  top: 74px;
  left: 50%;
  width: min(440px, calc(100% - 24px));
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 16px;
  background: rgba(28, 24, 44, 0.94);
  color: #ffffff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
  animation: ask-in 0.25s ease both;
}

.ask-title {
  font: 700 15px/1.35 "Segoe UI", system-ui, sans-serif;
}

.ask-sub {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12.5px;
  line-height: 1.5;
}

.ask-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.ask-card .btn.ghost {
  color: #ffffff;
}

body.pip .ask-card {
  top: 46px;
}

@keyframes ask-in {
  from {
    opacity: 0;
    transform: translate(-50%, -10px);
  }
}

/* ---------------- Thư viện nhân vật nổi tiếng (tạo nhân vật) ---------------- */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.preset {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 3px 5px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

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

.preset.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.preset .art {
  width: 66px;
  height: 82px;
}

.preset .art .sb-avatar {
  overflow: hidden;
}

.preset .sb-root,
.preset .sb-eyes {
  animation: none;
}

.preset .pname {
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}

.preset .pseries {
  font-size: 10px;
  line-height: 1.2;
  text-align: center;
}
