/* ==========================================================================
   VPHub — hệ thống thiết kế
   Một theme tối duy nhất, dùng chung cho cả 5 ứng dụng. Mọi màu/khoảng cách
   đều đi qua biến ở :root để các view không tự phát minh ra giá trị riêng.
   ========================================================================== */

:root {
  /* nền, từ sâu nhất ra ngoài */
  --bg: #0a0d14;
  --bg-soft: #0f131c;
  --surface: #151a26;
  --surface-2: #1c2231;
  --surface-3: #242b3d;
  --border: #2a3245;
  --border-soft: #202737;

  /* chữ */
  --text: #e8ebf2;
  --text-dim: #a3abbe;
  --text-muted: #6f7893;

  /* nhấn */
  --accent: #6366f1;
  --accent-soft: #818cf8;
  --accent-dim: rgba(99, 102, 241, 0.16);
  --accent-grad: linear-gradient(135deg, #6366f1, #a855f7);
  --accent-glow: rgba(99, 102, 241, 0.4);   /* dùng cho box-shadow phát sáng quanh accent */

  --ok: #22c55e;
  --ok-dim: rgba(34, 197, 94, 0.14);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.14);
  --info: #38bdf8;

  /* quân cờ / bàn cờ */
  --mark-x: #f87171;
  --mark-o: #60a5fa;
  --board-cell: #f4f1e8;
  --board-line: #c9c3b4;
  --board-win: #fde047;

  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 7px;

  /* Shadow luôn thấp opacity + blur cao — depth nên cảm nhận được, không nên
     là thứ đầu tiên đập vào mắt. */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.22);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.55), 0 8px 16px rgba(0, 0, 0, 0.3);

  --sidebar: 252px;
  --topbar: 58px;

  /* Một typeface duy nhất cho toàn bộ hub. Inter/Segoe UI Variable nếu máy có
     sẵn (Windows 11), rồi ngã về chuỗi hệ thống — không trộn font thứ hai. */
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Noto Sans", sans-serif;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;

  /* Kính mờ cho sidebar/topbar/modal-backdrop. Theme tối dùng kính tối, theme
     sáng phải dùng kính SÁNG — nếu không chữ (màu theo --text của theme) sẽ
     chìm vào lớp kính tối cố định, gây "chữ mờ không đọc được" trên nền sáng. */
  --glass: rgba(15, 19, 28, 0.85);
  --glass-soft: rgba(15, 19, 28, 0.7);
  --scrim: rgba(5, 7, 12, 0.72);

  /* Mesh nền của theme mặc định (Midnight). Mỗi theme trong themes.css định
     nghĩa lại toàn bộ biến này kèm --mesh riêng. */
  --mesh:
    radial-gradient(60% 60% at 25% 0%, rgba(99, 102, 241, 0.16), transparent 70%),
    radial-gradient(50% 50% at 85% 8%, rgba(168, 85, 247, 0.12), transparent 70%),
    radial-gradient(45% 45% at 10% 90%, rgba(56, 189, 248, 0.06), transparent 70%);
}

* { box-sizing: border-box; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }
*::-webkit-scrollbar-thumb:hover { background: #333c52; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Mesh nền: hai đốm gradient toả từ góc trên, màu lấy theo theme đang chọn.
   Thuần trang trí — tạo chiều sâu, không cản đọc nội dung ở lớp trên. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--mesh);
  pointer-events: none;
  z-index: 0;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; }
/* Chữ lớn siết letter-spacing + line-height để trông "pro" hơn, theo đúng mẹo
   tiêu chuẩn: -2% tracking, 110-120% leading trên display text. */
h1 { font-size: 24px; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: 17px; letter-spacing: -0.01em; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent-soft); }

.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.center { display: grid; place-items: center; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ============================================================= bố cục ==== */
#app { position: relative; z-index: 1; display: flex; height: 100%; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--glass);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-grad);
  display: grid; place-items: center;
  font-weight: 800; font-size: 13px; letter-spacing: -0.02em; color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.brand-name { font-weight: 700; letter-spacing: -0.01em; font-size: 15px; }
.lang-pill {
  flex: 0 0 auto;
  height: 26px;
  min-width: 34px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}
.lang-pill:hover {
  background: var(--accent-dim);
  border-color: var(--accent-soft);
}

.nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px;
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  font: inherit;
  text-align: left;
  width: 100%;
  position: relative;
  transition: background 0.14s, color 0.14s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--text);
  border-color: var(--accent-soft);
}
.nav-item.active::before {
  content: ""; position: absolute; left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0;
  background: var(--accent-soft);
}
.nav-item svg { flex: 0 0 18px; width: 18px; height: 18px; }
.nav-label { font-weight: 550; font-size: 14px; }
.nav-badge {
  margin-left: auto;
  min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}
