* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: sans-serif;
}

body {
    background-color: #111; /* Slightly lighter dark background for laptop viewing */
    color: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center; /* Centers the app horizontally on large screens */
    height: 100dvh; /* Entire screen height */
}

/* Container separating main content from navigation */
.app-container {
    flex: 1; /* Takes up all space minus the bottom-nav */
    width: 100%;
    max-width: 480px; /* Constrains the app to a phone's width on laptops */
    position: relative;
    overflow: hidden;
    background: #000;
    box-shadow: 0 0 20px rgba(0,0,0,0.5); /* Adds a nice shadow edge for desktop */
}

/* GLOBAL HIDDEN CLASS FIX */
.hidden {
    display: none !important;
}

.feed-container {
    height: 100%; 
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
}

.feed-container::-webkit-scrollbar {
    display: none;
}

.post {
    height: 100%;
    width: 100%; /* Changed from 100vw to fit within the max-width container */
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-bottom: 1px solid #333;
    background: #000;
}

.post video, .post img {
    height: 100%; 
    width: 100%; /* Changed from 100vw to fit within the max-width container */
    scroll-snap-align: start;
    scroll-snap-stop: always; 
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    border-bottom: 1px solid #333;
    background: #000;
    object-fit: contain;
}

/* Instagram Reels Layout */
.post-overlay {
    position: absolute;
    bottom: 0; left: 0; right: 0; top: 0;
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 15px 15px 20px 15px;
}

.post-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: auto;
    max-width: 75%;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.9);
}

.post-author-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.post-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: #555;
    background-size: cover;
    background-position: center;
    border: 1px solid white;
}

.post-username {
    font-weight: bold;
    font-size: 1.1em;
}

.post-description {
    font-size: 0.9em;
    line-height: 1.3;
}

.post-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    pointer-events: auto;
    margin-bottom: 15px;
}

.like-btn {
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: 0.2s;
    border: 2px solid transparent;
    cursor: pointer;
    z-index: 50;
    -webkit-tap-highlight-color: transparent;
}

.like-btn.liked {
    color: #ff0050;
    border-color: #ff0050;
}

.like-count {
    font-size: 13px;
    text-shadow: 1px 1px 2px #000;
    font-weight: bold;
}

/* Navigation - Now standard flexbox layout, not absolutely positioned */
.bottom-nav {
    width: 100%;
    max-width: 480px; /* Ensures the nav bar doesn't stretch across the laptop screen */
    height: 70px;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid #222;
}

.nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #555;
    transition: color 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn.active {
    color: #fff;
}

.nav-btn span.material-icons {
    font-size: 32px;
    color: inherit;
}

/* Modals - Anchored to app-container to prevent overlapping navbar */
.modal {
    position: absolute; 
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000; /* Increased */
}

.modal-content {
    background: #222;
    padding: 20px;
    border-radius: 10px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    max-height: 100%;
    overflow-y: auto;
}

.full-modal {
    background: #000; 
    z-index: 1010; /* Increased */
}

.full-modal .full-screen-content {
    width: 100%; /* Changed from 100vw */
    height: 100%; 
    border-radius: 0;
    padding-top: 20px; 
    padding-bottom: 20px; 
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.close {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 28px;
    cursor: pointer;
    z-index: 50;
}

input, textarea {
    padding: 10px;
    border-radius: 5px;
    border: none;
    background: #333;
    color: white;
    resize: none;
}

button {
    padding: 12px;
    border-radius: 5px;
    border: none;
    background: #ff0050;
    color: white;
    cursor: pointer;
    font-weight: bold;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: #444;
    margin: 0 auto;
    background-size: cover;
    background-position: center;
}

.profile-header {
    text-align: center;
    margin-bottom: 20px;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
}

/* Container for each square on the profile grid */
.profile-grid-item {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    cursor: pointer;
    overflow: hidden;
    background: #222; /* Placeholder color while loading */
}

/* Make the image/video fill the square */
.profile-grid-item img, .profile-grid-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s;
}

.profile-grid-item:hover img, .profile-grid-item:hover video {
    opacity: 0.8;
}

/* The view count overlay */
.grid-view-count {
    position: absolute;
    bottom: 5px;
    left: 5px;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 4px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.9);
    pointer-events: none; /* Let clicks pass through to the video/image */
}

