@view-transition {
	navigation: auto;
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	font-family: "Varela Round", sans-serif;
}

/* ============================================================
   PALETTE  (plain values — no CSS variables, for old browsers)
   ------------------------------------------------------------
   body bg      #16181D          card bg     #1d212a
   sunken bg    #161b22          button bg   #2d3240
   btn hover    #3a4154          btn disabled #22262f
   text         #f3f6fb          dim text    #b9c3d4
   faint text   #7a8094          border      rgba(255,255,255,.08)
   shadow      0 10px 24px rgba(0,0,0,.18)
   ============================================================ */

/* -------- Colors: dark (default) -------- */
html, body { background-color: #16181D; }
html, body, button, input, select { color: #f3f6fb; }

button, a.login-link, .profile-row .pfp, .avatar { background: #2d3240; }
button:disabled, button:disabled:hover { background: #22262f; color: #7a8094; }

header, button, a.login-link, .stat, .banner, .avatar, .comment, input, .card, #post-comments {
	border: 1px solid rgba(255,255,255,.08);
}

input, select, textarea, .comment, .stat { background: #161b22; }
input::placeholder { color: #7a8094; }
input:focus { outline: 2px solid #3a4154; outline-offset: 1px; }

.card { background: #1d212a; box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.post { background: linear-gradient(180deg, #202330 0%, #1a1d27 100%); }
.comment { background: #161b22; }

.field, .post .post-desc, .stat span, #post-comments h3, .comment .meta { color: #b9c3d4; }

.post h2 { color: #f1f5ff; }
.profile p { color: #dfe8ff; }
.name, .bio, .post-card #post-text { color: #edf3ff; }
.comment-text { color: #f3f6fb; }

.like-btn.liked { color: #ff8aac; background: #33222b; border-color: #ff5c8a55; }
.admin-badge { background: #c0392b; color: #fff; }
.moderator-badge { background: #e67e22; color: #fff; }

.profile:hover { background: #00000042; }
.comment .pfp { background: #2d3240; }

/* Scrollbars — dark */
html, body, * {
	scrollbar-width: thin;
	scrollbar-color: #2d3240 #16181D;
	overscroll-behavior-x: auto;
	overscroll-behavior-y: contain;
}
*::-webkit-scrollbar { width: 20px; height: 20px; }
*::-webkit-scrollbar-track { background: #16181D; }
*::-webkit-scrollbar-thumb { background: #2d3240; border: 2px solid #16181D; border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: #3a4154; }
*::-webkit-scrollbar-thumb:active { background: #FF4141; }
*::-webkit-scrollbar-corner { background: #16181D; }

/* -------- Colors: light -------- */
@media (prefers-color-scheme: light) {
	html, body { background-color: #ffffff; }
	html, body, button, select { color: #1c1e21; }
	body input, body select { color: #1c1e21; border: 1px solid #d0d3da; }

	button, a.login-link, .profile-row .pfp, .avatar, .comment .pfp, #post-media img { background: #e4e6eb; }
	button:hover, a.login-link:hover { background: #d0d3da; }
	button:disabled, button:disabled:hover { background: #ebecef; color: #8a8f98; }

	#login-form button[type="submit"] { background: #d0d3da; }
	#login-form button[type="submit"]:hover { background: #b8bcc6; }

	body header {
		background: linear-gradient(to top, transparent 0, rgb(195 195 195) 60px), rgb(174 174 174 / 81%);
		box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
	}

	.card, .stat { background: #f3f4f6; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.10); }
	body .post { background: linear-gradient(180deg, #e8eaed 0%, #f3f4f6 100%); }

	body .post h2, body .post-card h2, body .post-card #post-text,
	body .comment-text, body .bio, body .name { color: #1c1e21; }

	.like-btn.liked { color: #e0426f; background: #ffe3ea; border-color: #ff8aac55; }

	header button:not(.profile-btn) img,
	.like-btn:not(.liked) img { filter: brightness(0); }

	body .profile p, body .meta, body .post .post-desc, .field,
	.stat span, .comment .meta, #post-comments h3 { color: #55606e; }

	input, select, textarea, .comment { background: #f3f4f6; }
	input::placeholder { color: #8a8f98; }
	input:focus { outline-color: #d0d3da; }
	.avatar { border-color: #f3f4f6; }
	#post-comments > form button { padding: 12px 20px; }

	html, body, * { scrollbar-color: #e4e6eb #ffffff; }
	*::-webkit-scrollbar-track,
	*::-webkit-scrollbar-corner { background: #ffffff; }
	*::-webkit-scrollbar-thumb { background: #e4e6eb; border-color: #ffffff; }
	*::-webkit-scrollbar-thumb:hover { background: #d0d3da; }

	.profile:hover { background: #e4e6eb44; }
}

/* ============================================================
   View transitions
   ============================================================ */
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes flip-out { from { transform: rotateY(0deg); opacity: 1; } to { transform: rotateY(-90deg); opacity: 0; } }
@keyframes flip-in { from { transform: rotateY(90deg); opacity: 0; } to { transform: rotateY(0deg); opacity: 1; } }

::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0.4s; animation-timing-function: ease; }
::view-transition-old(root) { animation-name: fade-out; }
::view-transition-new(root) { animation-name: fade-in; }

@media (prefers-reduced-motion: no-preference) {
	html:active-view-transition-type(flip)::view-transition { perspective: 1400px; }
	html:active-view-transition-type(flip)::view-transition-old(root) {
		transform-origin: 100% 50%;
		animation-name: flip-out;
		animation-duration: 400ms;
		animation-timing-function: ease-in;
	}
	html:active-view-transition-type(flip)::view-transition-new(root) {
		transform-origin: 0% 50%;
		animation-name: flip-in;
		animation-duration: 400ms;
		animation-timing-function: ease-out;
	}
}

/* ============================================================
   Shared radius — one place
   ============================================================ */
img, a, .banner, .profile, button, .stat, input, select, textarea, .comment {
	border-radius: 14px;
}

/* ============================================================
   Buttons & links
   ============================================================ */
button, a.login-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 8px 12px;
	font: inherit;
	cursor: pointer;
	text-decoration: none;
	transition: transform .2s ease, background .2s ease;
}
button:hover, a.login-link:hover { background: #3a4154; transform: translateY(-1px); }
button > *:not(:first-child), a.login-link > *:not(:first-child) { margin-left: 6px; }
button:disabled { cursor: not-allowed; transform: none; }
button:disabled:hover { transform: none; }

#login-form button[type="submit"] { background: #3a4154; }
#login-form button[type="submit"]:hover { background: #525e7a; transform: translateY(-1px); }

/* ============================================================
   Header
   ============================================================ */
@keyframes reveal-border {
	from { border-bottom-color: transparent; }
	to { border-bottom-color: rgba(255,255,255,.08); }
}

header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 16px 24px;
	background:
		linear-gradient(to top, transparent 0, rgba(32,33,43,1) 60px),
		rgba(32, 33, 43, 0.805);
	box-shadow: 0px 4px 16px 3px #000000b3;
	position: sticky;
	top: 0;
	backdrop-filter: blur(10px);
	border-top: none;
	border-left: none;
	border-right: none;
	z-index: 100;
	animation: reveal-border linear both;
	animation-timeline: scroll(root block);
	animation-range: 0 40px;
}

header img { display: none; }
header > section { display: flex; align-items: center; }
header > section > *:not(:first-child) { margin-left: 10px; }
header h1 { margin: 0; font-size: clamp(1.5rem, 2vw, 2.25rem); }
header > nav { overflow-x: auto; display: flex; }
header > nav > button { margin: 0 5px; }
header button img { width: 16px; height: 16px; display: block; pointer-events: none; border-radius: 0; }

header .profile-btn { width: 36px; height: 36px; padding: 0; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
header .profile-btn img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

@supports (top: env(titlebar-area-y)) { header button { -webkit-app-region: no-drag; } }

@media (display-mode: window-controls-overlay) {
	header {
		top: env(titlebar-area-y, 0);
		left: 0;
		width: 100%;
		height: calc(env(titlebar-area-height, auto) + 1px);
		padding: 0 4px;
		padding-right: calc(100% - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100%) + 24px);
		background:
			linear-gradient(
				to right,
				transparent calc(100% - (100% - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100%)) - 60px),
				rgba(32,33,43,1) calc(100% - (100% - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100%)))
			),
			rgba(32, 33, 43, 0.805);
		-webkit-app-region: drag;
		app-region: drag;
	}
	header button {
		-webkit-app-region: no-drag;
		app-region: no-drag;
	}
	header img {
		height: calc(env(titlebar-area-height, 0) - 8px);
		border-radius: 5px;
		display: block;
	}
}

/* ============================================================
   Layout
   ============================================================ */
main {
	box-shadow: inset 0 0 10px rgba(11,12,16,.9);
	padding: 20px 18px 32px;
	min-height: 100%;
	display: flex;
	justify-content: center;
	flex-direction: column;
	align-items: center;
}
main > * { flex: 1; width: 100%; }
#error-container { position: absolute; }

#posts-list, #search-results {
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	width: min(1200px, 100%);
	margin: 0 auto;
	padding: 0;
}
#posts-list > li { flex: 1 1 350px; max-width: 100rem; margin: 10px; cursor: pointer; }
#search-results > li { flex: 1 1 250px; max-width: 320px; margin: 10px; }
#search-results .profile-row { flex: 1 1 auto; max-width: 640px; margin: 10px; }

/* ============================================================
   Forms
   ============================================================ */
input, select, textarea { width: 100%; padding: 12px 14px; font: inherit; }
input { flex: 1; }
.field { font-size: 0.9rem; font-weight: 600; }

#login-form, #new-post-form { display: flex; flex-direction: column; }
#login-form > *:not(:first-child), #new-post-form > *:not(:first-child) { margin-top: 10px; }
#login-form button, #new-post-form button { width: 100%; margin-top: 6px; }
#new-post-form textarea { resize: vertical; min-height: 120px; }

.search-form, #post-comments > form { display: flex; max-width: 640px; margin: 0 auto 24px; }
.search-form > *:not(:first-child), #post-comments > form > *:not(:first-child) { margin-left: 10px; }
#post-comments > form { margin-bottom: 16px; }

/* ============================================================
   Cards
   ============================================================ */
.card { border-radius: 18px; }
.post, .post-card, .profile-card { padding: 12px; }
.login-card { max-width: 420px; padding: 24px; width: 100%; margin: auto; }
.login-card h1 { margin: 0 0 16px; font-size: 1.6rem; }
.post-card { max-width: 900px; }
.profile-card { overflow: hidden; }

/* ============================================================
   Feed post cards
   ============================================================ */
.post { display: flex; flex-direction: column; margin: 0; border-radius: 24px; min-height: 420px; }
.post h2 { margin: 12px 0 0; font-size: 1.15rem; line-height: 1.45; word-break: break-word; }
.post .post-desc { margin: 8px 0 0; word-break: break-word; white-space: pre-wrap; font-size: 0.95rem; line-height: 1.45; flex-grow: 1; }

.post img, .banner { display: block; width: 100%; height: 220px; object-fit: cover; transition: filter 100ms linear; }
.post img:hover { filter: brightness(0.7); }
.post .pfp, .avatar { width: 48px; height: 48px; object-fit: cover; }

.like-btn img { width: 16px; height: 16px; display: block; border-radius: 0; pointer-events: none; }
.like-btn img:hover { filter: none; }
.post .like-btn { align-self: flex-start; margin-top: 12px; }
.post-card .like-btn { margin-top: 16px; }

/* ============================================================
   Post detail
   ============================================================ */
.post-card .pfp { width: 48px; height: 48px; object-fit: cover; }
.post-card h2 { margin: 14px 0 0; font-size: 1.6rem; line-height: 1.4; word-break: break-word; }
.post-card .meta { margin-top: 8px; }
.post-card #post-text { margin: 16px 0 0; line-height: 1.6; white-space: pre-wrap; }

#post-media { margin-top: 16px; display: grid; gap: 12px; }
#post-media img { width: 100%; background: #131721; }
#profile-banner { background-color: gray; margin: -12px -12px 12px; }

#post-comments { margin-top: 24px; padding-top: 16px; }
#post-comments h3 { margin: 0 0 12px; font-size: 1.1rem; }
.comment { padding: 12px 14px; }
#post-comments .comment + .comment { margin-top: 10px; }
.comment .profile > *:not(:first-child) { margin-left: 8px; }
.comment .pfp { width: 32px; height: 32px; border-radius: 10px; object-fit: cover; }
.comment-text { margin: 8px 0 0; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.comment .meta { margin-top: 8px; font-size: 0.8rem; font-weight: 400; }
.comment .like-btn { align-self: flex-start; margin-top: 10px; padding: 6px 10px; }

/* ============================================================
   Profiles
   ============================================================ */
.profile, .profile-top { display: flex; align-items: center; }
.profile > *:not(:first-child) { margin-left: 10px; }
.profile p, .meta { margin: 0; font-size: 0.95rem; font-weight: 600; }

.profile-top { margin-bottom: 12px; }
.profile-top > *:not(:first-child) { margin-left: 16px; }

.avatar { width: 88px; height: 88px; border-radius: 18px; border: 4px solid #1d212a; }
.name { margin: 0; font-size: 2rem; }
.meta { margin-top: 6px; color: #b9c3d4; font-weight: 400; }
.bio { line-height: 1.6; white-space: pre-wrap; margin: 0 0 12px; }

.stats { display: flex; flex-wrap: wrap; margin: -6px; }
.stat { flex: 1 1 120px; display: flex; flex-direction: column; padding: 14px 12px; margin: 6px; }
.stat strong { font-size: 1.3rem; }
.stat span { font-size: 0.9rem; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover strong, .stat.clickable:focus-visible strong { text-decoration: underline; }

#profile-follow { display: block; width: 100%; margin-bottom: 12px; }

.admin-badge, .moderator-badge {
	display: inline-block;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.04em;
	padding: 2px 8px;
	border-radius: 10px;
	margin-left: 8px;
	vertical-align: middle;
	text-transform: uppercase;
}
.admin-badge[hidden], .moderator-badge[hidden] { display: none; }

#posts-header { height: 10rem; }
#posts-owner-avatar { object-fit: cover; height: 100px; }

.profile-row { display: flex; align-items: center; padding: 14px; }
.profile-row > *:not(:first-child) { margin-left: 12px; }
.profile-row .pfp { width: 48px; height: 48px; object-fit: cover; }

/* ============================================================
   Misc
   ============================================================ */
#search-empty { max-width: 640px; margin: 0 auto; text-align: center; }

.tab-control > form { justify-content: space-evenly; }
.tab-control > form input { width: 100%; }
.tab-control > .tab-contents { display: flex; width: 100%; overflow-x: scroll; }
.tab-contents > li { width: 100%; flex: 0 0 auto; flex-shrink: 0; }

/* Spacing helper for gap-capable browsers */
@supports (gap: 1px) {
	header > section, .profile, #login-form, #new-post-form, .search-form, #post-comments > form { gap: 10px; }
	button, a.login-link { gap: 6px; }
	.profile-top { gap: 16px; }
	.stats, .profile-row { gap: 12px; }
	.comment .profile { gap: 8px; }
	#posts-list, #search-results { gap: 20px; }
	header > section > *:not(:first-child),
	.profile > *:not(:first-child),
	.profile-top > *:not(:first-child),
	.search-form > *:not(:first-child),
	#post-comments > form > *:not(:first-child),
	button > *:not(:first-child),
	a.login-link > *:not(:first-child),
	.profile-row > *:not(:first-child),
	.comment .profile > *:not(:first-child) { margin-left: 0; }
	#login-form > *:not(:first-child), #new-post-form > *:not(:first-child) { margin-top: 0; }
	#posts-list > li, #search-results > li, #search-results .profile-row, .stat { margin: 0; }
	.stats { margin: 0; }
}

@media (max-width: 640px) {
	main { padding-left: 12px; padding-right: 12px; }
	#posts-list > li { max-width: none; flex-basis: 100%; }
	.profile-top { align-items: flex-start; }
}
