:root {
  --bg: linear-gradient(180deg, #dfeaff 0%, #f4f0ff 55%, #ffeede 100%);
  --card: #ffffff;
  --text: #1c2435;
  --muted: #6b7890;
  --line: #e3e8f2;
  --accent: #4f6bff;
  --accent-text: #ffffff;
  --me: #4f6bff;
  --bot: #eef1f8;
  --danger: #e5484d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: linear-gradient(180deg, #101522 0%, #1a1730 60%, #2a1c2c 100%);
    --card: #1c2435;
    --text: #eef2fb;
    --muted: #9aa8c2;
    --line: #2c3750;
    --bot: #28324a;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
}

/* Chạy trong Electron: nền trong suốt để nhìn thấy desktop phía sau */
html.desktop, html.desktop body { background: transparent; }

#stage {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 2;
  will-change: transform; /* khung vẽ nhỏ đi theo nhân vật: chỉ dịch chuyển, không vẽ lại bố cục trang */
  /* Viền sáng mảnh + bóng đổ mềm quanh nhân vật để tách khỏi nền, màu đậm hơn một chút */
  filter: drop-shadow(0 0 1px rgba(255, 255, 255, .9)) drop-shadow(0 8px 14px rgba(20, 24, 50, .38)) contrast(1.06) saturate(1.18);
}

#hitbox {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 24px;
  outline-offset: 4px;
}
#hitbox:active { cursor: grabbing; }

#loading {
  position: fixed;
  inset: auto 0 40% 0;
  margin: 0;
  text-align: center;
  color: var(--muted);
}

/* Trình phát YouTube thu nhỏ */
/* ---- Trình phát YouTube ----
   data-mode="audio": thanh nhạc nhỏ gọn góc trên, video bị ẩn (chỉ nghe tiếng)
   data-mode="video": khung xem video nằm giữa màn hình, cỡ nhỏ / vừa / to (data-size) */
#tube {
  position: fixed;
  z-index: 6;
  color: #f4f6ff;
  background: rgba(16, 20, 34, .92);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, .1);
  overflow: hidden;
  transition: width .35s cubic-bezier(.2, .8, .2, 1), border-radius .35s, box-shadow .35s;
}
#tube[hidden] { display: none; }
#tube header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 14px;
}
#tube header button { color: inherit; width: 34px; height: 34px; border-radius: 10px; }
#tube header button:hover { background: rgba(255, 255, 255, .12); }
#tube-title {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tube-frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
.tube-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
/* Đang xem kênh truyền hình (trang chính thức nhúng trong khung): ẩn trình phát YouTube và nút tạm dừng của YouTube */
#tube[data-page="true"] #tube-video { display: none; }
#tube[data-page="true"] #tube-play { display: none; }
.tube-frame .tube-page { position: absolute; inset: 0; background: #000; }
#tube-mode::before { content: "🎬"; }
/* Nút tạm dừng / phát: hình tròn sáng màu, đổi biểu tượng theo trạng thái */
#tube #tube-play {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #ff6fb1, #7b8cff);
  box-shadow: 0 2px 10px rgba(123, 140, 255, .45);
  transition: transform .15s;
}
#tube #tube-play:hover { background: linear-gradient(135deg, #ff83bd, #8d9cff); transform: scale(1.08); }
#tube #tube-play:active { transform: scale(.94); }
#tube-play svg { width: 16px; height: 16px; fill: currentColor; }
#tube-play .icon-play { display: none; }
#tube[data-paused="true"] #tube-play .icon-play { display: block; }
#tube[data-paused="true"] #tube-play .icon-pause { display: none; }
#tube[data-paused="true"] .tube-eq i { animation-play-state: paused; }
#tube[data-mode="video"] #tube-mode::before { content: "🎧"; }

