/* ============================================
   CRITICAL UI FIX
   Fixes layout issues in Chat-List & Discover
   + Mobile Responsive Layout (Safe Areas, dvh, Scaling)
   + Theme-Aware (uses CSS variables for Dark/Light)
   ============================================ */

/* ========================================
   GLOBAL VIEWPORT & BODY FIX
   ======================================== */

html {
    background: var(--app-bg);
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    background: var(--app-bg) !important;
    color: var(--app-text);
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Safe area CSS variables for consistent use */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --nav-height: calc(56px + env(safe-area-inset-bottom, 0px));
}

/* Ensure all screens have proper background + viewport fill */
.screen {
    background: var(--app-bg) !important;
    position: fixed !important;
    top: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    min-height: 0 !important;
    flex-direction: column;
    overflow: hidden;
}

/* Mobile: Vollbild */
@media (max-width: 767px) {
    .screen {
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        box-shadow: none !important;
    }
}

/* Desktop: 9:16 Smartphone-Frame, zentriert */
@media (min-width: 768px) {
    .screen {
        width: calc(100vh * 9 / 16) !important;
        max-width: 100vw !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
        margin: 0 !important;
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.5) !important;
        border-left: 1px solid rgba(255, 255, 255, 0.06);
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }

    /* Popups & modals: constrain to the same phone frame on desktop */
    .popup-overlay {
        width: calc(100vh * 9 / 16) !important;
        max-width: 100vw !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%);
    }
}

/* ========================================
   FIX: CHAT SCREEN LAYOUT
   ======================================== */

#chatScreen {
    /* Position/Dimensionen werden von .screen geerbt (inkl. 9:16 Desktop-Frame) */
    display: none;
    flex-direction: column;
    background: var(--app-bg) !important;
    overflow: hidden;
}

#chatScreen.active,
#chatScreen[style*="display: flex"] {
    display: flex !important;
}

/* ========================================
   FIX: PROFILE SELECTION (Messages List)
   Must fill the entire screen above the nav bar.
   Overrides conflicting rules from:
   - chat-rebuild.css (display: block !important, padding)
   - critical-layout-fixes.css (align-items: center, padding)
   ======================================== */

#profileSelection {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: var(--nav-height) !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    padding: 0 !important;
    background: var(--app-bg) !important;
    overflow: hidden !important;
    z-index: 1;
    width: 100% !important;
    max-width: none !important;
}

/* Override chat-rebuild.css: display: block !important */
#profileSelection[style*="display: flex"] {
    display: flex !important;
}

#profileSelection .profile-selection-container {
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: 0;
    overflow: hidden;
    background: var(--app-bg);
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
}

/* Messages Header → handled in the card-design block below */

/* Online dot for unlocked contacts */
#profileSelection .contact-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--success-color, #66BB6A);
    border-radius: 50%;
    border: 2px solid var(--app-bg);
}

/* ========================================
   CONTACT LIST - PREMIUM CARD DESIGN
   ======================================== */

/* Messages Header */
#profileSelection .messages-header {
    position: relative !important;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 20px 20px 12px 20px !important;
    padding-top: calc(20px + env(safe-area-inset-top, 0px)) !important;
    background: transparent !important;
    border-bottom: none !important;
    box-shadow: none !important;
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    z-index: 5;
}

#profileSelection .messages-header h1 {
    font-size: 28px !important;
    font-weight: 800 !important;
    letter-spacing: -0.6px !important;
    background: linear-gradient(135deg, #ffffff 0%, #FF80AB 70%) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
    color: transparent !important;
    margin: 0 !important;
}

#profileSelection .messages-header::after {
    display: none !important;
}

/* Contact List - scrollable wrapper with card gap */
#profileSelection .contact-list {
    flex: 1 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: transparent !important;
    padding: 8px 14px 24px !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
}

/* Contact Card */
#profileSelection .contact-item {
    display: flex !important;
    align-items: center !important;
    gap: 14px !important;
    padding: 14px 16px !important;
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(233, 30, 99, 0.18) !important;
    border-radius: 20px !important;
    cursor: pointer !important;
    transition: all 0.22s cubic-bezier(0.34, 1.4, 0.64, 1) !important;
    min-height: unset !important;
    position: relative !important;
    overflow: hidden !important;
}

#profileSelection .contact-item:hover {
    background: rgba(255, 255, 255, 0.09) !important;
    border-color: rgba(233, 30, 99, 0.35) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(233, 30, 99, 0.12) !important;
}

