@import url('https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,400&display=swap');

/* =========================================================================
   mobile.css — STANDALONE mobile UI for /video and /text.
   Loaded only on mobile (<=979px) by mobile-chat.js.
   Scoped under `body.m-on` so it cannot affect desktop in any way.
   The desktop chat UI is hidden via `body.m-on .desktop-only { display:none }`.
   ========================================================================= */

body.m-on {
    margin: 0;
    background: #000;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

body.m-on .desktop-only,
body.m-on > header,
body.m-on > .modebar,
body.m-on main.app {
    display: none !important;
}

#mStage {
    position: fixed;
    inset: 0;
    z-index: 9999;
    color: #fff;
    font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #000;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    touch-action: none;          /* we handle gestures ourselves */
}

/* Two stacked tiles ============================================ */
#mStage .m-tiles {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    will-change: transform, opacity;
}
#mStage .m-tile {
    position: relative;
    flex: 1 1 50%;
    width: 100%;
    height: 50%;
    background: #0a0d12;
    overflow: hidden;
    will-change: transform, opacity;
}
#mStage .m-tile.dragging { transition: none; }
#mStage .m-tile.snapback { transition: transform .18s ease, opacity .18s ease; }
#mStage .m-tile.fly-out  {
    transition: transform .22s ease, opacity .22s ease;
    transform: translateX(-110%);
    opacity: 0;
}
#mStage .m-tile.partner { border-bottom: 2px solid #000; }
#mStage .m-tile video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}
#mStage .m-tile.self video { transform: scaleX(-1); }
#mStage .m-tile.partner video { transform: scaleX(-1); }

/* Idle hero ===================================================== */
#mStage .m-hero {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    gap: 14px;
    background:
        radial-gradient(700px 350px at 50% 28%, rgba(34, 136, 145, .22), transparent 60%),
        linear-gradient(180deg, #0e1620 0%, #0a0d12 100%);
    z-index: 4;
    pointer-events: none;
}
#mStage .m-online {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .14);
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 600;
    backdrop-filter: blur(8px);
}
#mStage .m-online .m-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 10px #4ade80;
    animation: mDot 1.6s ease-in-out infinite;
}

@keyframes mDot {
    50% { opacity: .55; }
}
#mStage .m-title {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 4px 0 2px;
}
#mStage .m-arrow {
    font-size: 36px;
    line-height: 1;
    animation: mArrow 1.6s ease-in-out infinite;
}

@keyframes mArrow {
    0%, 100% { transform: translateX(12px);  opacity: .35; }
    50%      { transform: translateX(-12px); opacity: 1; }
}
#mStage .m-sub {
    font-size: 13px;
    color: rgba(255, 255, 255, .72);
}

/* Hide hero when matched / searching / face-gating */
body.m-on.matched #mStage .m-hero,
body.m-on.searching #mStage .m-hero,
body.m-on.m-gate #mStage .m-hero { display: none; }

/* Searching overlay */
#mStage .m-search {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 14px;
    background: rgba(0, 0, 0, .35);
    z-index: 5;
    pointer-events: none;
}

body.m-on.searching #mStage .m-search,
body.m-on.m-gate #mStage .m-search { display: flex; }
#mStage .m-spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mSpin .9s linear infinite;
}

@keyframes mSpin {
    to { transform: rotate(360deg); }
}

/* "Connecting" overlay — matched but first video frame not yet rendered.
   Different from the searching spinner: a teal sonar-ping expands and fades,
   making it clear we're connected and just waiting for the stream. */
#mStage .m-connecting-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: #0a0d12;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
#mStage .m-ping {
    position: relative;
    width: 52px;
    height: 52px;
}
#mStage .m-ping::before,
#mStage .m-ping::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(34, 136, 145, .9);
    animation: mPing 1.6s cubic-bezier(0, 0, .2, 1) infinite;
}
#mStage .m-ping::after { animation-delay: -.8s; }
@keyframes mPing {
    0%   { transform: scale(.4); opacity: 1; }
    100% { transform: scale(2.8); opacity: 0; }
}