/* Sóng nhạc nhảy nhảy cạnh tên bài */
.tube-eq { display: inline-flex; align-items: flex-end; gap: 2px; width: 16px; height: 14px; flex: none; }
.tube-eq i {
  flex: 1;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, #ff6fb1, #7b8cff);
  transform-origin: bottom;
  animation: tube-eq 0.9s ease-in-out infinite;
}
.tube-eq i:nth-child(2) { animation-delay: -.3s; }
.tube-eq i:nth-child(3) { animation-delay: -.6s; }
.tube-eq i:nth-child(4) { animation-delay: -.15s; }
@keyframes tube-eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .tube-eq i { animation: none; transform: scaleY(.6); } }

/* Chỉ nghe nhạc: thanh nhỏ dạng viên thuốc ở góc trên bên trái, trình phát vẫn chạy nhưng không nhìn thấy */
#tube[data-mode="audio"] {
  left: 16px;
  top: 16px;
  width: min(320px, calc(100vw - 32px));
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(20, 30, 60, .3);
}
#tube[data-mode="audio"] .tube-sizes { display: none; }
#tube[data-mode="audio"] .tube-frame {
  position: absolute;
  width: 4px;
  height: 4px;
  opacity: 0.01;
  pointer-events: none;
  overflow: hidden;
}

/* Xem video: khung giữa màn hình, viền bo tròn, đổ bóng sâu */
#tube[data-mode="video"] {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(8, 12, 28, .55), 0 0 0 1px rgba(255, 255, 255, .06) inset;
  animation: tube-in .35s cubic-bezier(.2, .8, .2, 1);
}
#tube[data-mode="video"][data-size="s"] { width: min(420px, calc(100vw - 32px)); }
#tube[data-mode="video"][data-size="m"] { width: min(720px, calc(100vw - 32px), calc((100vh - 110px) * 16 / 9)); }
#tube[data-mode="video"][data-size="l"] { width: min(1180px, calc(100vw - 32px), calc((100vh - 70px) * 16 / 9)); }
#tube[data-mode="video"] .tube-frame { margin: 0 8px 8px; border-radius: 12px; overflow: hidden; }
@keyframes tube-in { from { opacity: 0; transform: translate(-50%, -46%) scale(.96); } }

/* Xem video toàn màn hình (nút ⛶ hoặc lệnh "toàn màn hình"): khung phủ kín màn hình điện thoại / cửa sổ,
   video nằm giữa, to hết cỡ. Bấm ⛶ lần nữa (hoặc "thu nhỏ video") để về cửa sổ nhỏ. */
#tube-full { font-size: 17px; }
#tube[data-mode="audio"] #tube-full { display: none; }
#tube[data-full="true"][data-mode="video"] {
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  transform: none !important;
  border-radius: 0;
  box-shadow: none;
  background: #000;
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: none;
  transition: none;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
#tube[data-full="true"][data-mode="video"] .tube-frame {
  flex: 1;
  min-height: 0;
  margin: 0;
  border-radius: 0;
  aspect-ratio: auto;
}
#tube[data-full="true"] .tube-sizes { display: none; }

/* Khung đã được xếp cạnh nhân vật (vị trí, bề rộng tính trong main.js theo cỡ nhân vật) */
#tube.placed {
  transform: none;
  transition: width .35s cubic-bezier(.2, .8, .2, 1), left .35s cubic-bezier(.2, .8, .2, 1), bottom .35s cubic-bezier(.2, .8, .2, 1), border-radius .35s, box-shadow .35s;
}
#tube.placed[data-mode="video"] { animation: tube-pop .35s cubic-bezier(.2, .8, .2, 1); }
@keyframes tube-pop { from { opacity: 0; transform: scale(.96); } }