#profileSelection .contact-item:active {
    transform: scale(0.97) !important;
    background: rgba(233, 30, 99, 0.1) !important;
    border-color: rgba(233, 30, 99, 0.3) !important;
}

/* Contact Avatar */
#profileSelection .contact-avatar {
    position: relative;
    flex-shrink: 0;
}

#profileSelection .contact-avatar-img {
    width: 52px !important;
    height: 52px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 22px !important;
    font-weight: 800 !important;
    color: white !important;
    background: linear-gradient(140deg, var(--primary-color, #E91E63) 0%, var(--primary-light, #F06292) 45%, var(--secondary-color, #7C4DFF) 100%) !important;
    box-shadow: 0 0 0 2px rgba(233, 30, 99, 0.25), 0 4px 16px rgba(233, 30, 99, 0.3) !important;
}

/* Online dot */
#profileSelection .contact-online-dot {
    position: absolute !important;
    bottom: 1px !important;
    right: 1px !important;
    top: auto !important;
    left: auto !important;
    width: 13px !important;
    height: 13px !important;
    background: #4ade80 !important;
    border-radius: 50% !important;
    border: 2.5px solid #190B14 !important;
    animation: cPulse 2.4s ease-in-out infinite !important;
}

@keyframes cPulse {
    0%, 100% { box-shadow: 0 0 5px rgba(74, 222, 128, 0.4); }
    50%       { box-shadow: 0 0 12px rgba(74, 222, 128, 0.75); }
}

/* Contact Info */
#profileSelection .contact-info {
    flex: 1;
    min-width: 0;
}

#profileSelection .contact-name {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
}

#profileSelection .contact-name h3 {
    font-size: 16px !important;
    font-weight: 700 !important;
    color: #ffffff !important;
    margin: 0 !important;
    letter-spacing: -0.2px !important;
}

#profileSelection .contact-verified {
    color: var(--primary-color, #E91E63) !important;
    font-size: 15px !important;
}

#profileSelection .contact-preview {
    font-size: 13.5px !important;
    color: rgba(255, 255, 255, 0.42) !important;
    margin: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

/* Contact Meta */
#profileSelection .contact-meta {
    flex-shrink: 0;
    text-align: right;
}

#profileSelection .contact-time {
    font-size: 12px !important;
    color: rgba(233, 30, 99, 0.6) !important;
    font-weight: 500 !important;
}

/* ========================================
   FIX: DISCOVER SCREEN LAYOUT
   Premium Swipe UI — Tinder/Bumble-style
   ======================================== */

#discoverScreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    display: none;
    flex-direction: column;
    background: var(--app-bg) !important;
    overflow: hidden;
}

#discoverScreen.active,
#discoverScreen[style*="display: flex"] {
    display: flex !important;
}

/* Discover Header — minimal, modern */
#discoverScreen .discover-header {
    position: relative;
    flex-shrink: 0;
    height: auto !important;
    min-height: 52px;
    padding-top: env(safe-area-inset-top, 0px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent !important;
    border-bottom: none;
    z-index: 10;
}

#discoverScreen .discover-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--app-text) !important;
    margin: 0;
    padding: 10px 0;
    letter-spacing: -0.3px;
}

#discoverScreen .discover-header-icon {
    font-size: 20px;
}

/* Cards Area — full-width, uses absolute positioning to stay above nav */
#discoverScreen .discover-cards-area {
    position: absolute !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: var(--nav-height);
    padding-top: 60px;
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

/* Card Stack — flex-fill so it takes remaining space above action buttons */
#discoverScreen .discover-card-stack {
    position: relative;
    width: 100%;
    max-width: 400px;
    flex: 1;
    min-height: 0;
    max-height: none;
}

/* Cards — premium feel with stronger shadows */
#discoverScreen .discover-card {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    border-radius: 24px;
    overflow: hidden;
    background: var(--app-surface-2) !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#discoverScreen .discover-card.card-top {
    z-index: 3;
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Behind cards — smooth depth effect */
#discoverScreen .discover-card.card-behind-1 {
    z-index: 2;
    transform: scale(0.96) translateY(10px);
    pointer-events: none;
    opacity: 0.7;
}

#discoverScreen .discover-card.card-behind-1 .discover-card-details,
#discoverScreen .discover-card.card-behind-1 .discover-card-info {
    visibility: hidden;
}

#discoverScreen .discover-card.card-behind-2 {
    z-index: 1;
    transform: scale(0.92) translateY(20px);
    pointer-events: none;
    opacity: 0.4;
}

