:root {
	--spacing-xs: 4px;
	--spacing-sm: 8px;
	--spacing-md: 16px;
	--spacing-lg: 24px;
	--spacing-xl: 32px;
	--spacing-2xl: 48px;
	
	--radius-sm: 8px;
	--radius-md: 12px;
	--radius-lg: 30px;
	--radius-xl: 28px;
	
	--shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
	--shadow-md: 0 4px 8px rgba(0,0,0,0.15);
	--shadow-lg: 0 10px 25px rgba(0,0,0,0.2);
	--shadow-xl: 0 20px 40px rgba(0,0,0,0.3);
	
	--timing-fast: 150ms;
	--timing-base: 250ms;
	--timing-slow: 350ms;
	
	--z-canvas: 1;
	--z-content: 10;
	--z-overlay: 100;
	--z-modal: 1000;
	
	--status-height: 44px;
	--gesture-height: 0px;
	--app-icon-size: 90px;
	--app-label-height: 30px;
	--app-spacing: 24px;
}

body[data-app="home"] {
	--bg-primary: #000000;
	--text-primary: #ffffff;
	--text-secondary: rgba(255,255,255,0.7);
}

body[data-app="me"] {
	--bg-primary: #1a1a2e;
	--text-primary: #eee;
	--accent: #f39c12;
}

body[data-app="naquatic"] {
	--bg-primary: #1a1a1e;
	--text-primary: #ffffff;
	--accent: #94dffc;
	font-family: 'Exo 2', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-app="naquatic"] .app-container {
	/* Background goes on the container, unmasked */
	background-image: url('/assets/images/apps/naquatic-background.jpg');
	background-size: 140% auto;
	background-position: top center;
	background-attachment: scroll;
	background-repeat: no-repeat;
	background-color: #000;
}

body[data-app="naquatic"] .app-content {
	/* Remove background from here, apply mask to content only */
	background: transparent;

	/* FUNCTIONAL TOP OF MASK - This exact configuration works for the mask image:
	   -webkit-mask-image: url('/assets/images/apps/naquatic-background-mask.jpg');
	   mask-image: url('/assets/images/apps/naquatic-background-mask.jpg');
	   -webkit-mask-size: 140% auto;
	   mask-size: 140% auto;
	   -webkit-mask-position: top center;
	   mask-position: top center;
	   -webkit-mask-repeat: no-repeat;
	   mask-repeat: no-repeat;
	   -webkit-mask-mode: luminance;
	   mask-mode: luminance;
	*/

	/* Composite mask: image for top, white gradient for content below */
	/* Mask image is 10% as tall as it is wide, at 140% viewport width = 14vw height */
	-webkit-mask-image:
		url('/assets/images/apps/naquatic-background-mask.jpg'),
		linear-gradient(to bottom, transparent 0, transparent 14vw, white 14vw, white 100%);
	mask-image:
		url('/assets/images/apps/naquatic-background-mask.jpg'),
		linear-gradient(to bottom, transparent 0, transparent 14vw, white 14vw, white 100%);
	/* Size both masks appropriately */
	-webkit-mask-size: 140% auto, 100% 100%;
	mask-size: 140% auto, 100% 100%;
	/* Position them correctly */
	-webkit-mask-position: top center, center;
	mask-position: top center, center;
	/* No repeat */
	-webkit-mask-repeat: no-repeat, no-repeat;
	mask-repeat: no-repeat, no-repeat;
	/* CRITICAL: Luminance mode for the image */
	-webkit-mask-mode: luminance;
	mask-mode: luminance;
	/* Composite with add to combine both masks */
	-webkit-mask-composite: add;
	mask-composite: add;
}

body[data-app="naquatic"] .naquatic-content {
	padding-top: 150px;
	position: relative;
}

body[data-app="naquatic"] #statusBar {
	background: linear-gradient(to bottom, rgba(0, 0, 0, 0.95), rgba(0, 0, 0, 0.6));
}

body[data-app="volunteering"] {
	--bg-primary: #2e7d32;
	--text-primary: #ffffff;
	--accent: #66bb6a;
}

body[data-app="toys"] {
	--bg-primary: #6a1b9a;
	--text-primary: #ffffff;
	--accent: #ba68c8;
}

body[data-app="games"] {
	--bg-primary: #37474f;
	--text-primary: #ffffff;
	--accent: #ff6b6b;
}

body[data-app="message"] {
	--bg-primary: #0277bd;
	--text-primary: #ffffff;
	--accent: #29b6f6;
}

body[data-app="linkedin"] {
	--bg-primary: #0077b5;
	--text-primary: #ffffff;
	--accent: #00a0dc;
}

body[data-app="settings"] {
	--bg-primary: #424242;
	--text-primary: #ffffff;
	--accent: #9e9e9e;
}

* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html, body {
	height: 100%;
	overflow: hidden;
	position: fixed;
	width: 100%;
}

body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	background-color: var(--bg-primary, #000);
	color: var(--text-primary, #fff);
	transition: background-color var(--timing-base) ease;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

#bgCanvas {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	z-index: var(--z-canvas);
	opacity: 1;
	transition: opacity var(--timing-slow) ease;
	pointer-events: none;
}

body:not([data-app="home"]) #bgCanvas {
	opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
	#bgCanvas {
		display: none;
	}
}

