:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #dbdbdb;
    --text: #262626;
    --text-dim: #8e8e8e;
    --accent: #0095f6;
    --danger: #ed4956;
    --like: #ed4956;
    --gradient: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
}

[data-theme="dark"] {
    --bg: #000000;
    --surface: #121212;
    --border: #262626;
    --text: #f5f5f5;
    --text-dim: #a8a8a8;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: inherit; text-decoration: none; }
input, textarea, button { font-family: inherit; }

.app-shell {
    display: flex;
    min-height: 100vh;
}

.page-content {
    flex: 1;
    max-width: 630px;
    margin: 0 auto;
    padding: 20px 12px 80px;
    width: 100%;
}

/* ---------- Sidebar (desktop) / bottom nav (mobile) ---------- */

.sidebar {
    display: none;
    flex-direction: column;
    width: 220px;
    border-right: 1px solid var(--border);
    padding: 24px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    font-family: 'Brush Script MT', cursive;
    font-size: 26px;
    padding: 12px;
    margin-bottom: 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    position: relative;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text);
    width: 100%;
    text-align: left;
}

.nav-item:hover { background: var(--bg); }
.nav-item.active { font-weight: 700; }
.nav-icon { font-size: 22px; width: 24px; text-align: center; }

.theme-switch { display: flex; align-items: center; }
.logout-btn { margin-top: auto; }

.badge {
    background: var(--danger);
    color: #fff;
    border-radius: 999px;
    font-size: 11px;
    padding: 1px 6px;
    position: absolute;
    left: 30px;
    top: 6px;
}
.badge.hidden { display: none; }

.bottom-nav {
    display: flex;
    justify-content: space-around;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    z-index: 50;
}
.bottom-nav .nav-item { flex-direction: column; gap: 2px; padding: 4px 8px; width: auto; }
.bottom-nav .nav-label { display: none; }
.bottom-nav .theme-switch, .bottom-nav .logout-btn { display: none; }

@media (min-width: 900px) {
    .sidebar { display: flex; }
    .bottom-nav { display: none; }
    .page-content { padding-top: 32px; padding-bottom: 32px; }
}

/* ---------- Stories row ---------- */

.stories-row {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 10px 4px 18px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.story-avatar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    flex-shrink: 0;
    width: 68px;
}

.story-ring {
    width: 60px; height: 60px; border-radius: 50%;
    padding: 2.5px;
    background: var(--gradient);
}
.story-ring.viewed { background: var(--border); }

.story-ring img {
    width: 100%; height: 100%; border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--surface);
    display: block;
}

.story-avatar span {
    font-size: 12px;
    color: var(--text);
    max-width: 68px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Post card ---------- */

.post-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 24px;
}

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

.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.avatar-md { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 90px; height: 90px; border-radius: 50%; object-fit: cover; }

.post-header .username { font-weight: 600; font-size: 14px; }
.post-header .dot { color: var(--text-dim); margin: 0 4px; }
.post-header .time { color: var(--text-dim); font-size: 13px; }
.post-header .spacer { flex: 1; }

.post-media {
    width: 100%;
    max-height: 700px;
    object-fit: cover;
    display: block;
    background: #000;
    cursor: pointer;
}

.post-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 12px 4px;
    font-size: 24px;
}

.icon-btn { background: none; border: none; cursor: pointer; color: var(--text); padding: 0; line-height: 1; }
.icon-btn.liked { color: var(--like); }
.post-actions .spacer { flex: 1; }
.icon-btn.save-btn { opacity: 0.55; }
.icon-btn.save-btn.saved { opacity: 1; }

.post-likes { padding: 4px 12px; font-weight: 600; font-size: 14px; }
.post-caption { padding: 0 12px 6px; font-size: 14px; }
.post-caption .username { font-weight: 600; margin-right: 6px; }
.post-comments-preview { padding: 0 12px; color: var(--text-dim); font-size: 14px; cursor: pointer; }
.post-time-full { padding: 6px 12px 12px; color: var(--text-dim); font-size: 11px; text-transform: uppercase; }