#discoverScreen .discover-card.card-behind-2 .discover-card-details,
#discoverScreen .discover-card.card-behind-2 .discover-card-info,
#discoverScreen .discover-card.card-behind-2 .discover-card-image {
    visibility: hidden;
}

/* Card Image — dominant, 65% height */
#discoverScreen .discover-card-image {
    width: 100%;
    height: 65% !important;
    max-height: none !important;
    background-size: cover;
    background-position: center 25%;
    position: relative;
}

/* Gradient overlay — smooth cinematic look */
#discoverScreen .discover-card-image::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 70%;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.85) 0%,
        rgba(0, 0, 0, 0.4) 40%,
        transparent 100%
    );
    pointer-events: none;
}

/* Card Info Overlay — bolder, cleaner */
#discoverScreen .discover-card-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    z-index: 2;
    color: white;
}

#discoverScreen .discover-card-name {
    font-size: 28px;
    font-weight: 800;
    margin: 0;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    letter-spacing: -0.5px;
}

#discoverScreen .discover-card-age {
    font-size: 20px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
}

/* Card Details — themed surface */
#discoverScreen .discover-card-details {
    padding: 16px 20px;
    background: var(--app-surface-2) !important;
    flex: 1;
}

#discoverScreen .discover-card-tagline {
    font-size: 15px;
    color: var(--app-text-secondary) !important;
    margin: 0 0 12px 0;
    line-height: 1.4;
}

#discoverScreen .discover-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#discoverScreen .discover-tag {
    background: var(--app-surface) !important;
    border: 1px solid var(--app-border);
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--app-text-secondary) !important;
    transition: all 0.2s ease;
}

/* Action Buttons — larger, more prominent, always visible above nav */
#discoverScreen .discover-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 12px 0 8px;
    flex-shrink: 0;
    position: relative;
    z-index: 5;
}

#discoverScreen .discover-action-btn {
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

/* Skip Button — refined */
#discoverScreen .discover-skip-btn {
    width: 60px;
    height: 60px;
    background: var(--app-surface-2);
    border: 2px solid var(--app-border) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

#discoverScreen .discover-skip-btn svg {
    stroke: var(--app-text-secondary);
    width: 26px;
    height: 26px;
}

#discoverScreen .discover-skip-btn:active {
    transform: scale(0.88);
    background: var(--app-surface);
}

/* Like Button — vibrant, glowing */
#discoverScreen .discover-like-btn {
    width: 72px;
    height: 72px;
    background: linear-gradient(135deg, var(--primary-color, #E91E63) 0%, var(--primary-light, #F06292) 50%, #F48FB1 100%);
    box-shadow: 0 6px 24px rgba(233, 30, 99, 0.45), 0 2px 8px rgba(233, 30, 99, 0.2);
}

#discoverScreen .discover-like-btn svg {
    width: 30px;
    height: 30px;
    fill: white;
}

#discoverScreen .discover-like-btn:active {
    transform: scale(0.88);
    box-shadow: 0 3px 12px rgba(233, 30, 99, 0.3);
}

#discoverScreen .discover-action-btn:active {
    transform: scale(0.88);
}

/* Empty State — centered, beautiful */
#discoverScreen .discover-empty {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    gap: 16px;
}

#discoverScreen .discover-empty.visible {
    display: flex;
}

#discoverScreen .discover-empty-icon {
    font-size: 48px;
    margin-bottom: 4px;
}

#discoverScreen .discover-empty h3 {
    color: var(--app-text) !important;
    font-size: 20px;
    margin: 0;
}

#discoverScreen .discover-empty p {
    color: var(--app-text-secondary) !important;
    font-size: 15px;
    margin: 0;
    line-height: 1.5;
}

/* Refresh Button in empty state */
#discoverScreen .discover-refresh-btn {
    margin-top: 8px;
    padding: 12px 32px;
    border: none;
    border-radius: 24px;
    background: linear-gradient(135deg, var(--primary-color, #E91E63), var(--primary-light, #F06292));
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(233, 30, 99, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#discoverScreen .discover-refresh-btn:active {
    transform: scale(0.95);
}

/* ========================================
   DISCOVER: DARK MODE ENHANCEMENTS
   ======================================== */

[data-theme="dark"] #discoverScreen .discover-card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] #discoverScreen .discover-card-image::after {
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.95) 0%,
        rgba(0, 0, 0, 0.5) 40%,
        transparent 100%
    );
}