/* Top bar (status + report) */
#mStage .m-top {
    position: absolute;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    z-index: 6;
    pointer-events: none;
}
#mStage .m-brand {
    pointer-events: none;
    font-weight: 800;
    font-size: 14px;
    color: #fff;
    letter-spacing: -0.01em;
    text-shadow: 0 1px 4px rgba(0, 0, 0, .7);
    background: rgba(0, 0, 0, .35);
    padding: 4px 10px;
    border-radius: 999px;
    backdrop-filter: blur(8px);
}
#mStage .m-report {
    pointer-events: auto;
    background: rgba(0, 0, 0, .45);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 999px;
    width: 36px;
    height: 36px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

body.m-on.matched #mStage .m-report { display: inline-flex; }

/* Bottom action bar removed — composer is always visible. */
#mStage .m-bottom { display: none; }

/* Msgs sit above the composer */
#mStage .m-msgs {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-height: 38dvh;
    overflow-y: auto;
    padding: 10px 12px 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 6;
    pointer-events: auto;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
    scrollbar-width: none;
}
#mStage .m-msgs::-webkit-scrollbar { display: none; }
#mStage .m-msgs .m-msg {
    max-width: 84%;
    padding: 7px 11px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.35;
    word-wrap: break-word;
    backdrop-filter: blur(6px);
}
#mStage .m-msgs .m-msg.them {
    align-self: flex-start;
    background: rgba(0, 0, 0, .55);
    border-bottom-left-radius: 4px;
    color: #fff;
}
#mStage .m-msgs .m-msg.me {
    align-self: flex-end;
    background: rgba(34, 136, 145, .85);
    border-bottom-right-radius: 4px;
    color: #fff;
}
#mStage .m-msgs .m-msg.sys {
    align-self: center;
    background: rgba(0, 0, 0, .45);
    color: rgba(255, 255, 255, .92);
    font-size: 12px;
    border-radius: 999px;
    padding: 4px 10px;
}

body.m-on:not(.matched) #mStage .m-msgs { display: none; }

/* Composer (always visible, transparent floating bar) ============ */
#mStage .m-composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent, rgba(0,0,0,.45) 60%);
    display: flex;
    gap: 8px;
    align-items: center;
    z-index: 10;
    pointer-events: none;
    transition: transform .15s ease;
    will-change: transform;
}
#mStage .m-composer input {
    pointer-events: auto;
    flex: 1 1 auto;
    min-width: 0;
    background: rgba(0, 0, 0, .42);
    border: 1px solid rgba(255, 255, 255, .18);
    color: #fff;
    padding: 11px 14px;
    border-radius: 999px;
    /* 16px prevents iOS Safari from zooming on focus. */
    font-size: 16px;
    line-height: 1.2;
    outline: none;
    backdrop-filter: blur(10px);
    -webkit-appearance: none;
    appearance: none;
}
#mStage .m-composer input::placeholder { color: rgba(255, 255, 255, .55); }
#mStage .m-composer .m-send {
    pointer-events: auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(34, 136, 145, .92);
    color: #fff;
    border: none;
    font-size: 16px;
    flex: 0 0 auto;
    backdrop-filter: blur(10px);
}

/* Composer disabled in idle (no partner to message) */
body.m-on:not(.matched) #mStage .m-composer { opacity: .45; }
body.m-on:not(.matched) #mStage .m-composer input { pointer-events: none; }
body.m-on:not(.matched) #mStage .m-composer .m-send { pointer-events: none; }

/* Old whole-stack swipe classes removed — swipe now animates only the
   partner tile (see .m-tile.dragging/.snapback/.fly-out above). */

/* Toast ========================================================== */
#mStage .m-toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, .75);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s;
}
#mStage .m-toast.show { opacity: 1; }

/* Typing dots in mobile chat overlay ============================== */
#mStage .m-msg.m-typing {
    display: inline-flex;
    gap: 4px;
    padding: 9px 12px;
    align-items: center;
}
#mStage .m-msg.m-typing > span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .85);
    animation: m-tdot 1.2s infinite ease-in-out;
}
#mStage .m-msg.m-typing > span:nth-child(2) { animation-delay: .15s; }
#mStage .m-msg.m-typing > span:nth-child(3) { animation-delay: .3s; }
@keyframes m-tdot {
    0%, 80%, 100% { transform: translateY(0);    opacity: .4; }
    40%           { transform: translateY(-4px); opacity: 1; }
}

