:root {
    --bg: #ffffff;
    --bg-secondary: #f8f8fa;
    --bg-tertiary: #f0f0f2;
    --text: #1a1a1a;
    --text-secondary: #6b6b6b;
    --text-tertiary: #9a9a9a;
    --accent: #0066ff;
    --accent-hover: #0052cc;
    --red: #ff3b30;
    --green: #34c759;
    --orange: #ff9500;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

.dark {
    --bg: #1a1a1a;
    --bg-secondary: #252525;
    --bg-tertiary: #2d2d2d;
    --text: #ffffff;
    --text-secondary: #a0a0a0;
    --text-tertiary: #6b6b6b;
    --border: #333333;
    --border-light: #2d2d2d;
    --accent: #3399ff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
    scroll-behavior: smooth;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg);
}

.page {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 16px;
    padding-bottom: calc(80px + var(--safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page.active { display: flex; }

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 16px;
}

.loading-logo {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: -2px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 16px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
    border-bottom: 2px solid var(--border);
    margin-bottom: 16px;
}

.nav-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--text);
}

.nav-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text);
    font-size: 16px;
    text-decoration: none;
}

.nav-btn:active {
    background: var(--bg-tertiary);
    transform: scale(0.95);
}

.tab-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    background: var(--bg);
    border-top: 2px solid var(--border);
    padding: 8px 16px;
    padding-bottom: calc(8px + var(--safe-bottom));
    display: flex;
    justify-content: space-around;
    z-index: 100;
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    padding: 6px 12px;
    transition: all 0.15s ease;
    position: relative;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-item i { font-size: 22px; }
.tab-item.active { color: var(--accent); }

.badge {
    position: absolute;
    top: 0;
    right: 2px;
    background: var(--red);
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
}

.card {
    background: var(--bg);
    border: 2px solid var(--border);
    padding: 16px;
    margin-bottom: 12px;
    transition: background 0.15s ease;
}

.card:active { background: var(--bg-secondary); }

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

.avatar {
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 18px;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-sm { width: 32px; height: 32px; font-size: 14px; }
.avatar-lg { width: 80px; height: 80px; font-size: 32px; }

.avatar-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.post-name {
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
}

.post-time {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.post-text {
    margin: 12px 0;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.post-text a {
    color: var(--accent);
    text-decoration: underline;
}

.post-text .hashtag {
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}

.post-image {
    margin: 12px -16px;
    cursor: pointer;
}

.post-image img {
    width: 100%;
    max-height: 400px;
    object-fit: cover;
    border-top: 2px solid var(--border);
    border-bottom: 2px solid var(--border);
    background: var(--bg-tertiary);
}

.post-actions {
    display: flex;
    gap: 24px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--border-light);
}

.action-btn {
    background: none;
    border: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    transition: all 0.15s ease;
    font-family: inherit;
}

.action-btn:active { opacity: 0.7; }
.action-btn.liked { color: var(--red); }
.action-btn.saved { color: var(--accent); }

.comments-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--border-light);
}

.comment-item {
    margin-bottom: 12px;
    padding: 10px;
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
}

.comment-input-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    align-items: center;
}

.input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    font-family: inherit;
    transition: border 0.15s ease;
    border-radius: 4px;
}

.input:focus { border-color: var(--accent); }

textarea.input {
    resize: vertical;
    min-height: 80px;
}

.btn {
    padding: 12px 20px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    border: 2px solid var(--border);
    background: var(--bg);
    color: var(--text);
    transition: all 0.15s ease;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    border-radius: 4px;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:active { background: var(--accent-hover); }

.btn-danger {
    color: var(--red);
    border-color: var(--red);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.toast-container {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}

.toast {
    background: var(--text);
    color: var(--bg);
    padding: 12px 24px;
    font-size: 13px;
    font-weight: 600;
    border: 2px solid var(--border);
    max-width: 90vw;
    text-align: center;
    pointer-events: auto;
    animation: toastIn 0.3s ease;
}

.toast.removing {
    animation: toastOut 0.3s ease forwards;
}

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

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

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

.empty-state i {
    font-size: 40px;
    margin-bottom: 16px;
    display: block;
}

.divider {
    border: none;
    border-top: 2px solid var(--border);
    margin: 16px 0;
}

.section-title {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 12px;
}

.profile-stats {
    display: flex;
    gap: 16px;
    margin: 16px 0;
}

.stat {
    flex: 1;
    text-align: center;
    padding: 12px;
    border: 2px solid var(--border);
}

.stat-value {
    font-size: 24px;
    font-weight: 800;
}

.stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.lightbox.active { display: flex; }

.lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 12px;
}

.message-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: flex-end;
}

.message-row.mine { flex-direction: row-reverse; }

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-row.mine .message-bubble {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.message-bubble img {
    max-width: 200px;
    margin-top: 8px;
    cursor: pointer;
    border-radius: 4px;
}

.message-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
}

.message-status {
    font-size: 10px;
    opacity: 0.7;
    text-align: right;
    margin-top: 2px;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    align-items: center;
    border-top: 2px solid var(--border);
    margin-top: 8px;
}

.chat-attach-btn {
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
}

.reactions-bar {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.reaction {
    padding: 4px 8px;
    border: 2px solid var(--border);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s ease;
    background: var(--bg);
    border-radius: 4px;
}

.reaction:active { background: var(--bg-tertiary); }
.reaction.active { border-color: var(--accent); background: var(--bg-secondary); }

.form-group {
    margin-bottom: 12px;
}

.form-label {
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.error-text {
    color: var(--red);
    font-size: 12px;
    margin-top: 4px;
}

.auth-form {
    max-width: 400px;
    margin: 40px auto;
    padding: 24px;
    border: 2px solid var(--border);
}

.auth-form h1 {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 24px;
    text-align: center;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border: 2px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    background: var(--bg);
    border: none;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.auth-tab.active {
    background: var(--accent);
    color: white;
}

.offline-banner {
    background: var(--orange);
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 13px;
    font-weight: 600;
    display: none;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.offline-banner.show { display: block; }

.create-post-form {
    border: 2px solid var(--border);
    padding: 16px;
    margin-bottom: 16px;
}

.char-count {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 4px;
}

.image-preview {
    max-width: 100%;
    max-height: 200px;
    margin: 8px 0;
    border: 1px solid var(--border);
}

.upload-progress {
    text-align: center;
    padding: 8px;
    color: var(--accent);
    font-weight: 600;
    font-size: 13px;
}

.feed-filter {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.feed-filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.link-text {
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

@media (max-width: 400px) {
    .nav-title { font-size: 22px; }
    .post-actions { gap: 16px; }
    .profile-stats { gap: 8px; }
    .stat { padding: 8px; }
    .stat-value { font-size: 20px; }
}