body.reduced-motion #bgCanvas {
	display: block;
}

body.reduced-motion .app-container {
	transition: opacity var(--timing-base) ease !important;
}

body.reduced-motion .screen {
	transition: opacity var(--timing-base) ease !important;
	transform: scale(1) !important;
}

body.reduced-motion .app-icon:hover,
body.reduced-motion .app-icon:active {
	transform: none !important;
}

body.reduced-motion .folder-content {
	animation: none !important;
}

body.reduced-motion .folder-backdrop {
	animation: none !important;
}

.folder-overlay.no-animation .folder-content,
.folder-overlay.instant-open .folder-content {
	animation: none !important;
	transform: translate(-50%, -50%) scale(1) !important;
	opacity: 1 !important;
}

.folder-overlay.no-animation .folder-backdrop,
.folder-overlay.instant-open .folder-backdrop {
	animation: none !important;
	opacity: 1 !important;
}

.folder-overlay.instant-open .folder-title {
	animation: none !important;
	opacity: 1 !important;
}

#statusBar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	height: var(--status-height);
	z-index: var(--z-content);
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 var(--spacing-lg);
	background: linear-gradient(to bottom, rgba(0,0,0,0.3), transparent);
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
}

/* Hide status bar on mobile */
@media (max-width: 768px) {
	#statusBar {
		display: none;
	}

	#viewport {
		top: 0;
	}
}

.status-left, .status-right {
	flex: 1;
	display: flex;
	align-items: center;
	font-size: 14px;
	font-weight: 600;
}

.status-left {
	justify-content: flex-start;
}

.status-right {
	justify-content: flex-end;
}

.status-center {
	flex: 2;
	display: flex;
	justify-content: center;
	align-items: center;
}

#clock, #achievement, #statusText {
	position: relative;
	z-index: 2;
	color: var(--text-primary);
	text-shadow: 0 1px 2px rgba(0,0,0,0.5);
	font-size: 14px;
	font-weight: 600;
}

#statusText {
	opacity: 0.9;
}

#viewport {
	position: fixed;
	top: var(--status-height);
	left: 0;
	right: 0;
	bottom: 0;
	overflow: hidden;
	z-index: var(--z-content);
}

.screen {
	position: absolute;
	width: 100%;
	height: 100%;
	opacity: 0;
	transform: scale(0.95);
	transition: opacity var(--timing-base) ease, transform var(--timing-base) ease;
	pointer-events: none;
}

.screen.active {
	opacity: 1;
	transform: scale(1);
	pointer-events: auto;
}

.app-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: var(--app-spacing);
	padding: var(--spacing-xl) var(--spacing-lg);
	max-width: 500px;
	margin: 0 auto;
}

@media (max-width: 400px) {
	.app-grid {
		grid-template-columns: repeat(4, 1fr);
		gap: var(--spacing-md);
		padding: var(--spacing-lg) var(--spacing-md);
	}
}

.app-icon {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: var(--spacing-xs);
	cursor: pointer;
	transition: transform var(--timing-fast) ease;
	-webkit-tap-highlight-color: transparent;
}

.app-icon:hover {
	transform: scale(1.1);
}

.app-icon:active {
	transform: scale(0.95);
}

.icon-image {
	width: var(--app-icon-size);
	height: var(--app-icon-size);
	background: rgba(255,255,255,0.15);
	backdrop-filter: blur(20px);
	-webkit-backdrop-filter: blur(20px);
	border-radius: var(--radius-lg);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 48px;
	box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.3), var(--shadow-md);
	position: relative;
	overflow: hidden;
}

.icon-with-image::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-radius: var(--radius-lg);
	pointer-events: none;
	z-index: 1;
}

/* Firefox-specific fixes for photo icons */
@-moz-document url-prefix() {
	.icon-image.firefox-photo {
		backdrop-filter: none !important;
		-webkit-backdrop-filter: none !important;
		background: white !important;
		filter: none !important;
		box-shadow: none !important;
		border: none !important;
	}

	.icon-image.firefox-photo img {
		opacity: 1 !important;
		filter: none !important;
	}

	/* Hide the border overlay on Firefox */
	.icon-with-image.firefox-photo::after {
		display: none !important;
	}

	/* CRITICAL: Add white background to ALL image containers in Firefox */
	div:has(> img) {
		background: white !important;
	}

	/* Remove ALL filters and effects from images */
	img {
		filter: none !important;
		opacity: 1 !important;
		mix-blend-mode: normal !important;
	}
}

.folder .icon-image {
	box-shadow: var(--shadow-md);
	background: rgba(0,0,0,0.4);
	backdrop-filter: blur(15px);
	-webkit-backdrop-filter: blur(15px);
}

.folder-preview {
	display: grid;
	grid-template-columns: 1fr 1fr;
	grid-template-rows: 1fr 1fr;
	padding: 8px;
	gap: 4px;
}