[data-theme="dark"] #discoverScreen .discover-skip-btn {
    background: var(--app-surface-2);
    border-color: var(--app-border) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] #discoverScreen .discover-like-btn {
    box-shadow: 0 6px 24px rgba(233, 30, 99, 0.5), 0 0 40px rgba(233, 30, 99, 0.15);
}

[data-theme="dark"] #discoverScreen .discover-tag {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--app-text-secondary) !important;
}

[data-theme="dark"] #discoverScreen .discover-card-details {
    background: var(--app-surface-2) !important;
    border-top: 1px solid var(--app-border);
}

/* ========================================
   DISCOVER: LIGHT MODE REFINEMENTS
   ======================================== */

:root #discoverScreen .discover-card {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
}

:root #discoverScreen .discover-tag {
    background: #f5f5f7 !important;
    border-color: var(--border-color, #2E2433);
}

/* ========================================
   FIX: APP NAVIGATION
   ======================================== */

.app-nav {
    position: fixed !important;
    bottom: 0;
    height: var(--nav-height);
    display: flex;
    align-items: flex-start;
    justify-content: space-around;
    background: var(--app-bg) !important;
    border-top: 1px solid var(--app-border-subtle);
    z-index: 100;
    padding-top: 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Mobile: volle Breite */
@media (max-width: 767px) {
    .app-nav {
        left: 0;
        right: 0;
        max-width: none !important;
        transform: none !important;
    }
}

/* Desktop: an 9:16-Frame ausrichten */
@media (min-width: 768px) {
    .app-nav {
        width: calc(100vh * 9 / 16) !important;
        max-width: 100vw !important;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 0;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--app-text-muted);
    transition: color 0.2s ease;
}

.nav-item svg {
    stroke: currentColor;
}

.nav-item span {
    font-size: 11px;
    font-weight: 500;
}

.nav-item.active {
    color: var(--app-nav-active) !important;
}

.nav-item.active svg {
    stroke: var(--app-nav-active);
}

.nav-item.active span {
    color: var(--app-nav-active);
}

/* ========================================
   FIX: SCREEN ISOLATION
   ======================================== */

/* Hide all screens by default */
.screen {
    display: none !important;
}

/* Only show active screen */
.screen.active,
.screen[style*="display: flex"],
.screen[style*="display: block"] {
    display: flex !important;
}

/* ========================================
   FIX: AUTH SCREEN - Theme Aware
   ======================================== */

#authScreen {
    justify-content: center;
    align-items: center;
}

#authScreen .auth-container {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 16px;
    padding: 32px 24px;
}

#authScreen .auth-container h2 {
    color: var(--app-text);
}

#authScreen .auth-subtitle {
    color: var(--app-text-secondary);
}

#authScreen .auth-toggle {
    background: var(--app-surface-2);
    border-radius: 12px;
}

#authScreen .toggle-btn {
    color: var(--app-text-secondary);
}

#authScreen .toggle-btn.active {
    background: var(--primary-color, #E91E63);
    color: #ffffff;
}

#authScreen .auth-form .input-group label {
    color: var(--app-text-secondary);
}

#authScreen .auth-form input {
    background: var(--app-surface-2);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

#authScreen .auth-form input::placeholder {
    color: var(--app-text-muted);
}

#authScreen .auth-form input:focus {
    border-color: var(--primary-color, #E91E63);
}

#authScreen .divider span {
    background: var(--app-surface);
    color: var(--app-text-muted);
}

#authScreen .btn-google {
    background: var(--app-surface-2);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

/* Verification & Reset screens styling */
#verificationScreen .auth-container,
#passwordResetScreen .auth-container,
#passwordResetVerifyScreen .auth-container {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 16px;
    color: var(--app-text);
}

#verificationScreen h2,
#passwordResetScreen h2,
#passwordResetVerifyScreen h2 {
    color: var(--app-text);
}

#verificationScreen .auth-subtitle,
#passwordResetScreen .auth-subtitle,
#passwordResetVerifyScreen .auth-subtitle {
    color: var(--app-text-secondary);
}

#verificationScreen,
#passwordResetScreen,
#passwordResetVerifyScreen {
    justify-content: center;
    align-items: center;
}

#passwordResetScreen .auth-form input,
#passwordResetVerifyScreen input {
    background: var(--app-surface-2);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

/* Ensure proper stacking */
#authScreen { z-index: 10; }
#chatScreen { z-index: 20; }
#discoverScreen { z-index: 20; }
#profileScreen { z-index: 20; }
#creditsScreen { z-index: 25; }
#friendsScreen { z-index: 20; }
#revealDecideScreen { z-index: 20; }