.comment-form {
    display: flex;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    gap: 8px;
}
.comment-form input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    color: var(--text);
    font-size: 14px;
}
.comment-form button {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}
.comment-form button:disabled { color: var(--text-dim); cursor: default; }

/* ---------- Forms (auth) ---------- */

.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    width: 100%;
    max-width: 350px;
    text-align: center;
}

.auth-box .brand { font-size: 38px; margin-bottom: 24px; }

.field {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

.btn-primary {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-outline {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    font-size: 14px;
}

.btn-follow { background: var(--accent); color: #fff; border: none; }

.auth-switch { margin-top: 14px; font-size: 14px; color: var(--text-dim); }
.error-msg { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 16px; }
.demo-hint { font-size: 12px; color: var(--text-dim); margin-top: 16px; line-height: 1.6; }

/* ---------- Profile ---------- */

.profile-header {
    display: flex;
    gap: 24px;
    align-items: center;
    padding: 20px 8px;
    flex-wrap: wrap;
}
.profile-meta h2 { margin: 0 0 8px; font-weight: 400; }
.profile-stats { display: flex; gap: 24px; margin: 10px 0; font-size: 14px; }
.profile-stats b { display: block; }
.profile-bio { font-size: 14px; white-space: pre-wrap; }

.post-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}
.post-grid img, .post-grid video {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    cursor: pointer;
    background: #000;
}

/* ---------- Explore ---------- */

.explore-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 4px;
}
.explore-grid img, .explore-grid video {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    cursor: pointer;
}

/* ---------- Messages ---------- */

.conv-list { display: flex; flex-direction: column; }
.conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}
.conv-item .preview { color: var(--text-dim); font-size: 13px; }
.conv-item .conv-main { flex: 1; min-width: 0; }
.conv-item .preview, .conv-item .username { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-shell { display: flex; flex-direction: column; height: calc(100vh - 100px); }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 4px; display: flex; flex-direction: column; gap: 6px; }
.msg-bubble { max-width: 70%; padding: 8px 14px; border-radius: 18px; font-size: 14px; }
.msg-mine { align-self: flex-end; background: var(--accent); color: #fff; }
.msg-theirs { align-self: flex-start; background: var(--border); color: var(--text); }
.chat-input-row { display: flex; gap: 8px; padding: 8px 4px; border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* ---------- Notifications ---------- */

.notif-item { display: flex; align-items: center; gap: 12px; padding: 10px 8px; }
.notif-item.unread { background: rgba(0,149,246,0.06); }
.notif-item .text { flex: 1; font-size: 14px; }
.notif-item .time { color: var(--text-dim); font-size: 12px; }

/* ---------- Create post ---------- */

.create-shell { max-width: 500px; margin: 0 auto; }
.filter-strip { display: flex; gap: 10px; overflow-x: auto; padding: 12px 0; }
.filter-chip { flex-shrink: 0; text-align: center; cursor: pointer; }
.filter-chip img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; display: block; }
.filter-chip span { font-size: 11px; color: var(--text-dim); }
.filter-chip.active span { color: var(--text); font-weight: 600; }
.preview-media { width: 100%; max-height: 400px; object-fit: cover; border-radius: 8px; margin-bottom: 12px; background: #000; }
textarea.field { resize: vertical; min-height: 80px; }

/* ---------- Story viewer ---------- */

.story-viewer {
    position: fixed; inset: 0; background: #000;
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
}
.story-viewer img, .story-viewer video { max-width: 100%; max-height: 100%; }
.story-progress { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 4px; }
.story-progress .seg { flex: 1; height: 2px; background: rgba(255,255,255,0.4); border-radius: 2px; overflow: hidden; }
.story-progress .seg .fill { height: 100%; width: 0; background: #fff; }
.story-close { position: absolute; top: 16px; right: 16px; color: #fff; font-size: 28px; background: none; border: none; cursor: pointer; }
.story-user { position: absolute; top: 20px; left: 16px; color: #fff; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.story-nav-zone { position: absolute; top: 0; bottom: 0; width: 30%; cursor: pointer; }

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