/* Huy hiệu của kênh đã tắt thông báo: vẫn đếm nhưng bỏ màu đỏ báo động. */
.nav-badge.quiet { background: var(--surface-3); color: var(--text-muted); }

.side-section {
  margin-top: auto;
  border-top: 1px solid var(--border-soft);
  padding: 10px 12px;
  min-height: 0;
  display: flex; flex-direction: column;
}
.side-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 8px;
}
.presence-list { overflow-y: auto; display: flex; flex-direction: column; gap: 3px; max-height: 190px; }
.presence-row { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 13px; }

.me-card {
  border-top: 1px solid var(--border-soft);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
}

.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  height: var(--topbar);
  flex: 0 0 var(--topbar);
  border-bottom: 1px solid var(--border-soft);
  background: var(--glass-soft);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
}
.view { flex: 1 1 auto; overflow: auto; padding: 18px; min-height: 0; }
.view.flush { padding: 0; overflow: hidden; }

/* ============================================================= linh kiện == */
.avatar {
  flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff;
  letter-spacing: 0.3px;
  user-select: none;
  object-fit: cover;   /* chỉ áp dụng khi avatar là <img>; vô hại trên div */
}
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; }
.dot.off { background: var(--text-muted); }
.dot.warn { background: var(--warn); }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-xs);
}
.card.tight { padding: 12px; }
.card-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 12px;
}

button {
  font: inherit; font-weight: 600;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, opacity 0.14s, box-shadow 0.14s, transform 0.1s;
  /* nowrap giữ nhãn nút trên một dòng, nhưng nút nằm trong flex row vẫn bị co
     nhỏ hơn nội dung. Không có hai dòng dưới thì chữ tràn khỏi viền và đè lên
     nút bên cạnh. Có rồi thì chữ dài bị cắt bằng "…", đọc ra ngay là chật chỗ.
     Nút nào cần nhãn nhiều dòng thì đặt lại white-space: normal (.app-tile,
     .level-btn) — cao tự giãn nên overflow không cắt gì. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
button:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-muted); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { transform: none; }
button:disabled { opacity: 0.42; cursor: not-allowed; }
button.primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}
button.primary:hover:not(:disabled) {
  filter: brightness(1.12);
  background: var(--accent-grad);
  box-shadow: 0 4px 16px var(--accent-glow);
}
button.primary:active:not(:disabled) { box-shadow: 0 1px 4px var(--accent-glow); }
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.danger { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
button.sm { padding: 6px 11px; font-size: 13px; }
button.xs { padding: 3px 8px; font-size: 12px; font-weight: 500; }
button.icon { padding: 7px; display: grid; place-items: center; }
button.icon svg { width: 17px; height: 17px; }

:where(button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

input, select, textarea {
  font: inherit;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  min-width: 0;
  width: 100%;
}
/* Ô nhập đứng cạnh nút trong một .row.
 *
 * width:100% ở trên biến ô nhập thành một flex item có kích cỡ gốc bằng CẢ hàng,
 * nên khi hàng chật flexbox chia phần co theo tỉ lệ kích cỡ gốc và cái nút bé
 * cũng bị co theo. Kết quả: nút "Gửi" ở chat phòng bị cắt mất 4px trên mọi game.
 * Cho ô nhập lấy kích cỡ gốc là nội dung rồi tự giãn ra thì nút giữ đúng bề
 * ngang của chữ, còn ô nhập vẫn chiếm hết phần trống như trước. */
.row > input, .row > select, .row-wrap > input, .row-wrap > select {
  flex: 1 1 auto;
  width: auto;
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }
textarea.code { font-family: var(--mono); font-size: 13px; line-height: 1.55; }
select { cursor: pointer; }
option { background: var(--surface-2); color: var(--text); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.hint { font-size: 12px; color: var(--text-muted); }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.check input { width: auto; accent-color: var(--accent); cursor: pointer; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
}
.chip.ok { background: var(--ok-dim); border-color: var(--ok); color: var(--ok); }
.chip.warn { background: var(--warn-dim); border-color: var(--warn); color: var(--warn); }
.chip.danger { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }
.chip.accent { background: var(--accent-dim); border-color: var(--accent-soft); color: var(--accent-soft); }

.banner {
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 13px;
  border: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.banner.ok { background: var(--ok-dim); border-color: var(--ok); color: var(--text); }
.banner.danger { background: var(--danger-dim); border-color: var(--danger); color: var(--text); }
.banner.warn { background: var(--warn-dim); border-color: var(--warn); color: var(--text); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border-soft); }
.tab {
  padding: 9px 15px;
  border: none; border-bottom: 2px solid transparent;
  background: none; border-radius: 0;
  color: var(--text-muted); font-weight: 600;
}
.tab:hover:not(:disabled) { background: var(--surface-2); color: var(--text-dim); }
.tab.active { color: var(--text); border-bottom-color: var(--accent-soft); background: none; }

.table-wrap { overflow: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); max-height: 420px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  padding: 7px 11px; text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  font-size: 12px; font-weight: 700;
  color: var(--text-dim);
}
tbody tr:hover { background: var(--surface-2); }
td { font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); max-width: 340px; overflow: hidden; text-overflow: ellipsis; }