/* ========================================
   FIX: ACTUAL CHAT VIEW (WhatsApp-Style)
   Full screen, no nav footer, input sticky bottom
   ======================================== */

#actualChat {
    position: absolute !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0; /* Full height - no nav bar space */
    display: none;
    flex-direction: column !important;
    background: var(--app-bg) !important;
    z-index: 200; /* Above nav bar */
    overflow: hidden !important;
}

#actualChat[style*="display: flex"] {
    display: flex !important;
}

/* Chat Header - themed + Safe Area */
#actualChat .chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: var(--app-surface-3);
    border-bottom: 1px solid var(--app-border-subtle);
    min-height: calc(56px + env(safe-area-inset-top, 0px));
    z-index: 5;
    /* Override position:fixed from chat-rebuild.css */
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    height: auto !important;
}

#actualChat .chat-back-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--app-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

#actualChat .chat-back-btn:active {
    background: rgba(128,128,128,0.15);
}

#actualChat .chat-partner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

#actualChat .chat-partner-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

#actualChat .chat-partner-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--app-text);
    margin: 0;
}

#actualChat .chat-partner-handle {
    font-size: 12px;
    color: var(--app-text-secondary);
    margin: 0;
}

/* Hide soulmate badge and header actions in chat to keep it clean */
#actualChat .soulmate-level-badge {
    display: none;
}

#actualChat .chat-header-actions {
    display: none;
}

/* Hide chat tabs */
#actualChat .chat-tabs {
    display: none;
}

/* Chat Messages area - CRITICAL: Reset position:fixed from chat-rebuild.css */
#actualChat .chat-messages {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    padding-bottom: 8px;
    background: var(--app-bg);
    /* Reset position:fixed from chat-rebuild.css so messages stay in flex flow */
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
}

/* Message bubbles themed */
#actualChat .message {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    max-width: 85%;
}

#actualChat .message.received {
    align-self: flex-start;
}

#actualChat .message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

#actualChat .message-bubble {
    background: var(--app-msg-received);
    border-radius: 16px;
    padding: 10px 14px;
    color: var(--app-text);
    font-size: 15px;
    line-height: 1.4;
    max-width: 100%;
    word-wrap: break-word;
}

#actualChat .message.sent .message-bubble {
    background: var(--primary-color, #E91E63);
    color: #ffffff;
}

#actualChat .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

#actualChat .message-time {
    font-size: 11px;
    color: var(--app-text-muted);
    display: block;
    margin-top: 4px;
}

#actualChat .message-date-separator {
    text-align: center;
    margin: 16px 0;
    color: var(--app-text-muted);
    font-size: 12px;
}

#actualChat .message-date-separator span {
    background: var(--app-bg);
    padding: 0 12px;
}

/* Chat Input - sticky at bottom */
#actualChat .chat-input-area {
    flex-shrink: 0;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--app-surface-3);
    border-top: 1px solid var(--app-border-subtle);
}

#actualChat .chat-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

#actualChat .chat-input-field {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--app-surface-2);
    border: 1px solid var(--app-border);
    border-radius: 24px;
    padding: 8px 12px;
    gap: 8px;
}

#actualChat .chat-input-field input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 15px;
    color: var(--app-text);
    min-width: 0;
}

#actualChat .chat-input-field input::placeholder {
    color: var(--app-text-muted);
}

#actualChat .input-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--app-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
}

#actualChat .input-action-btn.send-btn {
    color: var(--primary-color, #E91E63);
}

#actualChat .card-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--app-surface-2);
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

/* Chat input footer info */
#actualChat .chat-input-footer {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px 0;
    font-size: 11px;
    color: var(--app-text-faded);
}

/* Hide open quizzes list in chat */
#actualChat #openQuizzesList {
    display: none !important;
}

/* ========================================
   FIX: QUIZ FLOW - True Fullscreen Overlay
   Uses position:fixed to cover entire viewport
   including the nav bar underneath
   ======================================== */

#quizFlow {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: none;
    flex-direction: column;
    background: var(--app-bg) !important;
    z-index: 9000; /* Above everything including nav bar */
    overflow: hidden;
}

#quizFlow[style*="display: flex"] {
    display: flex !important;
}

/* Quiz close button (top-right) */
.quiz-close-btn {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 16px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--app-surface-2);
    color: var(--app-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 20;
    transition: background 0.2s ease;
}