/* Make the icon match the small text size */
.grid-view-count .material-icons {
    font-size: 14px;
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
    font-size: 14px;
}

.profile-stats div {
    cursor: pointer;
    background: #333;
    padding: 8px 15px;
    border-radius: 8px;
    text-align: center;
}

.profile-stats strong {
    display: block;
    font-size: 18px;
}

.edit-controls {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: 250px;
    margin: 0 auto 20px auto;
}

.feed-follow-btn {
    background: transparent;
    border: 1px solid white;
    color: white;
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 15px;
    cursor: pointer;
    transition: 0.2s;
}

.feed-follow-btn.following {
    background: white;
    color: black;
}

.list-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 15px;
}

.list-user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #333;
    border-radius: 8px;
    cursor: pointer;
}

.list-user-row:hover {
    background: #444;
}

.more-options-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    z-index: 15;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}

.post-menu {
    position: absolute;
    top: 60px;
    right: 20px;
    background: #222;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 5px;
    z-index: 100; 
}

.post-menu button {
    background: transparent;
    color: #ff4444; 
    font-size: 14px;
    padding: 10px 15px;
    width: 100%;
}

.single-post-view {
    padding: 0; 
    background: #000;
}
#singlePostContainer {
    width: 100%;
    height: 100%;
}


/* --- Double Tap Heart Animation --- */
/* Update the .tap-heart class in style.css */
.tap-heart {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    color: #ff0050; 
    font-size: 180px; /* Increased from 120px to 180px */
    opacity: 0;
    z-index: 100;
    pointer-events: none;
    text-shadow: 0 0 50px rgba(0,0,0,0.8); /* Stronger shadow for the larger icon */
    animation: popHeart 0.8s ease-out forwards;
}

@keyframes popHeart {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    15% { transform: translate(-50%, -50%) scale(5); opacity: 0.9; } /* Slightly larger pop */
    30% { transform: translate(-50%, -50%) scale(4); opacity: 1; }
    70% { transform: translate(-50%, -50%) scale(4); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(7); opacity: 0; } /* Larger exit scale */
}

/* Top Feed Navigation */
.top-nav {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 20px;
    z-index: 10;
    pointer-events: auto;
}

.top-nav-btn {
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    font-size: 16px;
    font-weight: bold;
    padding: 5px 10px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    transition: 0.2s;
}

.top-nav-btn.active {
    color: #fff;
    border-bottom: 2px solid #fff;
    border-radius: 0;
}

/* Views and Caught Up Divider */
.view-btn {
    background: transparent;
    color: white;
    border: none;
    font-size: 28px;
    cursor: default;
}

.caught-up-divider {
    height: 100%;
    width: 100%;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #111;
    color: #aaa;
    text-align: center;
    border-bottom: 1px solid #333;
}

.caught-up-divider span {
    font-size: 48px;
    color: #4CAF50;
    margin-bottom: 10px;
}

/* --- Comment Section Styles --- */
#commentsModal { z-index: 1050 !important; }