/* Người dùng tự đặt khung (kéo thanh tiêu đề để dời, kéo góc dưới phải để đổi cỡ): vị trí tính từ mép trên */
#tube.custom { bottom: auto; }
/* Khung hẹp (điện thoại, hoặc người dùng thu nhỏ): bỏ nhóm nút Nhỏ / Vừa / To cho tên bài và chỗ nắm kéo có đất (đổi cỡ bằng cách kéo góc) */
#tube { container-type: inline-size; }
@container (max-width: 430px) {
  #tube .tube-sizes { display: none; }
}
#tube header { cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
#tube header button { cursor: pointer; }
#tube.dragging { transition: none !important; animation: none !important; box-shadow: 0 34px 90px rgba(8, 12, 28, .7), 0 0 0 2px rgba(123, 140, 255, .55); }
#tube.dragging header { cursor: grabbing; }
/* Đang kéo qua chỗ không thả được (đè khung chat / nội dung đang xem): viền đỏ, thả ra khung sẽ về chỗ cũ */
#tube.dragging.bad { box-shadow: 0 34px 90px rgba(8, 12, 28, .7), 0 0 0 2px #ff5a6e; opacity: .82; }
#tube.dragging.bad header { cursor: not-allowed; }
#tube.dragging iframe { pointer-events: none; } /* đang kéo thì video không "nuốt" chuột */
#tube[data-full="true"] header { cursor: default; }
.tube-grip {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 24px;
  height: 24px;
  z-index: 2;
  cursor: nwse-resize;
  touch-action: none;
}
.tube-grip::before {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border-right: 2px solid rgba(255, 255, 255, .6);
  border-bottom: 2px solid rgba(255, 255, 255, .6);
  border-radius: 0 0 5px 0;
  transition: border-color .15s;
}
.tube-grip:hover::before, #tube.dragging .tube-grip::before { border-color: #ff8cc4; }
/* Thanh nhạc: kéo mép phải để dài / ngắn */
#tube[data-mode="audio"] .tube-grip { top: 0; width: 8px; height: auto; cursor: ew-resize; }
#tube[data-mode="audio"] .tube-grip::before { display: none; }
#tube[data-full="true"] .tube-grip { display: none; }

/* Kênh truyền hình: nút "chỉ hiện video" (sáng lên khi đang bật) */
#tube-focus svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tube #tube-focus { display: grid; place-items: center; }
#tube:not([data-page="true"]) #tube-focus, #tube[data-mode="audio"] #tube-focus { display: none; }
#tube[data-focus="true"] #tube-focus { color: #fff; background: linear-gradient(135deg, #ff6fb1, #7b8cff); }
.tube-frame { overflow: hidden; }
/* Dải hướng dẫn lần đầu xem kênh truyền hình (trang hỏi điều khoản): người dùng tự bấm Đồng ý trong khung */
#tube-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0 8px 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.35;
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
}
#tube-hint[hidden], #tube[data-mode="audio"] #tube-hint { display: none; }
#tube-hint span { flex: 1 1 180px; }
#tube-hint button {
  flex: none;
  width: auto;
  white-space: nowrap;
  height: 30px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
}
#tube-hint button:hover { background: rgba(255, 255, 255, .22); }
#tube-hint #tube-done { background: linear-gradient(135deg, #ff6fb1, #7b8cff); }

/* ---------- Danh sách phím tắt / câu lệnh (nút bánh răng trên khung chat) ---------- */
#shortcuts-open svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; }
#shortcuts-open[aria-expanded="true"] { color: var(--accent); background: var(--bot); border-radius: 10px; }
#panel { position: fixed; } /* làm mốc cho danh sách phủ lên phần thân khung chat */
#shortcuts {
  position: absolute;
  inset: 57px 0 0 0; /* ngay dưới thanh tiêu đề khung chat */
  z-index: 4;
  display: flex;
  flex-direction: column;
  background: var(--card);
  animation: shortcuts-in .18s ease-out;
}
#shortcuts[hidden] { display: none; }
@keyframes shortcuts-in { from { opacity: 0; transform: translateY(6px); } }
.shortcuts-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0 8px;
  padding: 10px 8px 8px 16px;
  border-bottom: 1px solid var(--line);
}
.shortcuts-head strong { font-size: 14.5px; }
.shortcuts-head span { order: 3; flex-basis: 100%; font-size: 12px; color: var(--muted); }
.shortcuts-head button { margin-left: auto; width: 32px; height: 32px; }
/* Ô tìm lệnh (kính lúp) */
.shortcuts-search {
  order: 4;
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 8px 0 0;
  padding: 0 12px;
  height: 36px;
  border-radius: 999px;
  background: var(--bot);
  border: 1px solid var(--line);
}
.shortcuts-search:focus-within { border-color: var(--accent); }
.shortcuts-search svg { flex: none; width: 17px; height: 17px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.shortcuts-search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 13.5px; }
.shortcuts-search input::-webkit-search-cancel-button { cursor: pointer; }
#shortcuts-list [hidden] { display: none !important; } /* dòng / tiêu đề nhóm bị lọc đi */
#shortcuts-list .shortcuts-empty { margin: 18px 8px; font-size: 13px; color: var(--muted); text-align: center; }
#shortcuts-list { flex: 1; overflow-y: auto; padding: 4px 10px 14px; overscroll-behavior: contain; }
#shortcuts-list h4 { margin: 14px 6px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
#shortcuts-list button {
  display: block;
  width: 100%;
  height: auto;
  padding: 8px 10px;
  text-align: left;
  border-radius: 10px;
  line-height: 1.35;
}
#shortcuts-list button:hover, #shortcuts-list button:focus-visible { background: var(--bot); }
#shortcuts-list button b { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); }
#shortcuts-list button b i { font-style: normal; font-weight: 500; color: var(--accent); }
#shortcuts-list button small { display: block; margin-top: 1px; font-size: 12px; color: var(--muted); }
#shortcuts-list button.top { background: var(--bot); border: 1px solid var(--line); margin-top: 8px; }

