/* ============================================
   MoodyJar - Stylesheet
   Dark theme, mobile-first, Apple-style UI
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@1,700&family=DM+Sans:wght@400;500;600&display=swap');

/* --- CSS Variables --- */
:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #1e1e1e;
    --bg-card-hover: #252525;
    --bg-input: #2a2a2a;
    --text-primary: #e8e8e8;
    --text-secondary: #8a8a8a;
    --text-muted: #5a5a5a;
    --accent-purple: #a477e0;
    --accent-purple-light: #b794f0;
    --accent-red: #e8445a;
    --accent-red-glow: rgba(232, 68, 90, 0.3);
    --accent-green: #4ade80;
    --border: #2a2a2a;
    --border-light: #333;
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 999px;
    --shadow-card: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-fab: 0 4px 20px rgba(164, 119, 224, 0.4);
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --max-width: 640px;
    --nav-height: 70px;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    /* Fix iOS: lock the html/body to viewport so fixed positioning is stable */
    height: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Header --- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
}

.header-wrapper {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    font-style: italic;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.tagline {
    font-size: 13px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

/* --- Main Content --- */
.main {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 12px 16px;
    padding-bottom: calc(var(--nav-height) + 30px);
}

/* --- Post Card --- */
.post-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 12px;
    transition: background 0.2s ease;
    animation: fadeInUp 0.4s ease both;
}

.post-card:hover {
    background: var(--bg-card-hover);
}

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

.post-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.post-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg-input);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.post-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.post-avatar-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2a2a2a, #3a3a3a);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.post-avatar-icon svg {
    width: 22px;
    height: 22px;
    fill: var(--text-secondary);
}

.post-meta {
    display: flex;
    flex-direction: column;
}

.post-username {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.post-date {
    font-size: 12px;
    color: var(--text-muted);
}

.post-body {
    font-size: 18px;
    line-height: 1.55;
    color: var(--text-primary);
    margin-bottom: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.post-hashtags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.hashtag {
    font-size: 13px;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

.post-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.post-stats {
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: default;
}

.stat-like {
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.stat-like:hover {
    color: var(--accent-red);
}

.stat-like.liked {
    color: var(--accent-red);
}

.stat-like.liked svg {
    fill: var(--accent-red);
    filter: drop-shadow(0 0 6px var(--accent-red-glow));
}

.stat svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    transition: all 0.2s ease;
}

.stat-like.liked svg {
    stroke: var(--accent-red);
}

.post-actions {
    display: flex;
    gap: 12px;
}

.post-action-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.post-action-btn:hover {
    color: var(--text-secondary);
}

.post-action-btn svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

.delete-btn {
    color: var(--text-muted);
}

.delete-btn:hover {
    color: var(--accent-red);
}

/* Like animation */
@keyframes likePopUp {
    0% { transform: scale(1); }
    30% { transform: scale(1.35); }
    60% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.like-animate svg {
    animation: likePopUp 0.4s ease;
}

/* --- Bottom Navigation --- */
.bottom-nav-wrapper {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    /* iOS Safari fix: forces GPU layer, prevents disappearing on scroll */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    /* Prevent iOS from hiding this during rubber-band scroll */
    -webkit-overflow-scrolling: auto;
}

.bottom-nav {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--nav-height);
    padding: 0 20px;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    transition: color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover,
.nav-btn.active {
    color: var(--text-primary);
}

.nav-btn svg {
    width: 26px;
    height: 26px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
}

.nav-btn span {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* FAB (Floating Action Button) */
.fab {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--accent-purple);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-fab);
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    top: -14px;
}

.fab:hover {
    background: var(--accent-purple-light);
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(164, 119, 224, 0.5);
}

.fab:active {
    transform: scale(0.95);
}

.fab svg {
    width: 28px;
    height: 28px;
    stroke: white;
    stroke-width: 2.5;
    fill: none;
}

/* --- Create Post Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 300;
    display: none;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.25s ease;
}

.modal-overlay.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    width: 100%;
    max-width: var(--max-width);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 28px 24px;
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0));
    animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    max-height: 85dvh;
    overflow-y: auto;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: var(--bg-input);
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.modal-close svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.compose-area {
    width: 100%;
    min-height: 160px;
    max-height: 300px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease;
}

.compose-area::placeholder {
    color: var(--text-muted);
}

.compose-area:focus {
    border-color: var(--accent-purple);
}

/* Emoji Picker */
.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 12px 0;
    max-height: 90px;
    overflow-y: auto;
}

.emoji-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.emoji-btn:hover {
    background: var(--bg-input);
    transform: scale(1.2);
}

.emoji-btn:active {
    transform: scale(0.9);
}

/* Hashtag Preview */
.hashtag-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
    padding: 0;
    transition: all 0.3s ease;
}

.hashtag-preview:not(:empty) {
    padding: 10px 0;
    min-height: 32px;
}

.hashtag-preview .tag {
    font-size: 13px;
    color: var(--accent-purple);
    background: rgba(164, 119, 224, 0.1);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    animation: fadeInUp 0.25s ease both;
}

.compose-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
}

.char-count {
    font-size: 13px;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.char-count.warning {
    color: #f59e0b;
}

.char-count.danger {
    color: var(--accent-red);
}

.btn-post {
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    padding: 12px 32px;
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-post:hover {
    background: var(--accent-purple-light);
    transform: scale(1.02);
}

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

.btn-post:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.recaptcha-wrapper {
    margin-top: 16px;
    display: flex;
    justify-content: center;
}

/* --- Profile Page --- */
.profile-header {
    text-align: center;
    padding: 30px 20px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-avatar svg {
    width: 40px;
    height: 40px;
    fill: white;
}

.profile-username {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.profile-joined {
    font-size: 13px;
    color: var(--text-muted);
}

.profile-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 20px;
}

.profile-stat {
    text-align: center;
}

.profile-stat-number {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.profile-stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 14px 24px;
    border-radius: var(--radius-full);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
    animation: toastIn 0.35s ease, toastOut 0.35s ease 2.5s forwards;
    pointer-events: auto;
    border: 1px solid var(--border-light);
}

.toast.success {
    border-color: var(--accent-green);
}

.toast.error {
    border-color: var(--accent-red);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.9);
    }
}

/* --- Loading States --- */
.loading-skeleton {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
    height: 180px;
    margin-bottom: 12px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-text {
    font-size: 16px;
    color: var(--text-secondary);
}

/* --- Scroll to top --- */
.scroll-top {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 150;
    transition: all 0.2s ease;
}

.scroll-top.visible {
    display: flex;
}

.scroll-top:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

.scroll-top svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* --- Responsive --- */
@media (min-width: 768px) {
    .main {
        padding: 20px;
    }

    .post-body {
        font-size: 17px;
    }
}

/* --- Share link popup --- */
.share-popup {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 350;
    display: none;
    align-items: center;
    justify-content: center;
}

.share-popup.active {
    display: flex;
}

.share-popup-inner {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.share-popup-inner p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 16px;
}

.share-url {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    text-align: center;
    outline: none;
    margin-bottom: 12px;
}

.btn-copy {
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    padding: 10px 28px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
#feed {
    padding-bottom: 100px;
}