.quiz-close-btn:hover,
.quiz-close-btn:active {
    background: var(--app-border);
}

/* Quiz container - fills entire quiz overlay */
#quizFlow .quiz-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Quiz header - fixed at top with safe area */
#quizFlow .quiz-header {
    flex-shrink: 0;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    position: relative;
    z-index: 10;
}

/* Quiz content - scrollable, fills remaining space */
#quizFlow .quiz-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

/* Unlock modal - also truly fullscreen */
.unlock-modal {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    z-index: 9001; /* Above quiz */
}

.unlock-modal-content {
    height: 100%;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ========================================
   SCROLLBAR STYLING (Theme-Aware)
   ======================================== */

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--app-scrollbar);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--app-scrollbar-hover);
}

/* ========================================
   MOBILE RESPONSIVE LAYOUT OVERRIDES
   Safe Areas, dvh, Proper Scaling
   ======================================== */

/* --- PROFILE SCREEN FIX --- */
#profileScreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    display: none;
    flex-direction: column;
    overflow: hidden !important; /* Don't scroll the whole screen */
    background: var(--profile-bg, var(--app-bg)) !important;
}

#profileScreen.active,
#profileScreen[style*="display: flex"] {
    display: flex !important;
}

/* Profile hero - auto height, no fixed constraints */
#profileScreen .profile-hero {
    flex-shrink: 0;
    overflow: hidden;
}

/* Profile content - scrollable, proper bottom space */
#profileScreen .profile-content {
    flex: 1;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(20px + var(--nav-height)) !important; /* Space for nav */
}

/* Profile avatar - sized in mobile-first fixes below */

/* Profile nav - inside the screen */
#profileScreen > .app-nav {
    position: absolute !important;
    flex-shrink: 0;
}

/* --- AUTH SCREEN FIX --- */
#authScreen {
    height: 100%;
    height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

#authScreen .auth-container {
    max-width: 400px;
    width: calc(100% - 32px);
    margin: auto;
}

/* --- VERIFICATION / RESET SCREENS --- */
#verificationScreen,
#passwordResetScreen,
#passwordResetVerifyScreen {
    height: 100%;
    height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: env(safe-area-inset-top, 0px);
}

/* --- CREDITS SCREEN FIX --- */
#creditsScreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    height: 100dvh;
    display: none;
    flex-direction: column;
    overflow: hidden !important;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: 0 !important;
}

#creditsScreen.active,
#creditsScreen[style*="display: flex"] {
    display: flex !important;
}

#creditsScreen .store-header {
    flex-shrink: 0;
    position: relative !important;
    z-index: 2;
}

#creditsScreen .store-container {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 24px !important;
    min-height: 0 !important;
}

#creditsScreen .app-nav {
    flex-shrink: 0;
    position: relative !important;
}

/* Quiz safe areas handled in quiz-container/header/content above */

/* --- DISCOVER SCREEN - Proper bottom for nav --- */
#discoverScreen > .app-nav {
    position: absolute !important;
    flex-shrink: 0;
}

/* ========================================
   MOBILE-SPECIFIC BREAKPOINTS
   ======================================== */

/* Small phones - discover adjustments (profile handled in mobile-first section below) */
@media screen and (max-height: 667px) {
    #discoverScreen .discover-card-name {
        font-size: 24px !important;
    }

    #discoverScreen .discover-skip-btn {
        width: 52px;
        height: 52px;
    }

    #discoverScreen .discover-like-btn {
        width: 62px;
        height: 62px;
    }
}

/* Very small phones (320px height - landscape or tiny phones) */
@media screen and (max-height: 568px) {
    /* Compact nav */
    .app-nav {
        height: calc(48px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .nav-item span {
        font-size: 9px;
    }
}

/* Notch phones - extra safe area padding */
@supports (padding-top: env(safe-area-inset-top)) {
    #profileScreen .profile-hero {
        padding-top: calc(20px + env(safe-area-inset-top, 0px)) !important;
    }

    #discoverScreen .discover-header {
        padding-top: env(safe-area-inset-top, 0px);
    }

    #actualChat .chat-header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    #profileSelection .messages-header {
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }
}

/* ========================================
   PREVENT DOUBLE SCROLLBARS
   Only content areas should scroll
   ======================================== */

#chatScreen,
#discoverScreen,
#profileScreen,
#creditsScreen {
    overflow: hidden !important;
}