/* Khung chat tự ẩn khi lâu không dùng: mờ dần rồi mới ẩn */
#panel.leaving { opacity: 0; transform: translateY(10px) scale(.985); transition: opacity .32s ease, transform .32s ease; pointer-events: none; }

/* Nút chọn cỡ video: Nhỏ / Vừa / To */
.tube-sizes {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
}
#tube .tube-sizes button {
  width: auto;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  color: rgba(244, 246, 255, .7);
}
#tube[data-size="s"] .tube-sizes [data-size="s"],
#tube[data-size="m"] .tube-sizes [data-size="m"],
#tube[data-size="l"] .tube-sizes [data-size="l"] {
  color: #fff;
  background: linear-gradient(135deg, #ff6fb1, #7b8cff);
  box-shadow: 0 2px 8px rgba(123, 140, 255, .45);
}
@media (max-width: 480px) {
  #tube .tube-sizes button { padding: 0 7px; }
}

#bubble {
  position: fixed;
  z-index: 4;
  max-width: min(320px, calc(100vw - 24px));
  max-height: 40vh;
  overflow-y: auto;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 6px 24px rgba(20, 30, 60, .22);
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  transform: translateX(-50%);
  cursor: pointer;
}

#panel {
  position: fixed;
  z-index: 5;
  right: 16px;
  bottom: 16px;
  width: 360px;
  height: min(540px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(20, 30, 60, .28);
  overflow: hidden;
}
#panel[hidden] { display: none; }

#panel header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--line);
}
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.who span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: transparent;
  cursor: pointer;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
}
button:hover { background: var(--bot); }
button:disabled { opacity: .4; cursor: not-allowed; }
#sound[aria-pressed="false"] { opacity: .45; }
#handsfree[aria-pressed="false"] { opacity: .55; }
#handsfree[aria-pressed="true"] { background: var(--accent); box-shadow: 0 0 0 3px rgba(79, 107, 255, .25); }
.msg.note a { color: var(--accent); font-weight: 600; text-decoration: none; }
.msg.note a:hover { text-decoration: underline; }

#skin {
  max-width: 120px;
  height: 32px;
  padding: 0 6px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bot);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

#log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: 16px;
  line-height: 1.45;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 4px; }
.msg.model { align-self: flex-start; background: var(--bot); border-bottom-left-radius: 4px; }
.msg.note { align-self: center; font-size: 13px; color: var(--muted); text-align: center; }
.msg.system { align-self: center; font-size: 13px; color: var(--danger); text-align: center; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }

#moves {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 84px;
  padding: 8px 10px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
}
#moves button {
  width: auto;
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
  background: var(--bot);
  border-radius: 16px;
}
#moves button:hover { filter: brightness(0.95); }

