:root {
    --bg: #000000;
    --surface: rgba(255, 255, 255, 0.04);
    --surface-elevated: rgba(255, 255, 255, 0.08);
    --accent: #ffffff;
    --accent-muted: rgba(255, 255, 255, 0.6);
    --text: #ffffff;
    --muted: rgba(255, 255, 255, 0.45);
    --error: #ff3b30;
    --ios-blur: blur(25px) saturate(180%);
    --ios-border: rgba(255, 255, 255, 0.1);
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

body.no-scroll {
    overflow: hidden;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* --- App Layout --- */
.app-container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    padding-bottom: calc(100px + var(--safe-bottom));
    position: relative;
}

.bg-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(circle at 0% 0%, rgba(255, 255, 255, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(100, 100, 255, 0.03) 0%, transparent 50%);
}

/* --- Header & Profile --- */
.profile-section {
    padding: calc(100px + var(--safe-top)) 24px 24px;
    text-align: center;
    animation: fadeIn 0.6s ease-out;
}

.avatar-wrapper {
    position: relative;
    width: 110px;
    height: 110px;
    margin: 0 auto 20px;
}

.avatar-glow {
    position: absolute;
    inset: -5px;
    background: linear-gradient(45deg, #fff, rgba(255, 255, 255, 0.2));
    border-radius: 50%;
    padding: 2px;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    opacity: 0.5;
}

.profile-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid var(--bg);
    background: #111;
}

.profile-info h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
}

.profile-info p {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.profile-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-glass {
    background: var(--surface);
    border: 1px solid var(--ios-border);
    color: #fff;
    padding: 10px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: var(--ios-blur);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-glass:active {
    transform: scale(0.95);
    background: var(--surface-elevated);
}

/* --- Stats --- */
.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 24px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--ios-border);
    padding: 12px 8px;
    border-radius: 20px;
    text-align: center;
    backdrop-filter: var(--ios-blur);
    transition: transform 0.3s ease;
}

.stat-card:active {
    transform: scale(0.98);
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1px;
}

.stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 700;
}

/* --- Content Tabs --- */
.content-tabs {
    border-top: 1px solid var(--ios-border);
    margin-top: 8px;
}

.tab-header {
    display: flex;
    justify-content: center;
    padding: 12px 0;
    gap: 40px;
}

.tab-item {
    color: var(--muted);
    padding: 8px;
    cursor: pointer;
    position: relative;
    transition: color 0.3s;
}

.tab-item.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Image Grid --- */
.image-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2px;
    padding: 2px;
    animation: fadeIn 0.8s ease-out;
}

.grid-item {
    aspect-ratio: 1;
    background: #0a0a0a;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.grid-item:hover img {
    transform: scale(1.05);
}

/* --- Bottom Sheet Modals --- */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sheet-content {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #111;
    border-radius: 32px 32px 0 0;
    /* Optimized bottom padding since bottom-nav is hidden when sheet is open */
    padding: 32px 24px calc(24px + var(--safe-bottom));
    z-index: 1001;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    max-width: 480px;
    margin: 0 auto;
    border-top: 1px solid var(--ios-border);
    /* Enable scrolling within the sheet */
    max-height: 85vh;
    overflow-y: auto;
    scrollbar-width: none;
    /* Firefox */
}

/* Comments sheet specific overrides to keep input pinned at bottom and list scrollable */
#comments-sheet-overlay {
    z-index: 1002;
}

#comments-sheet {
    z-index: 1003;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#comments-sheet .comments-list {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 12px;
}

.sheet-content::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.sheet-overlay.active {
    display: block;
    opacity: 1;
}

.sheet-content.active {
    transform: translateY(0);
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--surface-elevated);
    border-radius: 2px;
    margin: -16px auto 24px;
}

.sheet-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}

/* --- Form Elements --- */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 8px;
    padding-left: 4px;
}

.input-glass {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--ios-border);
    border-radius: 16px;
    padding: 14px 18px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.input-glass:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-primary {
    width: 100%;
    background: #fff;
    color: #000;
    border: none;
    padding: 16px;
    border-radius: 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
    transition: transform 0.2s;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-danger {
    width: 100%;
    background: rgba(255, 59, 48, 0.1);
    color: var(--error);
    border: 1px solid rgba(255, 59, 48, 0.2);
    padding: 16px;
    border-radius: 18px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* --- Friends List --- */
.friends-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px;
    border-radius: 16px;
    transition: background 0.2s;
}

.friend-item:active {
    background: var(--surface);
}

.friend-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: #111;
}

.friend-info h4 {
    font-size: 1rem;
    font-weight: 600;
}

.friend-info p {
    font-size: 0.85rem;
    color: var(--muted);
}

/* --- Post Detail --- */
.post-detail-img {
    width: 100%;
    max-height: 32vh;
    border-radius: 24px;
    object-fit: contain;
    background: #000;
    margin-bottom: 16px;
    border: 1px solid var(--ios-border);
}

.post-meta {
    margin-bottom: 24px;
}

/* --- Loader --- */
.loader {
    display: flex;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* --- Likes and Comments inside Post Detail --- */
.post-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    margin-top: 16px;
}

.like-text {
    font-weight: 700;
    color: #ff3b30;
    font-size: 0.88rem;
}

.like-text.just-liked {
    animation: likePop 0.4s var(--spring, cubic-bezier(0.34, 1.56, 0.64, 1)) forwards;
}

@keyframes likePop {
    0%  { transform: translateY(6px) scale(0.8); opacity: 0; }
    60% { transform: translateY(-2px) scale(1.08); opacity: 1; }
    100%{ transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes heartBurst {
    0%  { transform: scale(1);   opacity: 1; fill: none; }
    40% { transform: scale(1.7); opacity: 1; fill: #ff3b30; color: #ff3b30; }
    70% { transform: scale(2.2); opacity: 0.6; }
    100%{ transform: scale(2.5); opacity: 0; }
}

.anim-burst {
    animation: heartBurst 0.38s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    pointer-events: none;
    color: #ff3b30;
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-bottom: 20px;
    max-height: 250px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.comment-item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    animation: commentIn 0.3s cubic-bezier(0.25, 1, 0.5, 1) both;
}

@keyframes commentIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--ios-border);
    background: #1a1a1a;
}

.comment-body {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 14px;
    border-radius: 16px;
    border: 1px solid var(--ios-border);
}

.comment-user {
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 3px;
    color: #fff;
}

.comment-text {
    font-size: 0.85rem;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.9);
    word-break: break-word;
}

.comment-time {
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 4px;
    display: block;
}

.comment-input-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--ios-border);
    border-radius: 20px;
    padding: 6px 6px 6px 14px;
    margin-top: auto;
    flex-shrink: 0;
}

.comment-input-wrapper input {
    flex: 1;
    background: none;
    border: none;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
    padding: 8px 0;
    font-family: inherit;
}

.comment-input-wrapper button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.comment-input-wrapper button:active {
    transform: scale(0.88);
}

.comment-action-btn {
    cursor: pointer;
    width: 24px;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.comment-action-btn:active {
    transform: scale(0.82);
}

.comment-count-text {
    font-size: 0.88rem;
    color: var(--muted);
    font-weight: 500;
    margin-left: 2px;
}

.reply-tag {
    color: #3897f0;
    font-weight: 600;
    margin-right: 4px;
    cursor: pointer;
}
