/* ============ Biến & nền tảng ============ */
:root {
    --bg: #18191a;
    --bg-2: #242526;
    --surface: #242526;
    --surface-2: #3a3b3c;
    --input: #3a3b3c;
    --border: #3e4042;
    --text: #e4e6eb;
    --muted: #b0b3b8;
    --accent: #2d88ff;
    --accent-2: #4fb3ff;
    --male: #3ea6ff;
    --female: #ff5fa2;
    --random: #ffb547;
    --danger: #ff4d5e;
    --radius: 1.25rem;
    --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* Mọi kích thước dùng rem: trên điện thoại, cỡ gốc tự co theo chiều rộng và chiều cao màn hình
   (máy 360×640 ≈ 84%, máy lớn giữ 100%) nên toàn bộ giao diện đồng bộ với màn hình. */
html { font-size: 16px; }
@media (max-width: 900px) {
    html { font-size: clamp(11px, min(4vw, 2.1vh), 16px); }
    @supports (height: 1dvh) { html { font-size: clamp(11px, min(4vw, 2.1dvh), 16px); } }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }
.grad {
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
}
.glass {
    background: var(--surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(1.125rem);
    -webkit-backdrop-filter: blur(1.125rem);
    border-radius: var(--radius);
}

/* Nền ánh sáng mờ */
.bg-orbs { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg); }
/* Quầng sáng: dùng radial-gradient thay cho filter: blur() cỡ lớn (rất nặng với GPU điện thoại, gây giật khi cuộn/gõ) */
.bg-orbs span { position: absolute; border-radius: 50%; background: radial-gradient(closest-side, var(--c), transparent); opacity: .5; animation: float 18s ease-in-out infinite; will-change: transform; }
.bg-orbs span:nth-child(1) { width: 36rem; height: 36rem; --c: var(--accent); top: -7.5rem; left: -5rem; }
.bg-orbs span:nth-child(2) { width: 33rem; height: 33rem; --c: #0aa6c9; bottom: -8.75rem; right: -3.75rem; animation-delay: -6s; }
.bg-orbs span:nth-child(3) { width: 26rem; height: 26rem; --c: #c0307c; top: 45%; left: 55%; opacity: .25; animation-delay: -11s; }
@keyframes float { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(2.5rem,-1.875rem) scale(1.1); } }

/* ============ Nút & ô nhập ============ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.75rem 1.25rem; border-radius: 0.875rem; font-weight: 600; font-size: 0.9375rem;
    transition: transform .15s, box-shadow .2s, background .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-sm { padding: 0.5rem 0.875rem; font-size: 0.8125rem; border-radius: 0.625rem; }
.btn-primary { background: linear-gradient(135deg, var(--accent), #3b95ff 60%, var(--accent-2)); color: #fff; box-shadow: 0 0.5rem 1.75rem -0.5rem rgba(45, 136, 255, .7); }
.btn-primary:hover { box-shadow: 0 0.75rem 2.125rem -0.5rem rgba(45, 136, 255, .9); transform: translateY(-1px); }
.btn-ghost { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: rgba(255,255,255,.2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.field { display: block; margin-bottom: 1rem; }
.field > span { display: block; font-size: 0.8125rem; color: var(--muted); margin-bottom: 0.375rem; font-weight: 500; }
.field input[type=text], .field input[type=password] {
    width: 100%; padding: 0.8125rem 0.9375rem; font: inherit; font-size: 0.9375rem; color: var(--text);
    background: var(--input); border: 1px solid var(--border); border-radius: 0.75rem; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 0.25rem rgba(45, 136, 255, .2); }

.seg { display: flex; gap: 0.5rem; }
.seg label { flex: 1; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
    display: block; text-align: center; padding: 0.6875rem 0.5rem; border-radius: 0.75rem; font-size: 0.875rem; font-weight: 500;
    background: var(--input); border: 1px solid var(--border); color: var(--muted); transition: all .2s;
}
.seg input:checked + span { color: #fff; border-color: var(--accent); background: rgba(45, 136, 255, .22); box-shadow: 0 0 0 0.1875rem rgba(45, 136, 255, .15); }
.seg input:focus-visible + span { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.seg-sm { margin-bottom: 0.75rem; }
.seg-sm span { padding: 0.5625rem 0.375rem; font-size: 0.8125rem; }

/* ============ Logo ============ */
.logo { display: inline-flex; align-items: center; gap: 0.625rem; font-weight: 800; font-size: 1.25rem; letter-spacing: -.3px; }
.logo-mark {
    display: block; flex: none; width: 2.25rem; height: 2.25rem; border-radius: 0.6875rem;
    box-shadow: 0 0.375rem 1.25rem -0.25rem rgba(77, 163, 255, .7);
}
.logo-mark img { display: block; width: 100%; height: 100%; }

/* ============ Trang đăng nhập ============ */
.auth-body { min-height: 100vh; }
.auth-wrap {
    min-height: 100vh; max-width: 70rem; margin: 0 auto; padding: 2rem 1.5rem;
    display: grid; grid-template-columns: 1.1fr 1fr; gap: 3.5rem; align-items: center;
}
.auth-hero h1 { font-size: clamp(2.125rem, 5vw, 3.5rem); line-height: 1.1; font-weight: 800; letter-spacing: -1.5px; margin: 1.625rem 0 1.125rem; }
.auth-hero > p { color: var(--muted); font-size: 1.0625rem; max-width: 30rem; }
.hero-points { list-style: none; margin-top: 1.75rem; display: grid; gap: 0.75rem; color: #cfd3e4; }
.hero-points li { display: flex; gap: 0.625rem; align-items: center; }

.auth-card { padding: 1.875rem; box-shadow: 0 1.875rem 5rem -1.875rem rgba(0,0,0,.8); }
.tabs { display: flex; gap: 0.375rem; padding: 0.3125rem; background: rgba(0,0,0,.3); border-radius: 0.875rem; margin-bottom: 1.5rem; }
.tab { flex: 1; padding: 0.625rem; border-radius: 0.625rem; font-weight: 600; font-size: 0.875rem; color: var(--muted); transition: all .2s; }
.tab.active { background: var(--surface-2); color: #fff; box-shadow: 0 2px 0.625rem rgba(0,0,0,.3); }
.divider { display: flex; align-items: center; gap: 0.875rem; margin: 1.375rem 0 1.125rem; color: var(--muted); font-size: 0.8125rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ============ Thanh trên & trang chủ ============ */
.topbar {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    max-width: 70rem; margin: 0 auto; padding: 1.375rem 1.5rem;
}
.user-chip { display: flex; align-items: center; gap: 0.75rem; padding: 0.375rem 0.5rem 0.375rem 0.375rem; background: var(--surface); border: 1px solid var(--border); border-radius: 62.4375rem; }
.avatar { display: grid; place-items: center; width: 2.375rem; height: 2.375rem; border-radius: 50%; font-weight: 700; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 0.875rem; }
.user-meta small { color: var(--muted); font-size: 0.75rem; }

.home { max-width: 70rem; margin: 0 auto; padding: 1.5rem 1.5rem 3.75rem; }
.home-head { text-align: center; margin: 1.5rem 0 2.75rem; }
.home-head h1 { font-size: clamp(1.75rem, 4.2vw, 2.75rem); font-weight: 800; letter-spacing: -1px; }
.home-head p { color: var(--muted); margin-top: 0.625rem; font-size: 1.0625rem; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.375rem; }
.card {
    --c: var(--accent);
    position: relative; text-align: left; padding: 2rem 1.75rem; overflow: hidden;
    display: flex; flex-direction: column; gap: 0.625rem;
    transition: transform .25s, border-color .25s, box-shadow .25s;
}
.card::before {
    content: ''; position: absolute; inset: 0; opacity: 0; transition: opacity .3s;
    background: radial-gradient(26.25rem 13.75rem at 20% 0%, color-mix(in srgb, var(--c) 35%, transparent), transparent 70%);
}
.card:hover { transform: translateY(-0.375rem); border-color: color-mix(in srgb, var(--c) 60%, transparent); box-shadow: 0 1.5rem 3.75rem -1.5rem color-mix(in srgb, var(--c) 70%, transparent); }
.card:hover::before { opacity: 1; }
.card > * { position: relative; }
.card-male { --c: var(--male); }
.card-female { --c: var(--female); }
.card-random { --c: var(--random); }
.card-icon {
    display: grid; place-items: center; width: 4rem; height: 4rem; border-radius: 1.125rem; font-size: 2rem; margin-bottom: 0.625rem;
    color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.card h2 { font-size: 1.375rem; font-weight: 700; }
.card p { color: var(--muted); font-size: 0.9375rem; flex: 1; }
.card-go { margin-top: 0.75rem; font-weight: 600; color: var(--c); transition: transform .2s; }
.card:hover .card-go { transform: translateX(0.375rem); }
.note { text-align: center; color: var(--muted); font-size: 0.8438rem; margin-top: 2.75rem; }

/* ============ Lớp phủ tìm kiếm ============ */
.overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1.5rem; background: rgba(10, 10, 10, .84); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.search-box { text-align: center; padding: 2.5rem 2.25rem; width: 100%; max-width: 26.25rem; }
.search-box h2 { margin-top: 1.625rem; font-size: 1.375rem; }
.search-box p { color: var(--muted); margin: 0.5rem 0 1.625rem; font-size: 0.875rem; }
.radar { position: relative; width: 7.5rem; height: 7.5rem; margin: 0 auto; display: grid; place-items: center; }
.radar i { position: relative; z-index: 1; font-style: normal; font-size: 1.875rem; width: 4rem; height: 4rem; border-radius: 50%; display: grid; place-items: center; filter: drop-shadow(0 0.5rem 1rem rgba(77, 163, 255, .45)); }
.radar i img { display: block; width: 100%; height: 100%; }
.radar span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--accent-2); opacity: 0; animation: ping 2.4s cubic-bezier(.2,.6,.3,1) infinite; }
.radar span:nth-child(2) { animation-delay: .8s; }
.radar span:nth-child(3) { animation-delay: 1.6s; }
@keyframes ping { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.4); opacity: 0; } }

/* ============ Phòng trò chuyện ============ */
.room-body { background: #05060a; height: 100dvh; overflow: hidden; }
.room { height: 100dvh; display: flex; flex-direction: column; padding: 0.875rem; gap: 0.875rem; max-width: 87.5rem; margin: 0 auto; }
.stage { position: relative; flex: 1; min-height: 0; border-radius: 1.5rem; overflow: hidden; background: radial-gradient(37.5rem 25rem at 50% 40%, #2a2b2c, #121314); border: 1px solid var(--border); }
#remoteVideo { width: 100%; height: 100%; object-fit: cover; background: #000; }

.peer-tag, .timer { position: absolute; top: 1rem; padding: 0.5rem 0.875rem; border-radius: 62.4375rem; font-size: 0.875rem; display: flex; align-items: center; gap: 0.5rem; background: rgba(10,11,16,.55); }
.peer-tag { left: 1rem; }
.peer-tag small { color: var(--muted); }
.peer-tag .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: #34d399; box-shadow: 0 0 0.625rem #34d399; }
.timer { right: 1rem; font-variant-numeric: tabular-nums; font-weight: 600; }

.pip {
    position: absolute; right: 1rem; bottom: 1rem; width: clamp(6.875rem, 22vw, 15rem); aspect-ratio: 4 / 3;
    border-radius: 1rem; overflow: hidden; background: #111; border: 2px solid rgba(255,255,255,.18);
    box-shadow: 0 0.875rem 2.5rem rgba(0,0,0,.6); z-index: 3;
}
.pip video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.pip-off { position: absolute; inset: 0; display: grid; place-items: center; background: #14151f; color: var(--muted); font-size: 0.8125rem; }

.status {
    position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 0.625rem; text-align: center; padding: 1.5rem; background: rgba(8, 9, 14, .86);
}
.status h2 { font-size: 1.375rem; }
.status p { color: var(--muted); max-width: 26.25rem; font-size: 0.9062rem; }
.status.no-spinner .spinner { display: none; }
.spinner { width: 2.875rem; height: 2.875rem; border-radius: 50%; border: 0.25rem solid rgba(255,255,255,.12); border-top-color: var(--accent-2); animation: spin 0.9s linear infinite; margin-bottom: 0.5rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { display: flex; justify-content: center; align-items: center; gap: 1rem; padding: 0.75rem 1.25rem; width: fit-content; margin: 0 auto; border-radius: 62.4375rem; }
.ctl {
    display: grid; place-items: center; width: 3.375rem; height: 3.375rem; border-radius: 50%;
    background: var(--surface-2); border: 1px solid var(--border); transition: transform .15s, background .2s;
}
.ctl:hover { background: rgba(255,255,255,.16); }
.ctl:active { transform: scale(.92); }
.ico { width: 1.5rem; height: 1.5rem; fill: currentColor; }
.ctl .off { display: none; }
.ctl.is-off { background: #fff; color: #111; }
.ctl.is-off .on { display: none; }
.ctl.is-off .off { display: block; }
.ctl-leave {
    width: 4.5rem; padding: 0; height: 3.375rem; border-radius: 62.4375rem; grid-auto-flow: column; gap: 0.625rem;   /* chỉ biểu tượng, không kèm chữ */
    background: var(--danger); border-color: transparent; font-weight: 600; font-size: 0.9375rem; color: #fff;
}
.ctl-leave:hover { background: #ff6573; }


/* ============ Phụ trợ chung ============ */
.tap-play {
    position: absolute; left: 50%; bottom: 1.125rem; transform: translateX(-50%); z-index: 4;
    padding: 0.75rem 1.25rem; border-radius: 62.4375rem; font-weight: 600; font-size: 0.875rem; white-space: nowrap;
    background: rgba(24, 25, 26, .88); border: 1px solid var(--border);
}
.ctl:focus-visible, .btn:focus-visible, .card:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 0.1875rem; }
.room-body { overscroll-behavior: none; touch-action: manipulation; }
.controls, .ctl { user-select: none; -webkit-user-select: none; }
.auth-body { min-height: 100dvh; }
.auth-wrap { min-height: 100dvh; }

/* Máy tính: video của đối phương hiển thị đủ khung, không bị cắt (kể cả khi họ dùng điện thoại dọc) */
@media (min-width: 901px) {
    #remoteVideo { object-fit: contain; background: transparent; }
}

/* Màn hình cảm ứng: tăng vùng chạm, ô nhập 16px để iOS không tự phóng to */
@media (pointer: coarse) {
    .btn { min-height: max(3rem, 44px); }
    .btn-sm { min-height: max(2.5rem, 38px); }
    .tab { min-height: max(2.75rem, 42px); }
    .field input[type=text], .field input[type=password] { font-size: 16px; min-height: max(3.125rem, 44px); }
    .seg span { min-height: max(2.875rem, 42px); display: grid; place-items: center; }
}

/* Thiết bị không có chuột: bỏ hiệu ứng hover bị "kẹt" sau khi chạm */
@media (hover: none) {
    .card:hover { transform: none; box-shadow: none; border-color: var(--border); }
    .card:hover::before { opacity: 0; }
    .card:hover .card-go { transform: none; }
    .card:active { transform: scale(.98); border-color: color-mix(in srgb, var(--c) 60%, transparent); }
    .card:active::before { opacity: 1; }
    .btn-primary:hover { transform: none; }
    .ctl:hover { background: var(--surface-2); }
    .ctl.is-off:hover { background: #fff; }
    .ctl-leave:hover { background: var(--danger); }
}

@media (prefers-reduced-motion: reduce) {
    .bg-orbs span { animation: none; }
    .overlay, .dialog { animation: none; }
}

/* ============ Máy tính bảng & điện thoại ============ */
@media (max-width: 900px) {
    .auth-wrap { grid-template-columns: 1fr; gap: 1.75rem; padding: 1.75rem 1.25rem; align-content: center; }
    .auth-hero { text-align: center; }
    .auth-hero > p { margin: 0 auto; }
    .hero-points { justify-items: center; }
    .auth-card { width: 100%; max-width: 32.5rem; margin: 0 auto; }

    /* Thẻ chọn kiểu tìm kiếm: dạng hàng ngang  [icon | tiêu đề + mô tả | mũi tên] */
    .cards { grid-template-columns: 1fr; gap: 0.875rem; max-width: 35rem; margin: 0 auto; }
    .card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2px 1rem; padding: 1.125rem 1.25rem; }
    .card-icon { grid-row: 1 / span 2; margin: 0; width: 3.5rem; height: 3.5rem; font-size: 1.75rem; }
    .card h2 { grid-column: 2; font-size: 1.1875rem; }
    .card p { grid-column: 2; grid-row: 2; font-size: 0.875rem; flex: none; }
    .card-go { grid-column: 3; grid-row: 1 / span 2; margin: 0; font-size: 0; }
    .card-go::after { content: '→'; font-size: 1.5rem; }
}

/* ============ Điện thoại ============ */
@media (max-width: 560px) {
    .auth-wrap { padding: calc(1.25rem + env(safe-area-inset-top)) 1rem calc(1.5rem + env(safe-area-inset-bottom)); gap: 1.375rem; }
    .auth-hero h1 { font-size: 2rem; letter-spacing: -1px; margin: 1rem 0 0.625rem; }
    .auth-hero > p { font-size: 0.9375rem; }
    .hero-points { display: none; }
    .auth-card { padding: 1.25rem; border-radius: 1.375rem; }
    .tabs { margin-bottom: 1.125rem; }

    .topbar { padding: calc(0.875rem + env(safe-area-inset-top)) 1rem 0.875rem; }
    .logo { font-size: 1.125rem; }
    .user-meta { display: none; }
    .home { padding: 0.5rem 1rem calc(2.5rem + env(safe-area-inset-bottom)); }
    .home-head { margin: 0.5rem 0 1.5rem; }
    .home-head p { font-size: 0.9375rem; }
    .note { margin-top: 1.625rem; font-size: 0.8125rem; }
    .search-box { padding: 2rem 1.375rem; }
}

/* ============ Phòng gọi: điện thoại dọc & xoay ngang ============
   Video chiếm toàn màn hình, thanh điều khiển nổi phía trên video */
@media (max-width: 700px), (max-height: 500px) and (orientation: landscape) {
    .room { position: relative; padding: 0; gap: 0; max-width: none; }
    .stage { border-radius: 0; border: 0; }
    #remoteVideo { object-fit: cover; }

    .peer-tag, .timer { top: calc(0.75rem + env(safe-area-inset-top)); font-size: 0.8125rem; padding: 0.4375rem 0.75rem; }
    .peer-tag { left: calc(0.75rem + env(safe-area-inset-left)); }
    .timer { right: calc(0.75rem + env(safe-area-inset-right)); }

    .controls {
        position: absolute; z-index: 5; margin: 0; gap: 0.875rem; padding: 0.625rem 0.875rem;
        background: rgba(24, 25, 26, .6);
    }
    .ctl { width: 3.5rem; height: 3.5rem; }
    .ctl-leave { width: 4.5rem; padding: 0; }
    .ctl-leave span { display: none; }
}

/* Điện thoại dọc: video nhỏ của mình ở góc trên phải, thanh điều khiển ở đáy */
@media (max-width: 700px) {
    .controls { left: 50%; transform: translateX(-50%); bottom: calc(1rem + env(safe-area-inset-bottom)); }
    .pip {
        top: calc(3.625rem + env(safe-area-inset-top)); right: calc(0.75rem + env(safe-area-inset-right)); bottom: auto;
        width: clamp(6rem, 28vw, 8.75rem); aspect-ratio: 3 / 4; border-radius: 0.875rem;
    }
    .tap-play { bottom: calc(6.25rem + env(safe-area-inset-bottom)); }
    .status { padding-bottom: calc(6.25rem + env(safe-area-inset-bottom)); }
}

/* Điện thoại xoay ngang: thanh điều khiển dọc bên phải, video của mình ở góc dưới */
@media (max-height: 500px) and (orientation: landscape) {
    .controls {
        flex-direction: column; right: calc(0.75rem + env(safe-area-inset-right)); top: 50%; bottom: auto;
        transform: translateY(-50%); border-radius: 2.25rem; padding: 0.75rem 0.625rem;
    }
    .ctl, .ctl-leave { width: 3.25rem; height: 3.25rem; }
    .pip {
        bottom: 0.75rem; right: calc(5.5rem + env(safe-area-inset-right)); top: auto;
        width: clamp(7.5rem, 22vw, 11.875rem); aspect-ratio: 4 / 3;
    }
    .tap-play { bottom: 0.875rem; }
    .status h2 { font-size: 1.125rem; }
}

/* ============ Thông báo & tìm kiếm ở nền ============ */
.notice { max-width: 40rem; margin: 0 auto 1.125rem; padding: 0.625rem 0.875rem; border-radius: 0.875rem; text-align: center; font-size: 0.875rem; color: #fff; background: var(--surface); border: 1px solid var(--border); }
.notify { max-width: 47.5rem; width: 100%; margin: 2rem auto 0; padding: 0.75rem 1rem; }
.notify-row { display: flex; align-items: center; gap: 0.75rem; }
.notify-icon { font-size: 1.25rem; flex: none; }
.notify-row p { flex: 1; min-width: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.4; }
.notify-row .btn { flex: none; }
.notify-more { margin-top: 0.375rem; }
.notify-more summary { cursor: pointer; font-size: 0.7812rem; color: var(--muted); padding: 0.25rem 0; list-style: none; user-select: none; }
.notify-more summary::-webkit-details-marker { display: none; }
.notify-more summary::before { content: '⚙ '; }
.notify-opts { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem 0.875rem; flex-wrap: wrap; padding-top: 0.375rem; }
.check { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; color: var(--muted); cursor: pointer; min-height: 2.25rem; }
.check input { width: 1.125rem; height: 1.125rem; accent-color: var(--accent); }

/* ============ Vừa khít màn hình điện thoại (không phải kéo xuống) ============ */
.home-body { height: auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }   /* height: auto: không bị "html, body { height: 100% }" ép đúng bằng màn hình (làm khoảng chừa cho thanh điều hướng bị nội dung đè lên) */
/* Trong flex dọc, margin:auto làm thanh trên co về vừa nội dung -> logo và nút Cài đặt bị kéo vào giữa, đè lên thanh điều hướng */
.home-body .topbar { width: 100%; }
.home-body .home { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: center; }

.overlay { overflow-y: auto; }
.search-box { max-height: calc(100dvh - 1.5rem); overflow-y: auto; }

@media (max-width: 560px) {
    .topbar { padding: calc(0.5rem + env(safe-area-inset-top)) 0.875rem 0.5rem; }
    .logo-mark { width: 2rem; height: 2rem; }
    .avatar { width: 2rem; height: 2rem; }
    .home { padding: 0.25rem 0.875rem calc(0.875rem + env(safe-area-inset-bottom)); }
    .home-head { margin: 0.25rem 0 0.875rem; }
    .home-head h1 { font-size: 1.5rem; letter-spacing: -.5px; }
    .home-head p { display: none; }

    .cards { gap: 0.625rem; }
    .card { padding: 0.75rem 1rem; gap: 0 0.875rem; border-radius: 1.125rem; }
    .card-icon { width: 2.875rem; height: 2.875rem; font-size: 1.5rem; border-radius: 0.875rem; }
    .card h2 { font-size: 1.0625rem; }
    .card p { font-size: 0.8125rem; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .card-go::after { font-size: 1.375rem; }

    .notify { margin-top: 0.75rem; padding: 0.5rem 0.75rem; border-radius: 1rem; }
    .notify-row p { font-size: 0.7812rem; }
    .notify-row .btn { min-height: 2.375rem; padding: 0.375rem 0.875rem; }
    .note { margin-top: 0.625rem; font-size: 0.7188rem; line-height: 1.4; }
    .notice { margin-bottom: 0.625rem; font-size: 0.8125rem; }

    .search-box { padding: 1.5rem 1.125rem; }
    .radar { width: 6rem; height: 6rem; }
    .radar i { width: 3.375rem; height: 3.375rem; font-size: 1.625rem; }
    .search-box h2 { margin-top: 1rem; font-size: 1.25rem; }
    .search-box p { margin: 0.375rem 0 1rem; }

    /* Trang đăng nhập / đăng ký gọn lại */
    .auth-wrap { padding-top: calc(0.75rem + env(safe-area-inset-top)); padding-bottom: calc(0.875rem + env(safe-area-inset-bottom)); gap: 0.875rem; }
    .auth-hero h1 { font-size: 1.75rem; margin: 0.75rem 0 0.375rem; }
    .auth-card { padding: 1rem; }
    .tabs { margin-bottom: 0.75rem; }
    .field { margin-bottom: 0.625rem; }
    .field > span { margin-bottom: 0.25rem; font-size: 0.7812rem; }
    .field input[type=text], .field input[type=password] { padding: 0.5625rem 0.8125rem; min-height: max(2.75rem, 42px); }
    .seg span { min-height: max(2.625rem, 40px); padding: 0.5rem 0.375rem; }
    .divider { margin: 0.75rem 0 0.625rem; }
    .seg-sm { margin-bottom: 0.5rem; }
    .btn { min-height: max(2.875rem, 42px); }
}

/* Điện thoại màn hình ngắn (iPhone SE, trình duyệt có thanh địa chỉ lớn...) */
@media (max-width: 560px) and (max-height: 700px) {
    .card { padding: 0.625rem 1rem; }
    .home-head { margin-bottom: 0.625rem; }
    .auth-hero > p { font-size: 0.875rem; }   /* vẫn hiện tiêu đề + mô tả; fit.js tự co lại nếu vẫn tràn */
    .search-box h2 { margin-top: 0.75rem; }
}

/* Điện thoại xoay ngang / màn hình rất thấp */
@media (max-height: 480px) and (orientation: landscape) {
    .topbar { padding-top: 0.375rem; padding-bottom: 0.375rem; }
    .home-head { margin: 0 0 0.5rem; }
    .home-head h1 { font-size: 1.25rem; }
    .home-head p, .card p, .note { display: none; }
    .cards { grid-template-columns: repeat(3, 1fr); max-width: none; gap: 0.5rem; }
    .card { grid-template-columns: auto 1fr; padding: 0.5rem 0.75rem; }
    .card-go { display: none; }
    .notify { margin-top: 0.5rem; }
    .radar { width: 4.375rem; height: 4.375rem; }
    .radar i { width: 2.5rem; height: 2.5rem; font-size: 1.25rem; }
    .search-box { padding: 0.875rem 1.125rem; }
    .search-box h2 { margin-top: 0.5rem; font-size: 1.0625rem; }
}

/* Khi fit.js thu nhỏ nội dung cho vừa màn hình: bỏ chiều cao tối thiểu để không dư khoảng trống */
.fit-on .auth-wrap { min-height: 0; align-content: start; }
.fit-on.home-body .home { flex: 0 0 auto; justify-content: flex-start; }

/* ============ Cài đặt ============ */
.icon-btn { width: max(2.5rem, 38px); height: max(2.5rem, 38px); min-height: max(2.5rem, 38px); padding: 0; font-size: 1.125rem; line-height: 1; position: relative; flex: none; }
.icon-btn.has-dot::after { content: ''; position: absolute; top: 0.375rem; right: 0.375rem; width: 0.5625rem; height: 0.5625rem; border-radius: 50%; background: var(--random); box-shadow: 0 0 0 2px var(--bg-2); }

.overlay-sheet { overflow-y: auto; }
.sheet { width: 100%; max-width: 30rem; max-height: calc(100dvh - 1.5rem); overflow-y: auto; padding: 1.25rem 1.375rem; background: rgba(36, 37, 38, .94); box-shadow: 0 1.875rem 5rem -1.25rem rgba(0, 0, 0, .8); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; margin-bottom: 0.25rem; }
.sheet-head h2 { font-size: 1.25rem; }

.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.875rem 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.set-text { display: flex; flex-direction: column; gap: 0.1875rem; min-width: 0; }
.set-text strong { font-size: 0.9375rem; }
.set-text small { color: var(--muted); font-size: 0.7812rem; line-height: 1.45; }
.set-row:has(input:disabled) { cursor: not-allowed; }
.set-row:has(input:disabled) .switch { opacity: .45; }   /* chỉ làm mờ công tắc, giữ lời giải thích dễ đọc */
.set-text small.set-detail { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.6875rem; opacity: .75; word-break: break-word; }

.switch { position: relative; flex: none; width: 3.125rem; height: 1.875rem; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch input:disabled { cursor: not-allowed; }
.switch i { position: absolute; inset: 0; border-radius: 62.4375rem; background: rgba(255, 255, 255, .14); border: 1px solid var(--border); transition: background .2s; }
.switch i::after { content: ''; position: absolute; top: 0.1875rem; left: 0.1875rem; width: 1.375rem; height: 1.375rem; border-radius: 50%; background: #fff; box-shadow: 0 2px 0.375rem rgba(0, 0, 0, .4); transition: transform .2s; }
.switch input:checked + i { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(1.25rem); }
.switch input:focus-visible + i { outline: 2px solid var(--accent-2); outline-offset: 2px; }


@media (max-width: 560px) {
    /* Bảng cài đặt nằm giữa màn hình, nhích lên trên một chút (đệm dưới lớn hơn đệm trên) */
    .overlay-sheet { place-items: center; padding: 0.75rem 0.75rem 3.5rem; }
    .sheet { width: 100%; border-radius: 1.375rem; padding: 1rem 1.125rem 1.125rem; }
    .set-row { padding: 0.75rem 0; }
}
@media (prefers-reduced-motion: reduce) { .switch i, .switch i::after { transition: none; } }

/* Bảng nổi trên điện thoại: sát mép màn hình hơn, chữ gọn hơn */
@media (max-width: 560px) {
    .overlay { padding: 0.75rem; }
    .search-box h2 { font-size: 1.1875rem; }
    .set-text strong { font-size: 0.9062rem; }
    .set-text small { font-size: 0.75rem; }
}
@media (max-width: 560px) and (max-height: 700px) {
    .radar { width: 5rem; height: 5rem; }
    .radar i { width: 2.875rem; height: 2.875rem; font-size: 1.375rem; }
    .search-box { padding: 1.125rem 1rem; }
    .sheet { padding-top: 0.75rem; }
    .set-row { padding: 0.5625rem 0; }
    .set-text small { line-height: 1.35; }
}

/* ============ Thanh điều hướng & hồ sơ ============ */
.tabbar { position: fixed; z-index: 40; display: flex; align-items: center; gap: 0.25rem; top: 1.25rem; left: 50%; transform: translateX(-50%); padding: 0.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.tab-item { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.5rem 1.1rem; border-radius: 999px; color: #fff; font-size: 0.9rem; font-weight: 600; transition: color .2s, background .2s; -webkit-tap-highlight-color: transparent; }
.tab-item:hover { color: #fff; }
.tab-item.active { color: #fff; background: var(--surface-2); }
.tab-item svg { width: 1.375rem; height: 1.375rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-item.active svg { fill: currentColor; }
.tab-item:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.avatar.has-img { background-size: cover; background-position: center; color: transparent; font-size: 0; }
.avatar-lg { width: 5.5rem; height: 5.5rem; font-size: 2rem; flex: none; }
.peer-avatar { width: 1.75rem; height: 1.75rem; border-radius: 50%; object-fit: cover; margin: -0.25rem 0 -0.25rem -0.4rem; }

.profile { max-width: 34rem; width: 100%; margin: 0 auto; padding: 1.5rem; }
.profile-top { display: flex; align-items: center; gap: 1.1rem; margin-bottom: 1.25rem; }
.profile-id { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.profile-id strong { font-size: 1.1rem; overflow-wrap: anywhere; }
.profile-id small { color: var(--muted); }
.profile-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.profile .set-row { border-bottom: 0; padding: 0.25rem 0 1rem; }

/* Điện thoại / máy tính bảng: thanh điều hướng dính đáy màn hình */
@media (max-width: 900px) {
    .tabbar { top: auto; bottom: 0; left: 0; right: 0; transform: none; justify-content: space-around; gap: 0; padding: 0.3rem 0.5rem calc(0.3rem + env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 0; background: rgba(24, 25, 26, .94); }
    .tab-item { flex: 1; max-width: 11rem; flex-direction: column; gap: 0.1rem; padding: 0.35rem 0.5rem; font-size: 0.7rem; border-radius: 0.875rem; min-height: max(3rem, 46px); background: none; }
    .tab-item.active { background: none; }
    .tab-item svg { width: 1.5rem; height: 1.5rem; }
    .home-body { padding-bottom: calc(var(--tabbar-h, calc(4.5rem + env(safe-area-inset-bottom))) + 1rem); }   /* --tabbar-h: chiều cao thật, đo bởi fit.js */
}
@media (max-width: 560px) {
    .profile { padding: 1rem; border-radius: 1.125rem; }
    .profile-top { margin-bottom: 0.9rem; gap: 0.9rem; }
    .avatar-lg { width: 4.75rem; height: 4.75rem; font-size: 1.75rem; }
    .profile .set-row { padding-bottom: 0.75rem; }
}
@media (max-width: 560px) and (max-height: 700px) {
    .avatar-lg { width: 4rem; height: 4rem; font-size: 1.5rem; }
    .profile .set-text small { display: none; }
}
@media (max-height: 480px) and (orientation: landscape) {
    .tabbar { padding-top: 0.15rem; padding-bottom: calc(0.15rem + env(safe-area-inset-bottom)); }
    .tab-item { flex-direction: row; min-height: 2.5rem; font-size: 0.8rem; }
    .home-body { padding-bottom: calc(var(--tabbar-h, calc(3rem + env(safe-area-inset-bottom))) + 0.75rem); }
}

/* ============ Danh sách nút tìm kiếm xếp sát phía trên, căn trái, thẳng hàng (điện thoại / máy tính bảng) ============ */
@media (max-width: 900px) {
    .home-body .home { justify-content: flex-start; }
    .home { padding-top: 0.5rem; }
    .home-head { text-align: left; margin: 0.25rem 0 0.875rem; }
    .home-head h1 { font-size: 1.375rem; letter-spacing: -0.02em; }
    .cards { max-width: none; width: 100%; margin: 0; gap: 0.625rem; }
    .card { width: 100%; }
    .note { text-align: left; margin-top: 1rem; }
}

/* Nền phẳng màu xám than (bỏ các quầng sáng màu) */
.bg-orbs span { display: none; }

/* Màn hình máy tính hẹp (901–1040px): bớt tên người dùng để thanh điều hướng ở giữa không chạm vào khung tài khoản */
@media (min-width: 901px) and (max-width: 1040px) {
    .home-body .user-meta { display: none; }
}

/* ============ Chế độ tìm kiếm: gọi video / nhắn tin (chữ mô tả trong thẻ đổi theo chế độ) ============ */
.m-text { display: none; }
.mode-text .m-text { display: inline; }
.mode-text .m-video { display: none; }

/* ============ Phòng nhắn tin (chat.php) ============ */
.chat-stage .peer-tag, .chat-stage .timer { z-index: 3; }
.chat-log {
    position: absolute; inset: 0; z-index: 1; overflow-y: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column; gap: 0.5rem; padding: 4.25rem 1rem 1rem;
    scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent;
}
.chat-log::before { content: ''; flex: 1 0 0; }          /* đẩy tin nhắn xuống sát ô nhập khi còn ít tin */
.chat-hint { align-self: center; text-align: center; max-width: 24rem; color: var(--muted); font-size: 0.78rem; padding: 0.375rem 0.875rem; border-radius: 62.4375rem; background: rgba(255, 255, 255, .06); }
.chat-sys { align-self: center; text-align: center; max-width: 90%; color: var(--muted); font-size: 0.8rem; padding: 0.375rem 0.875rem; border-radius: 62.4375rem; background: rgba(255, 255, 255, .06); margin: 0.25rem 0; }

.msg-group { display: flex; align-items: flex-end; gap: 0.5rem; max-width: min(82%, 36rem); margin-top: 0.375rem; }
.msg-group.mine { align-self: flex-end; }
.msg-group.theirs { align-self: flex-start; }
.msg-col { display: flex; flex-direction: column; gap: 0.1875rem; min-width: 0; }
.msg-group.mine .msg-col { align-items: flex-end; }
.msg-avatar { width: 1.75rem; height: 1.75rem; border-radius: 50%; object-fit: cover; flex: none; }

.bubble { max-width: 100%; padding: 0.5rem 0.8125rem 0.375rem; border-radius: 1.125rem; font-size: 0.9688rem; line-height: 1.45; overflow-wrap: anywhere; }
.bubble-text { white-space: pre-wrap; }
.bubble time { display: block; margin-top: 0.125rem; text-align: right; font-size: 0.6875rem; opacity: .6; font-variant-numeric: tabular-nums; }
.theirs .bubble { background: var(--surface-2); border-bottom-left-radius: 0.375rem; }
.mine .bubble { background: linear-gradient(135deg, var(--accent), #1f6fe0); color: #fff; border-bottom-right-radius: 0.375rem; }
.bubble.pending { opacity: .6; }
.bubble.failed { background: #5a2a30; }
.bubble-err { color: #ffb3bb; font-size: 0.72rem; }
button.bubble-err { text-align: left; text-decoration: underline; cursor: pointer; padding: 0.125rem 0; }

.typing { align-self: flex-start; display: flex; gap: 0.25rem; margin: 0.25rem 0 0 2.25rem; padding: 0.75rem 0.875rem; border-radius: 1.125rem; border-bottom-left-radius: 0.375rem; background: var(--surface-2); }
.typing span { width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--muted); animation: typing-dot 1.2s ease-in-out infinite; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-0.25rem); opacity: 1; } }

/* Thanh nhập tin: rời phòng · ô nhập · gửi (thay cho thanh mic/camera của phòng video) */
.composer { position: relative; z-index: 10; transform: none; left: auto; right: auto; top: auto; bottom: auto; flex-direction: row; align-items: flex-end; width: 100%; max-width: none; margin: 0; gap: 0.5rem; padding: 0.5rem; border-radius: 1.875rem; }
.composer textarea {
    flex: 1; min-width: 0; resize: none; overflow-y: auto; min-height: 3.375rem; max-height: 8rem;
    padding: 0.875rem 1.125rem; border-radius: 1.6875rem; border: 1px solid var(--border);
    background: var(--input); color: var(--text); font: inherit; font-size: 1rem; line-height: 1.4; outline: none;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { border-color: var(--accent); }
.composer textarea:disabled { opacity: .55; cursor: not-allowed; }
.composer .ctl, .composer .ctl-leave { flex: none; width: 3.375rem; height: 3.375rem; }
.composer .ctl-leave { padding: 0; }
.ctl-send { background: var(--accent); border-color: transparent; color: #fff; }
.ctl-send:hover { background: #4a9bff; }
.ctl-send:disabled { opacity: .4; cursor: not-allowed; background: var(--accent); }

@media (max-width: 700px), (max-height: 500px) and (orientation: landscape) {
    .chat-room { padding: 0; gap: 0; }
    .chat-room .composer { margin: 0.5rem; margin-bottom: calc(0.5rem + env(safe-area-inset-bottom)); width: auto; background: rgba(36, 37, 38, .96); }
    .chat-log { padding-top: calc(3.75rem + env(safe-area-inset-top)); padding-left: 0.75rem; padding-right: 0.75rem; }
    .chat-stage .status { padding-bottom: 1.5rem; }
    .msg-group { max-width: 88%; }
}
@media (max-height: 500px) and (orientation: landscape) {
    .chat-room .composer { margin-right: calc(0.5rem + env(safe-area-inset-right)); margin-left: calc(0.5rem + env(safe-area-inset-left)); }
    .chat-log { padding-top: calc(3.25rem + env(safe-area-inset-top)); }
}
@media (hover: none) {
    .ctl-send:hover { background: var(--accent); }
}
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; opacity: .8; } }

/* Đối phương thoát website nhưng chưa rời phòng */
.away-note { position: absolute; z-index: 3; top: 4rem; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 2rem); padding: 0.4375rem 0.875rem; border-radius: 62.4375rem; text-align: center; font-size: 0.78rem; color: #ffd9a0; background: rgba(40, 32, 18, .92); border-color: rgba(255, 181, 71, .35); }
@media (max-width: 700px), (max-height: 500px) and (orientation: landscape) {
    .away-note { top: calc(3.75rem + env(safe-area-inset-top)); }
}


/* ============ Hiệu năng ============ */
/* Phòng gọi video: các nút/nhãn nổi phía trên video đang phát không dùng backdrop-filter (mỗi khung hình video buộc phải làm mờ lại -> giật) */
.room-body .glass { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(24, 25, 26, .78); }
/* Danh sách tin nhắn: cuộn mượt kiểu quán tính trên iOS cũ */
.chat-log { -webkit-overflow-scrolling: touch; }
/* Ảnh/video không bị kéo giãn ngoài ý muốn khi chạm giữ */
video { background: #000; }
/* Màn hình yếu: bỏ chuyển động trang trí */
@media (max-width: 900px) and (prefers-reduced-motion: no-preference) {
    .bg-orbs span { animation-duration: 28s; }
}


/* Popup thông báo (lỗi đăng nhập / đăng ký) */
.dialog { width: 100%; max-width: 22rem; padding: 1.625rem 1.5rem 1.5rem; text-align: center; color: #fff; background: rgba(36, 37, 38, .96); border: 1px solid var(--border); animation: pop .2s ease-out; }
.dialog-icon { width: 3.25rem; height: 3.25rem; margin: 0 auto 0.875rem; border-radius: 50%; display: grid; place-items: center; font-size: 1.625rem; font-weight: 800; color: #ff4d5e; background: rgba(255, 77, 94, .15); }
.dialog h2 { font-size: 1.1875rem; line-height: 1.3; color: #fff; }
.dialog p { margin: 0.5rem 0 0; font-size: 0.9375rem; line-height: 1.5; color: #e4e6eb; }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }

/* ============ Phòng nhắn tin: emoji, ảnh, video ============ */
.composer .ctl-tool { flex: none; width: 2.5rem; height: 2.5rem; margin-bottom: 0.4375rem; background: transparent; border-color: transparent; color: var(--accent); }
.composer .ctl-tool:hover:not(:disabled) { background: rgba(255, 255, 255, .08); }
.composer .ctl-tool:disabled { opacity: .35; cursor: not-allowed; }
.composer .ctl-tool[aria-expanded="true"] { background: rgba(255, 255, 255, .12); }

.emoji-panel { position: absolute; right: 0.5rem; bottom: calc(100% + 0.5rem); z-index: 20; width: min(22rem, calc(100% - 1rem)); max-height: 18rem; display: flex; flex-direction: column; padding: 0.5rem; border-radius: 1.125rem; background: rgba(36, 37, 38, .98); box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, .5); animation: pop .15s ease-out; }
.emoji-tabs { display: flex; gap: 0.125rem; padding-bottom: 0.375rem; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.emoji-tab { flex: none; width: 2.25rem; height: 2.25rem; border-radius: 0.625rem; font-size: 1.25rem; line-height: 1; }
.emoji-tab:hover { background: rgba(255, 255, 255, .08); }
.emoji-tab.active { background: var(--surface-2); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr)); gap: 0.125rem; overflow-y: auto; padding-top: 0.375rem; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.emoji-btn { height: 2.5rem; border-radius: 0.625rem; font-size: 1.5rem; line-height: 1; }
.emoji-btn:hover, .emoji-btn:active { background: var(--surface-2); }

.bubble-emoji, .mine .bubble-emoji, .theirs .bubble-emoji { background: none; padding: 0 0.125rem; }
.bubble-emoji .bubble-text { font-size: 2.6rem; line-height: 1.15; }
.bubble-emoji time { color: var(--muted); opacity: 1; }

.bubble-media { padding: 0.25rem; }
.bubble-media time { padding: 0 0.375rem; }
.bubble-media.pending { opacity: .92; }
.media-frame { position: relative; width: min(18rem, 66vw); min-height: 6rem; max-height: 24rem; border-radius: 0.875rem; overflow: hidden; background: rgba(0, 0, 0, .28); }
.media-open { display: block; width: 100%; height: 100%; padding: 0; cursor: zoom-in; }
.media-frame img, .media-frame video { display: block; width: 100%; height: 100%; max-height: 24rem; object-fit: cover; background: #000; }
.media-frame video { object-fit: contain; }
.media-frame.gated img, .media-frame.gated video { filter: blur(1.75rem) brightness(.7); transform: scale(1.12); pointer-events: none; }
.media-gate { position: absolute; inset: 0; display: grid; place-items: center; padding: 0.5rem; color: #fff; font-size: 0.875rem; font-weight: 600; text-align: center; background: rgba(0, 0, 0, .22); cursor: pointer; }
.media-frame.broken { display: grid; place-items: center; }
.media-frame.broken img, .media-frame.broken video { display: none; }
.media-frame.broken::after { content: 'Không thể hiển thị tệp này'; padding: 1rem; color: var(--muted); font-size: 0.8125rem; text-align: center; }
.media-progress { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); }
.media-progress span { padding: 0.25rem 0.625rem; border-radius: 62.4375rem; background: rgba(0, 0, 0, .6); color: #fff; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.media-progress::after { content: ''; position: absolute; left: 0; bottom: 0; height: 0.25rem; width: var(--p, 0%); background: var(--accent); transition: width .15s linear; }

.chat-toast { position: absolute; left: 50%; bottom: 0.75rem; z-index: 6; transform: translateX(-50%); width: max-content; max-width: min(90%, 26rem); padding: 0.625rem 0.875rem; border-radius: 0.875rem; background: rgba(36, 37, 38, .96); border: 1px solid var(--border); color: #fff; font-size: 0.875rem; line-height: 1.4; text-align: center; box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, .5); }

.lightbox { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: calc(3.5rem + env(safe-area-inset-top)) 1rem calc(1rem + env(safe-area-inset-bottom)); background: rgba(0, 0, 0, .92); }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 0.5rem; }
.lightbox-close { position: absolute; top: calc(0.75rem + env(safe-area-inset-top)); right: 0.75rem; width: 2.5rem; height: 2.5rem; border-radius: 50%; background: rgba(255, 255, 255, .14); color: #fff; font-size: 1.125rem; line-height: 1; }
@media (prefers-reduced-motion: reduce) { .emoji-panel { animation: none; } }

/* Màn hình rất hẹp (≤ 380px): thu gọn thanh nhập để ô gõ chữ vẫn đủ rộng */
@media (max-width: 380px) {
    .chat-room .composer { gap: 0.25rem; padding: 0.375rem; }
    .composer .ctl, .composer .ctl-leave { width: 3rem; height: 3rem; }
    .composer .ctl-tool { width: 2.25rem; height: 2.25rem; margin-bottom: 0.375rem; }
}

/* Khung tin nhắn và ô soạn tin liền nhau thành một khối (không còn khoảng hở) */
.chat-room { gap: 0; }
.chat-room .chat-stage { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: none; }
.chat-room .composer { margin: 0; padding: 0.625rem 0.75rem; border-radius: 0 0 1.5rem 1.5rem; border: 1px solid var(--border); border-top-color: rgba(255, 255, 255, .06); background: #18191a; }
@media (max-width: 700px), (max-height: 500px) and (orientation: landscape) {
    .chat-room .composer { width: 100%; margin: 0; border-radius: 0; border-left: none; border-right: none; border-bottom: none; padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom)); }
}
@media (max-height: 500px) and (orientation: landscape) {
    .chat-room .composer { padding-left: calc(0.5rem + env(safe-area-inset-left)); padding-right: calc(0.5rem + env(safe-area-inset-right)); }
}
@media (max-width: 380px) {
    .chat-room .composer { padding: 0.375rem 0.375rem calc(0.375rem + env(safe-area-inset-bottom)); }
}

/* Bảng emoji: hàng chọn nhóm không bị co lại (trước đây lưới emoji chiếm chỗ làm hàng nhóm bị cắt/đè) */
.emoji-tabs { flex: none; min-height: 2.75rem; overflow-y: hidden; padding: 0.125rem 0 0.375rem; }
.emoji-grid { flex: 1 1 auto; min-height: 0; }

/* ============ Tin nhắn thoại ============ */
.composer .ctl-mic:not(:disabled) { color: var(--accent); }
.composer.recording #msgInput, .composer.recording #btnAttach, .composer.recording #btnEmoji, .composer.recording #btnMic { display: none !important; }
.rec-bar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.625rem; min-height: 3.375rem; padding: 0 1rem 0 0.375rem; border-radius: 1.6875rem; background: var(--input); border: 1px solid var(--border); }
.rec-bar .ctl-tool { margin-bottom: 0; color: #ff6b78; }
.rec-dot { flex: none; width: 0.625rem; height: 0.625rem; border-radius: 50%; background: #ff4d5e; animation: rec-blink 1s ease-in-out infinite; }
.rec-time { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 0.875rem; }
@keyframes rec-blink { 50% { opacity: .25; } }

.voice-frame { display: flex; align-items: center; gap: 0.625rem; width: min(15rem, 62vw); min-height: 0; max-height: none; padding: 0.3125rem 0.75rem 0.3125rem 0.3125rem; overflow: visible; background: transparent; aspect-ratio: auto; }
.voice-play { flex: none; display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; background: var(--accent); color: #fff; }
.mine .voice-play { background: #fff; color: #1f6fe0; }
.voice-play .i-pause, .voice-frame.playing .voice-play .i-play { display: none; }
.voice-frame.playing .voice-play .i-pause { display: block; }
.voice-track { position: relative; flex: 1; height: 0.375rem; border-radius: 62.4375rem; background: rgba(255, 255, 255, .25); cursor: pointer; }
.voice-track::before { content: ''; position: absolute; inset: -0.625rem 0; }   /* vùng bấm rộng hơn để dễ tua trên điện thoại */
.voice-fill { height: 100%; width: 0; border-radius: inherit; background: #fff; }
.voice-time { flex: none; min-width: 2.25rem; text-align: right; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.voice-frame audio { display: none; }
.voice-frame.broken { display: flex; }
.voice-frame.broken > * { display: none; }
.voice-frame.broken::after { content: 'Không phát được tin nhắn thoại này trên thiết bị của bạn'; padding: 0.5rem; color: inherit; opacity: .8; }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }

/* ============ Phòng nhắn tin: mất mạng & tin nhắn mới ============ */
.net-note { color: #fff; background: rgba(36, 37, 38, .96); border-color: var(--border); }
.new-msg-pill { position: absolute; left: 50%; bottom: 0.75rem; z-index: 5; transform: translateX(-50%); padding: 0.5rem 1rem; border-radius: 62.4375rem; background: var(--accent); color: #fff; font-size: 0.875rem; font-weight: 600; box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, .45); }
.new-msg-pill:hover { background: #4a9bff; }

/* Bảng emoji: nền đặc, không trong suốt (trước đây quy tắc .room-body .glass làm nền chỉ còn 78% nên nhìn xuyên thấy tin nhắn) */
.chat-room .emoji-panel { background: #242526; border: 1px solid var(--border); backdrop-filter: none; -webkit-backdrop-filter: none; }

/* Tên đăng nhập (@...) dưới tên hiển thị trong hồ sơ */
.profile-username { color: #b0b3b8; font-size: 0.875rem; font-weight: 500; overflow-wrap: anywhere; }

/* Popup: nút ✕ đóng ở góc trên bên phải (thay cho nút "Đóng") */
.dialog { position: relative; }
.dialog-close { position: absolute; top: 0.75rem; right: 0.75rem; }   /* cùng kiểu nút ✕ của bảng Cài đặt (btn-ghost icon-btn) */
.dialog h2 { padding: 0 2.5rem; }   /* tiêu đề không chạm vào nút ✕ */

.dialog:focus { outline: none; }
.dialog-close:focus:not(:focus-visible) { outline: none; }

/* Phòng nhắn tin: ô nhập không có viền xanh khi đang gõ; các biểu tượng (ảnh, emoji, ghi âm, gửi) màu trắng, không nền xanh */
.chat-room .composer textarea:focus { border-color: var(--border); outline: none; box-shadow: none; }
.chat-room .composer .ctl-tool, .chat-room .composer .ctl-mic:not(:disabled) { color: #fff; }
.chat-room .composer .ctl-send, .chat-room .composer .ctl-send:disabled { background: transparent; border-color: transparent; color: #fff; }
.chat-room .composer .ctl-send:hover:not(:disabled) { background: rgba(255, 255, 255, .08); }
.chat-room .composer .rec-bar .ctl-tool { color: #ff6b78; }   /* nút hủy ghi âm vẫn màu đỏ */

/* ============ Chặn người dùng ============ */
.peer-block { display: grid; place-items: center; width: 1.875rem; height: 1.875rem; margin: -0.25rem -0.375rem -0.25rem 0.125rem; border-radius: 50%; color: var(--muted); flex: none; }
.peer-block:hover { background: rgba(255, 255, 255, .12); color: #ff6b78; }
.peer-block:disabled { opacity: .4; }
.peer-block .ico { width: 1.125rem; height: 1.125rem; }
.dialog-icon .ico { width: 1.625rem; height: 1.625rem; }
.dialog .btn-block { margin-top: 1.25rem; }
.dialog .dialog-err { margin: 0.75rem 0 0; color: #ff8a95; font-size: 0.875rem; }

.block-section { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.block-head { margin: 0 0 0.25rem; font-size: 0.9375rem; font-weight: 700; }
.block-note { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.8125rem; line-height: 1.45; }
.block-empty { margin: 0; color: var(--muted); font-size: 0.875rem; }
.block-list { list-style: none; margin: 0; padding: 0 0.25rem 0 0; display: flex; flex-direction: column; gap: 0.75rem; }
.block-item { display: flex; align-items: center; gap: 0.75rem; }
.block-item img { flex: none; width: 2.5rem; height: 2.5rem; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.block-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.block-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9375rem; }
.block-meta small { color: var(--muted); font-size: 0.8125rem; }
.block-item .btn { flex: none; }

/* Nút "Danh sách chặn" trong Cài đặt + popup danh sách (cùng kích thước bảng Cài đặt, danh sách dài thì cuộn bên trong) */
.set-list-links { margin-top: 0.25rem; }
.set-link { width: 100%; background: none; border: 0; border-bottom: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; border-radius: 0.75rem; }
.set-link:hover .set-chevron { transform: translateX(2px); }
.set-link-end { display: flex; align-items: center; gap: 0.375rem; flex: none; color: var(--muted); }
.set-chevron { width: 1.375rem; height: 1.375rem; transition: transform .15s; }
.set-count { min-width: 1.5rem; padding: 0.125rem 0.5rem; border-radius: 62.4375rem; background: var(--surface-2); color: #fff; font-size: 0.8125rem; font-weight: 600; text-align: center; }
.sheet-block { display: flex; flex-direction: column; overflow: hidden; }
.sheet-block .sheet-head, .sheet-block .block-note, .sheet-block .block-empty { flex: none; }
.sheet-block .block-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

/* Popup thông báo dạng thông tin (biểu tượng "i" màu xanh) */
.dialog-icon.info { color: var(--accent); background: rgba(45, 136, 255, .15); font-family: Georgia, "Times New Roman", serif; font-style: italic; }
/* Popup thông báo dạng thành công (dấu ✓ màu xanh lá) */
.dialog-icon.success { color: #34d399; background: rgba(52, 211, 153, .15); }

/* Chấm xanh lá trước "… người đang hoạt động" trong bảng tìm kiếm */
#searchSub.is-online::before { content: ''; display: inline-block; width: 0.5625rem; height: 0.5625rem; margin-right: 0.4375rem; border-radius: 50%; vertical-align: 0.0625rem; background: #31d07a; box-shadow: 0 0 0 0 rgba(49, 208, 122, .55); animation: online-pulse 2s ease-out infinite; }
@keyframes online-pulse { 0% { box-shadow: 0 0 0 0 rgba(49, 208, 122, .55); } 70% { box-shadow: 0 0 0 0.375rem rgba(49, 208, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(49, 208, 122, 0); } }
@media (prefers-reduced-motion: reduce) { #searchSub.is-online::before { animation: none; } }

/* ============ Bảng xếp hạng ============ */
.rank { max-width: 34rem; width: 100%; margin: 0 auto; padding: 1.25rem; }
.rank-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.rank-head strong { display: block; font-size: 1.0625rem; }
.rank-head small { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.8125rem; }
.rank-reset { flex: none; padding: 0.3rem 0.65rem; border-radius: 62.4375rem; background: var(--surface-2); color: #e4e6eb; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.rank-me { margin-bottom: 0.875rem; padding: 0.7rem 0.875rem; border-radius: 0.875rem; background: rgba(45, 136, 255, .12); border: 1px solid rgba(45, 136, 255, .35); color: #fff; font-size: 0.875rem; font-weight: 600; }
.rank-empty { padding: 1.25rem 0.5rem; color: var(--muted); font-size: 0.9rem; text-align: center; }
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.375rem; }
.rank-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.55rem 0.625rem; border-radius: 0.875rem; }
.rank-item.is-me { background: rgba(45, 136, 255, .1); }
.rank-item.top1 { background: linear-gradient(90deg, rgba(255, 200, 61, .14), transparent 70%); }
.rank-item.top2 { background: linear-gradient(90deg, rgba(200, 210, 225, .12), transparent 70%); }
.rank-item.top3 { background: linear-gradient(90deg, rgba(222, 150, 90, .13), transparent 70%); }
.rank-pos { flex: none; width: 2rem; text-align: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-item.top1 .rank-pos, .rank-item.top2 .rank-pos, .rank-item.top3 .rank-pos { font-size: 1.5rem; line-height: 1; }
.rank-avatar { flex: none; width: 2.625rem; height: 2.625rem; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.rank-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.rank-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9375rem; }
.rank-info small, .rank-score small { color: var(--muted); font-size: 0.78rem; }
.rank-score { flex: none; display: flex; flex-direction: column; align-items: flex-end; }
.rank-score strong { font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .rank { padding: 1rem 0.875rem; border-radius: 1.125rem; } }

/* Máy tính, cửa sổ không đủ rộng: thanh tab không được đè lên khung tên người dùng (profile.js: fitTabbar) */
@media (min-width: 901px) {
    .chip-compact .topbar .user-chip .user-meta { display: none; }
    .tabs-compact .tabbar .tab-item span { display: none; }
    .tabs-compact .tabbar .tab-item { padding: 0.5rem 0.85rem; }
}

/* Popup thông báo trang chủ (announcement.php) */
.ann-dialog { max-width: 34rem; padding: 2rem 2rem 1.75rem; }
.ann-dialog h2 { font-size: 1.375rem; }
/* Biểu tượng chuông: trắng trên nền tròn xanh chuyển sắc, rung nhẹ một lần khi mở */
.ann-icon { width: 3.75rem; height: 3.75rem; margin: 0 auto 0.875rem; border-radius: 50%; display: grid; place-items: center;
            background: linear-gradient(140deg, #6ec1ff 0%, #2d88ff 55%, #1f6fe0 100%);
            box-shadow: 0 0.5rem 1.5rem rgba(45, 136, 255, .45), inset 0 1px 0 rgba(255, 255, 255, .35); }
.ann-icon svg { width: 52%; height: 52%; fill: #fff; transform-origin: 50% 15%; animation: ann-ring 1.1s ease-in-out .25s 1; }
@keyframes ann-ring { 0%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); } 45% { transform: rotate(9deg); } 60% { transform: rotate(-6deg); } 75% { transform: rotate(3deg); } }
@media (prefers-reduced-motion: reduce) { .ann-icon svg { animation: none; } }
/* Nội dung dài thì cuộn bên trong, nhưng popup cao gần hết màn hình trước khi phải cuộn */
.ann-text { text-align: center; white-space: normal; overflow-wrap: anywhere; font-size: 1rem; line-height: 1.6;
            max-height: calc(100vh - 17rem); max-height: calc(100dvh - 17rem); overflow-y: auto; }
/* Điện thoại: popup gọn hơn */
@media (max-width: 560px) {
    .ann-dialog { max-width: 22.5rem; padding: 1.375rem 1.125rem 1.125rem; border-radius: 1.25rem; }
    .ann-dialog .dialog-close { top: 0.625rem; right: 0.625rem; width: 2.25rem; height: 2.25rem; min-height: 2.25rem; font-size: 1rem; }
    .ann-icon { width: 3rem; height: 3rem; margin-bottom: 0.625rem; }
    .ann-dialog h2 { font-size: 1.125rem; padding: 0 2.25rem; }
    .ann-text { font-size: 0.875rem; line-height: 1.5; margin-top: 0.375rem; max-height: calc(100vh - 14rem); max-height: calc(100dvh - 14rem); }
    .ann-btn { margin-top: 1rem; min-height: 2.75rem; padding: 0.625rem 1rem; font-size: 0.9375rem; }
}
.ann-btn { margin-top: 1.25rem; }