#form {
  display: flex;
  gap: 6px;
  padding: 4px 10px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
#message {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  font: inherit;
  font-size: 16px; /* >=16px để iOS không tự phóng to khi gõ */
  color: var(--text);
  background: var(--bot);
  border: 1px solid transparent;
  border-radius: 20px;
  outline: none;
}
#message:focus { border-color: var(--accent); }
#send, #mic { display: grid; place-items: center; border-radius: 50%; }
#send { background: var(--accent); color: var(--accent-text); }
#send:hover { background: var(--accent); filter: brightness(1.1); }
#send svg { width: 19px; height: 19px; fill: currentColor; transform: translateX(1px); }
#mic { background: var(--bot); color: var(--text); }
#mic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
#mic svg rect { fill: currentColor; stroke: none; }
#mic.unavailable { opacity: .55; }
#attach { display: grid; place-items: center; border-radius: 50%; color: var(--text); }
#attach svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* Ảnh chờ gửi: ô xem trước nhỏ ngay trên ô nhập */
#attach-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 12px 0;
  padding: 6px 6px 6px 6px;
  border-radius: 14px;
  background: var(--bot);
}
#attach-preview[hidden] { display: none; }
#attach-thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; flex: none; }
#attach-name { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#attach-remove { width: 32px; height: 32px; border-radius: 50%; }

/* Ảnh trong tin nhắn đã gửi */
/* Việc làm hộ trên trang khác: nút "Xem trang", "Chép ảnh"... và ảnh kết quả mang về */
.msg.note.task button {
  margin: 4px 3px 0;
  padding: 4px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
/* Thẻ yêu cầu giao cho công cụ vẽ ảnh: biểu tượng, nội dung (tối đa 3 dòng), nút Xem gọn */
.task-card {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-radius: 14px;
  background: var(--bot);
  border: 1px solid var(--line);
}
.task-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-size: 17px;
}
.task-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.task-body strong { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.task-body span {
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
#panel .task-view {
  flex: none;
  width: auto;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
#panel .task-view:hover { background: var(--accent); filter: brightness(1.08); }

/* Dòng tiến độ đang làm: một dòng duy nhất, có chấm nhấp nháy */
.msg.note.progress { display: inline-flex; align-items: center; gap: 8px; }
.msg.note.progress::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: progress-blink 1s ease-in-out infinite;
}
@keyframes progress-blink { 50% { opacity: .2; } }

/* Đầu khung chat: ô chọn nhân vật làm tiêu đề (chữ đậm), trạng thái nhỏ bên dưới, các nút gọn */
#panel .who #skin {
  align-self: flex-start;
  max-width: 100%;
  height: 24px;
  margin-left: -2px;
  padding: 0 4px 0 2px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border-radius: 8px;
}
#panel .who #skin:hover { background: var(--bot); }
/* Ô chọn giọng nói: nằm ngay dưới ô chọn nhân vật, nhỏ và nhạt hơn */
#panel .who #voice-pick {
  align-self: flex-start;
  max-width: 100%;
  height: 20px;
  margin: 1px 0 0 -2px;
  padding: 0 2px;
  font: inherit;
  font-size: 11.5px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  outline: 0;
}
#panel .who #voice-pick:hover, #panel .who #voice-pick:focus-visible { background: var(--bot); color: var(--text); }
#panel .who #voice-pick option { color: var(--text); background: var(--card); }
#panel header button { width: 36px; height: 36px; flex: none; }

.msg.model.photo { padding: 4px; background: transparent; display: flex; flex-direction: column; gap: 4px; }
.msg.model.photo img { display: block; max-width: min(260px, 100%); max-height: 300px; border-radius: 14px; cursor: zoom-in; }
.msg.model.photo a.save-photo {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}
.msg.model.photo a.save-photo:hover { filter: brightness(1.08); }
.msg.user.photo { padding: 4px; background: transparent; }
.msg.user.photo img { display: block; max-width: min(240px, 100%); max-height: 260px; border-radius: 14px; cursor: zoom-in; }