/* Keep messages above the keyboard when it's open */
body.m-on.kb-open #mStage .m-msgs {
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-height: 28dvh;
}

/* Hide the welcome card on mobile entirely (mobile UI replaces it) */
body.m-on #welcome { display: none !important; }

/* Report modal must sit above #mStage on mobile */
body.m-on #reportModal.active { z-index: 10001; }

/* Leave-call confirmation dialog ================================== */
#mLeaveDlg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    z-index: 10002;
    background: rgba(0, 0, 0, 0);
    transition: background .2s ease;
    pointer-events: none;
}
#mLeaveDlg.open {
    background: rgba(0, 0, 0, .55);
    pointer-events: auto;
}
#mLeaveDlg .mld-card {
    width: 100%;
    background: #1a1d24;
    border-radius: 20px 20px 0 0;
    padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform .28s cubic-bezier(.32,1,.38,1);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#mLeaveDlg.open .mld-card {
    transform: translateY(0);
}
#mLeaveDlg .mld-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
}
#mLeaveDlg .mld-sub {
    margin: 0 0 8px;
    font-size: 14px;
    color: rgba(255,255,255,.65);
    line-height: 1.45;
}
#mLeaveDlg .mld-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#mLeaveDlg .mld-stay {
    padding: 14px;
    border-radius: 14px;
    border: none;
    background: #228891;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
#mLeaveDlg .mld-leave {
    padding: 14px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.15);
    background: transparent;
    color: rgba(255,255,255,.8);
    font-size: 16px;
    cursor: pointer;
}

/* ================================================================
   TEXT MODE — full-screen themed chat layout
   Active when body.m-on.m-text (WEB_RC_MODE === 'text')
   JS resizes #mStage height/top to match visualViewport so the
   keyboard never covers content — no per-element offset math needed.
   ================================================================ */

/* Stage: themed, flex column */
body.m-on.m-text #mStage {
    background: var(--bg);
    color: var(--text);
    font-family: 'Nunito', sans-serif;
}

/* Hide video tiles */
body.m-on.m-text #mTiles { display: none !important; }

/* Allow scroll in the message area (base CSS sets touch-action:none on stage) */
body.m-on.m-text #mMsgs {
    touch-action: pan-y;
    overscroll-behavior: contain;
}

/* ---- Header ---- */
body.m-on.m-text .m-top {
    position: relative;          /* flex item, not absolute */
    flex-shrink: 0;
    height: 54px;
    box-sizing: border-box;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 0 16px;
    pointer-events: auto;
    z-index: 6;
}
body.m-on.m-text .m-brand {
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    text-shadow: none;
    color: var(--text);
    padding: 0;
    font-size: 15px;
    font-weight: 800;
    font-family: 'Nunito', sans-serif;
    letter-spacing: -0.01em;
}

/* Top-right container (Next btn + Report btn) */
#mStage .m-top-right {
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none; /* container passthrough; buttons set their own */
}

/* Report button in text mode */
body.m-on.m-text .m-report {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-2);
    width: 34px;
    height: 34px;
    font-size: 14px;
    pointer-events: auto;
}

/* "Next" button (text mode, shown only when matched) */
.m-next-btn {
    pointer-events: auto;
    padding: 7px 18px;
    border-radius: 999px;
    background: #228891;
    color: #fff;
    border: none;
    font-size: 13px;
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    display: none;
    letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent;
}
body.m-on.m-text.matched .m-next-btn { display: inline-block; }

/* ---- Messages (matched only — avoids z-index pointer-event blockage) ---- */
body.m-on.m-text.matched #mMsgs {
    position: absolute;
    top: 54px;
    left: 0; right: 0;
    /* bottom = composer height + small gap.
       #mStage is resized by JS to vv.height, so this bottom is always
       measured from the TOP of the keyboard, never behind it. */
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-height: none;
    padding: 14px 16px 10px;
    -webkit-mask-image: none;
    mask-image: none;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Message bubbles — #mMsgs ID needed to beat base specificity (#mStage .m-msgs .m-msg) */