/* Only these content areas scroll */
#profileSelection .contact-list,
#profileScreen .profile-content,
#actualChat .chat-messages,
#creditsScreen .credits-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Prevent body scroll leak */
body.quiz-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100%;
    height: 100%;
}

/* ========================================
   POPUP/MODAL OVERLAYS - Theme Aware
   ======================================== */

.popup-overlay .popup-content {
    background: var(--app-surface);
    color: var(--app-text);
    border: 1px solid var(--app-border);
}

.popup-overlay .popup-content h3 {
    color: var(--app-text);
}

.popup-overlay .popup-content p {
    color: var(--app-text-secondary);
}

/* Credits store theme */
#creditsScreen .store-header {
    background: var(--app-bg);
    color: var(--app-text);
}

#creditsScreen .store-header h2 {
    color: var(--app-text);
}

#creditsScreen .store-container {
    color: var(--app-text);
}

#creditsScreen .credit-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

#creditsScreen .credit-card h3 {
    color: var(--app-text);
}

#creditsScreen .card-description {
    color: var(--app-text-secondary);
}

#creditsScreen .store-footer {
    color: var(--app-text-secondary);
}

#creditsScreen .store-footer p {
    color: var(--app-text-secondary);
}

#creditsScreen .store-subtitle {
    color: var(--app-text-secondary);
}

#creditsScreen .price {
    color: var(--app-text);
}

#creditsScreen .price-per {
    color: var(--app-text-secondary);
}

#creditsScreen .current-balance {
    color: var(--app-text);
}

#creditsScreen .back-btn {
    color: var(--app-text);
}

#creditsScreen .card-badge {
    background: var(--app-surface);
    color: var(--app-text-secondary);
}

#creditsScreen .store-footer {
    border-top-color: var(--app-border);
}

#creditsScreen .card-icon svg {
    stroke: var(--primary-color, #E91E63);
}

/* Dark mode overrides for credits store - specificity boost */
[data-theme="dark"] #creditsScreen {
    background: var(--app-bg, #0a0a0a) !important;
}

