/* ChatWiu mobile layout overrides. Load after public.css. */

button,
a,
.stage-control,
.stage-action,
.setting-select-button,
.gender-options label,
.chat-settings-button,
.InterFaceCtl {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

@media (max-width: 767px) {
    :root {
        --cw-mobile-control-size: 40px;
        --cw-mobile-edge: 10px;
    }

    html,
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        overflow: hidden;
        overscroll-behavior: none;
        background: #050810;
    }

    body:has(section[data-where="main"]) {
        position: fixed;
        inset: 0;
    }

    section[data-where="main"] {
        width: 100%;
        height: 100dvh;
        min-height: 0 !important;
        padding: 0 !important;
        overflow: hidden;
        background: #050810;
    }

    section[data-where="main"] .InfoSectionArea,
    footer[data-where="main"] {
        display: none !important;
    }

    section[data-where="main"] > .DefaultViewArea,
    section[data-where="main"] > .DefaultViewArea > .container,
    section[data-where="main"] .ViewFormArea,
    section[data-where="main"] .BaseFormArea {
        width: 100%;
        max-width: none !important;
        height: 100%;
        min-height: 0 !important;
        margin: 0;
        padding: 0 !important;
        overflow: hidden;
    }

    .chatwiu-app,
    .chatwiu-stage,
    .remote-stage {
        position: relative;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: #050810;
    }

    .remoteVideoArea,
    .remote-stage .remoteVideo {
        position: absolute;
        inset: 0;
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        max-height: none !important;
        margin: 0;
        padding: 0;
        aspect-ratio: auto !important;
        object-fit: cover;
        visibility: visible !important;
        opacity: 1 !important;
        background: #050810;
    }

    .remoteVideoArea {
        z-index: 1;
        overflow: hidden;
    }

    .local-box {
        position: absolute;
        top: max(72px, calc(env(safe-area-inset-top) + 60px));
        right: 10px;
        z-index: 30;
        width: clamp(96px, 28vw, 132px);
        min-width: 0;
        max-width: none;
        height: auto;
        aspect-ratio: 3 / 4;
        overflow: hidden;
        border: 1px solid rgba(255,255,255,.2);
        border-radius: 12px;
        background: #111827;
        box-shadow: 0 8px 24px rgba(0,0,0,.42);
    }

    .localVideoArea {
        position: absolute;
        inset: 0;
    }

    .local-box .localVideo {
        display: block;
        width: 100% !important;
        height: 100% !important;
        aspect-ratio: auto !important;
        object-fit: cover;
    }

    .local-video-label {
        left: 6px;
        bottom: 6px;
        padding: 3px 6px;
        border-radius: 5px;
        font-size: .62rem;
    }

    .connection-badge {
        top: max(48px, calc(env(safe-area-inset-top) + 36px));
        left: 10px;
        z-index: 32;
        gap: 6px;
        padding: 7px 9px;
        font-size: .7rem;
    }

    .match-status-overlay {
        z-index: 8;
        padding: 18px;
    }

    .match-status-card {
        width: min(310px, calc(100vw - 36px));
        max-width: none;
        padding: 18px 16px;
        border-radius: 14px;
    }

    .match-status-icon {
        width: 40px;
        height: 40px;
        margin-bottom: 10px;
        border-radius: 11px;
        font-size: 1.05rem;
    }

    .match-status-title { font-size: .94rem; }
    .match-status-description { font-size: .74rem; }

    .chatwiu-app[data-match-state="connected"] .match-status-overlay {
        display: none !important;
    }

    .LoadingIconArea {
        top: max(58px, calc(env(safe-area-inset-top) + 48px));
    }

    .LoginBtnArea {
        top: calc(50% + 86px);
        left: 50%;
        z-index: 35;
        gap: 7px;
        transform: translateX(-50%);
    }

    .start-guest-button {
        gap: 7px;
        padding: 9px 14px;
        border-radius: 10px;
        font-size: .78rem;
    }

    .login-link { font-size: .7rem; }

    .stage-controls {
        position: absolute !important;
        left: 50% !important;
        right: auto !important;
        bottom: max(8px, env(safe-area-inset-bottom)) !important;
        z-index: 50;
        display: flex !important;
        width: max-content !important;
        max-width: calc(100vw - 16px) !important;
        align-items: center;
        justify-content: center;
        gap: 5px;
        margin: 0;
        padding: 5px;
        overflow: hidden;
        border: 1px solid rgba(255,255,255,.1);
        border-radius: 14px;
        background: rgba(8,12,20,.9);
        box-shadow: 0 8px 24px rgba(0,0,0,.35);
        transform: translateX(-50%) !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .stage-control,
    .stage-action {
        height: var(--cw-mobile-control-size) !important;
        min-height: var(--cw-mobile-control-size) !important;
        border-radius: 10px;
        font-size: .84rem;
    }

    .stage-control {
        display: flex !important;
        flex: 0 0 var(--cw-mobile-control-size) !important;
        width: var(--cw-mobile-control-size) !important;
        min-width: var(--cw-mobile-control-size) !important;
        align-items: center;
        justify-content: center;
        padding: 0 !important;
    }

    .stage-action {
        display: flex !important;
        flex: 0 0 auto !important;
        min-width: 0 !important;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 0 9px !important;
        font-size: .72rem;
    }

    .stage-control.d-none,
    .stage-action.d-none,
    .remote-media-control.d-none {
        display: none !important;
    }

    .control-divider,
    .volume-control {
        display: none !important;
    }

    .chatwiu-app:not([data-match-state="connected"]) .remote-media-control {
        display: none !important;
    }

    .chatwiu-chat {
        position: absolute !important;
        inset: 0;
        z-index: 20;
        display: none !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        border: 0;
        background: transparent;
        pointer-events: none;
    }

    .chatwiu-app[data-match-state="connected"] .chatwiu-chat {
        display: block !important;
    }

    .TopCtlArea,
    .chat-empty-state {
        display: none !important;
    }

    .TextChatArea {
        position: absolute;
        inset: 0;
        z-index: 21;
        min-height: 0;
        overflow: hidden;
        background: transparent;
        pointer-events: none;
    }

    .ChatTextView {
        position: absolute;
        right: var(--cw-mobile-edge);
        bottom: calc(112px + env(safe-area-inset-bottom));
        left: var(--cw-mobile-edge);
        z-index: 22;
        display: flex;
        width: auto;
        height: auto;
        max-height: 34dvh;
        padding: 0 !important;
        gap: 5px;
        overflow: hidden;
        justify-content: flex-end;
        pointer-events: none;
    }

    .ChatTextView.d-none { display: none !important; }

    .ChatTextView div {
        width: fit-content;
        max-width: 80%;
        padding: 6px 9px !important;
        border-radius: 10px !important;
        color: #fff;
        background: rgba(20,28,43,.82);
        font-size: .72rem;
        line-height: 1.35;
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    .TextChatBtnArea {
        position: absolute !important;
        right: var(--cw-mobile-edge);
        bottom: calc(72px + env(safe-area-inset-bottom)) !important;
        left: var(--cw-mobile-edge);
        z-index: 45;
        display: flex !important;
        align-items: center;
        gap: 6px;
        padding: 0 !important;
        border: 0;
        background: transparent;
        pointer-events: auto;
    }

    .InterFaceCtl {
        display: grid;
        flex: 0 0 38px;
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
        place-items: center;
        border-radius: 10px;
        font-size: .82rem;
    }

    .MessageInputArea {
        min-width: 0;
        flex: 1;
    }

    .MessageInputArea.d-none { display: none !important; }

    .message-composer {
        min-height: 38px;
        padding: 3px 3px 3px 10px;
        border-radius: 11px;
        background: rgba(13,20,34,.86);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .message-composer input {
        font-size: 16px !important;
    }

    .message-composer button {
        width: 32px;
        height: 32px;
        border-radius: 8px;
        font-size: .8rem;
    }

    .ChatBoxArea {
        width: 100% !important;
        height: 100% !important;
    }

    .chatwiu-modal .modal-dialog {
        display: flex;
        align-items: flex-end;
        min-height: 100dvh;
        margin: 0;
    }

    .chatwiu-modal .modal-content {
        width: 100%;
        max-height: 82dvh;
        padding-bottom: env(safe-area-inset-bottom);
        overflow: hidden;
        border-radius: 20px 20px 0 0;
        border-bottom: 0;
    }

    .chatwiu-modal .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 340px) {
    :root { --cw-mobile-control-size: 36px; }
    .stage-controls { gap: 3px; padding: 4px; }
    .stage-action { padding: 0 7px !important; font-size: .68rem; }
    .local-box { width: 92px; }
}

@media (max-width: 767px) and (orientation: landscape) {
    .local-box {
        top: max(8px, env(safe-area-inset-top));
        width: clamp(84px, 18vw, 112px);
        aspect-ratio: 4 / 3;
    }

    .match-status-card { padding: 12px 14px; }
    .match-status-icon { display: none; }
    .LoginBtnArea { top: calc(50% + 54px); }
    .ChatTextView { max-height: 24dvh; }
}