.empty {
  display: grid; place-items: center; gap: 8px;
  padding: 40px 20px; text-align: center;
  color: var(--text-muted);
}
.empty svg { width: 34px; height: 34px; opacity: 0.4; }

.spinner {
  width: 15px; height: 15px; flex: 0 0 auto;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent-soft);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* thông báo nổi */
#toasts {
  position: fixed; right: 16px; bottom: 16px;
  z-index: 200;
  display: flex; flex-direction: column-reverse; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  animation: toast-in 0.18s ease-out;
}
.toast.danger { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }

/* thông báo tin nhắn mới — khác .toast ở chỗ bấm được để mở kênh chat, nên nằm
   ở container riêng có pointer-events mặc định. */
#notices {
  position: fixed; right: 16px; top: 16px;
  z-index: 190;
  display: flex; flex-direction: column; gap: 8px;
  width: min(340px, calc(100vw - 32px));
}
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-soft);
  border-radius: var(--radius);
  padding: 10px 11px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  opacity: 1;
  transition: opacity 0.2s, transform 0.2s, border-color 0.14s, background 0.14s;
  animation: toast-in 0.18s ease-out;
}
.notice:hover { background: var(--surface-3); border-color: var(--accent-soft); }
/* Thẻ mời bật thông báo: không tự tắt, nên phải khác thẻ tin nhắn để người
   dùng thấy ngay đây là câu hỏi cần trả lời chứ không phải thông báo thoáng
   qua. Con trỏ mặc định vì hành động nằm ở hai cái nút, không phải cả thẻ. */
.notice-invite { cursor: default; border-left-color: var(--warn); }
.notice-invite:hover { background: var(--surface-2); border-color: var(--border); }
.notice-invite .notice-title { white-space: normal; }
.notice-icon {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-dim); color: var(--accent-soft);
}
.notice-body { flex: 1 1 auto; min-width: 0; }
.notice-title { font-size: 13px; font-weight: 650; }
.notice-text {
  font-size: 12.5px; color: var(--text-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}

/* lớp phủ dạng hộp thoại */
.modal-back {
  position: fixed; inset: 0; z-index: 150;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 14px;
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.97); } }

/* hộp thoại chọn (phong cấp cờ vua…) */
.choice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-dim); }
.choice-glyph { font-size: 32px; line-height: 1; }
.choice-label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); }

/* =================================================== modal cài đặt ======= */
.settings-modal { max-width: 460px; }
.settings-avatar-preview .avatar.lg { box-shadow: var(--shadow-sm); }

/* danh sách kênh đã tắt thông báo riêng, trong modal Cài đặt */
.muted-list {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 4px; padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
}
.muted-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.muted-row svg { flex: 0 0 13px; color: var(--text-muted); }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 8px;
}
.theme-swatch {
  display: flex; flex-direction: column; gap: 8px;
  align-items: flex-start;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  transition: border-color 0.14s, transform 0.14s, box-shadow 0.14s;
}
.theme-swatch:hover:not(:disabled) { border-color: var(--text-muted); transform: translateY(-1px); }
.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.theme-swatch-colors { display: flex; gap: 4px; }
.theme-swatch-colors span {
  width: 20px; height: 20px; border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.theme-swatch-name { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }

/* ====================================================== màn hình hẹp ===== */
.sidebar-toggle { display: none; }

@media (max-width: 860px) {
  :root { --sidebar: 230px; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 120;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 110;
    background: var(--scrim);
  }
  .sidebar-toggle { display: grid; }
  .view { padding: 12px; }
}