body.m-on.m-text #mMsgs .m-msg {
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
    line-height: 1.45;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-radius: 18px;
    max-width: 80%;
}
body.m-on.m-text #mMsgs .m-msg.them {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
}
body.m-on.m-text #mMsgs .m-msg.me {
    background: #228891;
    color: #fff;
    border: none;
    border-bottom-right-radius: 5px;
}
body.m-on.m-text #mMsgs .m-msg.sys {
    background: transparent;
    color: var(--text-2);
    font-size: 12px;
    border-radius: 999px;
    border: none;
    padding: 4px 12px;
    font-weight: 600;
}
/* Typing dots in text mode */
body.m-on.m-text #mMsgs .m-msg.m-typing > span {
    background: var(--text-2);
}

/* ---- Composer: solid themed bar ---- */
/* Use #mStage to beat base opacity rule: body.m-on:not(.matched) #mStage .m-composer */
body.m-on.m-text #mStage .m-composer {
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    /* position: fixed + bottom: 0 from base CSS, contained within #mStage,
       which JS shrinks to vv.height — so composer stays above keyboard. */
}
body.m-on.m-text #mStage .m-composer input {
    background: var(--panel-2);
    border: 1.5px solid var(--border);
    color: var(--text);
    font-family: 'Nunito', sans-serif;
    font-size: 15px;
}
body.m-on.m-text #mStage .m-composer input::placeholder {
    color: var(--text-2);
    opacity: 0.65;
}
body.m-on.m-text #mStage .m-composer .m-send {
    background: #228891;
    color: #fff;
    box-shadow: 0 2px 8px rgba(34,136,145,.3);
}
/* Disable state when not matched — must use #mStage to override base ID rule */
body.m-on.m-text:not(.matched) #mStage .m-composer       { opacity: 1; }
body.m-on.m-text:not(.matched) #mStage .m-composer input { pointer-events: none; opacity: 0.38; }
body.m-on.m-text:not(.matched) #mStage .m-composer .m-send {
    pointer-events: none;
    opacity: 0.38;
    box-shadow: none;
}

/* ---- Idle panel ---- */
.m-text-idle {
    display: none;
    position: absolute;
    top: 54px; left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    z-index: 5;
    background: var(--bg);
    text-align: center;
    padding: 32px 28px;
    box-sizing: border-box;
}
body.m-on.m-text:not(.searching):not(.matched):not(.m-gate) .m-text-idle { display: flex; }

.m-text-idle .m-online {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
    font-family: 'Nunito', sans-serif;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    padding: 6px 16px;
}
.m-text-idle .m-online .m-dot {
    box-shadow: 0 0 6px #4ade80;
}
.m-text-idle-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.m-text-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    font-family: 'Nunito', sans-serif;
    line-height: 1.15;
}
.m-text-sub {
    font-size: 14px;
    color: var(--text-2);
    font-family: 'Nunito', sans-serif;
    line-height: 1.55;
    max-width: 240px;
    font-weight: 500;
}
.m-text-start {
    padding: 16px 52px;
    border-radius: 16px;
    background: #228891;
    color: #fff;
    font-size: 16px;
    font-weight: 800;
    font-family: 'Nunito', sans-serif;
    border: none;
    cursor: pointer;
    letter-spacing: 0.01em;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 20px rgba(34,136,145,.38);
    transition: transform .1s ease, opacity .12s;
}
.m-text-start:active { transform: scale(0.96); opacity: .88; }

/* ---- Finding panel ---- */
.m-text-finding {
    display: none;
    position: absolute;
    top: 54px; left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 5;
    background: var(--bg);
    text-align: center;
}
body.m-on.m-text.searching .m-text-finding,
body.m-on.m-text.m-gate .m-text-finding { display: flex; }

/* Spinner — use #mStage to beat base ID specificity */
body.m-on.m-text #mStage .m-spinner {
    width: 44px;
    height: 44px;
    border-color: var(--border);
    border-top-color: #228891;
}
.m-text-finding-label {
    color: var(--text-2);
    font-size: 14px;
    font-weight: 600;
    font-family: 'Nunito', sans-serif;
    letter-spacing: 0.01em;
}
.m-text-stop {
    padding: 12px 36px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-size: 15px;
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .12s;
}
.m-text-stop:active { opacity: .6; }
