* { box-sizing: border-box; }
html { color-scheme: light dark; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip-link { position: absolute; top: -48px; left: 8px; background: var(--accent-fill); color: var(--on-accent); padding: .6rem 1rem; border-radius: var(--radius-sm); z-index: 999; }
.skip-link:focus { top: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

.topbar { position: sticky; top: 0; z-index: 40; background: var(--glass-bg, var(--bg)); border-bottom: 1px solid var(--border); backdrop-filter: blur(14px); }
.topbar-inner { max-width: 1100px; margin: 0 auto; height: var(--topbar-h); display: flex; align-items: center; gap: 1.2rem; padding: 0 1.2rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--font-display); font-weight: 800; font-size: 1.2rem; background: linear-gradient(135deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.search-box { flex: 1; max-width: 340px; display: flex; align-items: center; gap: .6rem; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: .5rem .9rem; position: relative; }
.search-box input { flex: 1; background: none; border: none; outline: none; color: var(--text); min-height: 30px; }
.search-dropdown { display: none; position: absolute; top: calc(100% + 8px); left: 0; right: 0; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: .6rem; z-index: 50; }
.search-dropdown.open { display: block; }
.search-dropdown h5 { font-size: .68rem; text-transform: uppercase; color: var(--text-faint); margin-bottom: .4rem; padding: 0 .4rem; }
.search-result-row { display: flex; align-items: center; gap: .6rem; padding: .5rem .4rem; border-radius: var(--radius-sm); cursor: pointer; font-size: .84rem; }
.search-result-row:hover, .search-result-row:focus-visible { background: var(--bg-sunken); }
.search-empty { padding: .6rem .4rem; font-size: .82rem; color: var(--text-faint); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-soft); cursor: pointer; position: relative; }
.icon-btn:hover { color: var(--info-text); border-color: var(--accent); }
.icon-btn.active-nav { color: var(--info-text); border-color: var(--accent); }
.count-dot { position: absolute; top: -3px; right: -3px; width: 16px; height: 16px; border-radius: 50%; background: var(--like); color: var(--on-accent); font-size: .6rem; font-weight: 800; display: grid; place-items: center; }
.avatar { border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--on-accent); flex-shrink: 0; }
.mobile-nav-toggle { display: none; }
@media (max-width: 640px) {
  .search-box { display: none; }
  .mobile-nav-toggle { display: grid !important; }
}

.layout { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.2rem; display: grid; grid-template-columns: 1fr 300px; gap: 1.6rem; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }
.view { display: none; }
.view.active { display: block; }

/* Stories */
.stories-row { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: 1.2rem; }
.story { display: flex; flex-direction: column; align-items: center; gap: .4rem; flex-shrink: 0; cursor: pointer; border: none; background: none; padding: 0; font: inherit; color: inherit; }
.story-ring { width: 62px; height: 62px; border-radius: 50%; padding: 3px; background: linear-gradient(135deg, var(--accent), var(--accent-2), #f4a340); }
.story-ring.seen { background: var(--border); }
.story-ring .avatar { width: 100%; height: 100%; font-size: 1.1rem; border: 3px solid var(--bg); }
.story span { font-size: .72rem; color: var(--text-soft); max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Post card */
.post-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 1.2rem; overflow: hidden; }
.post-head { display: flex; align-items: center; gap: .7rem; padding: .9rem 1rem; }
.post-head strong { font-size: .86rem; }
.post-head .time { font-size: .72rem; color: var(--text-faint); }
.feed-source-tag { margin-left: auto; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: .25rem .55rem; border-radius: 999px; background: var(--bg-sunken); color: var(--text-faint); }
.feed-source-tag.feed-source-trending { background: var(--accent-soft); color: var(--info-text); }
.feed-source-tag.feed-source-suggested { background: var(--accent-soft); color: var(--info-text); }
.post-media { position: relative; aspect-ratio: 1.2; background: linear-gradient(135deg, var(--bg-sunken), var(--border)); display: grid; place-items: center; font-size: 2.4rem; cursor: pointer; overflow: hidden; }
.dbl-like-heart { position: absolute; inset: 0; display: grid; place-items: center; font-size: 5rem; color: #fff; opacity: 0; pointer-events: none; text-shadow: 0 2px 12px rgba(0,0,0,.3); }
.dbl-like-heart.pop { animation: dblLikePop .7s ease; }
@keyframes dblLikePop { 0% { opacity: 0; transform: scale(.4); } 30% { opacity: 1; transform: scale(1.15); } 45% { transform: scale(1); } 100% { opacity: 0; transform: scale(1); } }
.post-actions { display: flex; align-items: center; gap: 1rem; padding: .8rem 1rem .3rem; }
.post-actions button { background: none; border: none; cursor: pointer; color: var(--text-soft); display: flex; align-items: center; gap: .4rem; font-size: .84rem; font-weight: 600; }
.post-actions button.liked { color: var(--like); }
.post-actions button.liked svg { fill: var(--like); }
.post-actions .save-btn.active { color: var(--text); }
.story-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; z-index: 150; }
.story-overlay.open { display: flex; }
.story-viewer { position: relative; width: 100%; max-width: 400px; height: 88vh; max-height: 720px; background: #111; border-radius: var(--radius-lg); overflow: hidden; }
.story-progress-row { display: flex; gap: 4px; padding: .6rem; position: absolute; top: 0; left: 0; right: 0; z-index: 3; }
.story-progress-track { flex: 1; height: 3px; background: rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; }
.story-progress-fill { height: 100%; width: 0%; background: #fff; }
.story-progress-fill.done { width: 100%; }
.story-progress-fill.run { animation: storyFill linear forwards; }
@keyframes storyFill { from { width: 0%; } to { width: 100%; } }
.story-header { position: absolute; top: 1.1rem; left: .8rem; right: .8rem; display: flex; align-items: center; gap: .6rem; z-index: 3; color: #fff; }
.story-avatar { width: 32px; height: 32px; font-size: .68rem; }
.story-close { margin-left: auto; background: none; border: none; color: #fff; font-size: 1.1rem; cursor: pointer; width: 40px; height: 40px; display: grid; place-items: center; }
.story-media { position: absolute; inset: 0; display: grid; place-items: center; font-size: 5rem; background: linear-gradient(135deg, #2b2b3a, #12121c); }
.story-zone { position: absolute; top: 0; bottom: 0; width: 30%; cursor: pointer; }
.story-zone-left { left: 0; }
.story-zone-right { right: 0; }
.toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: .6rem 1.1rem; border-radius: 999px; font-size: .82rem; font-weight: 600; opacity: 0; transform: translateY(10px); transition: all .25s ease; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: translateY(0); }
.post-actions .spacer { flex: 1; }
.post-caption { padding: .3rem 1rem .5rem; font-size: .85rem; }
.post-caption strong { margin-right: .4rem; }
.post-comments-count { padding: 0 1rem .9rem; font-size: .78rem; color: var(--text-faint); cursor: pointer; }

/* Right sidebar */
.side-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 1.2rem; margin-bottom: 1rem; position: sticky; top: calc(var(--topbar-h) + 20px); }
.side-card h4 { font-size: .84rem; margin-bottom: .9rem; }
.suggest-row { display: flex; align-items: center; gap: .7rem; margin-bottom: .8rem; }
.suggest-row:last-child { margin-bottom: 0; }
.suggest-info { flex: 1; min-width: 0; }
.suggest-name { font-size: .82rem; font-weight: 700; }
.suggest-meta { font-size: .72rem; color: var(--text-faint); }
.follow-btn { background: none; border: none; color: var(--info-text); font-weight: 700; font-size: .78rem; cursor: pointer; min-height: 36px; padding: 0 .5rem; }
.follow-btn.following { color: var(--text-faint); }

/* Loading skeleton */
.skeleton-post { height: 380px; border-radius: var(--radius-md); background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--border) 50%, var(--bg-sunken) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; margin-bottom: 1.2rem; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Modal (comments) */
.modal-overlay { position: fixed; inset: 0; background: rgba(10,10,15,.6); display: none; align-items: center; justify-content: center; z-index: 200; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--bg-elevated); border-radius: var(--radius-lg); max-width: 480px; width: 100%; max-height: 82vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--text-soft); width: 40px; height: 40px; display: grid; place-items: center; }
.modal-comments { flex: 1; overflow-y: auto; padding: 1rem 1.2rem; }
.comment-row { display: flex; gap: .7rem; margin-bottom: 1rem; }
.comment-body { font-size: .84rem; }
.comment-time { font-size: .7rem; color: var(--text-faint); margin-top: .2rem; }
.modal-add-comment { display: flex; gap: .6rem; padding: 1rem 1.2rem; border-top: 1px solid var(--border); }
.modal-add-comment input { flex: 1; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: .6rem 1rem; color: var(--text); min-height: 40px; }
.modal-add-comment button { background: none; border: none; color: var(--info-text); font-weight: 700; cursor: pointer; min-height: 40px; padding: 0 .6rem; }

/* Profile */
.profile-head { display: flex; align-items: center; gap: 2rem; margin-bottom: 1.6rem; flex-wrap: wrap; }
.profile-stats { display: flex; gap: 1.6rem; }
.profile-stat { text-align: center; }
.profile-stat .num { font-family: var(--font-display); font-weight: 800; font-size: 1.1rem; }
.profile-stat .label { font-size: .74rem; color: var(--text-faint); }
.profile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.profile-grid .cell { aspect-ratio: 1; background: linear-gradient(135deg, var(--bg-sunken), var(--border)); display: grid; place-items: center; font-size: 1.6rem; border-radius: 6px; cursor: pointer; border: none; padding: 0; width: 100%; }

/* Notifications list */
.notif-row { display: flex; align-items: center; gap: .8rem; padding: .9rem .6rem; border-bottom: 1px solid var(--border); cursor: pointer; border-radius: var(--radius-sm); width: 100%; text-align: left; background: none; border-left: none; border-right: none; border-top: none; font: inherit; color: inherit; }
.notif-row:hover, .notif-row:focus-visible { background: var(--bg-sunken); }
.notif-row:last-child { border-bottom: none; }
.notif-row.unread { background: var(--accent-soft); }
.notif-empty { text-align: center; padding: 2rem 1rem; color: var(--text-faint); }

/* Messages / chat */
.chat-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 460px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
@media (max-width: 700px) { .chat-shell { grid-template-columns: 1fr; } .chat-shell.thread-open .chat-list { display: none; } .chat-shell:not(.thread-open) .chat-body { display: none; } }
.chat-back { display: none; background: none; border: none; cursor: pointer; padding: .4rem; color: var(--text-soft); }
@media (max-width: 700px) { .chat-back { display: grid; place-items: center; width: 36px; height: 36px; } }
.chat-list { border-right: 1px solid var(--border); overflow-y: auto; }
.chat-thread-row { display: flex; gap: .7rem; padding: .9rem 1rem; cursor: pointer; width: 100%; text-align: left; background: none; border: none; font: inherit; color: inherit; }
.chat-thread-row:hover, .chat-thread-row.active, .chat-thread-row:focus-visible { background: var(--bg-sunken); }
.chat-body { display: flex; flex-direction: column; }
.chat-body-head { display: none; align-items: center; gap: .6rem; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
@media (max-width: 700px) { .chat-body-head { display: flex; } }
.typing-indicator { align-self: flex-start; font-size: .78rem; color: var(--text-faint); font-style: italic; }
.read-receipt { font-size: .68rem; color: var(--text-faint); margin-top: .2rem; text-align: right; }
.chat-messages { flex: 1; padding: 1.2rem; overflow-y: auto; display: flex; flex-direction: column; gap: .7rem; }
.chat-bubble { max-width: 70%; padding: .6rem .9rem; border-radius: 14px; font-size: .84rem; }
.chat-bubble.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.chat-bubble.theirs { align-self: flex-start; background: var(--bg-sunken); }
.chat-input-row { display: flex; gap: .6rem; padding: 1rem; border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; padding: .6rem 1rem; color: var(--text); }
.chat-input-row button { background: var(--accent); color: #fff; border: none; border-radius: 999px; padding: .6rem 1.2rem; font-weight: 700; cursor: pointer; }

.mobile-nav-toggle { display: none; }