.folder-icon {
	font-size: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.icon-label {
	font-size: 15px;
	color: var(--text-primary);
	text-align: center;
	text-shadow: 0 1px 2px rgba(0,0,0,0.5);
	max-width: var(--app-icon-size);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.folder-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: var(--z-modal);
	display: none;
}

.folder-overlay.active,
.folder-overlay.closing {
	display: block;
}

.folder-backdrop {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0,0,0,0.7);
	backdrop-filter: blur(20px);
	-webkit-backdrop-filter: blur(20px);
	opacity: 0;
}

.folder-content {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(calc(-50% + var(--icon-offset-x, 0px)), calc(-50% + var(--icon-offset-y, 0px))) scale(0.2);
	width: 90%;
	max-width: 360px;
	max-height: 70%;
	background: rgba(30,30,30,0.95);
	backdrop-filter: blur(30px);
	-webkit-backdrop-filter: blur(30px);
	border-radius: var(--radius-xl);
	padding: var(--spacing-lg);
	box-shadow: var(--shadow-xl);
	opacity: 0;
	overflow: visible;
	display: flex;
	flex-direction: column;
	margin-top: 20px;
}

.folder-overlay.active:not(.closing) .folder-content {
	animation: folderGrowIn 0.35s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.folder-overlay.active:not(.closing) .folder-backdrop {
	animation: folderBackdropIn 0.35s ease forwards;
}

.folder-overlay.active:not(.closing) .folder-title {
	animation: folderTitleIn 0.35s ease forwards;
}

.folder-overlay.closing .folder-content {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
	animation: folderGrowOut 0.35s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.folder-overlay.closing .folder-backdrop {
	opacity: 1;
	animation: folderBackdropOut 0.35s ease forwards;
}

.folder-overlay.closing .folder-title {
	opacity: 1;
	animation: folderTitleOut 0.35s ease forwards;
}

.folder-title {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	top: -45px;
	font-size: 26px;
	font-weight: 600;
	color: #fff;
	z-index: 10;
	text-align: center;
	pointer-events: none;
	white-space: nowrap;
	opacity: 0;
}

.folder-close {
	background: rgba(255,255,255,0.1);
	border: none;
	color: #fff;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	font-size: 20px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background var(--timing-fast) ease;
}

.folder-close:hover {
	background: rgba(255,255,255,0.2);
}

.folder-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: var(--spacing-md);
	overflow-y: auto;
	flex: 1;
	padding: var(--spacing-xs);
}

.folder-grid .app-icon {
	margin: 0;
}

.folder-grid .icon-image {
	width: 50px;
	height: 50px;
	font-size: 24px;
	border-radius: 12px;
}

.folder-grid .icon-label {
	font-size: 11px;
}

.app-container {
	position: fixed;
	top: var(--status-height);
	left: 0;
	right: 0;
	bottom: 0;
	z-index: var(--z-overlay);
	background: var(--bg-primary);
	opacity: 0;
	transform: scale(0.8);
	transform-origin: var(--app-origin-x, 50%) var(--app-origin-y, 50%);
	transition: opacity var(--timing-base) ease, transform var(--timing-base) cubic-bezier(0.25, 0.46, 0.45, 0.94);
	pointer-events: none;
}

.app-container.active {
	opacity: 1;
	transform: scale(1);
	pointer-events: auto;
}

.app-container.animating-in {
	animation: appZoomIn var(--timing-slow) cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.app-container.animating-out {
	animation: appZoomOut var(--timing-base) cubic-bezier(0.55, 0.055, 0.675, 0.19) forwards;
}

@keyframes appZoomIn {
	from {
		opacity: 0;
		transform: scale(0.3);
	}
	to {
		opacity: 1;
		transform: scale(1);
	}
}

@keyframes appZoomOut {
	from {
		opacity: 1;
		transform: scale(1);
	}
	to {
		opacity: 0;
		transform: scale(0.3);
	}
}

.app-content {
	padding: var(--spacing-lg);
	overflow-y: auto;
	height: 100%;
	-webkit-overflow-scrolling: touch;
}


.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
	border: 0;
}

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

@keyframes scaleIn {
	from { transform: translate(-50%, -50%) scale(0.9); opacity: 0; }
	to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes folderGrowIn {
	from { 
		transform: translate(calc(-50% + var(--icon-offset-x, 0px)), calc(-50% + var(--icon-offset-y, 0px))) scale(0.2); 
		opacity: 0; 
	}
	to { 
		transform: translate(-50%, -50%) scale(1); 
		opacity: 1; 
	}
}

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

@keyframes folderTitleIn {
	0% { opacity: 0; }
	50% { opacity: 0; }
	100% { opacity: 1; }
}

@keyframes folderGrowOut {
	from { 
		transform: translate(-50%, -50%) scale(1); 
		opacity: 1; 
	}
	to { 
		transform: translate(calc(-50% + var(--icon-offset-x, 0px)), calc(-50% + var(--icon-offset-y, 0px))) scale(0.2); 
		opacity: 0; 
	}
}

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

@keyframes folderTitleOut {
	0% { opacity: 1; }
	50% { opacity: 0; }
	100% { opacity: 0; }
}