[data-theme="dark"] #creditsScreen .store-header {
    background: var(--app-bg, #0a0a0a) !important;
    border-bottom-color: var(--app-border, #2a2a2a) !important;
}

[data-theme="dark"] #creditsScreen .credit-card.popular {
    background: linear-gradient(135deg, #1a1218, #251520) !important;
    border-color: var(--primary-color, #E91E63) !important;
}

[data-theme="dark"] #creditsScreen .btn-purchase {
    background: var(--primary-color, #E91E63);
    color: #ffffff;
}

/* ========================================
   CARD MODAL - DARK MODE
   ======================================== */

[data-theme="dark"] #cardModal {
    background: rgba(0, 0, 0, 0.75);
}

[data-theme="dark"] .card-modal-panel {
    background: var(--app-bg, #0a0a0a) !important;
}

[data-theme="dark"] .card-modal-header {
    background: var(--app-bg, #0a0a0a) !important;
    border-bottom-color: var(--app-border, #2a2a2a) !important;
}

[data-theme="dark"] .card-modal-header h3 {
    color: #ffffff !important;
}

[data-theme="dark"] .card-modal-close,
[data-theme="dark"] .card-modal-back {
    background: #1a1a1a !important;
    color: var(--text-secondary, #B0B0B0) !important;
}

[data-theme="dark"] .card-modal-close:hover,
[data-theme="dark"] .card-modal-back:hover {
    background: #252525 !important;
}

[data-theme="dark"] .card-category-item {
    background: var(--app-surface, #141414) !important;
    border-color: var(--app-border, #2a2a2a) !important;
}

[data-theme="dark"] .card-question-item {
    background: var(--app-surface, #141414) !important;
    border-color: var(--app-border, #2a2a2a) !important;
}

[data-theme="dark"] .truth-joker-card {
    background: rgba(124, 77, 255, 0.08) !important;
    border-color: rgba(124, 77, 255, 0.2) !important;
}

[data-theme="dark"] .joker-msg-title {
    color: #b39dff !important;
}

[data-theme="dark"] .joker-msg-text {
    color: #9c8fcc !important;
}

[data-theme="dark"] .joker-msg-time {
    color: #6a5a9e !important;
}

/* Soulmate rank bar dark mode */
[data-theme="dark"] .soulmate-rank-bar {
    background: rgba(10, 10, 10, 0.95) !important;
    border-bottom-color: var(--app-border, #2a2a2a) !important;
}

[data-theme="dark"] .rank-level-label,
[data-theme="dark"] .rank-next-label {
    color: var(--text-secondary, #B0B0B0) !important;
}

[data-theme="dark"] .rank-progress-track {
    background: #1a1a1a !important;
}

/* Notification/Privacy settings theme */
.settings-container {
    color: var(--app-text);
}

.settings-container h3 {
    color: var(--app-text);
}

.settings-container .settings-hint {
    color: var(--app-text-secondary);
}

.settings-container .setting-item {
    border-bottom: 1px solid var(--app-border-subtle);
}

.settings-container .setting-item strong {
    color: var(--app-text);
}

.settings-container .setting-item p {
    color: var(--app-text-secondary);
}

.settings-container .radio-option {
    color: var(--app-text);
}

.settings-container .settings-footer-note {
    color: var(--app-text-muted);
}

.profile-header {
    background: var(--app-bg);
    color: var(--app-text);
}

.profile-header h2 {
    color: var(--app-text);
}

.profile-header .back-btn {
    color: var(--app-text);
}

/* ========================================
   MOBILE-FIRST LAYOUT FIXES 2026-02-09
   1. Footer overlap - containers under footer
   2. Swipe mode - heart/dislike buttons hidden
   3. Profile - image/name out of viewport
   4. Remove Curious-XP from profile
   5. Add "Credits kaufen" button in profile
   ======================================== */

/* --- FIX: Profile screen - image/name out of viewport --- */
#profileScreen {
    display: none;
    flex-direction: column;
    overflow: hidden !important;
}

#profileScreen .profile-hero {
    flex-shrink: 0;
    min-height: 0 !important;
    max-height: none !important;
    height: auto !important;
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px 32px !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative !important;
    overflow: hidden !important;
}

#profileScreen .profile-hero-content {
    display: flex !important;
    flex-direction: column !important;
    gap: 14px !important;
    width: 100% !important;
    align-items: center !important;
    position: relative !important;
    z-index: 1 !important;
}

#profileScreen .profile-avatar-section {
    margin-bottom: 4px;
}

#profileScreen .profile-avatar {
    width: 88px !important;
    height: 88px !important;
    font-size: 34px !important;
}

#profileScreen .profile-avatar-ring {
    padding: 3px !important;
}

#profileScreen .profile-identity {
    text-align: center !important;
}

#profileScreen .profile-name {
    font-size: 24px !important;
    font-weight: 700 !important;
    margin: 0 !important;
    line-height: 1.2 !important;
}

#profileScreen .profile-content {
    flex: 1;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + var(--nav-height)) !important;
    margin-top: 0 !important;
    padding-top: 16px !important;
}

/* --- FIX 3: Remove Curious-XP display completely --- */
.profile-level-card {
    display: none !important;
}

/* --- FIX 4: "Credits kaufen" button in profile --- */
.profile-buy-credits-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 28px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary-color, #E91E63);
    border: none;
    border-radius: 28px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    letter-spacing: 0.3px;
    margin-top: 4px;
    flex-shrink: 0;
}

.profile-buy-credits-btn:active {
    transform: scale(0.95);
}

.profile-buy-credits-btn svg {
    stroke: var(--primary-color, #E91E63);
    flex-shrink: 0;
}

[data-theme="dark"] .profile-buy-credits-btn {
    background: rgba(233, 30, 99, 0.9);
    color: #ffffff;
}

[data-theme="dark"] .profile-buy-credits-btn svg {
    stroke: #ffffff;
}

/* --- FIX 5: Small screens - tighter profile hero --- */
@media screen and (max-height: 667px) {
    #profileScreen .profile-hero {
        padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 20px !important;
    }

    #profileScreen .profile-avatar {
        width: 72px !important;
        height: 72px !important;
        font-size: 28px !important;
    }

    #profileScreen .profile-name {
        font-size: 20px !important;
    }

    #profileScreen .profile-hero-content {
        gap: 10px !important;
    }

    .profile-buy-credits-btn {
        padding: 10px 24px;
        font-size: 14px;
    }

    #discoverScreen .discover-actions {
        padding: 8px 0 4px;
        gap: 20px;
    }
}

@media screen and (max-height: 568px) {
    #profileScreen .profile-hero {
        padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 16px !important;
    }

    #profileScreen .profile-avatar {
        width: 60px !important;
        height: 60px !important;
    }

    #profileScreen .profile-name {
        font-size: 18px !important;
    }

    .profile-buy-credits-btn {
        padding: 8px 20px;
        font-size: 13px;
    }
}