/* Kéo ảnh vào khung chat */
#panel.dropping::after {
  content: "Thả ảnh vào đây để gửi cho nhân vật";
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  color: var(--accent);
  font-weight: 600;
  pointer-events: none;
}
#mic.listening { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(229, 72, 77, .5); }
  100% { box-shadow: 0 0 0 14px rgba(229, 72, 77, 0); }
}

/* ---------- Điện thoại: khung chat là tấm trượt ở đáy màn hình, nhân vật đứng gọn phía trên ---------- */
@media (max-width: 719px) {
  #panel {
    left: 0;
    right: 0;
    bottom: var(--kb, 0px);
    width: auto;
    height: min(50dvh, 460px);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -10px 40px rgba(10, 16, 36, .35);
    transition: height .25s ease, bottom .15s ease;
  }
  /* Thanh kéo nhỏ ở mép trên cho giống tấm trượt của ứng dụng điện thoại */
  #panel::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 2px;
    background: var(--line);
  }
  #panel header { padding: 14px 6px 8px 16px; gap: 2px; }
  #panel header button { width: 38px; height: 38px; border-radius: 50%; }
  #name { font-size: 16px; }
  #skin { max-width: 96px; height: 30px; font-size: 13px; }
  #log { padding: 12px 12px 6px; }
  .msg { max-width: 88%; font-size: 15px; }

  /* Các nút động tác: một hàng, vuốt ngang; mờ dần ở mép phải để biết còn nữa */
  #moves {
    flex-wrap: nowrap;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 12px;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(90deg, #000 88%, transparent);
    -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent);
  }
  #moves::-webkit-scrollbar { display: none; }
  #moves button { height: 34px; padding: 0 12px; font-size: 13.5px; scroll-snap-align: start; }

  #form { gap: 8px; padding: 6px 12px max(12px, env(safe-area-inset-bottom)); }
  #message { height: 44px; border-radius: 22px; padding: 0 16px; }
  #mic, #send { width: 44px; height: 44px; }

  /* Đang gõ (bàn phím ảo bật): khung chat chiếm hết phần nhìn thấy, ẩn hàng động tác cho rộng chỗ */
  .kb-open #panel { height: calc(var(--vvh, 100dvh) - 8px); border-radius: 18px 18px 0 0; }
  .kb-open #moves { display: none; }
  .kb-open #form { padding-bottom: 8px; }

  #bubble { font-size: 14px; max-width: calc(100vw - 24px); }
}

/* Màn hình rất thấp (điện thoại xoay ngang): khung chat bên phải như máy tính */
@media (max-width: 719px) and (max-height: 480px) {
  #panel { left: auto; width: min(360px, 60vw); height: calc(100dvh - 16px); bottom: 8px; right: 8px; border-radius: 18px; }
  #panel::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #mic.listening { animation: none; }
}

/* Nhân vật đi ngủ: ẩn hết; trang web hiện một dòng nhỏ để chạm gọi dậy (bản desktop thì biến mất hẳn) */
#sleeping { display: none; }
.asleep #stage, .asleep #hitbox, .asleep #bubble, .asleep #panel, .asleep #tube { visibility: hidden; }
.asleep #sleeping {
  display: block;
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: rgba(30, 20, 50, 0.72);
  color: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.desktop.asleep #sleeping { display: none; }

/* App Android: nhân vật nổi trên màn hình trong cửa sổ nhỏ, nền trong suốt, không có khung chat */
html.bubble, html.bubble body { background: transparent; }
html.bubble #panel, html.bubble #bubble, html.bubble #loading, html.bubble #sleeping { display: none !important; }
/* Nhân vật nổi vẫn mở nhạc được: trình phát phải còn nằm trong trang (ẩn hẳn bằng display:none thì YouTube không phát), chỉ làm cho không nhìn thấy */
html.bubble #tube[data-mode="audio"]:not([hidden]) { left: 0 !important; top: 0 !important; width: 160px !important; opacity: 0 !important; pointer-events: none !important; }
/* Nhân vật nổi đang xem video: khung video chiếm phần trên cửa sổ nổi, bỏ các nút không dùng được ở đây */
html.bubble #tube .tube-sizes, html.bubble #tube-full, html.bubble #tube-mode, html.bubble .tube-grip { display: none !important; }
html.bubble #tube { animation: none !important; transition: none !important; }
html.bubble #tube header { cursor: default; }
/* App điện thoại: khung chat trên nền trong suốt, thấy màn hình điện thoại phía sau */
html.phone-app, html.phone-app body { background: transparent; }

