/* ============ Biến & nền tảng ============ */
:root {
    --bg: #0a0b10;
    --bg-2: #11131c;
    --surface: rgba(255, 255, 255, 0.045);
    --surface-2: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.09);
    --text: #eef0f7;
    --muted: #9aa0b4;
    --accent: #7c5cff;
    --accent-2: #00d4ff;
    --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: radial-gradient(75rem 43.75rem at 50% -10%, #1a1736 0%, var(--bg) 60%); }
.bg-orbs span { position: absolute; border-radius: 50%; filter: blur(5.625rem); opacity: .45; animation: float 18s ease-in-out infinite; }
.bg-orbs span:nth-child(1) { width: 26.25rem; height: 26.25rem; background: var(--accent); top: -7.5rem; left: -5rem; }
.bg-orbs span:nth-child(2) { width: 23.75rem; height: 23.75rem; background: #0aa6c9; bottom: -8.75rem; right: -3.75rem; animation-delay: -6s; }
.bg-orbs span:nth-child(3) { width: 18.75rem; height: 18.75rem; background: #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), #5b8cff 60%, var(--accent-2)); color: #fff; box-shadow: 0 0.5rem 1.75rem -0.5rem rgba(124, 92, 255, .7); }
.btn-primary:hover { box-shadow: 0 0.75rem 2.125rem -0.5rem rgba(124, 92, 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: rgba(0,0,0,.28); 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(124, 92, 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: rgba(0,0,0,.28); border: 1px solid var(--border); color: var(--muted); transition: all .2s;
}
.seg input:checked + span { color: #fff; border-color: var(--accent); background: rgba(124, 92, 255, .22); box-shadow: 0 0 0 0.1875rem rgba(124, 92, 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: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 0.6875rem; font-size: 1.25rem;
    background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
    box-shadow: 0 0.375rem 1.25rem -0.25rem rgba(124, 92, 255, .8);
}

/* ============ 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); }
.alert {
    background: rgba(255, 77, 94, .12); border: 1px solid rgba(255, 77, 94, .4); color: #ffb3bb;
    padding: 0.6875rem 0.875rem; border-radius: 0.75rem; font-size: 0.875rem; margin-bottom: 1.125rem;
}
.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(5, 6, 10, .78); backdrop-filter: blur(0.625rem); 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; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.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%, #1a1830, #0b0c14); 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, .82); backdrop-filter: blur(0.5rem);
}
.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: auto; padding: 0 1.625rem; height: 3.375rem; border-radius: 62.4375rem; grid-auto-flow: column; gap: 0.625rem;
    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(10, 11, 16, .8); border: 1px solid var(--border); backdrop-filter: blur(0.75rem);
    -webkit-backdrop-filter: blur(0.75rem);
}
.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 { 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(10, 11, 16, .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: #ffd9a0; background: rgba(255, 181, 71, .12); border: 1px solid rgba(255, 181, 71, .35); }
.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); }
.search-hint { margin: -0.5rem 0 1.125rem; }
.search-hint p { margin: 0 0 0.625rem; font-size: 0.8125rem; line-height: 1.5; }

/* ============ Vừa khít màn hình điện thoại (không phải kéo xuống) ============ */
.home-body { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.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; font-size: 1.0625rem; }
    .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 h1, .auth-hero > p { display: none; }
    .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(17, 19, 28, .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) { opacity: .5; cursor: not-allowed; }

.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; }

.set-test { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding-top: 0.875rem; }
.set-test small { color: var(--muted); font-size: 0.7812rem; }

@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 */
.set-ver { margin-top: 0.75rem; font-size: 0.6875rem; color: var(--muted); opacity: .7; text-align: center; }
@media (max-width: 560px) {
    .overlay { padding: 0.75rem; }
    .search-box h2 { font-size: 1.1875rem; }
    .search-hint p { font-size: 0.7812rem; }
    .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: var(--muted); font-size: 0.9rem; font-weight: 600; transition: color .2s, background .2s; -webkit-tap-highlight-color: transparent; }
.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--accent-2); 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; }
.profile-msg { min-height: 1.3em; margin-top: 0.75rem; text-align: center; font-size: 0.85rem; color: var(--muted); }
.profile-msg.ok { color: #6ee7b7; }
.profile-msg.err { color: #ffb3bb; }

/* Đ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(10, 11, 16, .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(3.75rem + env(safe-area-inset-bottom)); }
}
@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(2.75rem + env(safe-area-inset-bottom)); }
}

/* ============ 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; }
}