.comment-row {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.comment-content {
    background: #222;
    padding: 10px;
    border-radius: 8px;
    flex-grow: 1;
}

.comment-username {
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 4px;
    color: #fff;
}

.comment-text {
    font-size: 14px;
    word-break: break-word;
    color: #ddd;
}

.comment-input-area {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #333;
}

.comment-btn {
    background: transparent;
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    margin-bottom: -15px; /* Adjust spacing in the post-actions area */
    transition: 0.2s;
}

/* --- Modal Stacking Fixes --- */
#searchModal { z-index: 1010; }
#uploadModal { z-index: 1010; }
#profileModal { z-index: 1010; }
#authModal { z-index: 1015; }
#viewProfileModal { z-index: 1020 !important; }
#singlePostModal { z-index: 1100 !important; }
#listModal { z-index: 1040 !important; }
#commentsModal { z-index: 1050 !important; }

/* --- Direct Messages & Notifications --- */
.nav-badge {
    position: absolute;
    top: 5px;
    right: 15px;
    background: #ff0050;
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    border: 2px solid #000;
}

.chat-msg {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg.sent {
    background: #ff0050;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-msg.received {
    background: #333;
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

/* --- Play / Pause Indicator Animation --- */
.play-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 100px;
    color: rgba(255, 255, 255, 0.85);
    pointer-events: none; /* Let taps pass right through to the video */
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;
    text-shadow: 0 0 30px rgba(0,0,0,0.8);
}

/* When the video is paused, fade the triangle in */
.post.is-paused .play-indicator {
    opacity: 1;
    transform: translate(-50%, -50%) scale(3);
}

/* When playing, scale it up slightly before vanishing for a smooth pop effect */
.post:not(.is-paused) .play-indicator {
    opacity: 0;
    transform: translate(-50%, -50%) scale(3.9);
}

/* --- Carousel System --- */
.carousel-container {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    width: 100%;
    height: 100%;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    position: relative;
}

.carousel-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.carousel-item {
    flex: 0 0 100%;
    scroll-snap-align: center;
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.carousel-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 20;
    transition: 0.2s;
}

.carousel-btn:hover { background: rgba(0, 0, 0, 0.8); }
.carousel-btn.left { left: 10px; }
.carousel-btn.right { right: 10px; }

.carousel-dots {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 20;
}

.carousel-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transition: 0.2s;
}

.carousel-dot.active {
    background: white;
    transform: scale(1.2);
}

/* --- Upload Staging Area --- */
.staged-file {
    width: 65px;
    height: 65px;
    position: relative;
    border-radius: 5px;
    overflow: hidden;
    background: #222;
}

.staged-file img, .staged-file video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.staged-file-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(255, 0, 0, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

/* --- DM Enhancements --- */
.chat-msg-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    width: 100%;
}

.chat-msg-wrapper.sent {
    flex-direction: row-reverse;
}

.chat-msg {
    position: relative;
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
    user-select: none; /* Prevents text selection on double-tap */
}

/* Like Heart Indicator */
.chat-msg-liked-heart {
    position: absolute;
    bottom: -10px;
    font-size: 16px;
    color: #ff0050;
    background: #222;
    border-radius: 50%;
    padding: 3px;
    border: 2px solid #000;
}
.chat-msg-wrapper.sent .chat-msg-liked-heart { left: -5px; }
.chat-msg-wrapper.received .chat-msg-liked-heart { right: -5px; }

/* Reply Context Box inside bubble */
.chat-msg-reply-ref {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.2);
    padding: 6px;
    border-radius: 8px;
    margin-bottom: 6px;
    border-left: 2px solid rgba(255, 255, 255, 0.5);
    display: block;
}

/* File Previews in Chat */
.chat-file-preview {
    max-width: 200px;
    max-height: 250px;
    border-radius: 8px;
    margin-top: 5px;
    display: block;
    object-fit: cover;
}

/* Action Buttons (Reply/Like) next to message */
.chat-actions {
    display: flex;
    gap: 5px;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s;
}

/* Show actions on hover (Desktop) or when tapping around */
.chat-msg-wrapper:hover .chat-actions,
.chat-msg-wrapper:active .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    font-size: 18px;
    color: #777;
    cursor: pointer;
    background: #222;
    padding: 6px;
    border-radius: 50%;
}
.chat-action-btn:hover { background: #444; color: #fff; }

/* --- Message Metadata (Timestamps, Read Receipts, Names) --- */
.msg-sender-name {
    font-size: 11px;
    font-weight: bold;
    color: #ccc;
    margin-bottom: 4px;
}

.chat-msg-wrapper.sent .msg-sender-name {
    display: none; /* Don't show your own name to yourself */
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
}

.chat-msg-wrapper.received .msg-meta {
    justify-content: flex-start;
}

.msg-read-status {
    font-size: 14px !important;
}

.msg-read-status.read {
    color: #4CAF50; /* Green double ticks if read */
}

/* Group Checkbox Selection */
.group-member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px solid #333;
}
.group-member-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #ff0050;
}

/* Shared Post in Chat */
.shared-post-preview {
    background: rgba(0, 0, 0, 0.3);
    border-left: 3px solid #ff0050;
    padding: 8px;
    margin-top: 5px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}
.shared-post-preview:hover {
    background: rgba(0, 0, 0, 0.5);
}
.shared-post-header {
    font-size: 11px;
    color: #aaa;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
}
.shared-post-content {
    font-size: 13px;
    color: #eee;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Chat Like Counter */
.chat-like-counter {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: #ff0050;
    background: rgba(255, 0, 80, 0.1);
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
}