/* ---------- Thông báo có bản cập nhật mới ---------- */
#update-bar {
  position: fixed;
  z-index: 50;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 24px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 14px 40px rgba(20, 30, 60, .28);
  animation: update-in .35s cubic-bezier(.2, .8, .2, 1);
}
#update-bar.leaving { opacity: 0; transform: translate(-50%, -12px); transition: opacity .25s, transform .25s; }
@keyframes update-in { from { opacity: 0; transform: translate(-50%, -14px); } }
.update-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  font-size: 19px;
  background: linear-gradient(135deg, #ff6fb1, #7b8cff);
}
.update-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.update-text strong { font-size: 14.5px; }
.update-text span { font-size: 12.5px; color: var(--muted); }
#update-bar button {
  flex: none;
  width: auto;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
#update-bar .update-later { color: var(--muted); }
/* Dấu x đỏ nhỏ ở góc trên phải: tắt thông báo */
#update-bar .update-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  color: #fff;
  background: #ef4444;
  box-shadow: 0 2px 8px rgba(239, 68, 68, .45);
}
#update-bar .update-close:hover { background: #dc2626; }
#update-bar .update-now { background: var(--accent); color: var(--accent-text); padding: 0 14px; }
#update-bar .update-now:hover { background: var(--accent); filter: brightness(1.08); }
@media (max-width: 420px) {
  #update-bar { flex-wrap: wrap; }
  .update-text { flex-basis: calc(100% - 52px); }
  #update-bar .update-later { margin-left: auto; }
}


/* ================= Giao diện khung chat: xanh đen, hơi trong mờ ================= */
#panel {
  --card: rgba(10, 24, 42, .80);
  --text: #eaf2ff;
  --muted: #9db0cc;
  --line: rgba(255, 255, 255, .10);
  --bot: rgba(255, 255, 255, .09);
  --accent: #3ea6ff;
  --accent-text: #04121f;
  --me: #2d7df6;
  color: var(--text);
  background: linear-gradient(165deg, rgba(13, 32, 56, .84) 0%, rgba(8, 20, 36, .80) 100%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid rgba(120, 180, 255, .18);
  box-shadow: 0 16px 46px rgba(2, 10, 24, .5);
}
#panel header { border-bottom-color: var(--line); background: rgba(255, 255, 255, .03); }
#panel select option { background: #0f2238; color: #eaf2ff; } /* danh sách xổ xuống phải là nền đặc mới đọc được */
#panel .msg.model { border: 1px solid rgba(255, 255, 255, .06); }
#panel .msg.user { background: linear-gradient(135deg, #3b8cff, #2a6fe8); }
#panel #message { border-color: rgba(255, 255, 255, .10); }
#panel #message::placeholder { color: #8196b5; }
#panel #moves button { border: 1px solid rgba(255, 255, 255, .08); }
#panel #moves button:hover { background: rgba(62, 166, 255, .22); filter: none; }
#panel #log::-webkit-scrollbar, #shortcuts-list::-webkit-scrollbar { width: 8px; }
#panel #log::-webkit-scrollbar-thumb, #shortcuts-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 8px; }

/* ================= Bảng phím tắt (nút bánh răng) ================= */
#shortcuts {
  background: linear-gradient(170deg, rgba(12, 29, 51, .97) 0%, rgba(7, 18, 33, .97) 100%);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.shortcuts-head { padding: 12px 10px 0 14px; border-bottom: 0; gap: 0 8px; }
.shortcuts-head strong { font-size: 15px; letter-spacing: .01em; }
.shortcuts-head span { font-size: 12px; }
/* Ô tìm lệnh: nền sáng, viền xanh, có quầng sáng để dễ thấy */
.shortcuts-search {
  margin: 10px 4px 0 0;
  height: 40px;
  padding: 0 14px;
  background: rgba(255, 255, 255, .96);
  border: 2px solid #3ea6ff;
  box-shadow: 0 0 0 4px rgba(62, 166, 255, .16), 0 4px 14px rgba(0, 0, 0, .25);
  transition: box-shadow .15s ease;
}
.shortcuts-search:focus-within { border-color: #6fc1ff; box-shadow: 0 0 0 5px rgba(62, 166, 255, .30), 0 4px 14px rgba(0, 0, 0, .25); }
.shortcuts-search svg { width: 18px; height: 18px; stroke: #1b6fd6; stroke-width: 2.4; }
.shortcuts-search input { color: #0c1d33; font-size: 14px; font-weight: 500; }
.shortcuts-search input::placeholder { color: #6a7f9c; font-weight: 400; }
/* Các tab chọn nhóm */
#shortcuts-tabs {
  order: 5;
  flex-basis: 100%;
  display: grid;
  grid-template-columns: 1fr 1.12fr 1.18fr .8fr;
  gap: 3px;
  margin: 12px 4px 0 0;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
}
#shortcuts-tabs button {
  width: auto;
  height: 34px;
  margin: 0;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 9px;
  white-space: nowrap;
  overflow: hidden;
}
#shortcuts-tabs button span { order: 0; flex-basis: auto; font-size: 12px; color: inherit; } /* (đè luật chung của chữ phụ ở đầu bảng) */
#shortcuts-tabs button:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
#shortcuts-tabs button[aria-selected="true"] {
  color: #04121f;
  background: linear-gradient(135deg, #6fc1ff, #3ea6ff);
  box-shadow: 0 2px 10px rgba(62, 166, 255, .45);
}
/* Danh sách lệnh */
#shortcuts-list { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 6px; padding: 10px 12px 16px; }
#shortcuts-list h4 {
  flex-basis: 100%;
  margin: 10px 2px 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: .08em;
  color: #7fb9ff;
}
#shortcuts-list h4:first-child { margin-top: 2px; }
#shortcuts-list h4::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(127, 185, 255, .35), transparent); }
#shortcuts-list button {
  flex: 1 1 100%;
  margin: 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .07);
  border-left: 3px solid rgba(62, 166, 255, .55);
  transition: background .12s ease, transform .12s ease, border-color .12s ease;
}
#shortcuts-list button:hover, #shortcuts-list button:focus-visible {
  background: rgba(62, 166, 255, .16);
  border-color: rgba(62, 166, 255, .45);
  border-left-color: #6fc1ff;
  transform: translateX(2px);
}
#shortcuts-list button b { font-size: 13.5px; color: #f2f7ff; }
#shortcuts-list button b i { color: #ffd166; font-weight: 600; }
#shortcuts-list button small { margin-top: 2px; font-size: 11.8px; line-height: 1.4; color: #93a8c6; }
#shortcuts-list button.top { margin-top: 0; background: rgba(62, 166, 255, .10); border-color: rgba(62, 166, 255, .22); border-left-color: #3ea6ff; }
/* Hành động: ô nhỏ hai cột */
#shortcuts-list button.chip {
  flex: 1 1 calc(50% - 6px);
  min-width: 0;
  padding: 8px 10px;
  border-left-width: 1px;
  border-left-color: rgba(255, 255, 255, .07);
  text-align: center;
}
#shortcuts-list button.chip b { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#shortcuts-list button.chip small { display: none; }
#shortcuts-list button.chip:hover { transform: translateY(-1px); border-left-color: rgba(62, 166, 255, .45); }
#shortcuts-list .shortcuts-empty { flex-basis: 100%; }
#panel #moves, #panel #log, #shortcuts-list { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .22) transparent; }
#panel #moves::-webkit-scrollbar { width: 6px; }
#panel #moves::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .2); border-radius: 6px; }
#panel #moves::-webkit-scrollbar-button { display: none; }
